DBD-NET

 view release on metacpan or  search on metacpan

dbagent/agent.ec  view on Meta::CPAN

static char msg[256];
char tt[128];
int num=rgetmsg(SQLCODE,tt,sizeof(tt));

if (!num) sprintf(msg,"%d : %s",SQLCODE,tt);
else sprintf(msg,"unknown SQL err code : %d",SQLCODE);

return msg;
}

alloc_cursor()
{
int i;
for(i=0;i<MAX_CURSOR;i++)
if (!curs[i].opened) {
	bzero(&curs[i],sizeof(curs[0]));
	return i;
}
sqlca.sqlcode=SQLCODE = -276;
error("Max allowed concurrent %d", MAX_CURSOR);
return -1;

dbagent/agent.ec  view on Meta::CPAN

{
_iqdbase(dbname,0);
if (SQLCODE < 0) {
	error("connect db %s err %s", dbname, sqlerr());
	return 0;
}
return 1;
}


sql_prepare(stmt, cursor_n, desc_n)
$char *stmt;
int *cursor_n, *desc_n;
{
char *tt;
char cmd[16];
int i,cursor_num;
$int desc_cou;

i=0;
tt=stmt;
while (isspace(*tt)) tt++;
while (*tt && isalpha(*tt)) cmd[i++]=tolower(*tt++);
cmd[i]=0;
if (strstr("insert delete update create drop alter set begin commit",cmd)) {
	$prepare tsql from $stmt;
	if (SQLCODE < 0) {

dbagent/agent.ec  view on Meta::CPAN

		return 0;
	}
	*desc_n=0;
	return 1;
}
if (strcmp(cmd,"select")) {
	error("unknow sql command : %s", cmd);
	return 0;
}

if ((cursor_num=alloc_cursor())<0) return -1;
switch (cursor_num) {
	case 0:
#if	0
		error("sql stmt cursor %d %s\n", cursor_num, stmt);
#endif
		$prepare prep0 from $stmt;
		if (SQLCODE < 0) {
			error("cursor%d prepare %s",cursor_num,sqlerr());
			return 0;
		}
		$declare cur0 cursor for prep0;
		if (SQLCODE < 0) {
			error("cursor%d declare %s", cursor_num, sqlerr());
			return 0;
		}
		$allocate descriptor 'desc0' with max 128;
		if (SQLCODE < 0) {
			error("cursor%d allocate %s", cursor_num, sqlerr());
			return 0;
		}
		$open cur0;
		if (SQLCODE < 0) {
			error("cursor%d open %s", cursor_num, sqlerr());
			return 0;
		}
		$describe prep0 using sql descriptor 'desc0';
		if (SQLCODE < 0) {
			error("cursor%d open %s", cursor_num, sqlerr());
			return 0;
		}
		$get descriptor 'desc0' $desc_cou = count;
		if (SQLCODE < 0) {
			error("prepare cursor%d get desc %s", cursor_num, sqlerr());
			return 0;
		}
		break;
	case 1:
		$prepare prep1 from $stmt;
		if (SQLCODE < 0) {
			error("cursor%d prepare %s",cursor_num,sqlerr());
			return 0;
		}
		$declare cur1 cursor for prep1;
		if (SQLCODE < 0) {
			error("cursor%d declare %s", cursor_num, sqlerr());
			return 0;
		}
		$allocate descriptor 'desc1' with max 128;
		if (SQLCODE < 0) {
			error("cursor%d allocate %s", cursor_num, sqlerr());
			return 0;
		}
		$open cur1;
		if (SQLCODE < 0) {
			error("cursor%d open %s", cursor_num, sqlerr());
			return 0;
		}
		$describe prep1 using sql descriptor 'desc1';
		if (SQLCODE < 0) {
			error("cursor%d open %s", cursor_num, sqlerr());
			return 0;
		}
		$get descriptor 'desc1' $desc_cou = count;
		if (SQLCODE < 0) {
			error("prepare cursor%d get desc %s", cursor_num, sqlerr());
			return 0;
		}
		break;
	case 2:
		$prepare prep2 from $stmt;
		if (SQLCODE < 0) {
			error("cursor%d prepare %s",cursor_num,sqlerr());
			return 0;
		}
		$declare cur2 cursor for prep2;
		if (SQLCODE < 0) {
			error("cursor%d declare %s", cursor_num, sqlerr());
			return 0;
		}
		$allocate descriptor 'desc2' with max 128;
		if (SQLCODE < 0) {
			error("cursor%d allocate %s", cursor_num, sqlerr());
			return 0;
		}
		$open cur2;
		if (SQLCODE < 0) {
			error("cursor%d open %s", cursor_num, sqlerr());
			return 0;
		}
		$describe prep2 using sql descriptor 'desc2';
		if (SQLCODE < 0) {
			error("cursor%d open %s", cursor_num, sqlerr());
			return 0;
		}
		$get descriptor 'desc2' $desc_cou = count;
		if (SQLCODE < 0) {
			error("prepare cursor%d get desc %s", cursor_num, sqlerr());
			return 0;
		}
}
*cursor_n=cursor_num;
curs[cursor_num].descou = *desc_n= desc_cou;
curs[cursor_num].opened=1;
return 1;
}


sql_fetch(
int cursor, char *res, int colen[], int *tcolength, int *rtcol, int *descn)
{
$int i;
$int desc_count;
$int loop;
$int type;
$int len;
$char name[40];
int tlen=0;
$char bf[65536];
$short indicator;
int tcolen=0;

*descn=curs[cursor].descou;
if (!curs[cursor].tcolen) {
for ( i = 1 ; i <= curs[cursor].descou ; i++ ) {
switch (cursor) {
	case 0:
	$get descriptor 'desc0' value $i $type = type, $len = length, $name = name;
	break;
	case 1:
	$get descriptor 'desc1' value $i $type = type, $len = length, $name = name;
	break;
	case 2:
	$get descriptor 'desc2' value $i $type = type, $len = length, $name = name;
	break;
	default:
		break;
}
if (SQLCODE < 0) {
	error("sql_fetch: aa cursor%d get desc %s", cursor, sqlerr());
	return 0;
}
switch (type) {
	case SQLCHAR:
	/* leave len alone if char */
	break;
	case SQLINT:
	len = MAXINTLEN;
	break;
	case SQLSMINT:

dbagent/agent.ec  view on Meta::CPAN

	case SQLSMFLOAT:
	len = MAXSMFLOATLEN;
	break;
	case SQLFLOAT:
	len = MAXFLOATLEN;
	break;
}
colen[i-1]=len;
tcolen+=len;
} /* for */
curs[cursor].tcolen=tcolen;
memcpy(curs[cursor].colen,colen,sizeof(colen));
}
else {
	memcpy(colen,curs[cursor].colen,sizeof(colen));
	tcolen=curs[cursor].tcolen;
}

switch (cursor) {
	case 0:
		$fetch cur0 using sql descriptor 'desc0';
		break;
	case 1:
		$fetch cur1 using sql descriptor 'desc1';
		break;
	case 2:
		$fetch cur2 using sql descriptor 'desc2';
		break;
}

if (SQLCODE) {
	if (SQLCODE<0)
	  error("fetch xx cursor%d get desc %d %s", cursor, SQLCODE, sqlerr());
	return 0;
}

tlen=0;
#if	0
error("total desc:%d", curs[0].descou);
#endif
for(i = 1 ; i <= curs[cursor].descou ; i++ ) {
	switch (cursor) {
	case 0:
		$get descriptor 'desc0' value $i $bf = data, $type = type, $indicator=indicator;
	    break;
	case 1:
		$get descriptor 'desc1' value $i $bf = data, $type = type, $indicator=indicator;
	    break;
	case 2:
		$get descriptor 'desc2' value $i $bf = data, $type = type, $indicator=indicator;
	    break;
	}
	if (SQLCODE < 0) {
		error("sql_fetch -- data cursor%d get %d desc %s",
			cursor, i, sqlerr());
		return 0;
	}
#if	0
	printf("%s &", bf);
#endif
	strcpy(res+tlen, bf);
	tlen+=strlen(bf)+1;
}
*tcolength=tcolen;
*rtcol=tlen;
return 1;
}


close_cursor(int cur)
{
switch (cur) {
	case 0:
		$ close cur0;
		curs[0].opened=0;
		break;
	case 1:
		$ close cur1;
		curs[1].opened=0;
		break;
	case 2:
		$ close cur2;
		curs[2].opened=0;
		break;
	default:
		error("close_cursor: bad cursor no %d\n", cur);
}
if (SQLCODE < 0) {
	error("close cursor%d %s", cur, sqlerr());
	return 0;
}
return 1;
}

free_cursor(int cursor)
{
switch (cursor) {
	case 0:
	    $ free prep0;
	    $ free desc0;
	    $ deallocate descriptor 'desc0';
		curs[0].opened=0;
	    break;
	case 1:
	    $ free prep1;
	    $ free desc1;
	    $ deallocate descriptor 'desc1';

dbagent/cl.c  view on Meta::CPAN

rq.req=htonl(NET_CONNECTDB);
rq.len=htonl(strlen(s)+1);
netwrite(&rq,sizeof(rq));
netwrite(s,strlen(s)+1);
netread(&res,sizeof(res));
res.res=ntohl(res.res);
if (!res.res) printf("error:%s %s\n", neterr());
return res.res;
}

sql_prepare(char *s, int *cursorn, int *descn)
{
REQ rq;
RES res;
PREPARE_REP rep;
int len=strlen(s)+1;

rq.req=htonl(NET_PREPARE);
rq.len=htonl(len);
netwrite(&rq,sizeof(rq));
netwrite(s,strlen(s)+1);
netread(&res,sizeof(res));
res.res=ntohl(res.res);
if (!res.res) printf("prepare error %s", neterr());
netread(&rep,sizeof(rep));
*cursorn=ntohl(rep.cursorn);
*descn=ntohl(rep.descn);
}

sql_fetch(int cursorn, char *bf, int colen[], int *tcolen, int *descn)
{
REQ rq;
FETCH_REQ frq;
RES res;
FETCH_REP rep;
int rn,i;

rq.req=htonl(NET_FETCH);
rq.len=htonl(sizeof(FETCH_REQ));
netwrite(&rq,sizeof(rq));
frq.cursorn=htonl(cursorn);
netwrite(&frq,sizeof(frq));
netread(&res,sizeof(res));
res.res=ntohl(res.res);
if (!res.res)	{
	printf("fetch error %d %s\n", res.res, neterr());
	return res.res;
}
netread(&rep,sizeof(rep));
*descn=rep.descn=ntohl(rep.descn);
*tcolen=rep.tcolen=ntohl(rep.tcolen);
netread(colen,sizeof(int)*rep.descn);
for(i=0;i<rep.descn;i++)
	colen[i]=ntohl(colen[i]);
rn=netread(bf,rep.tcolen);
}

sql_close(int cursor)
{
REQ rq;
CLOSE_REQ req;

rq.req=htonl(NET_CLOSE);
rq.len=sizeof(req);
req.cursorn=cursor;
netwrite(&rq,sizeof(rq));
netwrite(&req,sizeof(req));
}

sql_getdbs(char *dbs, int *ndbs)
{
}

dbagent/net.c  view on Meta::CPAN

	s+=strlen(s)+1;
}
puts("");
}


