using Tcl with tdbc over MS SQL on Win x64

Viewed 390

We've been using tclodbc package for running queries against MS SQL Server for a few years. Now we have to switch to x64 process and tclodbc doesn't load because there is no x64 version.

We started looking at alternatives and tried tdbc but we are having problems with character fields passed as parameters. I created a test table with 2 integer columns and 2 varchar columns (50 and 100 long).

I am trying to insert records and the following happens: 1. If I insert records providing only 2 integer parameters everything works fine - 5 records get inserted (see code below). 2. If I insert records providing only 1 character parameter 1 record gets inserted and then the script fails with the following error: "[Microsoft][ODBC Driver 11 for SQL Server]String data, right truncation" 3. If I pass two character parameters or an integer parameter and a character parameter then nothing gets inserted - I get the same error as above.

I didn't test any other data types but it looks like something is wrong with character parameters (I also tried nvarchar and char type columns).

Here is my code:

package require tdbc::odbc
set con "Driver=\{ODBC Driver 11 for SQL Server\};server=server;database=database;Intergrated Security=True;Trusted_Connection=Yes"
tdbc::odbc::connection create db $con

set insert_cmd [db prepare {INSERT INTO dbo.testing_tdbc (f50,f100) VALUES(:f50,:f100) } ]
$insert_cmd paramtype f50 char 50
$insert_cmd paramtype f100 char 100

foreach fint [list 1 2 3 4 5] {
    set fi1 $fint
    set fi2 [expr {$fi1*2}]
    set f50 "${fi2}_${fi1}"
    set f100 $f50

    $insert_cmd execute
}

$insert_cmd close
db close

I tried the same with ODBC Driver 13 for SQL Server - all with the same result.

1 Answers
Related