n_settexisparam(), n_paramtx(), n_resetparamtx() - SQL interface

SYNOPSIS

int 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:

SERVER *se
The open server connection.
TX *tx
The prepared SQL statement (n_paramtx() only).
int ipar
The number of the parameter, starting at 1.
void *buf
A pointer to the data to be transmitted.
int *len
A pointer to the length of the data. This can be (int *)NULL to use the default length, which assumes a '\0' terminated string for character data.
int ctype
The type of the data. For text use SQL_C_CHAR.
int sqltype
The type of the field being inserted into. For varchar use SQL_LONGVARCHAR.

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


EXAMPLE

SERVER *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");
   ...


EXAMPLE

SERVER *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); }
   ...


Copyright © Thunderstone Software     Last updated: Apr 15 2024
Copyright © 2024 Thunderstone Software LLC. All rights reserved.