Skip to Content.
Sympa Menu

freetds - Re: dblib sample program does not run

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: Brian Bruns <camber AT umcc.ais.org>
  • To: TDS Development Group <freetds AT franklin.oit.unc.edu>
  • Subject: Re: dblib sample program does not run
  • Date: Wed, 1 Sep 1999 20:14:27 -0400 (EDT)



Here is 0.46 running against the JDBC server (in the interfaces), the only
changes are for login information and the database name was changed to
pubs2.

Can you test it against the JDBC server to determine if it is specially
related to SQL 7.0 or your configuration. The server is in the interfaces
but you'll need an internet connection to get to it of course.

Brian

[camber@amd133 samples]$ !cc
cc -o sample sample.c -I/usr/local/freetds/include
-L/usr/local/freetds/lib -lsybdb -lnsl
[camber@amd133 samples]$ ./sample
White from Menlo Park
Green from Oakland
Carson from Berkeley
O'Leary from San Jose
Straight from Oakland
Bennet from Berkeley
Dull from Palo Alto
Gringlesby from Covelo
Locksley from San Francisco
Yokomoto from Walnut Creek
Stringer from Oakland
MacFeather from Oakland
Karsen from Oakland
Hunter from Palo Alto
McBadden from Vacaville
[camber@amd133 samples]$


On Wed, 1 Sep 1999, Kenny Pang wrote:

> Hi
> I am new to FreeTDS. I successfully compiled and installed freetds 0.46
> in Redhat Linux 6.0. It was configured with "--with-tdsver=4.2".
> However when I try some very sample programs to retrieve rows from a MS
> SQL server, the results are not the one I expected. The sample program
> is extracted from the MS SQL server 7.0 online book. It caused
> segmentation fault in the line
>
> while (dbnextrow(dbproc) != NO_MORE_ROWS)
>
> When total while block is commented, it runs but the printf outputs some
> rubbish, instead of the correct column.
>
> The sample program and the compile option is attached. Can somebody tell
> me what stupid mistake I have made or anything I have missed. Thanks a
> lot...
>
> cc -o sample.c sample.c -I/usr/local/freetds/include
> -L/usr/local/freetds/lib -lsybdb -lnsl
> ------------------------------------------------------------------
> sample.c
> ------------------------------------------------------------------
> #include <stdio.h>
> #include <sqlfront.h>
> #include <sqldb.h>
> main()
>
> {
> DBPROCESS *dbproc; // The connection with SQL Server.
> LOGINREC *login; // The login information.
> DBCHAR name[100];
> DBCHAR city[100];
>
> // Install user-supplied error- and message-handling functions.
> dbinit ();
>
> // Get a LOGINREC.
> login = dblogin();
> DBSETLUSER(login, "sa");
> DBSETLPWD(login, "");
> DBSETLAPP(login, "example");
>
> // Get a DBPROCESS structure for communication with SQL Server.
> dbproc = dbopen(login, "eex861");
> // Retrieve some columns from the authors table in the // pubs
> database.
>
> // First, put the command into the command buffer.
> dbcmd(dbproc, "SELECT au_lname, city FROM pubs..authors");
> dbcmd(dbproc, " WHERE state = 'CA' ");
>
> // Send the command to SQL Server and start execution.
> dbsqlexec(dbproc);
>
> // Process the results.
> if (dbresults(dbproc) == SUCCEED)
> {
> // Bind column to program variables.
> dbbind(dbproc, 1, NTBSTRINGBIND, 0, name);
> dbbind(dbproc, 2, NTBSTRINGBIND, 0, city);
> // Retrieve and print the result rows.
>
> while (dbnextrow(dbproc) != NO_MORE_ROWS)
> {
> printf("%s from %s\n", name, city);
> }
> }
>
> // Close the connection to SQL Server.
> dbexit();
> return(0);
>
>
> ---
> You are currently subscribed to freetds as: camber AT ais.org
> To unsubscribe, forward this message to $subst('Email.Unsub')
>
>





Archive powered by MHonArc 2.6.24.

Top of Page