int fcnt;

void handle_req()
{
int n, cursorn, descn;
REQ rq;
RES rep;
char ttt[16*1024];
int max_rows[10];

fcnt=0;

for(;;) {
n=netread(&rq,sizeof(REQ));
rq.req=ntohl(rq.req);

dbagent/net.c  view on Meta::CPAN

			puterr();
		else {
			rep.res=htonl(rep.res);
			netwrite(&rep,sizeof(RES));
		}
		continue;
	}
	case NET_PREPARE:
	{
		netread(ttt,rq.len);
		rep.res=sql_prepare(ttt,&cursorn,&descn);
		if (!rep.res)
			puterr();
		else {
			PREPARE_REP pp;
			pp.cursorn=htonl(cursorn);
			pp.descn=htonl(descn);
			netwrite(&rep,sizeof(rep));
			netwrite(&pp,sizeof(PREPARE_REP));
			max_rows[cursorn]=16;
		}
		continue;
	}
	case NET_FETCH:
	{
		char *tt[MAXCOLUMN];
		int i,j, tlen,ofs,nrow;
		int colen[MAXCOLUMN],tcolen;
		char bf[128*1024] ;
		FETCH_REP qq;
		RES res;
		FETCH_REQ pp;
		int rtcol,datan,max_row;

		netread(&pp,sizeof(pp));
		cursorn=ntohl(pp.cursorn);
		/* Yes, it is dangerous if a row is too large, will use malloc */
		max_row=max_rows[cursorn]=128;
		for(datan=nrow=0;nrow<max_row;nrow++) {
			if (!(res.res=sql_fetch(cursorn,bf+datan,colen,&tcolen,
					&rtcol, &descn))) {
					break;
			}
			fcnt++;
			datan+=rtcol;
		}
		if (res.res) {
			max_row=sizeof(bf)/tcolen;
			max_rows[cursorn]=max_row;
		}
		qq.descn=htonl(descn);
		qq.tcolen=htonl(tcolen);
		qq.nrow=htonl(nrow);
		qq.datan=htonl(datan);
		if (nrow==0) {
			res.res=0;
			netwrite(&res,sizeof(res));
			continue;
		}

dbagent/net.c  view on Meta::CPAN

			colen[i]=htonl(colen[i]);
		netwrite(colen, sizeof(int)*descn);
		if (datan) netwrite(bf,datan);
#if	0
		printf("res:%d tcolen:%d\n", res.res, tcolen);
#endif
		continue;
	}
	case NET_CLOSE:
	{   CLOSE_REQ pp;
		int cursorn;
		netread(&pp,sizeof(pp));
		cursorn=ntohl(pp.cursorn);
		close_cursor(cursorn);
		printf("close %d\n", cursorn);
		exit(0);
	}
	case NET_FREE:
	{   CLOSE_REQ pp;
		int cursorn;
		cursorn=ntohl(pp.cursorn);
		free_cursor(cursorn);
		exit(0);
	}
  } /* switch */
} /* if */
} /* for */


}


