freetds AT lists.ibiblio.org
Subject: FreeTDS Development Group
List archive
- From: Michael Peppler <mpeppler AT peppler.org>
- To: "TDS Development Group" <freetds AT franklin.oit.unc.edu>
- Subject: Re: Draft 0.52 announcement
- Date: Wed, 27 Jun 2001 17:20:23 -0700
Brian Bruns writes:
>
> Of course, someone really interested in pushing placeholder support
> forward could send me small standalone C programs that demonstrate the
> usage in ctlib and/or ODBC and I'll see that it gets done. ;-)
Here's a minimal C snippet that I used to report a bug to Sybase...
Michael
----- First the "prepare" section:
ct_dynamic(cmd, CS_PREPARE, "BUG", CS_NULLTERM,
"insert tempdb..prepare_bug values(?, ?, ?, ?)", CS_NULLTERM);
if(ct_send(cmd) != CS_SUCCEED)
croak("ct_send failed in prepare");
while(ct_results(cmd, &restype) == CS_SUCCEED)
;
---- Sybase has now created a temporary stored proc
---- now - describe the parameters
ct_dynamic(cmd, CS_DESCRIBE_INPUT, "BUG",
CS_NULLTERM, NULL, CS_UNUSED);
ct_send(cmd);
while(ct_results(cmd, &restype) == CS_SUCCEED) {
if(restype == CS_DESCRIBE_RESULT) {
CS_INT num_param, outlen;
int i;
ct_res_info(cmd, CS_NUMDATA, &num_param, CS_UNUSED,
&outlen);
for(i = 1; i <= num_param; ++i) {
ct_describe(cmd, i, &datafmt[i-1]);
}
}
}
---- Now we have CS_DATAFMT struct for each of the input params
---- to the request.
---- so we can execute it with some parameters
execute(cmd, "BUG", &datafmt[0], "test", "Jan 1 1988", 123.4, 222.334);
where execute() looks like this:
void execute(
CS_COMMAND *cmd
, char *id
, CS_DATAFMT *datafmt
, char *p1
, char *p2
, double p3
, double p4
) {
CS_INT restype;
printf("execute called with %s, %s, %f, %f\n", p1, p2, p3, p4);
ct_dynamic(cmd, CS_EXECUTE, id, CS_NULLTERM,
NULL, CS_UNUSED);
datafmt[0].datatype = CS_CHAR_TYPE;
// printf("length value = %d\n", datafmt[0].maxlength);
ct_param(cmd, &datafmt[0], p1, CS_NULLTERM, 0);
datafmt[1].datatype = CS_CHAR_TYPE;
ct_param(cmd, &datafmt[1], p2, CS_NULLTERM, 0);
datafmt[2].datatype = CS_FLOAT_TYPE;
ct_param(cmd, &datafmt[2], &p3, sizeof(double), 0);
datafmt[3].datatype = CS_FLOAT_TYPE;
ct_param(cmd, &datafmt[3], &p4, sizeof(double), 0);
ct_send(cmd);
---- from now on it's a standard fetch all results loop...
while(ct_results(cmd, &restype) == CS_SUCCEED) {
printf("got restype %d\n", restype);
if(restype == CS_ROW_RESULT) {
int numcols, rows;
char string[20];
int i, len, ind, ival;
CS_DATAFMT output[2];
ct_res_info(cmd, CS_NUMDATA,
&numcols, CS_UNUSED, NULL);
for(i = 0; i < numcols; ++i) {
ct_describe(cmd, (i + 1),
&output[i]);
if(output[i].datatype == CS_CHAR_TYPE) {
ct_bind(cmd, (i + 1), &output[i],
&string, &len, &ind);
} else {
ct_bind(cmd, (i + 1), &output[i],
&ival, &len, &ind);
}
}
while(ct_fetch(cmd, CS_UNUSED, CS_UNUSED, CS_UNUSED, &rows) ==
CS_SUCCEED) {
printf("data = %.3s - %d\n", string, ival);
}
}
}
}
-
Draft 0.52 announcement,
Brian Bruns, 06/26/2001
- <Possible follow-up(s)>
- Re: Draft 0.52 announcement, Devin, 06/26/2001
- Re: Draft 0.52 announcement, Steve Langasek, 06/27/2001
- Re: Draft 0.52 announcement, Ryan Gendron, 06/27/2001
- Re: Draft 0.52 announcement, Brian Bruns, 06/27/2001
- Re: Draft 0.52 announcement, Michael Peppler, 06/27/2001
- Re: Draft 0.52 announcement, Brian Bruns, 06/27/2001
- Re: Draft 0.52 announcement, Brian Bruns, 06/27/2001
Archive powered by MHonArc 2.6.24.