Strange behaviour GetDatabaseString with an ODBC data source

Just starting out? Need help? Post your questions and find answers here.
dige
Addict
Addict
Posts: 1417
Joined: Wed Apr 30, 2003 8:15 am
Location: Germany
Contact:

Strange behaviour GetDatabaseString with an ODBC data source

Post 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,
"Daddy, I'll run faster, then it is not so far..."
User avatar
jacdelad
Addict
Addict
Posts: 2032
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: Strange behaviour GetDatabaseString with an ODBC data source

Post 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.
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
Post Reply