n_dotsql() - Prepare and execute a SQL statement

SYNOPSIS

#include "tstone.h"

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


DESCRIPTION
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.


EXAMPLE

/*
  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.
*/
SERVER *se;
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)
   {
      ...
      nrows=n_dotsql(ts,
                     "insert into docs values (counter, %s, %p%n, %<);",
                     text,thumbnail,nthumbnail,imagefile);
   }
   ...


SEE ALSO

n_settsql(), n_exectsql()


Copyright © Thunderstone Software     Last updated: Dec 10 2018
Copyright © 2019 Thunderstone Software LLC. All rights reserved.