dbagent/proto.h  view on Meta::CPAN

#define RES_OK (1)
#define RES_ERR (0)

typedef struct {
	char login_name[16];
	char passwd[16];
	char dbname[16];
} CONNECT_REQ;

typedef struct {
	int cursorn;
	int descn;
} PREPARE_REP;

typedef struct {
	int cursorn;
} FETCH_REQ;

typedef struct {
	int	descn;
	int tcolen;
	int nrow, datan;
} FETCH_REP;

typedef struct {
	int cursorn;
} CLOSE_REQ;

dbdnet/ChangeLog  view on Meta::CPAN


0.22
----

09/09/96:	Added @ary = $drh->func( '_ListDBs' ); method for getting
		a list of extant databases on the local Informix server.
		( From original code and suggestion by 
                  George.Vicherek@Sciatl.COM )

10/09/96:	Fixed all numeric types to return correctly. CHAR fields don't
		quite behave as planned, or perhaps they do. Added 'multicursor'
		test which proves that simultanous multiple cursors fails
		miserably.

		0.23 release.

17/09/96:	Added patch for bad column names as show in George Vicherek's
		splendid test case. ( extratests/primitives.pl exercises this )

18/09/96:	Wrapped in a patch to Makefile.PL from Christophe Martin.
		Added some other Makefile.PL patches of my own. It should now
		support cleaner builds on HP-UX ( spit! ) and correctly detect
		when dbdimp.ec has changed.

