Skip to content

Commit 13254b6

Browse files
authored
nanodbc: handle db2 xml data (#917)
* nanodbc: handle db2 xml data See upstream: nanodbc/nanodbc#430 * Fix merge derp * Update NEWS * tests: update _snaps/utils * tests: fixup datetimeoffset/pro driver failure * tests: update _snaps/utils again
1 parent 4ebef72 commit 13254b6

File tree

5 files changed

+15
-5
lines changed

5 files changed

+15
-5
lines changed

NEWS.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
# odbc (development version)
22

3-
* SQL Server: Support for `DATETIMEOFFSET` data type (#918).
4-
53
* Fix hang when parsing exceptionally long database errors (#916).
64

75
* DB2: Fix error when writing to temp tables (#910).
86

7+
* DB2: Add support for `DB2_XML` (#913).
8+
9+
* SQL Server: Support for `DATETIMEOFFSET` data type (#918).
10+
911
* SQL Server: Fix issues with argument propagation in bespoke
1012
S4 methods (#906).
1113

src/nanodbc/nanodbc.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@
6565
#include <sqlext.h>
6666

6767
// Driver specific SQL data type defines.
68+
#ifndef SQL_DB2_XML
69+
#define SQL_DB2_XML (-370)
70+
#endif
6871
// Microsoft has -150 thru -199 reserved for Microsoft SQL Server Native Client driver usage.
6972
// Originally, defined in sqlncli.h (old SQL Server Native Client driver)
7073
// and msodbcsql.h (new Microsoft ODBC Driver for SQL Server)
@@ -2986,6 +2989,7 @@ class result::result_impl
29862989
case SQL_VARBINARY:
29872990
case SQL_LONGVARBINARY:
29882991
case SQL_SS_UDT: // MSDN: Essentially, UDT is a varbinary type with additional metadata.
2992+
case SQL_DB2_XML:
29892993
col.ctype_ = SQL_C_BINARY;
29902994
col.blob_ = true;
29912995
col.clen_ = 0;

src/odbc_result.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
#ifndef SQL_SS_TIME2
99
#define SQL_SS_TIME2 (-154)
1010
#endif
11+
#ifndef SQL_DB2_XML
12+
#define SQL_DB2_XML (-370)
13+
#endif
1114
#ifndef SQL_SS_TIMESTAMPOFFSET
1215
#define SQL_SS_TIMESTAMPOFFSET (-155)
1316
#endif
@@ -755,6 +758,7 @@ std::vector<r_type> odbc_result::column_types(nanodbc::result const& r) {
755758
case SQL_BINARY:
756759
case SQL_VARBINARY:
757760
case SQL_LONGVARBINARY:
761+
case SQL_DB2_XML:
758762
types.push_back(raw_t);
759763
break;
760764
default:

tests/testthat/_snaps/utils.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
! ODBC failed with error 00000 from [unixODBC][Driver Manager].
2929
x Data source name not found and no default driver specified
3030
i See `?odbc::odbcListDataSources()` to learn more.
31-
i From 'nanodbc/nanodbc.cpp:1156'.
31+
i From 'nanodbc/nanodbc.cpp:1159'.
3232

3333
---
3434

@@ -39,7 +39,7 @@
3939
! ODBC failed with error 00000 from [SQLite].
4040
x no such table: boopbopbopbeep (1)
4141
* <SQL> 'SELECT * FROM boopbopbopbeep'
42-
i From 'nanodbc/nanodbc.cpp:1732'.
42+
i From 'nanodbc/nanodbc.cpp:1735'.
4343

4444
# rethrow_database_error() errors well when parse_database_error() fails
4545

tests/testthat/test-driver-sql-server.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ test_that("DATETIMEOFFSET", {
385385
field.types = list("tz_char" = "VARCHAR(50)", "tz" = "DATETIMEOFFSET"), overwrite = TRUE)
386386
res <- DBI::dbReadTable(con, tbl)
387387
expect_s3_class(res[[2]], "POSIXct")
388-
expect_equal(as.double(res[[2]][1] - as.POSIXct(res[[1]][1]), units = "hours"), 2)
388+
expect_equal(as.double(res[[2]][1] - as.POSIXct(res[[1]][1]), units = "hours"), 2, tolerance = 1E-4)
389389
})
390390

391391
test_that("package:odbc roundtrip test", {

0 commit comments

Comments
 (0)