Page 1 of 1

Strange behaviour GetDatabaseString with an ODBC data source

Posted: Thu Jul 11, 2024 1:50 pm
by dige
Tested with PB6.11 x64 Windows

I have a database that I query via ODBC. DatabaseUpdate() and DatabaseQuery() work.

But I just realised that when I query the result of a DatabaseQuery(), for example with GetdatabaseString()
then the content is deleted if I first select a higher column first.

OK: GetdatabaseString( DBID, 0) + ", " + GetdatabaseString( DBID, 1)

Fails: GetdatabaseString( DBID, 1) + ", " + GetdatabaseString( DBID, 0) -> Value for 0 is empty

Can anyone reproduce this or have I already messed something up somewhere else?

Code: Select all

OpenDatabaseRequester(0, #PB_Database_ODBC)
   
;       DatabaseUpdate(0, "INSERT INTO food (name, weight) VALUES ('apple', '10')")
;       DatabaseUpdate(0, "INSERT INTO food (name, weight) VALUES ('pear', '5')")
;       DatabaseUpdate(0, "INSERT INTO food (name, weight) VALUES ('banana', '20')")
      
If DatabaseQuery(0, "SELECT name, weight FROM food WHERE")
   While NextDatabaseRow(0)
      Debug GetDatabaseString(0, 0) + ", " + GetDatabaseString(0, 1)
   Wend
   FinishDatabaseQuery(0)
EndIf

; Result:  
; 
; apple, 10
; paer, 5
; banana, 20

If DatabaseQuery(0, "SELECT name, weight FROM food WHERE")
   While NextDatabaseRow(0)
      Debug GetDatabaseString(0, 1) + ", " + GetDatabaseString(0, 0)
   Wend
   FinishDatabaseQuery(0)
EndIf

; Result:  
; 
; 10,
; 5,
; 20,

Re: Strange behaviour GetDatabaseString with an ODBC data source

Posted: Thu Jul 11, 2024 2:24 pm
by jacdelad
That's always been so. I am querying a MSSQL server via ODBC and stumbled across this long ago. Just get all the results from number 0 to max (store them somewhere if needed). Don't know whether this is dependend from the server or the library.