n_dotsql() - Prepare and execute a SQL statement


#include "tstone.h"

int n_dotsql(ts,stmt,...)
TSQL   *ts;
char   *stmt;

n_dotsql() combines the functionality of n_settsql() and n_exectsql() into one call. It takes the statement format string as in n_settsql() followed by input variable pointers as in n_exectsql(). Any resultant rows are discarded.

It returns the number of rows that were processed on success or -1 on error.

This function is useful for performing one shot statements that don't generate any output or you don't care about the output. Like creating or dropping a table or inserting a single record.


  This example creates a table called docs with the following fields:

  Name    Type       Description
  ----    ----       -----------
  id      counter    a handy unique key field
  text    varchar    the text ocr'd off the image
  thumb   varbyte    a thumbnail of the original image
  image   indirect   the full size image

  Then it inserts one row into it.
TSQL   *ts;
char   *text;
byte   *thumbnail;
size_t  nthumbnail;
char   *imagefile;
int     nrows;

   if(n_dotsql(ts,"create table docs(id counter,text varchar(1000),
                      thumbnail varbyte,imagefile indirect);")>=0)
                     "insert into docs values (counter, %s, %p%n, %<);",


n_settsql(), n_exectsql()

Copyright © Thunderstone Software     Last updated: May 19 2023
Copyright © 2023 Thunderstone Software LLC. All rights reserved.