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

  1. /*
  2.  *  Program type:   Embedded Static SQL
  3.  *
  4.  *  Description:
  5.  *        This program updates a blob data type.
  6.  *        Project descriptions are added for a set of projects.
  7.  * The contents of this file are subject to the Interbase Public
  8.  * License Version 1.0 (the "License"); you may not use this file
  9.  * except in compliance with the License. You may obtain a copy
  10.  * of the License at http://www.Inprise.com/IPL.html
  11.  *
  12.  * Software distributed under the License is distributed on an
  13.  * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
  14.  * or implied. See the License for the specific language governing
  15.  * rights and limitations under the License.
  16.  *
  17.  * The Original Code was created by Inprise Corporation
  18.  * and its predecessors. Portions created by Inprise Corporation are
  19.  *
  20.  * Copyright (C) 2000 Inprise Corporation
  21.  * All Rights Reserved.
  22.  * Contributor(s): ______________________________________.
  23.  */
  24.  
  25. #include "example.h"
  26. #include <stdlib.h>
  27. #include <string.h>
  28. #include <stdio.h>
  29.  
  30. char *get_line (void);
  31.  
  32. static char *Proj_data[] =
  33. {
  34.     "VBASE",
  35.         "Design a video data base management system for ",
  36.         "controlling on-demand video distribution.",
  37.         0,
  38.     "DGPII",
  39.         "Develop second generation digital pizza maker ",
  40.         "with flash-bake heating element and ",
  41.         "digital ingredient measuring system.",
  42.         0,
  43.     "GUIDE",
  44.         "Develop a prototype for the automobile version of ",
  45.         "the hand-held map browsing device.",
  46.         0,
  47.     "MAPDB",
  48.         "Port the map browsing database software to run ",
  49.         "on the automobile model.",
  50.         0,
  51.     "HWRII",
  52.         "Integrate the hand-writing recognition module into the ",
  53.         "universal language translator.",
  54.         0,
  55.     0
  56. };
  57. int Inp_ptr = 0;
  58.  
  59. EXEC SQL
  60.     BEGIN DECLARE SECTION;
  61. EXEC SQL
  62.     END DECLARE SECTION;
  63.  
  64.  
  65. int main (void)
  66. {
  67.     BASED_ON project.proj_id    proj_id;
  68.     ISC_QUAD    blob_id;
  69.     int        len;
  70.     char ISC_FAR *    line; 
  71.     int        rec_cnt = 0;
  72.  
  73.     EXEC SQL
  74.         WHENEVER SQLERROR GO TO Error;
  75.  
  76.     /* Declare a blob insert cursor. */
  77.     EXEC SQL
  78.         DECLARE bc CURSOR FOR
  79.         INSERT BLOB proj_desc INTO project;
  80.  
  81.     /*
  82.      *  Get the next project id and update the project description.
  83.      */
  84.     line = get_line();
  85.     while (line)
  86.     {
  87.         /* Open the blob cursor. */
  88.         EXEC SQL
  89.             OPEN bc INTO :blob_id;
  90.  
  91.         strcpy(proj_id, line);
  92.         printf("\nUpdating description for project:  %s\n\n", proj_id);
  93.  
  94.         /* Get a project description segment. */
  95.         line = get_line();    
  96.         while (line)
  97.         {
  98.             printf("  Inserting segment:  %s\n", line);
  99.  
  100.             /* Calculate the length of the segment. */
  101.             len = strlen(line);
  102.  
  103.             /* Write the segment. */
  104.             EXEC SQL INSERT CURSOR bc VALUES (:line INDICATOR :len);
  105.             line = get_line();
  106.         }
  107.  
  108.         /* Close the blob cursor. */
  109.         EXEC SQL
  110.             CLOSE bc;
  111.  
  112.         /* Save the blob id in the project record. */
  113.         EXEC SQL
  114.             UPDATE project
  115.             SET proj_desc = :blob_id
  116.             WHERE proj_id = :proj_id;
  117.  
  118.         if (SQLCODE == 0L)
  119.             rec_cnt++;
  120.         else
  121.             printf("Input error -- no project record with key: %s\n", proj_id);
  122.         line = get_line();
  123.     }
  124.  
  125.     EXEC SQL
  126.         COMMIT RELEASE;
  127.  
  128.     printf("\n\nAdded %d project descriptions.\n", rec_cnt);
  129. return 0;
  130.         
  131. Error:
  132.     isc_print_sqlerror((short) SQLCODE, isc_status);
  133. return 1;
  134. }
  135.  
  136.  
  137. /*
  138.  *    Get the next input line, which is either a project id
  139.  *    or a project description segment.
  140.  */
  141. char *get_line (void)
  142. {
  143.     return Proj_data[Inp_ptr++];
  144. }
  145.  
  146.