18/09/96:	Wrapped in patches by Terry Nightingale based on Bill Hailes'
		isqlperl for supporting multi-cursors. Cleaned the type 
		handling code again.

		0.24 release.

26/09/96:	Patches from Terry arrived. This'll be the 0.25 release. Seems
		to work.

dbdnet/MANIFEST  view on Meta::CPAN

Informix.h
Informix.pm
Informix.xs
MANIFEST
Makefile
Makefile.PL
README
dbdimp.ec
dbdimp.h
extratests/dblist.pl
extratests/multicursor.pl
extratests/numerics.pl
extratests/original_0.20pl0_test.pl
extratests/primitives.pl
test.pl

dbdnet/NET.c  view on Meta::CPAN

    if (items != 1)
	croak("Usage: DBD::NET::db::disconnect(dbh)");
    {
	SV *	dbh = ST(0);
	D_imp_dbh(dbh);
	if ( !DBIc_ACTIVE(imp_dbh) ) {
		if (DBIc_WARN(imp_dbh) && !dirty)
			warn("disconnect: already logged off!");
		XSRETURN_YES;
	}
	/* Check for disconnect() being called whilst refs to cursors       */
	/* still exists. This needs some more thought.                      */
	/* XXX We need to track DBIc_ACTIVE children not just all children  */
	if (DBIc_KIDS(imp_dbh) && DBIc_WARN(imp_dbh) && !dirty) {
		warn("disconnect(%s) invalidates %d associated cursor(s)",
			SvPV(dbh,na), DBIc_KIDS(imp_dbh));
	}
	ST(0) = dbd_db_disconnect(dbh) ? &sv_yes : &sv_no;
    }
    XSRETURN(1);
}

