C+ MCSDEMO1
C.
C.  Demo using INFORMATION_SCHEMA DB.
C.
C.  Usage: ./mcsdemo1
C.         ./mcsdemo1 "your query"
C.
C-    LN 24/06/2010: v. 0.1c

      PROGRAM MCSDEMO1
      IMPLICIT NONE

      INCLUDE 'mcs_usrlib.inc'
      INTEGER status, LENSTR, DBExec_qry
      CHARACTER*200 qry

      DATA c_user /'mpe'/, c_password /'mpe2014pass'/,
     .     c_dbname /'INFORMATION_SCHEMA'/,
     .     c_query /'SELECT * FROM STATISTICS limit 20'/
C--

C- Optional arguments: the query (in "")
      CALL GETARG( 1, qry )
      IF (qry.NE.' ') c_query = qry

      WRITE(6,'("Using DB: ",A)') c_dbname(1:LENSTR(c_dbname))

      WRITE(6,'("The query: "/,2X,A)') c_query(1:LENSTR(c_query))
      status = DBExec_qry('localhost')
      IF (status.EQ.0) STOP 'Error in DB operations.'
      WRITE(6,*) "DB connection is open: ", DBConn_isOpen(dbc)

      CALL FieldInfo(1)

      CALL printTable()

C- 2 more queries, if not given.
      IF (qry.EQ.' ') THEN
        c_query = 'SHOW tables FROM '// c_dbname(1:LENSTR(c_dbname))
        WRITE(6,'("The query: "/,2X,A)') c_query(1:LENSTR(c_query))

        status = DBExec_qry('localhost')
        IF (status.EQ.0) STOP 'Error in DB operations.'

        CALL printTable()

        c_query = "SELECT table_name FROM "//
     .    c_dbname(1:LENSTR(c_dbname)) //".TABLES "//
     .    "where table_schema='test' AND table_type != 'View'";
        WRITE(6,'("The query: "/,2X,A)') c_query(1:LENSTR(c_query))

        status = DBExec_qry('localhost')
        IF (status.EQ.0) STOP 'Error in DB operations.'

        CALL printTable()
      ENDIF

C- Close connection
      CALL DBFree
      END
