home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Amiga 12 / MA_Cover_12.iso / libs / msqllib / example / arexx / dump.rexx
Encoding:
OS/2 REXX Batch file  |  1998-11-16  |  2.9 KB  |  122 lines

  1. /*
  2.     msql.library ARexx support example
  3.  
  4.     Dump first 5 fields of each tables of each db
  5.  
  6.     By Jürgen Schober
  7.  
  8.     Some little changes by Christophe Sollet
  9. */
  10.  
  11. /*options failat 15 */
  12. options results
  13.  
  14. if ~show('L',"msql.library") then do
  15.    if addlib('msql.library', 0,-30, 5) then do
  16.       say 'Added msql.library'
  17.    end
  18.    else do
  19.       say 'Support library (LIBS:msql.library) not available.'
  20.       say 'Aborting...'
  21.       exit(30)
  22.    end
  23. end
  24.  
  25. signal on BREAK_C
  26. signal on HALT
  27. signal on ERROR
  28.  
  29. connection = MsqlAllocConnection()
  30.  
  31. call MsqlConnect(connection) /* faster than MsqlConnect(connection, 'localhost') */
  32.  
  33. mre = MsqlListDBs(connection)
  34. i=0
  35. ndb = MsqlNumRows(mre)
  36. say 'DB(s):'
  37. do while i < ndb
  38.     say i + 1
  39.     i = i + 1
  40.     mro = MsqlFetchRow(mre)
  41.     dbname = MsqlGetField(mro, 0)
  42.     say dbname
  43.     if     MsqlSelectDB(connection, dbname) then do
  44.         mre2 = MsqlListTables(connection)
  45.         j = 0
  46.         say '     Table(s):'
  47.         do while j < MsqlNumRows(mre2)
  48.             j = j + 1
  49.             mro2 = MsqlFetchRow(mre2)
  50.             table = MsqlGetField(mro2, 0) 
  51.             say '    ' table
  52.     
  53.             /* 
  54.                 Dump first 5 fields (max) of the table 
  55.             */
  56.     
  57.             query = 'SELECT * FROM ' table
  58.                say '          Executing: ' query
  59.                 if ~MsqlQuery(connection,query) then do
  60.                 say 'Query Error:' MsqlGetErrMsg(connection)
  61.             end
  62.             else do
  63.                 mre3 = MsqlStoreResult(connection)
  64.  
  65.                 /* dump field names */
  66.  
  67.                 call MsqlFieldSeek(mre3,0)   /* just to make sure we start at 0 */
  68.                 r = MsqlFetchField(mre3)
  69.                 m = 0
  70.                 line = ''
  71.                 do while ((m < MsqlNumFields(mre3)) & (m < 5))
  72.                     field = MsqlGetFieldInfo(r,"name") 
  73.                     line = line "" field ' '
  74.                     r = MsqlFetchField(mre3)
  75.                     m = m + 1
  76.                 end
  77.                 say "             " line
  78.                 say "              ------------------------------------------------------------------"
  79.     
  80.                 /* dump field values */
  81.  
  82.                 n = 0
  83.                 do while n < MsqlNumRows(mre3)
  84.                     n = n + 1
  85.                     mro3 = MsqlFetchRow(mre3)
  86.  
  87.                     m = 0
  88.                     call MsqlFieldSeek(mre3,0)     
  89.                     r = MsqlFetchField(mre3)
  90.                     line = ''
  91.                     call MsqlFieldSeek(mre3,0)     
  92.                     do while ((m < MsqlNumFields(mre3)) & (m < 5))
  93.                         field = MsqlGetField(mro3,m) 
  94.                         line = line "" field ' '
  95.                         r = MsqlFetchField(mre3)
  96.                         m = m + 1
  97.                     end
  98.                     say "             " line
  99.                 end
  100.                 call MsqlFreeResult(mre3)
  101.             end
  102.             say "              ------------------------------------------------------------------"
  103.         end
  104.         call MsqlFreeResult(mre2)
  105.         say '--------------------'
  106.     end
  107. end
  108. call MsqlFreeResult(mre)
  109. call MsqlFreeConnection(connection)
  110.  
  111. call MsqlCleanup() /* Not really usefull here */
  112. exit
  113.  
  114. BREAK_C:
  115. HALT:
  116. ERROR:
  117.  
  118. /* Free All mSQL ressource before exit */
  119. say '***Break or Error on line' sigl
  120. call MsqlCleanup()
  121. exit
  122.