XS(XS_DBD__NET__db_DESTROY)
{
    dXSARGS;

dbdnet/NET.xs  view on Meta::CPAN

void
disconnect(dbh)
	SV *        dbh
	CODE:
	D_imp_dbh(dbh);
	if ( !DBIc_ACTIVE(imp_dbh) ) {
		if (DBIc_WARN(imp_dbh) && !dirty)
			warn("disconnect: already logged off!");
		XSRETURN_YES;
	}
	/* Check for disconnect() being called whilst refs to cursors       */
	/* still exists. This needs some more thought.                      */
	/* XXX We need to track DBIc_ACTIVE children not just all children  */
	if (DBIc_KIDS(imp_dbh) && DBIc_WARN(imp_dbh) && !dirty) {
		warn("disconnect(%s) invalidates %d associated cursor(s)",
			SvPV(dbh,na), DBIc_KIDS(imp_dbh));
	}
	ST(0) = dbd_db_disconnect(dbh) ? &sv_yes : &sv_no;


void
DESTROY(dbh)
	SV *        dbh
	CODE:
	D_imp_dbh(dbh);

dbdnet/cl.c  view on Meta::CPAN

#include <sys/time.h>

char *prgname="client";

#define MAX_OPEN_CURSOR (6)

static struct fet {
	int nrow;
	int row_i;
	int descn;
	int netfd,r_cursor;
	int colen[256],tcolen;
	char *bufptr, *buf;
	int bufsize;
} fetchbuf[MAX_OPEN_CURSOR];

void p_err(char *fmt,...)
{
	va_list args;

	va_start(args, fmt);

dbdnet/cl.c  view on Meta::CPAN

netwrite(fd,&rq,sizeof(rq));
netwrite(fd,&con,sizeof(con));
netread(fd,&res,sizeof(res));
res.res=ntohl(res.res);
if (!res.res) {
	neterr(fd);
}
return fd;
}

sql_prepare(int netfd, char *s, int *cursorn, int *descn)
{
REQ rq;
RES res;
PREPARE_REP rep;
int len=strlen(s)+1;
int curn;
int mycur;

for(curn=0;curn<MAX_OPEN_CURSOR;curn++)
if (!fetchbuf[curn].netfd) {
	*cursorn=curn;
	break;
}
if (curn==MAX_OPEN_CURSOR)
	p_err("Exceed max open cursor %d",MAX_OPEN_CURSOR);
rq.req=htonl(NET_PREPARE);
rq.len=htonl(len);
netwrite(netfd,&rq,sizeof(rq));
netwrite(netfd,s,strlen(s)+1);
netread(netfd,&res,sizeof(res));
res.res=ntohl(res.res);
if (!res.res) {
	neterr(netfd);
	return 0;
}
netread(netfd,&rep,sizeof(rep));
*descn=ntohl(rep.descn);
if (rep.descn) {
	fetchbuf[curn].r_cursor=ntohl(rep.cursorn);
	fetchbuf[curn].netfd=netfd;
	fetchbuf[curn].row_i=fetchbuf[curn].nrow=0;
}
return 1;
}

void putss(char *s, int n)
{
int i;
for(i=0;i<n;i++) {
	printf("%s|",s);
	s+=strlen(s)+1;
}
puts("");
}

sql_fetch(int cursorn, char *bf, int colen[], int *tcolen, int *descn)
{
REQ rq;
FETCH_REQ frq;
RES res;
FETCH_REP rep;
int rn,i,j,ofs;
char *tt;
struct fet *pfet=&fetchbuf[cursorn];
char *dat;
char *p;
int netfd=pfet->netfd;

copy_it:
if (pfet->row_i < pfet->nrow) {
	*descn=pfet->descn;
	memcpy(colen, pfet->colen, sizeof(int)*(*descn));
	*tcolen=pfet->tcolen;
	p=pfet->bufptr;

dbdnet/cl.c  view on Meta::CPAN

	pfet->bufptr=p+ofs;
	pfet->row_i++;
#if 0
	putss(bf,*descn);
#endif
	return 1;
}
rq.req=htonl(NET_FETCH);
rq.len=htonl(sizeof(FETCH_REQ));
netwrite(netfd,&rq,sizeof(rq));
frq.cursorn=htonl(pfet->r_cursor);
netwrite(netfd,&frq,sizeof(frq));
netread(netfd,&res,sizeof(res));
res.res=ntohl(res.res);
if (!res.res)   {
/*	neterr(netfd); */
	return 0;
}
netread(netfd,&rep,sizeof(rep));
pfet->descn=rep.descn=ntohl(rep.descn);
pfet->tcolen=rep.tcolen=ntohl(rep.tcolen);
pfet->nrow=rep.nrow=ntohl(rep.nrow);
rep.datan=ntohl(rep.datan);
#if	0
printf("cursorn:%d datan:%d\n", cursorn, rep.datan);
#endif
netread(netfd,colen,sizeof(int)*rep.descn);
for(i=0;i<rep.descn;i++) {
	pfet->colen[i]=colen[i]=ntohl(colen[i]);
}
#if 0
printf("descn:%d tcolen:%d nrow:%d datan:%d\n",
rep.descn, rep.tcolen, rep.nrow, rep.datan );
fflush(stdout);
#endif

dbdnet/cl.c  view on Meta::CPAN

		p+=strlen(p)+1;
	}
puts("");
}
#endif
pfet->bufptr=pfet->buf=dat;
pfet->row_i=0;
goto copy_it;
}

sql_close(int cursor)
{
REQ rq;
CLOSE_REQ req;
int netfd;

if (cursor<0 || cursor>=MAX_OPEN_CURSOR) {
	printf("Invalid cursor %d\n", cursor);
	return 0;
}
netfd=fetchbuf[cursor].r_cursor;
if (netfd<=0) {
	printf("Invalid cursor %d\n", cursor);
	return 0;
}
rq.req=htonl(NET_CLOSE);
rq.len=sizeof(req);
req.cursorn=fetchbuf[cursor].r_cursor;
netwrite(netfd,&rq,sizeof(rq));
netwrite(netfd,&req,sizeof(req));
close(fetchbuf[cursor].netfd);
fetchbuf[cursor].netfd=0;
}

