[freetds] A problem with MSSQL type uniqueidentifier
Alexander Larkin
sasha at chuhloma.ru
Wed Jul 1 07:01:28 EDT 2009
Hi,
Does freetds support uniqueidentifier field?
This is MSSQL specific type for GUID storage.
I get this (assert) error when I'm trying writing to this field (program
source test_uniqueidentifier.c attached):
gcc test_uniqueidentifier.c -lsybdb
sasha at lt:~/$ ./a.out
a.out: bcp.c:2474: _bcp_get_col_data: Assertion `converted_data_size >
0' failed.
err_handler: Msg 20050, Level 4err_handler: Attempt to convert data
stopped by syntax error in source field
I thougth that conversion from SYBVARCHAR to uniqueidentifier doesn't
work, so I should use uniqueidentifier, but there is no such a type in
standard FreeTDS header files. Anyway, I found "SYBUNIQUE = 36" in
header file ...FreeTDS/freetds-0.83.dev.20090626/include/tds.h (but
there is no SYBUNIQUE in sybdb.h or sqldb.h ).
If I use SYBUNIQUE = 36 /* 0x24 */ (defined in tds.h ) and fixed
len==16, then this error happens (see test_uniqueidentifier_b.c attached):
gcc test_uniqueidentifier_b.c -lsybdb
sasha at lt:~/$ ./a.out
a.out: test_uniqueidentifier_b.c:54: main: Assertion `fOK == 1' failed.
err_handler: Msg 20107, Level 7err_handler: It is illegal to use BCP
terminators with program variables other than SYBCHAR, SYBBINARY,
SYBTEXT, or SYBIMAGEАварийный останов
And only if I use length -1 (saying "this is fixed length field like INT
is") and type 36, then everything works exelent (see
test_uniqueidentifier_2.c attached):
gcc test_uniqueidentifier_2.c -lsybdb
sasha at lt:~/$ ./a.out
Sent rows 1
Also note that prefix/terminator is being ignored for varlen==-1
bcp_bind fields, but it is not clean from documentation (
http://www.freetds.org/reference/a00277.html#ga16 ) when you are reading
bcp_bind description.
The testing table I used for uniqueidentifier:
USE [DownloadNotifiesTest]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[TestUniqueidentifier](
[testfield] [uniqueidentifier] NULL
) ON [PRIMARY]
GO
Regards,
Sasha.
sasha at chuhloma.ru
avlarkin at iname.ru
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_uniqueidentifier.c
Type: text/x-csrc
Size: 2748 bytes
Desc: not available
Url : http://lists.ibiblio.org/pipermail/freetds/attachments/20090701/c9768ef4/attachment.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_uniqueidentifier_2.c
Type: text/x-csrc
Size: 2724 bytes
Desc: not available
Url : http://lists.ibiblio.org/pipermail/freetds/attachments/20090701/c9768ef4/attachment-0001.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_uniqueidentifier_b.c
Type: text/x-csrc
Size: 2748 bytes
Desc: not available
Url : http://lists.ibiblio.org/pipermail/freetds/attachments/20090701/c9768ef4/attachment-0002.bin
More information about the FreeTDS
mailing list