Skip to Content.
Sympa Menu

freetds - [freetds] Need Help on dblib program

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "Steven J. Backus" <backus AT math.utah.edu>
  • To: freetds AT lists.ibiblio.org
  • Subject: [freetds] Need Help on dblib program
  • Date: Wed, 30 Jul 2003 11:55:05 -0600 (MDT)

I'm having problems with a dblib program and hope you can help,
I've tried to simplify it as much as i can. I'm using sybase 12.0
and freetds 0.61. It works fine with the sybase libraries so I think
freetds is walking on some variable, or I'm declaring something
incorrectly.

Here's the table definition:

create table table1
(id int null,
aid int null,
did int null,
bmonth int null,
bday int null,
byear int null,
dmonth int null,
dday int null,
dyear int null,
dage float null,
gender varchar(1) null,
orderinlist int null,
i1 varchar(4) null,
i2 varchar(4) null,
i3 varchar(4) null,
i4 varchar(4) null,
i5 varchar(4) null,
family varchar(1) null)

Here's my program:

#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <sybfront.h>
#include <sybdb.h>
#include <syberror.h>

int err_handler();
int msg_handler();

FILE *ERR_CH;

main(int argc, char** argv) {
DBPROCESS *dbproc;
LOGINREC *login;
DBCHAR i1[5], i2[5], i3[5], i4[5], i5[5], family;
DBINT id, did, dmonth, dday, dyear, order;
float dage;

if ((ERR_CH = fopen("Test.Err", "w")) == NULL) {
perror("Test.Err");
exit(1);
}

dberrhandle(err_handler);
dbmsghandle(msg_handler);
putenv("SYBASE=/usr/local/freetds");

if (dbinit() == FAIL) {
fprintf(stderr, "Database failure\n");
exit(1);
}

login = dblogin();
DBSETLUSER(login, "backus");
DBSETLPWD(login, "maddog12");
dbproc = dbopen(login, NULL);

dbcmd(dbproc, "select id, did, dmonth, dday, dyear, ");
dbcmd(dbproc, "dage, orderinlist, i1, i2, i3, i4, i5, ");
dbcmd(dbproc, "family from table1 order by id ");
dbsqlexec(dbproc);
dbsqlexec(dbproc);
if(dbresults(dbproc) == SUCCEED) {
dbbind(dbproc, 1, INTBIND, (DBINT)0, (BYTE*) &id);
dbbind(dbproc, 2, INTBIND, (DBINT)0, (BYTE*) &did);
dbbind(dbproc, 3, INTBIND, (DBINT)0, (BYTE*) &dmonth);
dbbind(dbproc, 4, INTBIND, (DBINT)0, (BYTE*) &dday);
dbbind(dbproc, 5, INTBIND, (DBINT)0, (BYTE*) &dyear);
dbbind(dbproc, 6, REALBIND, (DBINT)0, (BYTE*) &dage);
dbbind(dbproc, 7, INTBIND, (DBINT)0, (BYTE*) &order);
dbbind(dbproc, 8, STRINGBIND, (DBINT)0, (BYTE*) i1);
dbbind(dbproc, 9, STRINGBIND, (DBINT)0, (BYTE*) i2);
dbbind(dbproc, 10, STRINGBIND, (DBINT)0, (BYTE*) i3);
dbbind(dbproc, 11, STRINGBIND, (DBINT)0, (BYTE*) i4);
dbbind(dbproc, 12, STRINGBIND, (DBINT)0, (BYTE*) i5);
dbbind(dbproc, 13, CHARBIND, (DBINT)0, (BYTE*) &family);
}
while(dbnextrow(dbproc) != NO_MORE_ROWS)
printf("%s\n", i5);
}

Here's the insert statement I use:

insert into table1 (id, aid, did, bmonth, bday, byear, dmonth,
dday, dyear, dage, gender, orderinlist, i1, i2, i3, i4, i5, family)
values (176936, 30256045, 300004, 10, 10, 1824, 2, 5, 1904, 79,
'M', 1, NULL, NULL, NULL, NULL, 'I64', 'Y');

In sqsh I do:

select i5 from table1;

i5
----
I64

But the program prints nothing.

I appreciate any help you can offer.

Steve




Archive powered by MHonArc 2.6.24.

Top of Page