home *** CD-ROM | disk | FTP | other *** search
- /*
- msql.library ARexx support example
-
- Dump first 5 fields of each tables of each db
-
- By Jürgen Schober
-
- Some little changes by Christophe Sollet
- */
-
- /*options failat 15 */
- options results
-
- if ~show('L',"msql.library") then do
- if addlib('msql.library', 0,-30, 5) then do
- say 'Added msql.library'
- end
- else do
- say 'Support library (LIBS:msql.library) not available.'
- say 'Aborting...'
- exit(30)
- end
- end
-
- signal on BREAK_C
- signal on HALT
- signal on ERROR
-
- connection = MsqlAllocConnection()
-
- call MsqlConnect(connection) /* faster than MsqlConnect(connection, 'localhost') */
-
- mre = MsqlListDBs(connection)
- i=0
- ndb = MsqlNumRows(mre)
- say 'DB(s):'
- do while i < ndb
- say i + 1
- i = i + 1
- mro = MsqlFetchRow(mre)
- dbname = MsqlGetField(mro, 0)
- say dbname
- if MsqlSelectDB(connection, dbname) then do
- mre2 = MsqlListTables(connection)
- j = 0
- say ' Table(s):'
- do while j < MsqlNumRows(mre2)
- j = j + 1
- mro2 = MsqlFetchRow(mre2)
- table = MsqlGetField(mro2, 0)
- say ' ' table
-
- /*
- Dump first 5 fields (max) of the table
- */
-
- query = 'SELECT * FROM ' table
- say ' Executing: ' query
- if ~MsqlQuery(connection,query) then do
- say 'Query Error:' MsqlGetErrMsg(connection)
- end
- else do
- mre3 = MsqlStoreResult(connection)
-
- /* dump field names */
-
- call MsqlFieldSeek(mre3,0) /* just to make sure we start at 0 */
- r = MsqlFetchField(mre3)
- m = 0
- line = ''
- do while ((m < MsqlNumFields(mre3)) & (m < 5))
- field = MsqlGetFieldInfo(r,"name")
- line = line "" field ' '
- r = MsqlFetchField(mre3)
- m = m + 1
- end
- say " " line
- say " ------------------------------------------------------------------"
-
- /* dump field values */
-
- n = 0
- do while n < MsqlNumRows(mre3)
- n = n + 1
- mro3 = MsqlFetchRow(mre3)
-
- m = 0
- call MsqlFieldSeek(mre3,0)
- r = MsqlFetchField(mre3)
- line = ''
- call MsqlFieldSeek(mre3,0)
- do while ((m < MsqlNumFields(mre3)) & (m < 5))
- field = MsqlGetField(mro3,m)
- line = line "" field ' '
- r = MsqlFetchField(mre3)
- m = m + 1
- end
- say " " line
- end
- call MsqlFreeResult(mre3)
- end
- say " ------------------------------------------------------------------"
- end
- call MsqlFreeResult(mre2)
- say '--------------------'
- end
- end
- call MsqlFreeResult(mre)
- call MsqlFreeConnection(connection)
-
- call MsqlCleanup() /* Not really usefull here */
- exit
-
- BREAK_C:
- HALT:
- ERROR:
-
- /* Free All mSQL ressource before exit */
- say '***Break or Error on line' sigl
- call MsqlCleanup()
- exit
-