stat2.e 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Program type: Embedded Static SQL
  3. *
  4. * Description:
  5. * This program demonstrates a singleton select.
  6. * A full name and phone number are displayed for
  7. * the CEO of the company.
  8. * The contents of this file are subject to the Interbase Public
  9. * License Version 1.0 (the "License"); you may not use this file
  10. * except in compliance with the License. You may obtain a copy
  11. * of the License at http://www.Inprise.com/IPL.html
  12. *
  13. * Software distributed under the License is distributed on an
  14. * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
  15. * or implied. See the License for the specific language governing
  16. * rights and limitations under the License.
  17. *
  18. * The Original Code was created by Inprise Corporation
  19. * and its predecessors. Portions created by Inprise Corporation are
  20. * Copyright (C) Inprise Corporation.
  21. *
  22. * All Rights Reserved.
  23. * Contributor(s): ______________________________________.
  24. */
  25. #include "example.h"
  26. #include <stdlib.h>
  27. #include <stdio.h>
  28. #define FIRSTLEN 15
  29. #define LASTLEN 20
  30. #define EXTLEN 4
  31. #define DEPTNO 3
  32. #define PHONELEN 20
  33. EXEC SQL
  34. BEGIN DECLARE SECTION;
  35. EXEC SQL
  36. END DECLARE SECTION;
  37. int main (void)
  38. {
  39. char first[FIRSTLEN + 1];
  40. char last[LASTLEN + 1];
  41. char ext[EXTLEN + 1];
  42. char phone[PHONELEN + 1];
  43. char dept[DEPTNO + 1];
  44. /*
  45. * Assume there's only one CEO.
  46. * Select the name and phone extension.
  47. */
  48. EXEC SQL
  49. SELECT first_name, last_name, phone_ext, dept_no
  50. INTO :first, :last, :ext, :dept
  51. FROM employee
  52. WHERE job_code = 'CEO';
  53. /* Check the SQLCODE to make sure only 1 row was selected. */
  54. if (SQLCODE)
  55. {
  56. isc_print_sqlerror((short)SQLCODE, gds__status);
  57. exit(1);
  58. }
  59. /*
  60. * Also, select the department phone number.
  61. */
  62. EXEC SQL
  63. SELECT phone_no
  64. INTO :phone
  65. FROM department
  66. WHERE dept_no = :dept;
  67. if (SQLCODE)
  68. {
  69. isc_print_sqlerror((short)SQLCODE, gds__status);
  70. exit(1);
  71. }
  72. printf("President: %s %s\t\t", first, last);
  73. printf("Phone #: %s x%s\n", phone, ext);
  74. EXEC SQL
  75. COMMIT RELEASE;
  76. exit(0);
  77. }