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

  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.  *
  21.  * Copyright (C) 2000 Inprise Corporation
  22.  * All Rights Reserved.
  23.  * Contributor(s): ______________________________________.
  24.  */
  25.  
  26. #include "example.h"
  27. #include <stdlib.h>
  28. #include <stdio.h>
  29.  
  30. #define    FIRSTLEN    15
  31. #define    LASTLEN        20
  32. #define EXTLEN        4
  33. #define DEPTNO        3
  34. #define PHONELEN    20
  35.  
  36. EXEC SQL
  37.     BEGIN DECLARE SECTION;
  38. EXEC SQL
  39.     END DECLARE SECTION;
  40.  
  41.  
  42. int main (void)
  43. {
  44.     char first[FIRSTLEN + 1];
  45.     char last[LASTLEN + 1];
  46.     char ext[EXTLEN + 1];
  47.     char phone[PHONELEN + 1];
  48.     char dept[DEPTNO + 1];
  49.  
  50.     /*
  51.      *  Assume there's only one CEO.
  52.      *  Select the name and phone extension.
  53.      */
  54.     EXEC SQL
  55.         SELECT first_name, last_name, phone_ext, dept_no
  56.         INTO :first, :last, :ext, :dept
  57.         FROM employee
  58.         WHERE job_code = 'CEO';
  59.  
  60.     /* Check the SQLCODE to make sure only 1 row was selected. */
  61.     if (SQLCODE)
  62.     {
  63.         isc_print_sqlerror((short)SQLCODE, gds__status);
  64.         exit(1);
  65.     }
  66.  
  67.     /*
  68.      *  Also, select the department phone number.
  69.      */
  70.  
  71.     EXEC SQL
  72.         SELECT phone_no
  73.         INTO :phone
  74.         FROM department
  75.         WHERE dept_no = :dept;
  76.  
  77.     if (SQLCODE)
  78.     {
  79.         isc_print_sqlerror((short)SQLCODE, gds__status);
  80.         exit(1);
  81.     }
  82.  
  83.     printf("President:  %s %s\t\t", first, last);
  84.     printf("Phone #:  %s  x%s\n", phone, ext);
  85.  
  86.     EXEC SQL
  87.         COMMIT RELEASE;
  88. exit(0);
  89. }
  90.  
  91.