Skip to Content.
Sympa Menu

freetds - Re: iodbc and freetds

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: yan AT cbmi.upmc.edu
  • To: TDS Development Group <freetds AT franklin.oit.unc.edu>
  • Subject: Re: iodbc and freetds
  • Date: Sun, 29 Aug 1999 19:16:38 -0400 (EDT)


Brian,

Sorry about that...
Here it is:

I modified the code a bit to see what tds_submit_query is
returning; otherwise the program just runs without returning anything.

> gmake tdstest
gcc -DPACKAGE=\"freetds\" -DVERSION=\"0.45\" -DSTDC_HEADERS=1
-DHAVE_SYS_WAIT_H=1 -DHAVE_UNISTD_H=1 -DWORDS_BIGENDIAN=1
-DHAVE_STRFTIME=1 -I. -I. -I/usr/local/freetds/include -g -O2
-DHW_LITTLE_ENDIAN -DTDS42 -c tdstest.c
/bin/sh ../libtool --mode=link gcc -g -O2 -DHW_LITTLE_ENDIAN -DTDS42 -o
tdstest tdstest.o debug.o -L/usr/local/freetds/lib -lsocket -ltds
gcc -g -O2 -DHW_LITTLE_ENDIAN -DTDS42 -o tdstest tdstest.o debug.o
-L/usr/local/freetds/lib -lsocket -ltds
> ./tdstest
rc: 2


#include <stdio.h>
#include <tds.h>


static char software_version[] = "$Id: tdstest.c,v 1.5 1999/06/13
00:07:17 camber Exp $";
static void *no_unused_var_warn[] = {software_version,
no_unused_var_warn};


char *value_as_string(
TDSSOCKET *tds,
int col_idx)
{
static char result[256];
const int type = tds->res_info->columns[col_idx]->column_type;
const char *row = tds->res_info->current_row;
const int offset = tds->res_info->columns[col_idx]->column_offset;
const void *value = (row+offset);

switch(type)
{
case SYBVARCHAR:
{
strncpy(result, (char *)value, sizeof(result)-1);
result[sizeof(result)-1] = '\0';
break;
}
case SYBINT4:
{
sprintf(result, "%d", *(int *)value);
break;
}
default:
{
strcpy(result, "NotImp");
break;
}
}
return result;
} /* value_as_string() */


