SYNOPSIS#include "tstone.h"
int n_resulttsql(ts,flag)
TSQL *ts;
int flag;
DESCRIPTIONn_resulttsql()
controls the reporting of resultant rows from SQL
INSERT
and DELETE
statements. By default INSERT
and DELETE
will not
report back the affected rows. Calling this function with flag
set to 1
will enable the reporting of affected rows. You then
must use n_gettsql()
to retrieve rows as with SELECT
s.
n_resulttsql()
must be called before n_settsql()
.
Pass flag
as 0
to disable report of the affected rows.
SELECT
statements always return matching rows, regardless of this
setting. n_dotsql()
is unaffected by this call. Results are
always suppressed.
n_resulttsql()
returns the previous flag
setting. There is
no error return.
EXAMPLETSQL *ts;
long when;
long date;
char *query;
...
/* delete rows without seeing them */
if(n_settsql(ts,"delete from history where Date<%lu;"))
{
when=time((time_t *)NULL); /* get current time */
when-=7*86400; /* subtract 7 days */
n_exectsql(ts,when); /* perform deletion */
}
...
/* delete rows and see them */
n_resulttsql(ts,1);
if(n_settsql(ts,"delete from history where Date<%lu;"))
{
when=time((time_t *)NULL); /* get current time */
when-=7*86400; /* subtract 7 days */
if(n_exectsql(ts,when)) /* perform deletion */
{
while(n_gettsql(ts,"%lu %s",&date,&query);
{
printf("%lu %s\n",date,query);
free(query);
}
}
}
...
SEE ALSOn_settsql()