net_disconnect(int fd)
{
int i;

for(i=0;i<MAX_OPEN_CURSOR;i++)
if (fetchbuf[i].netfd) {
	close(fetchbuf[i].netfd);
	fetchbuf[i].netfd=0;

dbdnet/dbdimp.c  view on Meta::CPAN

#include "NET.h"

DBISTATE_DECLARE;
static void iqfree();
static void free_cursor();
static void iqclose();

/*---------------------------------------------------*
 * Function:    new_cursor
 *
 * Purpose:     locates a free cursor from the array
 *
 * Arguments:   none
 *
 * Returns:     cursor id or -1 if not found
 *---------------------------------------------------*/

void
dbd_init(dbistate)
	dbistate_t *dbistate;
{
	DBIS = dbistate;
	dbd_errnum = GvSV(gv_fetchpv("DBD::NET::err",    1, SVt_IV));
	dbd_errstr = GvSV(gv_fetchpv("DBD::NET::errstr", 1, SVt_PV));
}

dbdnet/dbdimp.c  view on Meta::CPAN

}
*/

int
dbd_st_prepare(sth, statement)
	SV *sth;
	char *statement;
{
	D_imp_sth(sth);
	D_imp_dbh_from_sth;
	int i, inside_quote, cursor_num;
	char func[64];
	int desc_count,netfd;

	imp_sth->done_desc = 0;
	imp_sth->cda = &imp_sth->cdabuf;

	/* Parse statement for binds ( also, INSERTS! ) */
	/* Lowercase the statement first */
	netfd=imp_dbh->lda.svsock;

dbdnet/dbdimp.c  view on Meta::CPAN

	if ( strstr( func, "delete" ) != 0 ) {
	if ( dbis->debug >= 2 )
	    warn( "DELETE present in statement\n" );
	imp_sth->is_delete = 1;
	  }

	/** Do the special case stuff first */
	if ( ( imp_sth->is_create == 1 ) || ( imp_sth->is_drop == 1 ) ||
	 ( imp_sth->is_insert == 1 ) || ( imp_sth->is_delete == 1 ) ||
	 ( imp_sth->is_update == 1 ) ) {
		if (sql_prepare(netfd,statement,&cursor_num,&desc_count)<=0) {
			do_error();
			return 0;
		}
		DBIc_IMPSET_on( imp_sth );
		return 1;
	  }

	if (!sql_prepare(netfd,statement,&cursor_num,&desc_count)) {
		do_error();
		return 0;
	}
	/** Tell the sth how many fields we have in the cursor */
	imp_sth->fbh_num = desc_count;

	/** Reset row_num to 0 */
	imp_sth->row_num = 0;

	/* Store index into cursor array in statement handle */
	imp_sth->cursoridx = cursor_num;

	/* Get number of fields and space needed for field names      */
	if ( dbis->debug >= 2 )
	printf( "DBD::NET::dbd_db_prepare'imp_sth->fbh_num: %d\n",
		imp_sth->fbh_num );

	DBIc_IMPSET_on(imp_sth);
	return 1;
}

dbdnet/dbdimp.c  view on Meta::CPAN


  if ( dbis->debug >= 2 )
	  warn( "In: DBD::NET::dbd_describe()\n" );

  if (imp_sth->done_desc ) {
	  if ( dbis->debug >= 2 )
	  warn( "In: DBD::NET::dbd_describe()'done_desc = true\n" );
	  return 1;	/* success, already done it */
	}
  imp_sth->done_desc = 1;
  if (!sql_fetch(imp_sth->cursoridx, result, &f_cbufl[1], &t_cbufl,
	  &desc_count)) {
  	return 1; /* no more data */
  }

  field_info_loop = 0;
  imp_sth->row_num++;

  /* Assign the number of fields to fbh_num */

  /* allocate field buffers	*/

dbdnet/dbdimp.c  view on Meta::CPAN

	*SvEND(bufsv) = '\0'; /* consistent with perl sv_setpvn etc */

	return sv_2mortal(bufsv);
}

int
dbd_st_finish(sth)
	SV *sth;
{
	D_imp_sth(sth);
	/* Cancel further fetches from this cursor.                 */
	/* We don't close the cursor till DESTROY.                  */
	/* The application may re execute it.                       */
/* LOOK INTO   if (DBIc_ACTIVE(imp_sth) ) {
	do_error();
	return 0;
	} */
	DBIc_ACTIVE_off(imp_sth);
	return 1;
}

void
dbd_st_destroy(sth)
	SV *sth;
{
	D_imp_sth(sth);
	D_imp_dbh_from_sth;
	if (DBIc_ACTIVE(imp_dbh) /* && oclose(imp_sth->cda) */ ) {
	  }

	if ( dbis->debug >= 2 )
	warn( "In: DBD::NET::dbd_st_destroy, calling free_cursor(%d)\n",
	    imp_sth->cursoridx );
/*
	Need to free up resources so the cursor can be used again.
*/
	free_cursor (imp_sth->cursoridx);

	if ( dbis->debug >= 2 )
	warn( "In: DBD::NET::dbd_st_destroy, back from free_cursor\n" );

	/* XXX free contents of imp_sth here */
	DBIc_IMPSET_off(imp_sth);
}

int
dbd_st_STORE(sth, keysv, valuesv)
	SV *sth;
	SV *keysv;
	SV *valuesv;

dbdnet/dbdimp.c  view on Meta::CPAN

	return Nullsv;
	}
	if (cacheit) { /* cache for next time (via DBI quick_FETCH) */
	hv_store((HV*)SvRV(sth), key, kl, retsv, 0);
	(void)SvREFCNT_inc(retsv);      /* so sv_2mortal won't free it  */
	}
	return sv_2mortal(retsv);
}

/*---------------------------------------------------*
 * Function:    free_cursor
 *
 * Purpose:     frees/closes/deallocates/removes/obliterates ...
 *
 * Arguments:   cursor index
 *
 * Returns:     status
 *---------------------------------------------------*/

