stat6.e 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. * Copyright (C) Inprise Corporation.
  22. *
  23. * All Rights Reserved.
  24. * Contributor(s): ______________________________________.
  25. */
  26. #include "example.h"
  27. #include <stdlib.h>
  28. #include <stdio.h>
  29. EXEC SQL
  30. BEGIN DECLARE SECTION;
  31. EXEC SQL
  32. END DECLARE SECTION;
  33. int main (void)
  34. {
  35. BASED_ON department.department department;
  36. BASED_ON proj_dept_budget.quart_head_cnt hcnt;
  37. BASED_ON proj_dept_budget.quart_head_cnt tot;
  38. int fiscal_year = 1994; /* year parameter */
  39. char *project = "VBASE"; /* project parameter */
  40. short i;
  41. EXEC SQL
  42. WHENEVER SQLERROR GO TO Error;
  43. /*
  44. * Declare a cursor for selecting an array, given 2
  45. * 2 parameters (year and project).
  46. */
  47. EXEC SQL
  48. DECLARE proj_cnt CURSOR FOR
  49. SELECT department, quart_head_cnt[]
  50. FROM proj_dept_budget p, department d
  51. WHERE p.dept_no = d.dept_no
  52. AND year = :fiscal_year
  53. AND proj_id = :project
  54. ORDER BY department;
  55. printf("\n\t\t\tPROJECTED HEAD-COUNT REPORT\n");
  56. printf("\t\t\t (by department)\n\n");
  57. printf("FISCAL YEAR: %d\n", fiscal_year);
  58. printf("PROJECT ID : %s\n\n\n", project);
  59. printf("%-25s%10s%10s%10s%10s\n\n",
  60. "DEPARTMENT", "QTR1", "QTR2", "QTR3", "QTR4");
  61. /* Initialize quarterly totals. */
  62. for (i = 0; i < 4; i++)
  63. tot[i] = 0;
  64. EXEC SQL
  65. OPEN proj_cnt;
  66. /* Get and display each department's counts. */
  67. while (SQLCODE == 0)
  68. {
  69. EXEC SQL
  70. FETCH proj_cnt INTO :department, :hcnt;
  71. if (SQLCODE == 100)
  72. break;
  73. printf("%-25s%10ld%10ld%10ld%10ld\n",
  74. department, hcnt[0], hcnt[1], hcnt[2], hcnt[3]);
  75. for (i = 0; i < 4; i++)
  76. tot[i] += hcnt[i];
  77. }
  78. /* Display quarterly totals. */
  79. printf("\n%-25s%10ld%10ld%10ld%10ld\n\n",
  80. "TOTAL", tot[0], tot[1], tot[2], tot[3]);
  81. EXEC SQL
  82. CLOSE proj_cnt;
  83. EXEC SQL
  84. COMMIT WORK;
  85. return 0;
  86. Error:
  87. isc_print_sqlerror((short) SQLCODE, gds__status);
  88. return 1;
  89. }