home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 January / Chip_2001-01_cd1.bin / tema / interb / InterBase_WI-V6.0-server.exe / server / examples / gpre / stat8.e < prev    next >
Text File  |  2000-06-23  |  4KB  |  149 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.Interbase.com/IPL/
  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 Interbase Software Corporation
  18.  * and its successors. Portions created by Borland/Inprise are
  19.  * Copyright (C) 1992-1998 and 1999-2000 Borland/Inprise. Portions
  20.  * created by InterBase Software Corporation are Copyright (C)
  21.  * 1998-1999 InterBase Software Corporation.
  22.  *
  23.  * Copyright (C) 2000 InterBase Software Corporation
  24.  * All Rights Reserved.
  25.  * Contributor(s): ______________________________________.
  26.  */
  27.  
  28. #include "example.h"
  29. #include <stdlib.h>
  30. #include <string.h>
  31. #include <stdio.h>
  32.  
  33. char *get_line (void);
  34.  
  35. static char *Proj_data[] =
  36. {
  37.     "VBASE",
  38.         "Design a video data base management system for ",
  39.         "controlling on-demand video distribution.",
  40.         0,
  41.     "DGPII",
  42.         "Develop second generation digital pizza maker ",
  43.         "with flash-bake heating element and ",
  44.         "digital ingredient measuring system.",
  45.         0,
  46.     "GUIDE",
  47.         "Develop a prototype for the automobile version of ",
  48.         "the hand-held map browsing device.",
  49.         0,
  50.     "MAPDB",
  51.         "Port the map browsing database software to run ",
  52.         "on the automobile model.",
  53.         0,
  54.     "HWRII",
  55.         "Integrate the hand-writing recognition module into the ",
  56.         "universal language translator.",
  57.         0,
  58.     0
  59. };
  60. int Inp_ptr = 0;
  61.  
  62. EXEC SQL
  63.     BEGIN DECLARE SECTION;
  64. EXEC SQL
  65.     END DECLARE SECTION;
  66.  
  67.  
  68. int main (void)
  69. {
  70.     BASED_ON project.proj_id    proj_id;
  71.     ISC_QUAD    blob_id;
  72.     int        len;
  73.     char ISC_FAR *    line; 
  74.     int        rec_cnt = 0;
  75.  
  76.     EXEC SQL
  77.         WHENEVER SQLERROR GO TO Error;
  78.  
  79.     /* Declare a blob insert cursor. */
  80.     EXEC SQL
  81.         DECLARE bc CURSOR FOR
  82.         INSERT BLOB proj_desc INTO project;
  83.  
  84.     /*
  85.      *  Get the next project id and update the project description.
  86.      */
  87.     line = get_line();
  88.     while (line)
  89.     {
  90.         /* Open the blob cursor. */
  91.         EXEC SQL
  92.             OPEN bc INTO :blob_id;
  93.  
  94.         strcpy(proj_id, line);
  95.         printf("\nUpdating description for project:  %s\n\n", proj_id);
  96.  
  97.         /* Get a project description segment. */
  98.         line = get_line();    
  99.         while (line)
  100.         {
  101.             printf("  Inserting segment:  %s\n", line);
  102.  
  103.             /* Calculate the length of the segment. */
  104.             len = strlen(line);
  105.  
  106.             /* Write the segment. */
  107.             EXEC SQL INSERT CURSOR bc VALUES (:line INDICATOR :len);
  108.             line = get_line();
  109.         }
  110.  
  111.         /* Close the blob cursor. */
  112.         EXEC SQL
  113.             CLOSE bc;
  114.  
  115.         /* Save the blob id in the project record. */
  116.         EXEC SQL
  117.             UPDATE project
  118.             SET proj_desc = :blob_id
  119.             WHERE proj_id = :proj_id;
  120.  
  121.         if (SQLCODE == 0L)
  122.             rec_cnt++;
  123.         else
  124.             printf("Input error -- no project record with key: %s\n", proj_id);
  125.         line = get_line();
  126.     }
  127.  
  128.     EXEC SQL
  129.         COMMIT RELEASE;
  130.  
  131.     printf("\n\nAdded %d project descriptions.\n", rec_cnt);
  132. return 0;
  133.         
  134. Error:
  135.     isc_print_sqlerror((short) SQLCODE, isc_status);
  136. return 1;
  137. }
  138.  
  139.  
  140. /*
  141.  *    Get the next input line, which is either a project id
  142.  *    or a project description segment.
  143.  */
  144. char *get_line (void)
  145. {
  146.     return Proj_data[Inp_ptr++];
  147. }
  148.  
  149.