home *** CD-ROM | disk | FTP | other *** search
- OPT OSVERSION=37
- OPT PREPROCESS,REG=5
-
- /*
- msql.library simple example
- ©1998 Christophe Sollet (cfc@iname.com)
- AmigaE version by Piotr Gapinski (narg@polbox.com)
-
- This simple example list existing database and tables on
- a mSQL database engine running on the local host.
- */
-
-
- MODULE 'msql','libraries/msql'
-
- PROC main() HANDLE
- DEF co=NIL:PTR TO msqlConnection,
- mre:PTR TO m_result,mre2:PTR TO m_result,
- mro:PTR TO m_row,mro2:PTR TO m_row
- DEF a
-
- a:=msqlTypeNames(1)
- WriteF('\s\n',a)
- ->- open the library
- ->-
- IF (msqlbase:=OpenLibrary('msql.library',4))=NIL THEN Raise('OpenLibrary failed')
-
- ->- before doing any msql operation,
- ->- we need a valid MsqlConnection structure
- ->-
- IF (co:=MsqlAllocConnection())=NIL THEN Raise('MsqlAllocConnection failed')
-
- ->- now we'll attempt a connection
- ->- on a local mSQL database engine
- ->-
- IF (MsqlConnect(co,'localhost'))=NIL THEN Raise('MsqlConnect failed')
-
- ->- gets current DB list
- ->-
- IF (mre:=MsqlListDBs(co))=NIL THEN Raise('MsqlListDBs failed')
- WriteF('DB(s):\n')
-
- ->- now display DB list
- ->-
- WHILE (mro:=MsqlFetchRow(mre))
- WriteF('\s\n',mro.m_row)
-
- ->- for each DB, list tables
- ->-
- IF (MsqlSelectDB(co,mro.m_row))<>(-1)
- IF (mre2:=MsqlListTables(co))
- WriteF('\tTable(s):\n')
-
- ->- now display table list
- ->-
- WHILE mro2:=MsqlFetchRow(mre2) DO WriteF('\t\s\n',mro2.m_row)
- MsqlFreeResult(mre2)
- ENDIF
- ELSE
- MsqlFreeResult(mre)
- Raise('SelectDB failed')
- ENDIF
- ENDWHILE
- MsqlFreeResult(mre)
-
- EXCEPT DO
- IF (exception)
- WriteF('\s\n',exception)
- IF (co) THEN WriteF('\s\n',MsqlGetErrMsg(co))
- ENDIF
- IF (co)
- MsqlClose(co)
- MsqlFreeConnection(co)
- ENDIF
- IF (msqlbase) THEN CloseLibrary(msqlbase)
- ENDPROC
-