community.borland.com

Article #25432: API example of deleting a record

Problem:
Looking for a working api example of deleting a record.


Solution:
Here is an api example of deleting a record.

1) Copy and paste the following source into a source file.  For example, I 
     can create a file named, test.c, with the following source.

--------------------------------------------

#include 
#include 
#include 
#include 


 long dbStatus[32], SQLCODE;

void tsetsqlcode(char *msg)
{
  SQLCODE = isc_sqlcode(dbStatus);
  if (SQLCODE)  {
    fprintf(stderr, "SQL err %ld doing %sn", SQLCODE, msg);
    exit(1);
}  }

int main()
{
  isc_db_handle          db = 0;
  isc_tr_handle	           tr = 0;
  isc_stmt_handle       stmt= 0;
  char	          sqlstring[50], cnt_info[2], string[1024], dpb[256];
  int                                 dpb_len;

  // set up the dpb - database parameter buffer
  char *p_dpb = dpb;

  *p_dpb = isc_dpb_version1;   p_dpb++;

  *p_dpb = isc_dpb_user_name;  p_dpb++;
  *p_dpb = strlen("sysdba");  p_dpb++;
   strcpy(p_dpb, "sysdba");   p_dpb += strlen("sysdba");

  *p_dpb = isc_dpb_password;       p_dpb++;
  *p_dpb = strlen("masterkey"); p_dpb++;
  strcpy(p_dpb, "masterkey");   p_dpb += strlen("masterkey");

  dpb_len = p_dpb - dpb;

  strcpy(sqlstring, "employee.gdb");
  tsetsqlcode("opening db");
  (void) isc_attach_database(dbStatus, 0, sqlstring, &db, dpb_len, &dpb[0]);
  tsetsqlcode("starting transaction");
  (void) isc_start_transaction(dbStatus, &tr, 1, &db, 0, 0);
  tsetsqlcode("executing immed");
  strcpy(sqlstring, "delete from sales where po_number = 'V91E0210' ");
  isc_dsql_execute_immediate(dbStatus, &db, &tr, 0, sqlstring, 1, 0);
  tsetsqlcode("commit");
  (void) isc_commit_transaction(dbStatus, &tr);
  tsetsqlcode("closing db");
  (void) isc_detach_database(dbStatus, &db);
  exit(0);
}
-------------------------------------------
Notes:  

1) Be sure to include a WHERE clause in the DELETE statament 
     to limit the number of records deleted or the entire table will 
     have all of the reocrds in it deleted.

2) Before compile, be sure to have a copy of employee.gdb in 
     the same directory as the source file.

3) Compile and link the source file on your favorite platform.  
    See www.interbase.com for more details on compiling and 
    linking on the various platforms.

Example of compiling & linking under the Solaris platform:

%cc -w -c test.c
%cc test.o -o test -lgdsmt -lsocket -lthread -lnsl -ldl

3)  Run the program.

Example:

%test



Last Modified: 18-OCT-00