stat8.e 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. * Copyright (C) Inprise Corporation.
  20. *
  21. * All Rights Reserved.
  22. * Contributor(s): ______________________________________.
  23. */
  24. #include "example.h"
  25. #include <stdlib.h>
  26. #include <string.h>
  27. #include <stdio.h>
  28. char *get_line (void);
  29. static char *Proj_data[] =
  30. {
  31. "VBASE",
  32. "Design a video data base management system for ",
  33. "controlling on-demand video distribution.",
  34. 0,
  35. "DGPII",
  36. "Develop second generation digital pizza maker ",
  37. "with flash-bake heating element and ",
  38. "digital ingredient measuring system.",
  39. 0,
  40. "GUIDE",
  41. "Develop a prototype for the automobile version of ",
  42. "the hand-held map browsing device.",
  43. 0,
  44. "MAPDB",
  45. "Port the map browsing database software to run ",
  46. "on the automobile model.",
  47. 0,
  48. "HWRII",
  49. "Integrate the hand-writing recognition module into the ",
  50. "universal language translator.",
  51. 0,
  52. 0
  53. };
  54. int Inp_ptr = 0;
  55. EXEC SQL
  56. BEGIN DECLARE SECTION;
  57. EXEC SQL
  58. END DECLARE SECTION;
  59. int main (void)
  60. {
  61. BASED_ON project.proj_id proj_id;
  62. ISC_QUAD blob_id;
  63. int len;
  64. char * line;
  65. int rec_cnt = 0;
  66. EXEC SQL
  67. WHENEVER SQLERROR GO TO Error;
  68. /* Declare a blob insert cursor. */
  69. EXEC SQL
  70. DECLARE bc CURSOR FOR
  71. INSERT BLOB proj_desc INTO project;
  72. /*
  73. * Get the next project id and update the project description.
  74. */
  75. line = get_line();
  76. while (line)
  77. {
  78. /* Open the blob cursor. */
  79. EXEC SQL
  80. OPEN bc INTO :blob_id;
  81. strcpy(proj_id, line);
  82. printf("\nUpdating description for project: %s\n\n", proj_id);
  83. /* Get a project description segment. */
  84. line = get_line();
  85. while (line)
  86. {
  87. printf(" Inserting segment: %s\n", line);
  88. /* Calculate the length of the segment. */
  89. len = strlen(line);
  90. /* Write the segment. */
  91. EXEC SQL INSERT CURSOR bc VALUES (:line INDICATOR :len);
  92. line = get_line();
  93. }
  94. /* Close the blob cursor. */
  95. EXEC SQL
  96. CLOSE bc;
  97. /* Save the blob id in the project record. */
  98. EXEC SQL
  99. UPDATE project
  100. SET proj_desc = :blob_id
  101. WHERE proj_id = :proj_id;
  102. if (SQLCODE == 0L)
  103. rec_cnt++;
  104. else
  105. printf("Input error -- no project record with key: %s\n", proj_id);
  106. line = get_line();
  107. }
  108. EXEC SQL
  109. COMMIT RELEASE;
  110. printf("\n\nAdded %d project descriptions.\n", rec_cnt);
  111. return 0;
  112. Error:
  113. isc_print_sqlerror((short) SQLCODE, isc_status);
  114. return 1;
  115. }
  116. /*
  117. * Get the next input line, which is either a project id
  118. * or a project description segment.
  119. */
  120. char *get_line (void)
  121. {
  122. return Proj_data[Inp_ptr++];
  123. }