home *** CD-ROM | disk | FTP | other *** search
- {****************************************************************************
- **
- ** Copyright 1982-1997 Pervasive Software Inc. All Rights Reserved
- **
- ****************************************************************************}
- {****************************************************************************
- SQLSAMPP.PAS
- This is a simple sample designed to allow you to confirm your
- ability to compile, link, and execute a Scalable SQL application for
- your target 16-bit Borland Pascal DOS protected mode application.
-
- This program demonstrates the Pascal interface for Scalable SQL for
- DOS. It uses SQL-level functions to fetch records from the
- 'university' database that is included with Scalable SQL.
-
- This program does the following operations on the sample database:
- - logs into the database
- - gets a cursor
- - compiles a select statement
- - gets a record
- - displays selected portions of the retrieved record
- - logs out of the database
-
- IMPORTANT: Be sure to provide the complete path to the sample
- database location, as shown below for a particular case.
- See 'IMPORTANT', below.
-
- ****************************************************************************}
- PROGRAM sqlsampp (input, output);
-
- USES
- dos,
- sqlapip; { SQL Interface Unit }
-
- {*****************************************************************************
- Constants
- *****************************************************************************}
- CONST
- TRUE = 1;
- FALSE = 0;
- SUCCESS = 0;
- FAILURE = -1;
- STATEMENT_BUFFER_SIZE = 1024;
- BYTE_COUNT_SIZE = 2;
- SPACING_NOT_PERTINENT = 0;
- UserID : CHAR = #0;
- Password : CHAR = #0;
- Reserved : CHAR = #0;
- DDpath : string[ 20 ] = 'v:\ssql40\demodata'; { IMPORTANT }
- Datapath : string[ 20 ] = 'v:\ssql40\demodata'; { IMPORTANT }
- FETCH_FIRST : integer = 1;
- INTERNAL_FORMAT : integer = 0;
-
-
- {***************************************************************************
- Structures
- Definition of record from the 'person' table
- ****************************************************************************}
- TYPE
- PERSON_STRUCT = record
- RecLen : word;
- ID : longint;
- Dummy : longint;
- FirstName : array[1..16] of char;
- LastName : array[1..26] of char;
- PermStreet : array[1..31] of char;
- PermCity : array[1..31] of char;
- PermState : array[1..3] of char;
- PermZip : array[1..11] of char;
- PermCountry : array[1..21] of char;
- Street : array[1..31] of char;
- City : array[1..31] of char;
- State : array[1..3] of char;
- Zip : array[1..11] of char;
- Phone : array[1..10] of char;
- EmergencyPhone : array[1..20] of char;
- Unlisted : char;
- DateOfBirth : array[1..4] of char;
- EmailAddress : array[1..31] of char;
- Sex : char;
- Citizenship : array[1..21] of char;
- Survey : char;
- Smoker : char;
- Married : char;
- Children : char;
- Disability : char;
- Scholarship : char;
- Comments : array[1..200] of char;
- end;
-
- VAR
- cursorID : integer;
- statement : string [255];
- statlen : integer;
- loginFlag : integer;
- status : integer;
- bufferLength : integer;
- personRecord : PERSON_STRUCT;
- recordsRead : longint;
-
- {***********************************************************************
- Program starts here
- ************************************************************************}
- BEGIN { sqlsampp }
- writeln( '***** Scalable SQL Pascal Interface Demo *****' );
- writeln;
-
- loginFlag := FALSE;
- {**************************************************
- ** Login to the database
- **************************************************}
- status := XQLLogin(
- UserID,
- Password,
- DDpath[1],
- Datapath[1],
- Reserved,
- 1);
-
- writeln( 'XQLLogin status = ', status );
- if status <> SUCCESS then
- begin
- status := FAILURE;
- end
- else
- begin
- loginFlag := TRUE;
- end;
-
- if status = SUCCESS then
- begin
- {**************************************************
- ** Get a cursor ID
- **************************************************}
- status := XQLCursor (cursorID);
- writeln( 'XQLCursorID status = ', status );
- if status <> SUCCESS then
- begin
- status := FAILURE;
- end
- end;
-
- if status = SUCCESS then
- begin
- {**************************************************
- ** Compile the select statement
- **************************************************}
- statement := 'SELECT * from person where ID = 101135758 ' + #0;
- Statlen := length (Statement);
-
- status := XQLCompile(
- cursorID,
- statlen,
- statement [1] );
-
- writeln( 'XQLCompile status = ', status );
- if status > SUCCESS then
- begin
- status := FAILURE;
- end
- else
- begin
- writeln( 'SELECT * from person where ID = 101135758' );
- end;
- end;
-
- if status = SUCCESS then
- begin
- {**************************************************
- ** Fetch the record
- **************************************************}
- bufferLength := SizeOf( PERSON_STRUCT );
-
- recordsRead := 1;
- status := XQLFetch(
- cursorID,
- FETCH_FIRST,
- bufferLength,
- personRecord,
- recordsRead,
- INTERNAL_FORMAT,
- SPACING_NOT_PERTINENT );
-
- writeln( 'XQLFetch status = ', status );
- if status <> SUCCESS then
- begin
- status := FAILURE;
- end
- else
- begin
- writeln;
- writeln( 'Selected fields from the retrieved record are:' );
- writeln( 'Name: ', personRecord.FirstName, ' ',
- personRecord.LastName );
- writeln( 'Country: ', personRecord.PermCountry );
- writeln( 'Street: ', personRecord.PermStreet );
- writeln( 'City: ', personRecord.PermCity );
- writeln( 'State: ', personRecord.PermState );
- writeln( 'Zip: ', personRecord.PermZip );
- writeln;
- end;
- end;
-
- if loginFlag = TRUE then
- begin
- {**************************************************
- ** Logout of the database
- **************************************************}
- status := XQLLogout;
- writeln( 'XQLLogout status = ', status );
- end;
- END.
-