; MDBDUMP
;
; Program for Proteus
;
; (C) 2003-2004 Simone Zanella Productions
;
; This program displays the contents of all the tables included in the database
; specified as the first parameter.
#!proteus -z -j
!include "daodefs.prt"
IF LT(ARGC, 5)
CONSOLELN "Syntax: " ARGV(1) " " ARGV(2) \
" filename.mdb"
CONSOLELN "Write the contents of the tables inside filename.mdb"
ABORT 0
FI
; Open database
DBHandle = 0
OpenDB(@DBHandle, ARGV(5))
; Browse all tables
NumTab = DAODBGETTABCOUNT(DBHandle)
FOR X = 1 TO NumTab
V = DAODBGETTABINFO(DBHandle, X)
TabName = VECGET(V, 1)
VECFREE(V)
IF STRNEQ(LEFT(TabName, 4), "MSys")
CONSOLELN "Table: " TabName
CONSOLELN ""
rshandle = 0
; Print the contents of the table
IF OpenTable(DBHandle, @rshandle, TabName)
PrintRecord(rshandle)
DAORSCLOSE(rshandle)
DAORSFREE(rshandle)
FI
FI
NEXT
DAODBCLOSE(DBHandle)
DAODBFREE(DBHandle)
ABORT 0
FUNCTION OpenDB(dbhandle, s)
; Allocate database and try to open it; store into dbhandle its handle
dbhandle = DAODBNEW()
res = DAODBOPEN(dbhandle, s, 0, 0, "")
IF EQ(res, -1)
; Error
PrintErrors(dbhandle)
ABORT 1
FI
RETURN
FUNCTION OpenTable(dbhandle, rshandle, t)
; Open table t in database; store into rshandle its handle
rshandle = DAORSNEW(dbhandle)
res = DAORSOPEN(rshandle, _DAOCOpenTable, t, 0)
IF EQ(res, -1)
; Error
PrintErrors(dbhandle)
RETURN 0
FI
RETURN 1
FUNCTION PrintRecord(rshandle)
; Load field names into an array
nfield = DAORSGETFIELDCOUNT(rshandle)
fieldnames = VECNEW(nfield)
FOR x = 1 TO nfield
v = DAORSGETFIELDINFO(rshandle, x)
VECSET(fieldnames, x, VECGET(v, 1))
VECFREE(v)
NEXT
; If there are records...
IF NOT(AND(DAORSATTRIB(rshandle, _DAORSATTISBOF), DAORSATTRIB(rshandle, _DAORSATTISEOF)))
; ...for each record print the contents of all the fields
DAORSMOVEFIRST(rshandle)
WHILE NOT(DAORSATTRIB(rshandle, _DAORSATTISEOF))
FOR x = 1 TO nfield
CONSOLELN " Field: " PADR(VECGET(fieldnames, x), 20, " ") " Value: " DAORSGETFIELDVAL(rshandle, x)
NEXT
CONSOLELN ""
DAORSMOVENEXT(rshandle)
LOOP
FI
VECFREE(fieldnames)
RETURN
FUNCTION PrintErrors(dbhandle)
; Print all DAO errors resulting from last operation
numerr = DAOERRCOUNT(dbhandle)
FOR x = 1 TO numerr
CONSOLELN "Error " x ":"
CONSOLELN " Code : " DAOGETERRORNUM(dbhandle, x)
CONSOLELN " Description: " DAOGETERRORDESC(dbhandle, x)
CONSOLELN " Source : " DAOGETERRORSRC(dbhandle, x)
CONSOLELN ""
NEXT
RETURN