C+ MCSDEMO3
C.
C.  Demo using "regions" table in mpe2014 DB.
C.
C.  Usage: ./mcsdemo3
C.
C-    LN 24/06/2010: v. 0.1c

      PROGRAM MCSDEMO3
      IMPLICIT NONE

      INCLUDE 'mcs_usrlib.inc'
      INTEGER   i, status, dummy, id, LENSTR, DBConnect
      INTEGER*8 vec
      CHARACTER*32 coords
      CHARACTER*16 idname, catname

      DATA c_user /'mpe'/, c_password /'mpe2014pass'/,
     .     c_dbname /'mpe2014'/,
     .     c_query /'SELECT htmID_6,GSChtm FROM regions limit 20'/
C--

c...      null = ifd_null()   ! this is defined in DBConnect

      WRITE(6,'("The query: "/,2X,A)') c_query(1:LENSTR(c_query))

      status = DBConnect('localhost')
      WRITE(6, '(A)') 'Connected'
      IF (status.EQ.0) STOP 'Error in DBConnect.'
      dbq = new_Query( null, dbc, 0 )
      CALL Query_prepare( dbq, c_query )
      CALL Query_execute( dbq, 1 )
      IF (ifd_got_error() .eq. 1) THEN
        WRITE(6,*) ifd_last_error()
        STOP
      END IF

      n_rows = RecordSet_nRows( dbq )
      n_fields = RecordSet_nFields( dbq )
C. or
c      vec = RecordSet_rec( dbq )
c      n_fields = Record_count( vec )

      write(6,'("N_fields=",I6)') n_fields
      write(6,'("N_rows=",I6)') n_rows

      DO 10 i=1,n_rows
        vec = RecordSet_rec(dbq)
        id = Data_ival(Record_field(vec, 0))
        idname = Data_sval(Record_field(vec, 1))
        WRITE(6, '(I10, 2X, A)') id, idname
        dummy = RecordSet_setNext(dbq)
  10  CONTINUE

      CALL DBFree
      END
