home *** CD-ROM | disk | FTP | other *** search
/ Datatid 1999 #6 / Datatid_1999-06.iso / internet / Tango352Promo / P.SQL / PTKPKG.1 / SQLSAMPD.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1997-04-14  |  7.3 KB  |  222 lines

  1. {****************************************************************************
  2. **
  3. **  Copyright 1982-1997 Pervasive Software Inc. All Rights Reserved
  4. **
  5. ****************************************************************************}
  6. {****************************************************************************
  7.    SQLSAMPD.PAS
  8.       This is a simple sample designed to allow you to confirm your
  9.       ability to compile, link, and execute a Scalable SQL application for
  10.       your target DOS real mode application.
  11.  
  12.       This program demonstrates the Pascal interface for Scalable SQL for
  13.       DOS.  It uses SQL-level functions to fetch records from the
  14.       'university' database that is  included with  Scalable SQL.
  15.  
  16.       This program does the following operations on the sample database:
  17.       - logs into the database
  18.       - gets a cursor
  19.       - compiles a select statement
  20.       - gets a record
  21.       - displays selected portions of the retrieved record
  22.       - logs out of the database
  23.  
  24.       IMPORTANT: Be sure to provide the complete path to the sample
  25.       database location, as shown below for a particular case.
  26.       See 'IMPORTANT', below.
  27.  
  28. ****************************************************************************}
  29. PROGRAM sqlsampd (input, output);
  30.  
  31. USES
  32.    dos,
  33.    sqlapid;    { SQL Interface Unit }
  34.  
  35. {*****************************************************************************
  36.    Constants
  37. *****************************************************************************}
  38. CONST
  39.    TRUE    =  1;
  40.    FALSE   =  0;
  41.    SUCCESS =  0;
  42.    FAILURE = -1;
  43.    STATEMENT_BUFFER_SIZE = 1024;
  44.    BYTE_COUNT_SIZE       = 2;
  45.    SPACING_NOT_PERTINENT = 0;
  46.    UserID   : CHAR = #0;
  47.    Password : CHAR = #0;
  48.    Reserved : CHAR = #0;
  49.    DDpath   : string[ 20 ] = 'v:\ssql40\demodata';      { IMPORTANT }
  50.    Datapath : string[ 20 ] = 'v:\ssql40\demodata';      { IMPORTANT }
  51.    FETCH_FIRST        : integer = 1;
  52.    INTERNAL_FORMAT    : integer = 0;
  53.  
  54.  
  55. {***************************************************************************
  56.    Structures
  57.    Definition of record from the 'person' table
  58. ****************************************************************************}
  59. TYPE
  60.    PERSON_STRUCT = record
  61.       RecLen         : word;
  62.       ID             : longint;
  63.       Dummy          : longint;
  64.       FirstName      : array[1..16] of char;
  65.       LastName       : array[1..26] of char;
  66.       PermStreet     : array[1..31] of char;
  67.       PermCity       : array[1..31] of char;
  68.       PermState      : array[1..3] of char;
  69.       PermZip        : array[1..11] of char;
  70.       PermCountry    : array[1..21] of char;
  71.       Street         : array[1..31] of char;
  72.       City           : array[1..31] of char;
  73.       State          : array[1..3] of char;
  74.       Zip            : array[1..11] of char;
  75.       Phone          : array[1..10] of char;
  76.       EmergencyPhone : array[1..20] of char;
  77.       Unlisted       : char;
  78.       DateOfBirth    : array[1..4] of char;
  79.       EmailAddress   : array[1..31] of char;
  80.       Sex            : char;
  81.       Citizenship    : array[1..21] of char;
  82.       Survey         : char;
  83.       Smoker         : char;
  84.       Married        : char;
  85.       Children       : char;
  86.       Disability     : char;
  87.       Scholarship    : char;
  88.       Comments       : array[1..200] of char;
  89.    end;
  90.  
  91. VAR
  92.    cursorID     : integer;
  93.    statement    : string [255];
  94.    statlen      : integer;
  95.    loginFlag    : integer;
  96.    cursorIDFlag : integer;
  97.    status       : integer;
  98.    bufferLength : integer;
  99.    personRecord : PERSON_STRUCT;
  100.    recordsRead  : longint;
  101.  
  102. {***********************************************************************
  103.    Program starts here
  104. ************************************************************************}
  105. BEGIN { sqlsampd }
  106.    writeln( '***** Scalable SQL Pascal Interface Demo *****' );
  107.    writeln;
  108.  
  109.    loginFlag := FALSE;
  110.    cursorIDFlag := FALSE;
  111.    {**************************************************
  112.    ** Login to the database
  113.    **************************************************}
  114.    writeln('DDpath: ', DDpath);
  115.    writeln('DataPath: ', DataPath);
  116.    status := XQLLogin(
  117.                 UserID,
  118.                 Password,
  119.                 DDpath[1],
  120.                 Datapath[1],
  121.                 Reserved,
  122.                 1);
  123.  
  124.    writeln( 'XQLLogin status = ', status );
  125.    if status <> SUCCESS then
  126.       begin
  127.          status := FAILURE;
  128.       end
  129.    else
  130.       begin
  131.          loginFlag := TRUE;
  132.       end;
  133.  
  134.    if status = SUCCESS then
  135.       begin
  136.          {**************************************************
  137.          ** Get a cursor ID
  138.          **************************************************}
  139.          status := XQLCursor (cursorID);
  140.          writeln( 'XQLCursorID status = ', status );
  141.          if status <> SUCCESS then
  142.             begin
  143.                status := FAILURE;
  144.             end
  145.          else
  146.             begin
  147.                cursorIDFlag := TRUE;
  148.             end;
  149.       end;
  150.  
  151.    if status = SUCCESS then
  152.       begin
  153.          {**************************************************
  154.          ** Compile the select statement
  155.          **************************************************}
  156.          statement := 'SELECT * from person where ID = 101135758 ' + #0;
  157.          Statlen   := length (Statement);
  158.  
  159.          status := XQLCompile(
  160.                       cursorID,
  161.                       statlen,
  162.                       statement [1] );
  163.  
  164.          writeln( 'XQLCompile status = ', status );
  165.          if status > SUCCESS then
  166.             begin
  167.                status := FAILURE;
  168.             end
  169.          else
  170.             begin
  171.                writeln( 'SELECT * from person where ID = 101135758' );
  172.             end;
  173.        end;
  174.  
  175.    if status = SUCCESS then
  176.       begin
  177.          {**************************************************
  178.          ** Fetch the record
  179.          **************************************************}
  180.          bufferLength := SizeOf( PERSON_STRUCT );
  181.  
  182.          recordsRead := 1;
  183.          status := XQLFetch(
  184.                       cursorID,
  185.                       FETCH_FIRST,
  186.                       bufferLength,
  187.                       personRecord,
  188.                       recordsRead,
  189.                       INTERNAL_FORMAT,
  190.                       SPACING_NOT_PERTINENT );
  191.  
  192.          writeln( 'XQLFetch status = ', status );
  193.          if status <> SUCCESS then
  194.             begin
  195.                status := FAILURE;
  196.             end
  197.          else
  198.             begin
  199.                writeln;
  200.                writeln( 'Selected fields from the retrieved record are:' );
  201.                writeln( 'Name:    ', personRecord.FirstName, ' ',
  202.                                         personRecord.LastName );
  203.                writeln( 'Country: ', personRecord.PermCountry );
  204.                writeln( 'Street:  ', personRecord.PermStreet );
  205.                writeln( 'City:    ', personRecord.PermCity );
  206.                writeln( 'State:   ', personRecord.PermState );
  207.                writeln( 'Zip:     ', personRecord.PermZip );
  208.                writeln;
  209.             end;
  210.       end;
  211.  
  212.    if loginFlag = TRUE then
  213.       begin
  214.          {**************************************************
  215.          ** Logout of the database
  216.          **************************************************}
  217.          status := XQLLogout;
  218.          writeln( 'XQLLogout status = ', status );
  219.       end;
  220.  
  221. END.
  222.