Skip to content

Commit d322258

Browse files
pascalr0410quinnj
authored andcommitted
Fix for Uint8 / Uint16 Unicode string (#220)
* Fix truncated string when underlying database engine do not use Uint8 unicode data format. * Update for full unicode specification. Usage of field size is deleted, only data size remain to determine the length of data we need to read. This fix the bug that cause the driver to truncate string if the above two conditions are verified : - the underlying database engine use Uint16 in place of Uint8 for encoding unicode string. - the readed string size in greater than the half of the field size. Example for Uint16 encoding : - field size 10, string size 4 -> no bug - field size 10, string size 6 -> bug, only the firsts fives characters are returned According to MS Doc The function SQLDescribeCol, return among other things, the size in characters, not byte, of the field. the other ODBC functions used to retrieve data use length indicator in byte. (SQLBindCol, SQLFetchScroll) Another bug may be corrected when using Uint8 and many 3-bytes unicode characters. ! TO BE TESTED ! * Update test case for unicode char * Update for correct offset calculation * Delete test.jl Delete personal test file * add @inbound
1 parent a0cc3e5 commit d322258

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/Query.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,9 @@ function cast!(::Type{Union{String, Missing}}, source, col)
207207
elsize = source.sizes[col] + 1
208208
inds = source.indcols[col]
209209
@inbounds for i in 1:len
210-
ind = min(inds[i]|>Int, elsize|>Int)
210+
ind = inds[i]
211211
length = bytes2codeunits(T, max(ind, 0))
212-
c[i] = ind == API.SQL_NULL_DATA ? missing : (length == 0 ? "" : String(transcode(UInt8, data[cur:(cur + length - 1)])))
212+
c[i] = ind == API.SQL_NULL_DATA ? missing : (length == 0 ? "" : transcode(String, data[cur:(cur + length - 1)]))
213213
cur += elsize
214214
end
215215
return c

0 commit comments

Comments
 (0)