home *** CD-ROM | disk | FTP | other *** search
/ Freelog 42 / Freelog042.iso / Alu / Ancestrologie / Sources / InterBase_WI-V6.0.1-server.ZIP / examples / gpre / stat1.e < prev    next >
Encoding:
Text File  |  2001-01-05  |  2.2 KB  |  102 lines

  1. /*
  2.  *    Program type:   Embedded Static SQL
  3.  *
  4.  *    Description:
  5.  *        This program performs a simple update to an existing
  6.  *        table, asks the user whether to save the update, and
  7.  *        commits or undoes the transaction accordingly.
  8.  * The contents of this file are subject to the Interbase Public
  9.  * License Version 1.0 (the "License"); you may not use this file
  10.  * except in compliance with the License. You may obtain a copy
  11.  * of the License at http://www.Inprise.com/IPL.html
  12.  *
  13.  * Software distributed under the License is distributed on an
  14.  * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
  15.  * or implied. See the License for the specific language governing
  16.  * rights and limitations under the License.
  17.  *
  18.  * The Original Code was created by Inprise Corporation
  19.  * and its predecessors. Portions created by Inprise Corporation are
  20.  *
  21.  * Copyright (C) 2000 Inprise Corporation
  22.  * All Rights Reserved.
  23.  * Contributor(s): ______________________________________.
  24.  */
  25.  
  26. #include "example.h"
  27. #include <stdio.h>
  28. #include <stdlib.h>
  29.  
  30. int do_save (void);
  31. void clean_up (void);
  32.  
  33. EXEC SQL    
  34.     BEGIN DECLARE SECTION;
  35. EXEC SQL    
  36.     END DECLARE SECTION;
  37.  
  38.  
  39. int main (void)
  40. {
  41.     clean_up();
  42.  
  43.     /* Insert a new row. */
  44.     EXEC SQL
  45.         INSERT INTO country (country, currency)
  46.         VALUES ('Mexico', 'Peso');
  47.  
  48.     /* Check the SQLCODE directly */
  49.     if (SQLCODE)
  50.     {
  51.         isc_print_sqlerror((short)SQLCODE, gds__status);
  52.         exit(1);
  53.     }
  54.  
  55.     printf("\nAdding:  country = 'Mexico', currency = 'Peso'\n\n");
  56.  
  57.     /* Confirm whether to commit the update. */
  58.     if (do_save())
  59.     {
  60.         EXEC SQL
  61.             COMMIT RELEASE;
  62.         printf("\nSAVED.\n\n");
  63.     }
  64.     else
  65.     {
  66.         EXEC SQL
  67.             ROLLBACK RELEASE;
  68.         printf("\nUNDONE.\n\n");
  69.     }
  70. return 0;
  71. }
  72.  
  73.  
  74. /*
  75.  *    Ask the user whether to save the newly added row.
  76.  */
  77. int do_save (void)
  78. {
  79.     char    answer[10];
  80.  
  81.     printf("Save?  Enter 'y' for yes, 'n' for no:  ");
  82.     gets(answer);
  83.  
  84.     return (*answer == 'y' ? 1 : 0);
  85. }
  86.  
  87.  
  88. /*
  89.  *    If this is not the first time this program is run,
  90.  *    the example row may already exist -- delete the example
  91.  *    row in order to avoid a duplicate value error.
  92.  */
  93. void clean_up (void)
  94. {
  95.     EXEC SQL
  96.         DELETE FROM country
  97.         WHERE country =  'Mexico';
  98.  
  99.     EXEC SQL
  100.         COMMIT WORK;
  101. }
  102.