ich versuche schon seit gestern mit folgendem Prog die Anzahl der Spalten einer Tabelle zu ermitteln, das will irgendwie nicht gelingen. Wenn jemand von Euch da weiterhelfen könnte, würde ich mich sehr darüber freuen. Das kleine Programmbeisoiel hänge ich mal an.
Code: Alles auswählen
#SQL_CURSOR_STATIC = 3
#SQL_ATTR_CURSOR_TYPE = 6
#SQL_ATTR_CONCURRENCY = 7
#SQL_DBMS_VER = 18
#SQL_DRIVER_NOPROMPT = 0
#SQL_HANDLE_STMT = 3
#sqlNoDataFound = 100
Global hEnv.l, Alloc.l, hDbc.l, hStmt.l,Ret.b,intCols.l
Ergebnis.l = OpenLibrary(0,"ODBC32.dll")
MessageRequester("DLL",Str(Ergebnis))
;' internal use
InitDatabase()
Dim sqlfield$(30) ; storage For fields in tables
If OpenWindow(0, 100, 100, 195, 260, #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget, "PureBasic Window")
cbConnStr=0;
strDataSource.s = "DBQ=c:\Gruppe.mdb;DRIVER={Microsoft Access Driver (*.mdb)}";***********************
retcode= CallFunction(0,"SQLAllocEnv",@hEnv);
retcode=CallFunction(0,"SQLAllocConnect",hEnv,@hDbc);
retcode=CallFunction(0,"SQLSetConnectOption",hDbc,110,#SQL_CURSOR_STATIC)
retcode=CallFunction(0,"SQLDriverConnect",hDbc,#NULL,strDataSource,Len(strDataSource),szConnStr,1024,@cbConnStr,#SQL_DRIVER_NOPROMPT)
retcode=CallFunction(0,"SQLAllocHandle",#SQL_HANDLE_STMT,hDbc,@hStmt)
retcode=CallFunction(0,"SQLSetStmtOptio",hStmt,#SQL_ATTR_CURSOR_TYPE,intResultSetType)
retcode=CallFunction(0,"SQLSetStmtOption",hStmt,#SQL_ATTR_CONCURRENCY,intLockType)
retcode=CallFunction(0,"SQLGetInfo",hDbc,#SQL_DBMS_VER,DriverVersion,slen,@cbInfoValue)
retcode=CallFunction(0,"SQLAllocStmt",hDbc,@hStmt)
retcode=CallFunction(0,"SQLTables",hStmt,0,-3,0,-3,0,-3,"TABLE",Len("TABLE"));
Ret = CallFunction(0,"SQLFetch",hStmt)
While Ret <> #sqlNoDataFound
Owner.s = Space(254)
Name.s = Space(254)
Ret = SQLGetData_(hStmt, 4, 1, Owner, 254, 0)
Ret = SQLGetData_(hStmt, 3, 1, Name, 254, 0)
If Owner = "TABLE"
Liste.s = Liste+Name+";"
EndIf
Ret = CallFunction(0,"SQLFetch",hStmt)
Wend
MessageRequester("Liste",Liste)
SQL.s = "SELECT * FROM TABELLE";*********************************************
retcode= CallFunction(0,"ExecDirect",SQL);
Debug retcode
retcode=CallFunction(0,"SQLNumResultCols",hStmt,@intCols);
FieldCount = intCols
Debug FieldCount
Repeat
EventID.l = WaitWindowEvent()
If EventID = #PB_EventCloseWindow ; If the user has pressed on the close button
Quit = 1
EndIf
Until Quit = 1
EndIf
End
Eckhard!