Skip to content

Commit

Permalink
Added support for non-unicode
Browse files Browse the repository at this point in the history
  • Loading branch information
naqvis committed Jul 22, 2020
1 parent 7e15c21 commit 74442b8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion shard.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: odbc
version: 0.1.2
version: 0.1.3
description: |
ODBC connector for Crystal
Expand Down
2 changes: 1 addition & 1 deletion src/odbc.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ require "db"
require "./odbc/**"

module ODBC
VERSION = "0.1.2"
VERSION = "0.1.3"
end
11 changes: 9 additions & 2 deletions src/odbc/result_set.cr
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,18 @@ class ODBC::ResultSet < DB::ResultSet
fval = uninitialized Float64
check LibODBC.sql_get_data(@stmt_handle, col, LibODBC::SQL_C_DOUBLE, pointerof(fval), 0, pointerof(ind_ptr))
ind_ptr == LibODBC::SQL_NULL_DATA ? nil : fval
when LibODBC::SQL_CHAR, LibODBC::SQL_VARCHAR, LibODBC::SQL_LONGVARCHAR, LibODBC::SQL_WCHAR, LibODBC::SQL_WVARCHAR, LibODBC::SQL_WLONGVARCHAR
when LibODBC::SQL_CHAR, LibODBC::SQL_VARCHAR, LibODBC::SQL_LONGVARCHAR
dummy = Bytes.new(1)
check LibODBC.sql_get_data(@stmt_handle, col, LibODBC::SQL_C_CHAR, dummy.to_unsafe, 0, pointerof(ind_ptr))
return nil if ind_ptr == LibODBC::SQL_NULL_DATA
slen = ind_ptr
sbuf = Bytes.new(slen + 1)
check LibODBC.sql_get_data(@stmt_handle, col, LibODBC::SQL_C_CHAR, sbuf.to_unsafe, sbuf.size, pointerof(ind_ptr))
String.new(sbuf[...slen])
when LibODBC::SQL_WCHAR, LibODBC::SQL_WVARCHAR, LibODBC::SQL_WLONGVARCHAR
dummy = Bytes.new(1)
check LibODBC.sql_get_data(@stmt_handle, col, LibODBC::SQL_C_WCHAR, dummy.to_unsafe, 0, pointerof(ind_ptr))
return nil if ind_ptr == LibODBC::SQL_NULL_DATA

slen = (ind_ptr / 2).to_i
sbuf = Slice(UInt16).new(slen + 1)
check LibODBC.sql_get_data(@stmt_handle, col, LibODBC::SQL_C_WCHAR, sbuf.to_unsafe, (slen + 1)*2, pointerof(ind_ptr))
Expand Down

0 comments on commit 74442b8

Please sign in to comment.