Cannot send UTF-8 chars to MSSQL 2008

Niklas Lampén <[email protected]>
Newsgroups gmane.comp.db.tds.freetds
Message-ID <[email protected]>
Hi,

I'm trying to send a string "Найти" (which is Russian, I don't know what it means) from PHP to MSSQL server using FreeTDS, but I end up with empty column in MSSQL. Iäm using a stored procedure called Mod_Text_Put_Content with three parameters @Content (containing the string), @ContentId and @SiteId.

The string is originally in UTF-8. ISO-8859-1 compatible strings like "abc" are stored to database as expected.

I'm trying this with freetds-0.83.dev.20100522. Freetds-0.82 gives an error and does not send empty string to database.

I tested that my iconv works as expected by creating a file with string "Найти" in it and did:

# iconv -futf-8 -tucs2 --verbose -oucs2.txt utf8.txt
# iconv -fucs2 -tutf8 --verbose -outf8.txt_2 ucs2.txt
# hexdump utf8.txt
0000000 9dd0 b0d0 b9d0 82d1 b8d0 000a
000000b
# hexdump utf8.txt_2
0000000 9dd0 b0d0 b9d0 82d1 b8d0 000a
000000b
# hexdump ucs2.txt
0000000 041d 0430 0439 0442 0438 000a
000000c

My freetds.conf looks like this:
---
[global]
        text size = 64512
        port = 1433
        tds version = 8.0
[AavaDb2]
        host = *****
        client charset = UCS2
        dump file = /var/log/freetds/freetds.log
        dump file append = yes
---


Here's a dump from freetds:

rpc.c:84:dbrpcinit(0x8626028, Mod_Text_Put_Content, 0)
rpc.c:136:dbrpcinit() added rpcname "Mod_Text_Put_Content"
rpc.c:171:dbrpcparam(0x8626028, @Content, 0x0, 35, -1, 11, 0x8b45790)
rpc.c:263:dbrpcparam() added parameter "@Content"
rpc.c:171:dbrpcparam(0x8626028, @ContentId, 0x0, 39, -1, 4, 0x84938a0)
rpc.c:263:dbrpcparam() added parameter "@ContentId"
rpc.c:171:dbrpcparam(0x8626028, @SiteId, 0x0, 39, -1, 6, 0x8308f80)
rpc.c:263:dbrpcparam() added parameter "@SiteId"
rpc.c:282:dbrpcsend(0x8626028)
rpc.c:401:parm_info_alloc(): parameter null-ness = 0
rpc.c:331:parameter size = 11, data = 0x86b81a0, row_size = 0
rpc.c:336:copying 11 bytes of data to parameter #0
rpc.c:344:blob parameter supported, size 11 textvalue pointer is 0x86b9068
rpc.c:401:parm_info_alloc(): parameter null-ness = 0
rpc.c:331:parameter size = 4, data = 0x87cfe60, row_size = 0
rpc.c:336:copying 4 bytes of data to parameter #1
rpc.c:401:parm_info_alloc(): parameter null-ness = 0
rpc.c:331:parameter size = 6, data = 0x87cfe70, row_size = 0
rpc.c:336:copying 6 bytes of data to parameter #2
mem.c:615:tds_free_all_results()
util.c:162:Changed query state from IDLE to QUERYING
query.c:1330:tds_put_data_info putting param_name
query.c:1364:tds_put_data_info putting status
query.c:1465:tds_put_data: colsize = 11
util.c:337:tdserror(0x82a3bb8, 0x83400f0, 2402, 0)
dblib.c:7861:dbperror(0x8626028, 2402, 0)
dblib.c:7913:2402: "Error converting characters into server's character set. Some character(s) could not be converted"
dblib.c:7934:"Error converting characters into server's character set. Some character(s) could not be converted", client returns 2 (INT_CANCEL)
util.c:367:tdserror: client library returned TDS_INT_CANCEL(2)
util.c:390:tdserror: returning TDS_INT_CANCEL(2)
query.c:1533:tds_put_data: not null param varint_size = 4
query.c:1330:tds_put_data_info putting param_name
query.c:1364:tds_put_data_info putting status
query.c:1465:tds_put_data: colsize = 4
query.c:1533:tds_put_data: not null param varint_size = 2
query.c:1330:tds_put_data_info putting param_name
query.c:1364:tds_put_data_info putting status
query.c:1465:tds_put_data: colsize = 6
query.c:1533:tds_put_data: not null param varint_size = 2
util.c:162:Changed query state from QUERYING to PENDING
net.c:792:Sending packet
0000 03 01 00 98 00 00 01 00-14 00 4d 00 6f 00 64 00 |........ ..M.o.d.|
0010 5f 00 54 00 65 00 78 00-74 00 5f 00 50 00 75 00 |_.T.e.x. t._.P.u.|
0020 74 00 5f 00 43 00 6f 00-6e 00 74 00 65 00 6e 00 |t._.C.o. n.t.e.n.|
0030 74 00 00 00 08 40 00 43-00 6f 00 6e 00 74 00 65 |[email protected] .o.n.t.e|
0040 00 6e 00 74 00 00 23 0b-00 00 00 0b 04 00 22 00 |.n.t..#. ......".|
0050 00 00 00 00 0a 40 00 43-00 6f 00 6e 00 74 00 65 |[email protected] .o.n.t.e|
0060 00 6e 00 74 00 49 00 64-00 00 a7 04 00 0b 04 00 |.n.t.I.d ........|
0070 22 00 04 00 36 38 32 34-07 40 00 53 00 69 00 74 |"...6824 [email protected]|
0080 00 65 00 49 00 64 00 00-a7 06 00 0b 04 00 22 00 |.e.I.d.. ......".|
0090 06 00 6e 69 6b 6c 61 73-                        |..niklas|