static void free_cursor(sqc)
int sqc;
{
}

/*---------------------------------------------------
 * Function:    iqclose
 *
 * Purpose:    closes cursor
 *
 * Arguments:    cursor index
 *
 * Returns:    void
 *---------------------------------------------------*/

static void iqclose(sqc)
int sqc;
{
}

/*---------------------------------------------------
 * Function:    iqfree
 *
 * Purpose:    frees closed cursor
 *
 * Arguments:    cursor index
 *
 * Returns:    void
 *
 *---------------------------------------------------*/

static void iqfree(sqc)
int sqc;
{
}

dbdnet/dbdimp.h  view on Meta::CPAN

/* these are (almost) random values ! NOTE: DBD::Oracle hangover */
#define MAX_BIND_VARS 99
#define MAX_COLS 128

/** Maximum number of simltaneously open cursors */
#define MAX_CURSORS 9

/* various maiximum lengths for string representations */
/* In cases of uncertainty, I've erred on the side of caution */
#define MAXINTLEN       24
#define MAXSMINTLEN     12
#define MAXINTERVALLEN  26
#define MAXDTIMELEN     26
#define MAXMONEYLEN     34
#define MAXDATELEN      11

dbdnet/dbdimp.h  view on Meta::CPAN


#define eb1 char
#define ub1 unsigned char
#define ub2 unsigned short
#define ub4 unsigned long
#define sb1 signed char
#define sb2 signed short
#define sb4 signed int
#define sword signed int

typedef enum cursorstate {
	closed,
	prepared,
	described,
	allocated,
	declared,
	opened
} cursorstate;

struct sqlta {
	short sqld;
	struct sqltype_struct *sqltype;
};

typedef struct {
	struct sqlda *udesc;
	struct sqlta *tdesc;
	char *buffer;
	cursorstate is_open;
	int sttmnttype;
	char *statement;
} cursor;

/* Define dbh implementor data structure */
struct imp_dbh_st {
	dbih_dbc_t com;         /* MUST be first element in structure   */

	Lda_Def lda;
	ub1     hda[HDA_SIZE];
};

/* Define sth implementor data structure */

dbdnet/dbdimp.h  view on Meta::CPAN

/*    imp_dbh_t *imp_dbh;
	U32       dbh_generation;
	U16       flags; */

	int is_create,
	is_drop,
	is_delete,
	is_insert,
	is_update;

	/* Current index of statement in cursor index? */
	int cursoridx;
	int row_num;

	/* Input Details	*/
	char      *statement;   /* sql (see sth_scan)		*/
	HV        *bind_names;

	/* Output Details	*/
	int        done_desc;   /* have we described this sth yet ?	*/
	int        fbh_num;     /* number of output fields		*/
	imp_fbh_t *fbh;	    /* array of imp_fbh_t structs	*/

dbdnet/extratests/multicursor.pl  view on Meta::CPAN

#!/usr/bin/perl -w
#
# Tests multiple simultaneous cursors being open
#
# Assuming we have a table of the schema in 'numerics.pl'

$dbname = "test";
$tablename1 = "test3";
$tablename2 = "test2";

use DBI;

$drh = DBI->install_driver( 'Informix' ) || die "Cannot load driver: $!\n";
$dbh = $drh->connect( 'dbhost', $dbname, 'blah', 'blah' );
if ( !defined $dbh ) {
    die "Cannot connect to database: $DBI::errstr\n";
  }