int main()
{
TDSLOGIN *login;
TDSSOCKET *tds;
int rc;
int i;

login = tds_alloc_login();
tds_set_passwd(login,"byteme4");
tds_set_user(login,"sa");
tds_set_app(login,"sqsh");
tds_set_host(login,"grill.cis.pitt.edu");
tds_set_library(login,"TDS-Library");
tds_set_server(login,"color");
tds_set_charset(login,"iso_1");
tds_set_language(login,"us_english");
tds_set_packet(login,512);

if (!(tds = tds_connect(login))) {
fprintf(stderr, "Login Failed!\n");
exit(1);
}

/* tds_submit_query(tds,"select db_name() dbname, user_name()
username"); */
/* tds_submit_query(tds,"select idx from groups"); */
tds_submit_query(tds,"use pharos select id from users where
id='shaykin'");
rc=tds_process_result_tokens(tds);
if (rc==TDS_SUCCEED)
{
for (i=0; i<tds->res_info->num_cols; i++)
{
printf("col %d\n Type: %d\n Name: %s\n Offset: %d\n",
i,
tds->res_info->columns[i]->column_type,
tds->res_info->columns[i]->column_name,
tds->res_info->columns[i]->column_offset);
}

while ((rc=tds_process_row_tokens(tds))==TDS_SUCCEED)
{
for (i=0; i<tds->res_info->num_cols; i++)
{
printf("col %i is %s\n", i, value_as_string(tds, i));
}
}
}
printf("rc: %d\n", rc);
return 0;
}



On Sun, 29 Aug 1999, Brian Bruns wrote:

>
> What kind of error messages or incorrect behaviour are you seeing? And on
> which boxes? There are some issues running certain things on Solaris (the
> the other message that just went out to the list). Are you trying to run
> DBD::Sybase, Sybperl, PHP? Which version of FreeTDS are you running? (I
> would highly recomend the snapshot).
>
> Brian
>
> On Sun, 29 Aug 1999 yan AT cbmi.upmc.edu wrote:
>
> > Brian,
> >
> > Thank you for the advice. I am still having the same problem
> > accessing my SQL 6.5 database from my Solaris 2.6 box. I tested the code
> > on my linux box and am having the same problem. I can give you access to
> > the database and if this would help you trace the problem (to the actual
> > sun box). I compiled freetds successfully and ran the samples for
> > tds successfully on my box. Here is the code and the interface
> > configuration I am using:
> >
> > #include <stdio.h>
> > #include <tds.h>
> >
> >
> > static char software_version[] = "$Id: tdstest.c,v 1.5 1999/06/13
> > 00:07:17 camber Exp $";
> > static void *no_unused_var_warn[] = {software_version,
> > no_unused_var_warn};
> >
> >
> > char *value_as_string(
> > TDSSOCKET *tds,
> > int col_idx)
> > {
> > static char result[256];
> > const int type = tds->res_info->columns[col_idx]->column_type;
> > const char *row = tds->res_info->current_row;
> > const int offset = tds->res_info->columns[col_idx]->column_offset;
> > const void *value = (row+offset);
> >
> > switch(type)
> > {
> > case SYBVARCHAR:
> > {
> > strncpy(result, (char *)value, sizeof(result)-1);
> > result[sizeof(result)-1] = '\0';
> > break;
> > }
> > case SYBINT4:
> > {
> > sprintf(result, "%d", *(int *)value);
> > break;
> > }
> > default:
> > {
> > strcpy(result, "NotImp");
> > break;
> > }
> > }
> > return result;
> > } /* value_as_string() */
> >
> >
> > int main()
> > {
> > TDSLOGIN *login;
> > TDSSOCKET *tds;
> > int rc;
> > int i;
> >
> > login = tds_alloc_login();
> > tds_set_passwd(login,"byteme4");
> > tds_set_user(login,"sa");
> > tds_set_app(login,"sqsh");
> > tds_set_host(login,"color");
> > tds_set_library(login,"TDS-Library");
> > tds_set_server(login,"pharos");
> > tds_set_charset(login,"iso_1");
> > tds_set_language(login,"us_english");
> > tds_set_packet(login,512);
> >
> > if (!(tds = tds_connect(login))) {
> > fprintf(stderr, "Login Failed!\n");
> > exit(1);
> > }
> >
> > /* tds_submit_query(tds,"select db_name() dbname, user_name()
> > username"); */
> > /* tds_submit_query(tds,"select idx from groups"); */
> > tds_submit_query(tds,"use pharos select id from users where
> > id='shaykin'");
> > while ((rc=tds_process_result_tokens(tds))==TDS_SUCCEED)
> > {
> > for (i=0; i<tds->res_info->num_cols; i++)
> > {
> > printf("col %d\n Type: %d\n Name: %s\n Offset: %d\n",
> > i,
> > tds->res_info->columns[i]->column_type,
> > tds->res_info->columns[i]->column_name,
> > tds->res_info->columns[i]->column_offset);
> > }
> >
> > while ((rc=tds_process_row_tokens(tds))==TDS_SUCCEED)
> > {
> > for (i=0; i<tds->res_info->num_cols; i++)
> > {
> > printf("col %i is %s\n", i, value_as_string(tds, i));
> > }
> > }
> > }
> > return 0;
> > }
> >
> > Interfaces
> >
> > JDBC
> > query tcp ether 192.138.151.39 4444
> > master tcp ether 192.138.151.39 4444
> >
> > myserver
> > query tcp ether 127.0.0.1 4000
> > master tcp ether 127.0.0.1 4000
> >
> > myserver2
> > query tcp ether 127.0.0.1 4001
> > master tcp ether 127.0.0.1 4001
> > color
> > query tcp ether 136.142.141.13 1433
> > pharos tcp ether 136.142.141.13 1433
> >
> >
> > The password and username will work for testing purposes.
> > The SQL database I am trying to access is pharos and I can access it from
> > my DBI:odbc perl scripts on a win32 platform (configured with odbc32
> > client). Any tips would be profusely welcomed.
> >
> >
> > Yantiff
> >
> > On Sun, 29 Aug 1999, Brian Bruns wrote:
> >
> > >
> > > Hi,
> > >
> > > The obdc library is extremely alpha quality (if that) right now. I
> > > wouldn't recommend using it. There is another group that created an
> > > ODBC
> > > driver on top of libtds and we will be merging that back into the main
> > > library soon instead of the ODBC driver that is presently there. (The
> > > new
> > > one will use unixODBC instead of iODBC for a driver manager).
> > >
> > > I would reccomend using dblib or ctlib for the time being if that is an
> > > option for you.
> > >
> > > Brian
> > >
> > > On Sun, 29 Aug 1999 yan AT cbmi.upmc.edu wrote:
> > >
> > > > To nay of you that have done this,
> > > >
> > > >
> > > > I compiled the iodbc-2.12.and successfully compiled the
> > > > libtdsodbc.so etc. libraries. However, I cannot find any sample code
> > > > that
> > > > shows me how to use it. Could anyone provide me with simple code
> > > > that
> > > > does freetdsodbc or instructions on how to do so?
> > > >
> > > > Yantiff
> > > >
> > >
> > >
> > > ---
> > > You are currently subscribed to freetds as: yan AT cbmi.upmc.edu
> > > To unsubscribe, forward this message to $subst('Email.Unsub')
> > >
> >
> > ---
> > You are currently subscribed to freetds as: camber AT ais.org
> > To unsubscribe, forward this message to $subst('Email.Unsub')
> >
> >
>
>
> ---
> You are currently subscribed to freetds as: yan AT cbmi.upmc.edu
> To unsubscribe, forward this message to $subst('Email.Unsub')
>




Archive powered by MHonArc 2.6.24.

Top of Page