[freetds] strange dbconvert

kris at bobbl.be kris at bobbl.be
Fri Mar 16 06:30:47 EDT 2007


Hi,

I am using dblib from the current freetds on a sqlserver 2k from a os x
machine.

Here is my debug code.

#include <sqlfront.h>
#include <sqldb.h>
#include <stdio.h>
#include <time.h>
#include <string.h>
#include <unistd.h>

int main (int argc, char * const argv[]) {
	DBPROCESS *dbproc;
	LOGINREC *login = dblogin();
	dbinit();
	DBSETLPWD(login, "blabla");
	DBSETLUSER(login, "kris");
	DBSETLAPP(login, "blabla");
	if(!(dbproc = dbopen(login, "some_server:1434"))) return 1;
	if(dbuse(dbproc, "some_db") != SUCCEED) return 1;
	if(dbcmd(dbproc, "SELECT a_char from a_table where (unique_key = '1' or
unique_key = '2')") != SUCCEED) return 1;
	if(dbsqlexec(dbproc) == FAIL) return 1;
	if(dbsqlok(dbproc) == FAIL) return 1;
	if(dbresults(dbproc) == SUCCEED) printf("%i\n", dbnumcols(dbproc));
	char put[100];
	int len;
	while(dbnextrow(dbproc) != NO_MORE_ROWS){
		len = dbconvert(dbproc, (dbcoltype(dbproc, 1)), (dbdata(dbproc, 1)),
(dbdatlen(dbproc, 1)), SYBVARCHAR, (BYTE *) put, 99);
		if(len == FAIL || len == -1) return 1;
		printf("-> %s <-\n", put);
	}
	dbloginfree(login);
	dbexit();
	if(dbproc) dbclose(dbproc);
    return 0;
}

this results in :

[Session started at 2007-03-16 11:17:30 +0100.]
1
->   <-
-> T <-

freetds has exited with status 0.

When i copy, paste and execute this query in query analyser it returns :

T
T

which is indeed in the database.
This field is a char of one long.
Anybody seen that error before ? Since I expected to see -> T <- twice.
It is always the same entry (i changed the order, and used other keys)

Thanks a lot,

Kris






More information about the FreeTDS mailing list