Skip to content
Ryan Culpepper edited this page Mar 20, 2018 · 11 revisions

ODBC DB2 Notes

Setup

The following links were useful in setting up a DB2 instance for testing:

ODBC Configuration

Always need to run . /home/db2inst1/sqllib/db2profile before doing anything.

Issue: decimal/numeric results don't work

This page suggests that DB2 does not support SQLSetDescField, which means that the set-numeric-descriptors method (which sets the precision, etc) won't work.

In fact, when I check the result of (SQLSetDescField/Int hdesc i SQL_DESC_TYPE SQL_C_NUMERIC), I get -1 (SQL_ERROR), but no diagnostic.

These docs indicate that the current code is using the wrong convention for calling SQLSetDescField with an integer value, but after fixing that issue the function still returned -1 without diagnostic.

But then these docs seem to contradict that theory.

I also tried changing the numeric/decimal case to use SQL_C_NUMERIC directly rather than SQL_ARD_TYPE, but it still failed (but with a different message).

Other references:

Decimals

Decimals

(query-list c "select cast(d as varchar(20)) from foon") '("1.23456" "100.00000")

When retrieved as SQL_C_BINARY, decimals are translated to scaled integers like this:

  1.23456    #x 00 00 01 23 45 6c    -- ie, one digit per nibble
100.00000    #x 00 01 00 00 00 0c    --     final sign nibble: c positive, d negative

Or could just use SQL_C_CHAR, but does it depend on locale? (Doesn't in my tests...)

Notes

No parameter types (unknown)

Use #:quirks (no-c-numeric)

Clone this wiki locally