May 24, 2022, 02:02:57 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Plus 255 characters SQL error

Started by Andy, December 09, 2018, 04:19:59 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

fasecero

Thank you very much, Andy. Don't worry, when I joined the forum there were people who helped me a LOT. Oh one thing, the math you did to get those 126 characters were the key to solve the unicode limit. You can notice it in the new hex string size [4 * MAX_UNICHARS + 6] your math put me on the right track.

One curious thing is how flexible VARBINARY is, it allow to overcome the limit we are imposing with VARBINARY(510). If I put there a value greater than 510, it gives an error. But with 510 works ok even if we exceed that size.

And for the first time I get what hex strings are capable of. They can hold unicode data inside non unicode strings. How cool is that? Similar to your own format: 200,3,187,3,187,3,187,3,187,3,187,3,187,3,0,0

----

On a final note to anyone using this, just be cautious with the buffer size on each place. They must match exactly to avoid any data overflow. The most simple thing to do is to define a constant at the beginning of the source with the desired size.

    $DEFINE MAX_UNICHARS 1000  ' MAXIMUN NUMBER OF UNICODE CHARACTER ALLOWED/WANTED
    IWSTRING buffer[MAX_UNICHARS]

Later on you can setup the remaining arrays sizes more easily

    UnicodeEditGetText(w1, EDIT_9, buffer, MAX_UNICHARS) ' getting unicode edit text

    istring unicodeHEX[4 * MAX_UNICHARS + 6] = WstringToHexString(unicodeData) ' creating the hex string

    istring unicodeHEX[4 * MAX_UNICHARS + 6] = "0x"  ' buffer size inside WstringToHexString

    dbBindVariable(hstmt, 3, buffer, branch_null, 2* MAX_UNICHARS) ' loading the unicode from the database

Andy

December 15, 2018, 06:15:44 AM #26 Last Edit: December 15, 2018, 06:17:15 AM by Andy
Fasecero,

Some great golden rules there - nicely put.

You will also have to use

dbGetData(hStmt,17,buffer,2* MAX_UNICHARS)  '<---- with a size (2* MAX_UNICHARS)

If you are using the dbGetData command.

Andy.
:)
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.