nakagami / firebirdsql

Firebird RDBMS sql driver for Go (golang)
MIT License
224 stars 60 forks source link

Correct size of column returned by buffer #118

Closed xhit closed 3 years ago

xhit commented 3 years ago

Fix #117

nakagami commented 3 years ago

One character is 4 bytes in utf-8, but not in other character encodings. we have to change the divide value depending on the character encoding, but I wonder if I can simply divide by 4?

Isn't it better to return the number of bytes instead of the number of characters, as it is now?

xhit commented 3 years ago

xSQLVAR.sqllen is only used for VARCHAR (SQL_TYPE_VARYING) and CHAR (SQL_TYPE_TEXT) but the first is ok because the returned value length is variable.

For CHAR is fixed, but FirebirdSQL maybe returns the *size of column max len used by charset by character** (in this case, 4 bytes for UTF-8).

So, we need test the size returned in buffer for databases and connection set in another encoding charset, because if logic above is true, the solution only apply to UTF-8.

xhit commented 3 years ago

For CHAR is fixed, but FirebirdSQL maybe returns the *size of column max len used by charset by character** (in this case, 4 bytes for UTF-8).

Tested. The sentence is true.

The length returned in buffer depends on charset set in connection string with charset param.

For example, with code in #117 and setting charLen := 5:

So, this driver should handle encoding to get the correct length.

xhit commented 3 years ago

@nakagami done. PTAL.

nakagami commented 3 years ago

Thanks, It seems good