rpc.c:319:dbrpcsend() returning SUCCEED
dblib.c:4584:dbsqlok(0x8626028)
dblib.c:4614:dbsqlok() not done, calling tds_process_tokens()
token.c:539:tds_process_tokens(0x83400f0, 0xffff8628, 0xffff8624, 0x6914)
util.c:162:Changed query state from PENDING to READING
net.c:608:Received header
0000 04 01 00 41 00 3b 01 00-                        |...A.;..|

net.c:662:Received packet
0000 04 01 00 41 00 3b 01 00-81 01 00 00 00 21 00 26 |...A.;.. .....!.&|
0010 04 09 43 00 6f 00 6e 00-74 00 65 00 6e 00 74 00 |..C.o.n. t.e.n.t.|
0020 49 00 64 00 d1 04 a8 1a-00 00 ff 01 00 c1 00 01 |I.d..... ........|
0030 00 00 00 79 00 00 00 00-fe 00 00 e0 00 00 00 00 |...y.... ........|
0040 00                     -                        |.|

token.c:554:processing result tokens.  marker is  81(TDS7_RESULT)
token.c:1570:processing TDS7 result metadata.
mem.c:615:tds_free_all_results()
token.c:1594:set current_results (1 column) to tds->res_info
token.c:1601:setting up 1 columns
token.c:1601:setting up 1 columns
token.c:1541:tds7_get_data_info:
        colname = ContentId (9 bytes)
        type = 38 (integer-null)
        server's type = 38 (integer-null)
        column_varint_size = 1
        column_size = 4 (4 on server)
token.c:1610: name                 size/wsize      type/wtype      utype
token.c:1611: -------------------- --------------- --------------- -------
token.c:1621: ContentId                  4/4            38/38            0
util.c:162:Changed query state from READING to PENDING
dblib.c:4645:dbsqlok() found result token
dblib.c:1640:dbresults(0x8626028)
dblib.c:1646:dbresults: dbresults_state is 1 (_DB_RES_RESULTSET_EMPTY)
token.c:539:tds_process_tokens(0x83400f0, 0xffff8628, 0xffff8624, 0x6914)
util.c:162:Changed query state from PENDING to READING
token.c:554:processing result tokens.  marker is  d1(ROW)
token.c:665:tds_process_tokens::SET_RETURN stopping on current token
util.c:162:Changed query state from READING to PENDING
dblib.c:1667:dbresults() tds_process_tokens returned 1 (TDS_SUCCEED),
                        result_type TDS_ROW_RESULT
dblib.c:1629:dbresults returning 1 (SUCCEED)
dblib.c:1785:dbnumcols(0x8626028)
dblib.c:1785:dbnumcols(0x8626028)
dblib.c:1989:dbnextrow(0x8626028)
dblib.c:2002:dbnextrow() dbresults_state = 2 (_DB_RES_RESULTSET_ROWS)
token.c:539:tds_process_tokens(0x83400f0, 0xffff8628, (nil), 0x1508)
util.c:162:Changed query state from PENDING to READING
token.c:554:processing result tokens.  marker is  d1(ROW)
token.c:2424:tds_process_row(): reading column 0
token.c:2169:tds_get_data: type 38, varint size 1
token.c:2230:tds_get_data(): wire column size is 4
util.c:162:Changed query state from READING to PENDING
buffering.h:306:buffer_transfer_bound_data(0x8626030 4040 -1 0x8626028 0)
dblib.c:2071:leaving dbnextrow() returning REG_ROW/MORE_ROWS
dblib.c:1811:dbcolname(0x8626028, 1)
dblib.c:3001:dbcollen(0x8626028, 1)
dblib.c:2977:dbcolsource(0x8626028, 1)
dblib.c:2779:dbcoltype(0x8626028, 1)
dblib.c:3107:dbdata(0x8626028, 1)
dblib.c:2779:dbcoltype(0x8626028, 1)
dblib.c:3107:dbdata(0x8626028, 1)
dblib.c:6971:dblastrow(0x8626028)
dblib.c:2729:dbclrbuf(0x8626028, 1)
dblib.c:1989:dbnextrow(0x8626028)
dblib.c:2002:dbnextrow() dbresults_state = 2 (_DB_RES_RESULTSET_ROWS)
token.c:539:tds_process_tokens(0x83400f0, 0xffff85b8, (nil), 0x1508)
util.c:162:Changed query state from PENDING to READING
token.c:554:processing result tokens.  marker is  ff(DONEINPROC)
token.c:2459:tds_process_end: more_results = 1
                was_cancelled = 0
                error = 0
                done_count_valid = 0
token.c:2490:                rows_affected = 1
util.c:162:Changed query state from READING to PENDING
dblib.c:2071:leaving dbnextrow() returning NO_MORE_ROWS


Any ideas how to fix this?



Best regards,


Niklas


_______________________________________________
FreeTDS mailing list
[email protected]
http://lists.ibiblio.org/mailman/listinfo/freetds
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.