Skip to Content.
Sympa Menu

freetds - RE: Still problems with text fields?

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: Don Burden <donb AT zirmed.com>
  • To: 'TDS Development Group' <freetds AT franklin.oit.unc.edu>
  • Subject: RE: Still problems with text fields?
  • Date: Fri, 26 Jul 2002 09:34:14 -0400


Ok, here's some comparisons:

TEST table:
row id
==== ====
1
2 1
3 12
4 123
5 12
6 1
7

First, code running on Win2000, compiled with .NET C++, accessing SQL2000:
...
#define MAXLEN 50
SQLCHAR sID[51]
...
SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &hstmt);
SQLExecDirect(hstmt,
(unsigned char *) "Select id from test",
SQL_NTS);
SQLBindCol(hstmt, 1, SQL_C_CHAR, sID, MAXLEN, &cbzName);
while (SQLFetch(hstmt)!= SQL_NO_DATA ))
printf("//%s//\n", sID);
...

id field was rtrimmed when changing types.

Run with id defined as char(20). Notice padding to 20 chars, not 50.
// //
//1 //
//12 //
//123 //
//12 //
//1 //
// //

Run with id defined as varchar(20)
////
//1//
//12//
//123//
//12//
//1//
////

Run with id defined as text
////
//1//
//12//
//123//
//12//
//1//
////

Outputs garbage data if length changed from MAXLEN to 0 or -1.
Returncode=-1 from SQLBindCol if length set to -1.

====================================================

Next, same code running on Linux, FreeTDS + unixODBC

Run with id defined as char(20) (notice output is 50 chars, not 20)
// //
//1 //
//12 //
//123 //
//12 //
//1 //
// //

Run with id defined as varchar(20) (Bad last row!)
////
//1 //
//12 //
//123 //
//12 //
//1 //
//1 //

Run with id defined as text
////
//1&//
//12//
//123@//
//123@//
//123@//
//123@//

Changing length to -1 appears to be the only way to get a non-blank filled,
null terminated string when field defined as varchar(20). (Bad last row
again!):
////
//1//
//12//
//123//
//12//
//1//
//1//






Archive powered by MHonArc 2.6.24.

Top of Page