stat7.e 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. * Copyright (C) Inprise Corporation.
  20. *
  21. * All Rights Reserved.
  22. * Contributor(s): ______________________________________.
  23. */
  24. #include "example.h"
  25. #include <stdlib.h>
  26. #include <stdio.h>
  27. EXEC SQL
  28. BEGIN DECLARE SECTION;
  29. BASED ON project.proj_name proj_name;
  30. BASED ON project.product prod_type;
  31. BASED ON project.proj_desc blob_id;
  32. BASED ON project.proj_desc.SEGMENT blob_segment;
  33. unsigned short blob_seg_len;
  34. EXEC SQL
  35. END DECLARE SECTION;
  36. int main (void)
  37. {
  38. EXEC SQL
  39. WHENEVER SQLERROR GO TO Error;
  40. /* Declare a table read cursor. */
  41. EXEC SQL
  42. DECLARE proj_cur CURSOR FOR
  43. SELECT proj_name, proj_desc, product
  44. FROM project
  45. WHERE product IN ('software', 'hardware', 'other')
  46. ORDER BY proj_name;
  47. /* Declare a blob read cursor. */
  48. EXEC SQL
  49. DECLARE blob_cur CURSOR FOR
  50. READ BLOB proj_desc
  51. FROM project;
  52. /* Open the table cursor. */
  53. EXEC SQL
  54. OPEN proj_cur;
  55. /*
  56. * For each project get and display project description.
  57. */
  58. while (SQLCODE == 0)
  59. {
  60. /* Fetch the blob id along with some other columns. */
  61. EXEC SQL
  62. FETCH proj_cur INTO :proj_name, :blob_id, :prod_type;
  63. if (SQLCODE == 100)
  64. break;
  65. printf("\nPROJECT: %-30s TYPE: %-15s\n\n", proj_name, prod_type);
  66. /* Open the blob cursor. */
  67. EXEC SQL
  68. OPEN blob_cur USING :blob_id;
  69. while (SQLCODE == 0)
  70. {
  71. /* Fetch a blob segment and a blob segment length. */
  72. EXEC SQL FETCH blob_cur INTO :blob_segment :blob_seg_len;
  73. if (SQLCODE == 100)
  74. break;
  75. printf(" %*.*s\n", blob_seg_len, blob_seg_len, blob_segment);
  76. }
  77. printf("\n");
  78. /* Close the blob cursor. */
  79. EXEC SQL
  80. CLOSE blob_cur;
  81. }
  82. EXEC SQL
  83. CLOSE proj_cur;
  84. EXEC SQL
  85. COMMIT;
  86. return 0;
  87. Error:
  88. isc_print_sqlerror((short) SQLCODE, gds__status);
  89. return 1;
  90. }