Bah.DBODBC : VarChar(1) Weirdness

BlitzMax Forums/Brucey's Modules/Bah.DBODBC : VarChar(1) Weirdness

Kittomer(Posted 2012) [#1]
I am working on a small database tool for work, and I seem to have trouble with the .nextRow() function hanging when any of the columns has a dataformat of "VarChar(1)".

Every other VarChar length works fine, but as soon as I add a column with VarChar(1), the code hangs:


_Q = _DB.executeQuery ("Select AUFTRART,BETRMITTELNR,MERKBRSTL,LINKKEY,ARTIKELBZ1,FERTIGTERM FROM PAKAPO WHERE AUFTRART = 'WZR' or AUFTRART = 'WZW' or AUFTRART = 'WZÄ' or AUFTRART = 'WZB'")
			
If _DB.hasError() ShowError(_DB)
			
While _Q.nextRow()
						
        _R = _Q.rowRecord()

        'Rest of processing code here
		
Wend



MERKBRSTL is a VarChar(1) column. Replacing it with any other non-VarChar(1) column works fine.

Am I crazy? Missing something obvious?


Kittomer(Posted 2012) [#2]
It seems .nextRow() calls getStringData(), which then gets trapped in an infinite (?) loop in it's While loop when trying to read a string of that type.

replacing

"If record.Length <= 0 Then"

with

"If record.Length <= 1 Then"

in getStringData() fixed this and my app works now, but I'm not sure this is a good idea, since I'm not quite sure what the loop does precisely to figure out when to exit properly (Darn pointers).


Henri(Posted 2012) [#3]
Hello Kittomer,
I had the same problem and my solution was kinda similar. I added "If bufferSize = 1 Then bufferSize = 2" clause in getstringdata(). When the field size is 1 and string data is expected somehow the result would not fit in 1 byte hence null was returned and it would go to infine loop. I thought that the string data in database was not UTF8 encoded as function expected and that was the cause of all the trouble. I didn't have the time to verify this.

-Henri


Brucey(Posted 2012) [#4]
The problem was that the buffer needs to be 1 larger the size of the column because the length of the column returned by the driver doesn't include the null terminator character, but the data being retrieved includes it.

So, for a varchar(1), the buffersize needs to be 2, etc…

Fixed in svn.


Dabhand(Posted 2012) [#5]
Brucey... Brucey... Is that... You!!! \o/

Dabz


GaryV(Posted 2012) [#6]
:)