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

  1. /*
  2.  *  Program type:   Embedded Static SQL
  3.  *    
  4.  *  Description:
  5.  *        This program selects an array data type.
  6.  *        Projected head count is displayed for the 4
  7.  *        quarters of some fiscal year for some project,
  8.  *        ordered by department name.
  9.  * The contents of this file are subject to the Interbase Public
  10.  * License Version 1.0 (the "License"); you may not use this file
  11.  * except in compliance with the License. You may obtain a copy
  12.  * of the License at http://www.Inprise.com/IPL.html
  13.  *
  14.  * Software distributed under the License is distributed on an
  15.  * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
  16.  * or implied. See the License for the specific language governing
  17.  * rights and limitations under the License.
  18.  *
  19.  * The Original Code was created by Inprise Corporation
  20.  * and its predecessors. Portions created by Inprise Corporation are
  21.  *
  22.  * Copyright (C) 2000 Inprise Corporation
  23.  * All Rights Reserved.
  24.  * Contributor(s): ______________________________________.
  25.  */
  26.  
  27. #include "example.h"
  28. #include <stdlib.h>
  29. #include <stdio.h>
  30.  
  31. EXEC SQL
  32.     BEGIN DECLARE SECTION;
  33. EXEC SQL
  34.     END DECLARE SECTION;
  35.  
  36.  
  37. int main (void)
  38. {
  39.     BASED_ON department.department                department;
  40.     BASED_ON proj_dept_budget.quart_head_cnt    hcnt;
  41.     BASED_ON proj_dept_budget.quart_head_cnt    tot;
  42.  
  43.     int        fiscal_year = 1994;                /* year parameter */
  44.     char    *project = "VBASE";                /* project parameter */
  45.     short    i;
  46.  
  47.     EXEC SQL
  48.         WHENEVER SQLERROR GO TO Error;
  49.  
  50.     /*
  51.      *    Declare a cursor for selecting an array, given 2
  52.      *    2 parameters (year and project).
  53.      */
  54.     EXEC SQL
  55.         DECLARE proj_cnt CURSOR FOR
  56.         SELECT department, quart_head_cnt[]
  57.         FROM proj_dept_budget p, department d
  58.         WHERE p.dept_no = d.dept_no
  59.         AND year = :fiscal_year
  60.         AND proj_id = :project
  61.         ORDER BY department;
  62.  
  63.     printf("\n\t\t\tPROJECTED HEAD-COUNT REPORT\n");
  64.     printf("\t\t\t      (by department)\n\n");
  65.     printf("FISCAL YEAR:  %d\n", fiscal_year);
  66.     printf("PROJECT ID :  %s\n\n\n", project);
  67.  
  68.     printf("%-25s%10s%10s%10s%10s\n\n",
  69.             "DEPARTMENT", "QTR1", "QTR2", "QTR3", "QTR4");
  70.  
  71.     /* Initialize quarterly totals. */
  72.     for (i = 0; i < 4; i++)    
  73.         tot[i] = 0;
  74.     
  75.     EXEC SQL
  76.         OPEN proj_cnt;
  77.  
  78.     /* Get and display each department's counts. */
  79.     while (SQLCODE == 0)
  80.     {
  81.         EXEC SQL
  82.             FETCH proj_cnt INTO :department, :hcnt;
  83.  
  84.         if (SQLCODE == 100)
  85.             break;
  86.  
  87.         printf("%-25s%10ld%10ld%10ld%10ld\n",
  88.                     department, hcnt[0], hcnt[1], hcnt[2], hcnt[3]);
  89.         
  90.         for (i = 0; i < 4; i++)
  91.             tot[i] += hcnt[i];
  92.     }
  93.  
  94.     /* Display quarterly totals. */
  95.     printf("\n%-25s%10ld%10ld%10ld%10ld\n\n",
  96.                     "TOTAL", tot[0], tot[1], tot[2], tot[3]);
  97.  
  98.     EXEC SQL
  99.         CLOSE proj_cnt;
  100.  
  101.     EXEC SQL
  102.         COMMIT WORK;
  103.  
  104. return 0;
  105.         
  106. Error:
  107.     isc_print_sqlerror((short) SQLCODE, gds__status);
  108. return 1;
  109. }
  110.  
  111.