SYNOPSISint n_settexisparam(se, ipar, buf, len, ctype, sqltype)
SERVER *se;
int ipar;
void *buf;
int *len;
int ctype;
int sqltype;
int n_paramtx(se, tx, ipar, buf, len, ctype, sqltype)
SERVER *se;
TX *tx;
int ipar;
void *buf;
int *len;
int ctype;
int sqltype;
int n_resetparamtx(se, tx)
SERVER *se;
TX *tx;
DESCRIPTION
These functions allow you to pass arbitrarily large or complex data into
a SQL statement. Sometimes there is data that won't work in the confines
of the simple C string that comprises an SQL statement. Large text fields
or binary data for example.
Call n_settexisparam()
to setup the parameter data before calling
n_texis()
or n_settx()
to prepare the SQL statement.
Call n_paramtx()
to setup parameters after n_preptx()
and
before n_exectx()
. If you have a statement you have already
executed once, and you want to execute again with different data, which
may have parameters unset which were previously unset you can call
n_resetparamtx()
. This is not neccessary if you will explicitly
set all the parameters.
Place a question mark (?
) in the SQL statement where you would
otherwise place the data.
These are the parameters:
n_paramtx()
only).
(int *)NULL
to use the default length, which
assumes a '\0'
terminated string for
character data.
Field type | sqltype | ctype | C type |
varchar | SQL_LONGVARCHAR | SQL_C_CHAR | char |
varbyte | SQL_BINARY | SQL_C_BINARY | byte |
date | SQL_DATE | SQL_C_LONG | long |
integer | SQL_INTEGER | SQL_C_INTEGER | long |
smallint | SQL_SMALLINT | SQL_C_SHORT | short |
float | SQL_FLOAT | SQL_C_FLOAT | float |
double | SQL_DOUBLE | SQL_C_DOUBLE | double |
varind | SQL_LONGVARCHAR | SQL_C_CHAR | char |
counter | SQL_COUNTER | SQL_C_COUNTER | ft_counter |
EXAMPLESERVER *se;
TX *tx;
char *description;
char *article;
int len;
...
description="a really large article";
article=...
len=...
if(!n_settexisparam(se,1,article,&len, SQL_C_CHAR, SQL_LONGVARCHAR))
puts("n_settexisparam failed");
else
if(!n_texis(se,"insert into docs values('%s',?);",description))
puts("insert failed");
...
EXAMPLESERVER *se;
TX *tx;
char *description;
char *article;
int lend, lena;
if(!n_preptx(se,tx,"insert into docs values(?,?);"))
{ puts("n_preptx Failed"); return(0); }
...
description="a really large article";
lend=strlen(description);
article=...
lena=strlen(article);
if(!n_paramtx(se,tx,1,description,&lend,SQL_C_CHAR,SQL_LONGVARCHAR)||
!n_paramtx(se,tx,2,article ,&lena,SQL_C_CHAR,SQL_LONGVARCHAR));
{ puts("n_paramtx Failed"); return(0); }
if(!n_exectx(se,tx))
{ puts("n_exectx Failed"); return(0); }
...