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

  1. /*
  2.  *  Program type:   Embedded Static SQL
  3.  *
  4.  *  Description:
  5.  *        This program selects a blob data type.
  6.  *        A set of project descriptions is printed.
  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 <stdio.h>
  28.  
  29. EXEC SQL
  30.     BEGIN DECLARE SECTION;
  31.  
  32. BASED ON project.proj_name            proj_name;
  33. BASED ON project.product            prod_type;
  34.  
  35. BASED ON project.proj_desc            blob_id;
  36. BASED ON project.proj_desc.SEGMENT        blob_segment;
  37. unsigned short                    blob_seg_len;
  38.  
  39. EXEC SQL
  40.     END DECLARE SECTION;
  41.  
  42.  
  43. int main (void)
  44. {
  45.     EXEC SQL
  46.         WHENEVER SQLERROR GO TO Error;
  47.  
  48.     /* Declare a table read cursor. */
  49.     EXEC SQL
  50.         DECLARE proj_cur CURSOR FOR
  51.         SELECT proj_name, proj_desc, product
  52.         FROM project
  53.         WHERE product IN ('software', 'hardware', 'other')
  54.         ORDER BY proj_name;
  55.  
  56.     /* Declare a blob read cursor. */
  57.     EXEC SQL
  58.         DECLARE blob_cur CURSOR FOR
  59.         READ BLOB proj_desc
  60.         FROM project;
  61.  
  62.     /* Open the table cursor. */
  63.     EXEC SQL
  64.         OPEN proj_cur;
  65.  
  66.     /*
  67.      *  For each project get and display project description.
  68.      */
  69.  
  70.     while (SQLCODE == 0)
  71.     {
  72.         /* Fetch the blob id along with some other columns. */
  73.         EXEC SQL
  74.             FETCH proj_cur INTO :proj_name, :blob_id, :prod_type;
  75.  
  76.         if (SQLCODE == 100)
  77.             break;
  78.  
  79.         printf("\nPROJECT:  %-30s   TYPE:  %-15s\n\n", proj_name, prod_type);
  80.  
  81.         /* Open the blob cursor. */
  82.         EXEC SQL
  83.             OPEN blob_cur USING :blob_id;
  84.  
  85.         while (SQLCODE == 0)
  86.         {
  87.             /* Fetch a blob segment and a blob segment length. */
  88.             EXEC SQL FETCH blob_cur INTO :blob_segment :blob_seg_len;
  89.  
  90.             if (SQLCODE == 100)
  91.                 break;
  92.  
  93.             printf("  %*.*s\n", blob_seg_len, blob_seg_len, blob_segment);
  94.         }
  95.         printf("\n");
  96.  
  97.         /* Close the blob cursor. */
  98.         EXEC SQL
  99.             CLOSE blob_cur;
  100.     }
  101.  
  102.     EXEC SQL
  103.         CLOSE proj_cur;
  104.  
  105.     EXEC SQL
  106.         COMMIT;
  107.  
  108. return 0;
  109.  
  110. Error:
  111.     isc_print_sqlerror((short) SQLCODE, gds__status);
  112. return 1;
  113. }
  114.  
  115.