# Open the first cursor
$sth1 = $dbh->prepare( "
    SELECT id1, id2, id3, id4, name
    FROM $tablename1" );
if ( !defined $sth1 ) {
    die "Cannot prepare sth1: $DBI::errstr\n";
  }

# Open the second cursor
$sth2 = $dbh->prepare( "
    SELECT id, name
    FROM $tablename2" );
if ( !defined $sth2 ) {
    die "Cannot prepare sth2: $DBI::errstr\n";
  }

$sth1->execute;
$sth2->execute;

dbdnet/extratests/original_0.20pl0_test.pl  view on Meta::CPAN


DBI->internal->{DebugDispatch} = 0;

$drh = DBI->install_driver( 'Informix' );

$dbh = $drh->connect( $dbhost, $dbname, 'user', 'pass' );
die "Cannot connect to test\n" unless $dbh;

print "*** Preparing SELECT * from systables ***\n";

$cursor = 
    $dbh->prepare( "SELECT * FROM systables" );

$cursor->execute;

print "*** Selecting data as an ary ***\n";

while ( @row = $cursor->fetchrow ) {
    print "Row: @row\n";
  }

$cursor->finish;
undef $cursor;

print "*** Preparing SELECT * FROM systables WHERE tabname = 'systables' ***\n";

$cursor2 = 
    $dbh->prepare( "SELECT tabname, owner
                    FROM systables
                    WHERE tabname = 'systables'" );

$cursor2->execute;

print "*** Selecting data as a list of specified vars ***\n";

while ( ( $tabname, $owner ) = $cursor2->fetchrow ) {
    print "tabname: $tabname\towner: $owner\n";
  }

$cursor2->finish;
undef $cursor2;

$cursor3 = 
    $dbh->do( "CREATE TABLE pants2 ( a INTEGER )" );

$dbh->disconnect;

dbdnet/extratests/primitives.pl  view on Meta::CPAN

#!/usr/bin/perl -w
#
# Exercises the returning of error codes in ESQL/C intermediate step failure

use strict;
use DBI;

my ($drh, $dbh, $cursor, @row ) ;

( $drh = DBI->install_driver( 'Informix' ) )
  or die "not ok: $DBI::errstr\n";
print "Installed\n" ;

( $dbh = $drh->connect('localhost', 'test','','') )
  or die "not ok: $DBI::errstr\n";
print "Connected\n" ;

( $cursor = $dbh->prepare( "SELECT x FROM test" ) )
  or die "not ok: $DBI::errstr\n";
print "Prepared\n" ;

( $cursor->execute )
  or die "not ok: $DBI::errstr\n";
print "Executed\n" ;

( @row = $cursor->fetchrow )
  and print "@row\n"
  or die "not ok: $DBI::errstr\n";
print "Fetched\n" ;

( $cursor->finish )
  or die "not ok: $DBI::errstr\n";
print "Finished\n" ;

undef $cursor;

( $dbh->disconnect )
    and print( "ok\n" )
    or die "not ok: $DBI::errstr\n";
print "Disconnected\n" ;

dbdnet/test.pl  view on Meta::CPAN

print "Testing: \$dbh->do( 'INSERT INTO $testtable VALUES ( 1, 'Alligator Descartes' )' ): ";
( $dbh->do( "INSERT INTO $testtable VALUES( 1, 'Alligator Descartes' )" ) )
    and print( "ok\n" )
    or die "not ok: $DBI::errstr\n";

print "Testing: \$dbh->do( 'DELETE FROM $testtable WHERE id = 1' ): ";
( $dbh->do( "DELETE FROM $testtable WHERE id = 1" ) )
    and print( "ok\n" )
    or die "not ok: $DBI::errstr\n";

print "Testing: \$cursor = \$dbh->prepare( 'SELECT FROM $testtable WHERE id = 1' ): ";
( $cursor = $dbh->prepare( "SELECT * FROM $testtable WHERE id = 1" ) )
    and print( "ok\n" )
    or print( "not ok: $DBI::errstr\n" );

print "Testing: \$cursor->execute: ";
( $cursor->execute )
    and print( "ok\n" )
    or print( "not ok: $DBI::errstr\n" );

print "*** Expect this test to fail with NO error message!\n";
print "Testing: \$cursor->fetchrow: ";
( @row = $cursor->fetchrow ) 
    and print( "ok: $row\n" )
    or print( "not ok: $DBI::errstr\n" );

print "Testing: \$cursor->finish: ";
( $cursor->finish )
    and print( "ok\n" )
    or print( "not ok: $DBI::errstr\n" );

# Temporary bug-plug
undef $cursor;

print "Re-testing: \$dbh->do( 'INSERT INTO $testtable VALUES ( 1, 'Alligator Descartes' )' ): ";
( $dbh->do( "INSERT INTO $testtable VALUES( 1, 'Alligator Descartes' )" ) )
    and print( "ok\n" )
    or die "not ok: $DBI::errstr\n";

print "Re-testing: \$cursor = \$dbh->prepare( 'SELECT FROM $testtable WHERE id = 1' ): ";
( $cursor = $dbh->prepare( "SELECT * FROM $testtable WHERE id = 1" ) )
    and print( "ok\n" )
    or die "not ok: $DBI::errstr\n";

#print "Rows returned should be: 1\nActual rows returned: $numrows\n";

print "Re-testing: \$cursor->execute: ";
( $cursor->execute )
    and print( "ok\n" )
    or die "not ok: $DBI::errstr\n";

print "Re-testing: \$cursor->fetchrow: ";
( @row = $cursor->fetchrow ) 
    and print( "ok\n" )
    or die "not ok: $DBI::errstr\n";

print "Re-testing: \$cursor->finish: ";
( $cursor->finish )
    and print( "ok\n" )
    or die "not ok: $DBI::errstr\n";

# Temporary bug-plug
undef $cursor;

print "Testing: \$dbh->do( 'UPDATE $testtable SET id = 2 WHERE name = 'Alligator Descartes'' ): ";
( $dbh->do( "UPDATE $testtable SET id = 2 WHERE name = 'Alligator Descartes'" ) )
    and print( "ok\n" )
    or die "not ok: $DBI::errstr\n";

print "Re-testing: \$dbh->do( 'DROP TABLE $testtable' ): ";
( $dbh->do( "DROP TABLE $testtable" ) )
    and print( "ok\n" )
    or die "not ok: $DBI::errstr\n";



( run in 0.422 second using v1.01-cache-2.11-cpan-4d50c553e7e )