Skip to Content.
Sympa Menu

freetds - [freetds] empty varchar with length == 1?

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "James K. Lowden" <jklowden AT freetds.org>
  • To: TDS Development Group <freetds AT lists.ibiblio.org>
  • Subject: [freetds] empty varchar with length == 1?
  • Date: Thu, 13 Dec 2007 23:48:34 -0500

I know we've been over this territory before, but I don't think in this
particular way: if you insert a zero-length string into a varchar on
Sybase, you get back 1-byte columnar data containing a space. I changed
the null.c test to reflect that.

I don't know what Sybase's db-lib dbdatlen() returns for this situation.
FreeTDS returns a length of 1, and dbdata() of course points to the 0x20.


Evidence follows in scintillating detail.

--jkl


Output of src/dblib/unittests/null.c:

query: if object_id('#null') is not NULL drop table #null
create table #null (n int, c VARCHAR(10) NULL)
query: insert into #null values(1, '') <= input
query: insert into #null values(2, NULL)
query: insert into #null values(3, ' ')
query: insert into #null values(4, 'a')
select c from #null where n = 1 ... got 0x804d080 and length 1
^^^^^^^^
output
select c from #null where n = 2 ... got 0x0 and length 0
select c from #null where n = 3 ... got 0x804d160 and length 1
select c from #null where n = 4 ... got 0x804d1a0 and length 1
query: drop table #null

Ribo report:

ROW Token (0xD1); variable length.
Column 1
Length [1]: 1
Row data [1]: " " (0x20)

TDSDUMP log:

net.c:626:Received packet
0000 61 23 00 00 00 01 00 00-06 74 65 6d 70 64 62 05
0010 67 75 65 73 74 05 23 6e-75 6c 6c 01 63 30 00 00
0020 00 02 00 00 00 27 0a 00-ae 01 00 00 d1 01 20 fd
^^^^^^^^
row token, len 1, space.
0030 10 00 02 00 01 00 00 00-

dblib.c:4554:dbsqlok() exits on result token 0x61
dblib.c:1593:dbresults(0x804f000)
dblib.c:1602:dbresults: dbresults_state is 0 (_DB_RES_INIT)
token.c:495:tds_process_tokens(0x8065000, 0xbfbff574, 0xbfbff578, 0x6914)
util.c:162:Changed query state from PENDING to READING
token.c:510:processing result tokens. marker is 61(ROWFMT2)
token.c:1713:tds5_process_result
mem.c:563:tds_free_all_results()
token.c:1737:num_cols=1
token.c:1840:col 0:
token.c:1841: column_name=[c]
token.c:1847: flags=30 utype=2 type=39 varint=1
token.c:1850: colsize=10 prec=0 scale=0
...
token.c:510:processing result tokens. marker is d1(ROW)
token.c:621:tds_process_tokens::SET_RETURN stopping on current token
util.c:162:Changed query state from READING to PENDING
dblib.c:1624:dbresults() tds_process_tokens returned 1 (TDS_SUCCEED),
result_type TDS_ROW_RESULT
dblib.c:1581:dbresults returning 1 (SUCCEED)
dblib.c:1942:dbnextrow(0x804f000)
dblib.c:1955:dbnextrow() dbresults_state = 2 (_DB_RES_RESULTSET_ROWS)
token.c:495:tds_process_tokens(0x8065000, 0xbfbff598, 0x0, 0x1508)
util.c:162:Changed query state from PENDING to READING
token.c:510:processing result tokens. marker is d1(ROW)
token.c:2166:tds_process_row(): reading column 0
token.c:1915:tds_get_data: type 39, varint size 1
token.c:1975:tds_get_data(): wire column size is 1
util.c:162:Changed query state from READING to PENDING
buffering.h:229:buffer_transfer_bound_data(0x804f008 4040 -1 0x804f000 0)
dblib.c:2024:leaving dbnextrow() returning REG_ROW/MORE_ROWS
dblib.c:3026:dbdatlen(0x804f000, 1)
dblib.c:3034:dbdatlen() type = 39, len= 1




  • [freetds] empty varchar with length == 1?, James K. Lowden, 12/13/2007

Archive powered by MHonArc 2.6.24.

Top of Page