8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-22 14:43:03 +01:00

Added v5_examples to the firebird2 tree

This commit is contained in:
skywalker 2001-07-23 16:05:46 +00:00
parent 816439e5d7
commit e42bda0013
78 changed files with 17022 additions and 0 deletions

68
src/v5_examples/align.h Normal file
View File

@ -0,0 +1,68 @@
/*
* The contents of this file are subject to the Interbase Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy
* of the License at http://www.Inprise.com/IPL.html
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code was created by Inprise Corporation
* and its predecessors. Portions created by Inprise Corporation are
* Copyright (C) Inprise Corporation.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/
/*
$Id: align.h,v 1.1 2001-07-23 16:05:46 skywalker Exp $
*/
#ifdef VMS
#define FB_ALIGN(n,b) (n)
#endif
#ifdef sun
#ifdef sparc
#define FB_ALIGN(n,b) ((n + b - 1) & ~(b - 1))
#endif
#endif
#ifdef hpux
#define FB_ALIGN(n,b) ((n + b - 1) & ~(b - 1))
#endif
#ifdef ultrix
#define FB_ALIGN(n,b) ((n + b - 1) & ~(b - 1))
#endif
#ifdef sgi
#define FB_ALIGN(n,b) ((n + b - 1) & ~(b - 1))
#endif
#ifdef _AIX
#define FB_ALIGN(n,b) ((n + b - 1) & ~(b - 1))
#endif
#ifdef __m88k__
#define FB_ALIGN(n,b) ((n + b - 1) & ~(b - 1))
#endif
#if (defined __osf__ && defined __alpha)
#define FB_ALIGN(n,b) ((n + b - 1) & ~(b - 1))
#endif
#ifdef mpexl
#define FB_ALIGN(n,b) ((n + b - 1) & ~(b - 1))
#endif
#if (defined(_MSC_VER) && defined(WIN32)) || (defined(__BORLANDC__) \
&& defined(__WIN32__))
#define FB_ALIGN(n,b) ((n + b - 1) & ~(b - 1))
#endif
#ifndef ALIGN
#define FB_ALIGN(n,b) ((n+1) & ~1)
#endif

142
src/v5_examples/api1.c Normal file
View File

@ -0,0 +1,142 @@
/*
* Program type: API Interface
*
* Description:
* This program creates a new database, given an SQL statement
* string. The newly created database is accessed after its
* creation, and a sample table is added.
*
* The SQLCODE is extracted from the status vector and is used
* to check whether the database already exists.
* The contents of this file are subject to the Interbase Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy
* of the License at http://www.Inprise.com/IPL.html
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code was created by Inprise Corporation
* and its predecessors. Portions created by Inprise Corporation are
* Copyright (C) Inprise Corporation.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "example.h"
#include <ibase.h>
int pr_error (long ISC_FAR *, char ISC_FAR *);
static char ISC_FAR *create_tbl = "CREATE TABLE dbinfo (when_created DATE)";
static char ISC_FAR *insert_date = "INSERT INTO dbinfo VALUES ('NOW')";
int main (ARG(int, argc), ARG(char **, argv))
ARGLIST(int argc)
ARGLIST(char **argv)
{
isc_db_handle newdb = NULL; /* database handle */
isc_tr_handle trans = NULL; /* transaction handle */
long status[20]; /* status vector */
long sqlcode; /* SQLCODE */
char create_db[160]; /* 'create database' statement */
char new_dbname[128];
if (argc > 1)
strcpy(new_dbname, argv[1]);
else
strcpy(new_dbname, "new.gdb");
/*
* Construct a 'create database' statement.
* The database name could have been passed as a parameter.
*/
sprintf(create_db, "CREATE DATABASE '%s'", new_dbname);
/*
* Create a new database.
* The database handle is zero.
*/
if (isc_dsql_execute_immediate(status, &newdb, &trans, 0, create_db, 1,
NULL))
{
/* Extract SQLCODE from the status vector. */
sqlcode = isc_sqlcode(status);
/* Print a descriptive message based on the SQLCODE. */
if (sqlcode == -902)
{
printf("\nDatabase already exists.\n");
printf("Remove %s before running this program.\n\n", new_dbname);
}
/* In addition, print a standard error message. */
if (pr_error(status, "create database"))
return 1;
}
isc_commit_transaction(status, &trans);
printf("Created database '%s'.\n\n", new_dbname);
/*
* Connect to the new database and create a sample table.
*/
/* newdb will be set to null on success */
isc_detach_database(status, &newdb);
if (isc_attach_database(status, 0, new_dbname, &newdb, 0, NULL))
if (pr_error(status, "attach database"))
return 1;
/* Create a sample table. */
isc_start_transaction(status, &trans, 1, &newdb, 0, NULL);
if (isc_dsql_execute_immediate(status, &newdb, &trans, 0, create_tbl, 1, NULL))
if (pr_error(status, "create table"))
return 1;
isc_commit_transaction(status, &trans);
/* Insert 1 row into the new table. */
isc_start_transaction(status, &trans, 1, &newdb, 0, NULL);
if (isc_dsql_execute_immediate(status, &newdb, &trans, 0, insert_date, 1, NULL))
if (pr_error(status, "insert into"))
return 1;
isc_commit_transaction(status, &trans);
printf("Successfully accessed the newly created database.\n\n");
isc_detach_database(status, &newdb);
return 0;
}
/*
* Print the status, the SQLCODE, and exit.
* Also, indicate which operation the error occured on.
*/
int pr_error (ARG(long ISC_FAR *, status), ARG(char ISC_FAR *, operation))
ARGLIST(long ISC_FAR * status)
ARGLIST(char ISC_FAR * operation)
{
printf("[\n");
printf("PROBLEM ON \"%s\".\n", operation);
isc_print_status(status);
printf("SQLCODE:%d\n", isc_sqlcode(status));
printf("]\n");
return 1;
}

212
src/v5_examples/api10.c Normal file
View File

@ -0,0 +1,212 @@
/*
* Program type: API
*
* Description:
* This program selects and updates an array type.
* Projected head count is displayed and updated for
* a set of projects.
* The contents of this file are subject to the Interbase Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy
* of the License at http://www.Inprise.com/IPL.html
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code was created by Inprise Corporation
* and its predecessors. Portions created by Inprise Corporation are
* Copyright (C) Inprise Corporation.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/
#include <stdlib.h>
#include <string.h>
#include <ibase.h>
#include <stdio.h>
#include "example.h"
char *sel_str =
"SELECT dept_no, quart_head_cnt FROM proj_dept_budget p \
WHERE fiscal_year = 1994 AND proj_id = 'VBASE' \
FOR UPDATE of quart_head_cnt";
char *upd_str =
"UPDATE proj_dept_budget SET quart_head_cnt = ? WHERE CURRENT OF S";
int main (ARG(int, argc), ARG(char **, argv))
ARGLIST(int argc)
ARGLIST(char **argv)
{
long hcnt[4];
ISC_QUAD array_id;
ISC_ARRAY_DESC desc;
long len;
char dept_no[6];
isc_db_handle DB = NULL;
isc_tr_handle trans = NULL;
long status[20];
short flag0 = 0, flag1 = 0;
isc_stmt_handle stmt = NULL;
isc_stmt_handle ustmt = NULL;
char ISC_FAR * cursor = "S";
XSQLDA ISC_FAR *osqlda, *isqlda;
long fetch_stat;
short i;
char empdb[128];
if (argc > 1)
strcpy(empdb, argv[1]);
else
strcpy(empdb, "employee.gdb");
if (isc_attach_database(status, 0, empdb, &DB, 0, NULL))
{
ERREXIT(status, 1)
}
if (isc_start_transaction(status, &trans, 1, &DB, 0, NULL))
{
ERREXIT(status, 1)
}
/*
* Set up the array description structure
*/
if (isc_array_lookup_bounds(status, &DB, &trans,
"PROJ_DEPT_BUDGET", "QUART_HEAD_CNT", &desc))
{
ERREXIT(status, 1)
}
/*
* Set-up the select statement.
*/
osqlda = (XSQLDA *) malloc(XSQLDA_LENGTH(2));
osqlda->sqln = 2;
osqlda->version = 1;
osqlda->sqlvar[0].sqldata = (char ISC_FAR *) dept_no;
osqlda->sqlvar[0].sqltype = SQL_TEXT + 1;
osqlda->sqlvar[0].sqlind = &flag0;
osqlda->sqlvar[1].sqldata = (char ISC_FAR *) &array_id;
osqlda->sqlvar[1].sqltype = SQL_ARRAY + 1;
osqlda->sqlvar[1].sqlind = &flag1;
isc_dsql_allocate_statement(status, &DB, &stmt);
isc_dsql_allocate_statement(status, &DB, &ustmt);
/* Prepare and execute query */
if (isc_dsql_prepare(status, &trans, &stmt, 0, sel_str, 1, osqlda))
{
ERREXIT(status, 1)
}
if (isc_dsql_execute(status, &trans, &stmt, 1, NULL))
{
ERREXIT(status, 1)
}
/* Needed for update current */
isc_dsql_set_cursor_name(status, &stmt, cursor, 0);
/*
* Set-up the update statement.
*/
isqlda = (XSQLDA ISC_FAR *) malloc(XSQLDA_LENGTH(1));
isqlda->sqln = 1;
isqlda->version = 1;
/* Use describe_bind to set up input sqlda */
if (isc_dsql_prepare(status, &trans, &ustmt, 0, upd_str, 1, NULL))
{
ERREXIT(status, 1)
}
isc_dsql_describe_bind(status, &ustmt, 1, isqlda);
isqlda->sqlvar[0].sqldata = (char ISC_FAR *) &array_id;
isqlda->sqlvar[0].sqlind = &flag1;
/*
* Fetch the head count for each department's 4 quarters;
* increase the head count by 1 for each quarter;
* and save the new head count.
*/
while ((fetch_stat = isc_dsql_fetch(status, &stmt, 1, osqlda)) == 0)
{
/* Get the current array values. */
if (!flag1)
{
len = sizeof(hcnt);;
if (isc_array_get_slice(status, &DB, &trans,
(ISC_QUAD ISC_FAR *) &array_id,
(ISC_ARRAY_DESC ISC_FAR *) &desc,
(void ISC_FAR *) hcnt,
(long ISC_FAR *) &len))
{ERREXIT (status, 1)};
dept_no [osqlda->sqlvar[0].sqllen] = '\0';
printf("Department #: %s\n\n", dept_no);
printf("\tCurrent counts: %ld %ld %ld %ld\n",
hcnt[0], hcnt[1], hcnt[2], hcnt[3]);
/* Add 1 to each count. */
for (i = 0; i < 4; i++)
hcnt[i] = hcnt[i] + 1;
/* Save new array values. */
if (isc_array_put_slice(status, &DB, &trans,
(ISC_QUAD ISC_FAR *) &array_id,
(ISC_ARRAY_DESC ISC_FAR *) &desc,
(void ISC_FAR *) hcnt,
(long ISC_FAR *) &len))
{ERREXIT (status, 1)};
/* Update the array handle. */
if (isc_dsql_execute(status, &trans, &ustmt, 1, isqlda))
{
ERREXIT(status, 1)
}
printf("\tNew counts : %ld %ld %ld %ld\n\n",
hcnt[0], hcnt[1], hcnt[2], hcnt[3]);
}
}
if (fetch_stat != 100L)
{
ERREXIT(status, 1)
}
isc_dsql_free_statement(status, &stmt, DSQL_close);
isc_dsql_free_statement(status, &ustmt, DSQL_close);
/* Do a rollback to keep from updating the sample db */
if (isc_rollback_transaction(status, &trans))
{
ERREXIT(status, 1)
}
if (isc_detach_database(status, &DB))
{
ERREXIT(status, 1)
}
free(osqlda);
free(isqlda);
return 0;
}

241
src/v5_examples/api11.c Normal file
View File

@ -0,0 +1,241 @@
/*
* Program type: API Interface
*
* Description:
* This program executes a stored procedure and selects from
* a stored procedure. First, a list of projects an employee
* is involved in is printed. Then the employee is added to
* another project. The new list of projects is printed again.
* The contents of this file are subject to the Interbase Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy
* of the License at http://www.Inprise.com/IPL.html
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code was created by Inprise Corporation
* and its predecessors. Portions created by Inprise Corporation are
* Copyright (C) Inprise Corporation.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/
#include <stdlib.h>
#include <string.h>
#include <ibase.h>
#include <stdio.h>
#include "example.h"
#define PROJLEN 5
#define BUFLEN 128
int select_projects (isc_db_handle db, int emp_no);
int add_emp_proj (isc_db_handle db, int emp_no, char ISC_FAR * proj_id);
int get_params (isc_db_handle db, int ISC_FAR * emp_no, char ISC_FAR * proj_id);
int main (ARG(int, argc), ARG(char **, argv))
ARGLIST(int argc)
ARGLIST(char **argv)
{
int emp_no;
char proj_id[PROJLEN + 2];
isc_db_handle db = NULL;
long status[20];
char empdb[128];
if (argc > 1)
strcpy(empdb, argv[1]);
else
strcpy(empdb, "employee.gdb");
if (isc_attach_database(status, 0, empdb, &db, 0, NULL))
{
ERREXIT(status, 1)
}
/*
* Add employee with id 8 to project 'MAPDB'.
*/
if (get_params(db, &emp_no, proj_id))
return 1;
/*
* Display employee's current projects.
*/
printf("\nCurrent projects for employee id: %d\n\n", emp_no);
if (select_projects(db, emp_no))
return 1;
/*
* Insert a new employee project row.
*/
printf("\nAdd employee id: %d to project: %s\n", emp_no, proj_id);
if (add_emp_proj(db, emp_no, proj_id))
return 1;
/*
* Display employee's new current projects.
*/
printf("\nCurrent projects for employee id: %d\n\n", emp_no);
if (select_projects(db, emp_no))
return 1;
if (isc_detach_database(status, &db))
{
ERREXIT(status, 1)
}
return 0 ;
}
/*
* Select from a stored procedure.
* Procedure 'get_emp_proj' gets employee's projects.
*/
int select_projects (ARG(isc_db_handle, db), ARG(int, emp_no))
ARGLIST(void *db)
ARGLIST(int emp_no)
{
char proj_id[PROJLEN + 2];
char selstr[BUFLEN];
short flag0 = 0;
isc_tr_handle trans = NULL;
long status[20];
isc_stmt_handle stmt = NULL;
XSQLDA ISC_FAR *sqlda;
long fetch_stat;
sprintf(selstr, "SELECT proj_id FROM get_emp_proj (%d) ORDER BY proj_id",
emp_no);
sqlda = (XSQLDA ISC_FAR *) malloc(XSQLDA_LENGTH(1));
sqlda->sqln = 1;
sqlda->version = 1;
if (isc_start_transaction(status, &trans, 1, &db, 0, NULL))
{
ERREXIT(status, 1)
}
if (isc_dsql_allocate_statement(status, &db, &stmt))
{
ERREXIT(status, 1)
}
if (isc_dsql_prepare(status, &trans, &stmt, 0, selstr, 1, sqlda))
{
ERREXIT(status, 1)
}
sqlda->sqlvar[0].sqldata = (char ISC_FAR *) proj_id;
sqlda->sqlvar[0].sqlind = &flag0;
sqlda->sqlvar[0].sqltype = SQL_TEXT + 1;
if (isc_dsql_execute(status, &trans, &stmt, 1, NULL))
{
ERREXIT(status, 1)
}
while ((fetch_stat = isc_dsql_fetch(status, &stmt, 1, sqlda)) == 0)
{
proj_id[PROJLEN] = '\0';
printf("\t%s\n", proj_id);
}
if (fetch_stat != 100L)
{
ERREXIT(status, 1)
}
if (isc_dsql_free_statement(status, &stmt, DSQL_close))
{
ERREXIT(status, 1)
}
if (isc_commit_transaction(status, &trans))
{
ERREXIT(status, 1)
}
free(sqlda);
return 0;
}
/*
* Execute a stored procedure.
* Procedure 'add_emp_proj' adds an employee to a project.
*/
int add_emp_proj (ARG(isc_db_handle, db), ARG(int, emp_no), ARG(char ISC_FAR *, proj_id))
ARGLIST(void *db)
ARGLIST(int emp_no)
ARGLIST(char *proj_id)
{
char exec_str[BUFLEN];
isc_tr_handle trans = NULL;
long status[20];
sprintf(exec_str, "EXECUTE PROCEDURE add_emp_proj %d, \"%s\"",
emp_no, proj_id);
if (isc_start_transaction(status, &trans, 1, &db, 0, NULL))
{
ERREXIT(status, 1)
}
if (isc_dsql_execute_immediate(status, &db, &trans, 0, exec_str, 1, NULL))
{
ERREXIT(status, 1)
}
if (isc_commit_transaction(status, &trans))
{
ERREXIT (status, 1)
}
return 0;
}
/*
* Set-up procedure parameters and clean-up old data.
*/
int get_params (ARG(void ISC_FAR *, db),
ARG(int ISC_FAR *, emp_no),
ARG(char ISC_FAR *, proj_id))
ARGLIST(void *db)
ARGLIST(int *emp_no)
ARGLIST(char *proj_id)
{
isc_tr_handle trans = NULL;
long status[20];
*emp_no = 8;
strcpy(proj_id, "MAPDB");
/* Cleanup: delete row from the previous run. */
if (isc_start_transaction(status, &trans, 1, &db, 0, NULL))
{
ERREXIT(status, 1)
}
if (isc_dsql_execute_immediate(status, &db, &trans, 0,
"DELETE FROM employee_project \
WHERE emp_no = 8 AND proj_id = 'MAPDB'", 1,
NULL))
{
ERREXIT(status, 1)
}
if (isc_commit_transaction(status, &trans))
{
ERREXIT(status, 1)
}
return 0;
}

381
src/v5_examples/api12.c Normal file
View File

@ -0,0 +1,381 @@
/*
* Program type: API Interface
*
* Description:
* This program has several active transactions:
*
* Sales order records are entered continuously (transaction 1).
*
* If it is discovered during transaction 1, that the customer
* placing the order is new, then a new customer record must be
* added (transaction 2).
*
* If the customer record uses a country that does not exist
* in the 'country' table, a new country record is added (transaction 3).
*
* Transaction 2 can be committed after the country is added.
* Transaction 1 can be committed after the customer record is added.
*
* Transactions 1, 2, and 3 can be undone individually, if the user
* decides not to save the sales, customer, or country changes.
* If transaction 3 is undone, transactions 1 and 2 must be undone.
* If transaction 2 is undone, transaction 1 must be undone.
*
* In addition, several independent transactions, selecting the
* customer number and the country records, take place during
* the three update transactions.
* The contents of this file are subject to the Interbase Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy
* of the License at http://www.Inprise.com/IPL.html
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code was created by Inprise Corporation
* and its predecessors. Portions created by Inprise Corporation are
* Copyright (C) Inprise Corporation.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/
#include <stdlib.h>
#include <string.h>
#include <ibase.h>
#include <stdio.h>
#include "example.h"
#define BUFLEN 512
char ISC_FAR * more_orders (void);
int do_trans (void);
int cleanup (void);
char *customer = "Maritime Museum";
char *country = "Cayman Islands";
char *currency = "CmnDlr";
isc_db_handle db = NULL;
isc_tr_handle sales_trans = NULL,
cust_trans = NULL,
cntry_trans = NULL,
trans = NULL;
long status[20];
static char *Sales[] = {"V88005", 0};
int Inp_ptr = 0;
char *trans_str = "SET TRANSACTION ISOLATION LEVEL READ COMMITTED";
int main (ARG(int, argc), ARG(char **, argv))
ARGLIST(int argc)
ARGLIST(char **argv)
{
char empdb[128];
if (argc > 1)
strcpy(empdb, argv[1]);
else
strcpy(empdb, "employee.gdb");
/* Zero the transaction handles. */
if (isc_attach_database(status, 0, empdb, &db, 0, NULL))
{
ERREXIT(status, 1)
}
/* Do the updates */
do_trans();
if (trans)
isc_rollback_transaction(status, &trans);
if (cust_trans)
isc_rollback_transaction(status, &cust_trans);
if (cntry_trans)
isc_rollback_transaction(status, &cntry_trans);
if (sales_trans)
isc_rollback_transaction(status, &sales_trans);
/* Remove them again */
cleanup();
if (trans)
isc_rollback_transaction(status, &trans);
isc_detach_database(status, &db);
return 0;
}
/*
* Function does all the work.
*/
int do_trans (void)
{
long cust_no;
char sales_str[BUFLEN + 1];
char cust_str[BUFLEN + 1];
char cntry_str[BUFLEN + 1];
char sel_str[BUFLEN + 1];
XSQLDA ISC_FAR *sqlda1, *sqlda2, *sqlda3;
isc_stmt_handle stmt0 = NULL,
stmt1 = NULL,
stmt2 = NULL;
short flag0 = 0, flag1 = 0;
long fetch_stat;
long sqlcode;
/* Prepare a query for fetching data. Make it read committed, so you
* can see your own updates.
*/
if (isc_dsql_execute_immediate(status, &db, &trans, 0, trans_str,
1, NULL))
{
ERREXIT(status, 1)
}
sprintf(sel_str, "SELECT cust_no FROM customer WHERE customer = '%s'",
customer);
if (isc_dsql_allocate_statement(status, &db, &stmt0))
{
ERREXIT(status, 1)
}
sqlda1 = (XSQLDA ISC_FAR *) malloc(XSQLDA_LENGTH(1));
sqlda1->sqln = 1;
sqlda1->version = 1;
if (isc_dsql_prepare(status, &trans, &stmt0, 0, sel_str, 1, sqlda1))
{
ERREXIT(status, 1)
}
sqlda1->sqlvar[0].sqldata = (char ISC_FAR *) &cust_no;
sqlda1->sqlvar[0].sqltype = SQL_LONG + 1;
sqlda1->sqlvar[0].sqlind = &flag0;
/* Prepare a query for checking if a country exists. */
sprintf(sel_str, "SELECT country FROM country WHERE country = '%s'",
country);
sqlda2 = (XSQLDA ISC_FAR *) malloc(XSQLDA_LENGTH(1));
sqlda2->sqln = 1;
sqlda2->version = 1;
if (isc_dsql_allocate_statement(status, &db, &stmt2))
{
ERREXIT(status, 1)
}
if (isc_dsql_prepare(status, &trans, &stmt2, 0, sel_str, 1, sqlda2))
{
ERREXIT(status, 1)
}
sqlda2->sqlvar[0].sqldata = (char ISC_FAR *) country;
sqlda2->sqlvar[0].sqltype = SQL_TEXT + 1;
sqlda2->sqlvar[0].sqlind = &flag1;
/*
* Start transaction 1 -- add a sales order.
* for a customer.
*/
cust_no = 9999;
/* This transaction is also read committed so it can see the results of
* other transactions
*/
if (isc_dsql_execute_immediate(status, &db, &sales_trans, 0, trans_str,
1, NULL))
{
ERREXIT(status, 1)
}
sprintf(sales_str, "INSERT INTO sales (po_number, cust_no, \
order_status, total_value) VALUES ('V88005', ?, \
'new', 2000)");
if (isc_dsql_allocate_statement(status, &db, &stmt1))
{
ERREXIT(status, 1)
}
if (isc_dsql_prepare(status, &trans, &stmt1, 0, sales_str, 1, NULL))
{
ERREXIT(status, 1)
}
/* Insert parameter (cust_no) used for sales insert */
sqlda3 = (XSQLDA ISC_FAR *) malloc(XSQLDA_LENGTH(1));
sqlda3->sqln = 1;
sqlda3->version = 1;
isc_dsql_describe_bind(status, &stmt1, 1, sqlda3);
sqlda3->sqlvar[0].sqldata = (char ISC_FAR *) &cust_no;;
sqlda3->sqlvar[0].sqlind = &flag0;
isc_dsql_execute(status, &sales_trans, &stmt1, 1, sqlda3);
sqlcode = isc_sqlcode(status);
if (sqlcode == -530)
{
/* Integrity constraint indicates missing primary key*/
printf ("No customer number %ld -- adding new customer \n", cust_no);
/*
* This a new customer.
* Start transaction 2 -- add a customer record.
*/
if (isc_start_transaction(status, &cust_trans, 1, &db, 0, NULL))
{
ERREXIT(status, 1)
}
sprintf(cust_str, "INSERT INTO customer (customer, country) \
VALUES ('%s', '%s')", customer, country);
printf("Adding a customer record for %s\n", customer );
/* Does the customer country exist in the validation table?
* Do a lookup this time instead of waiting for the constraint
* violation. Because trans is read committed, it will see
* updates on other transactions.
*/
if (isc_dsql_execute(status, &trans, &stmt2, 1, NULL))
{
ERREXIT(status, 1)
}
fetch_stat = isc_dsql_fetch(status, &stmt2, 1, sqlda2);
/*
* Country was not found in the validation table.
* Start transaction 3 -- add a country record.
*/
if (fetch_stat == 100L)
{
printf("Missing country record, adding %s\n", country);
if (isc_start_transaction(status, &cntry_trans, 1, &db, 0, NULL))
{
ERREXIT (status, 1)
}
sprintf(cntry_str, "INSERT INTO country VALUES ('%s', '%s')",
country, currency);
if (isc_dsql_execute_immediate(status, &db, &cntry_trans, 0,
cntry_str, 1, NULL))
{
ERREXIT(status, 1)
}
/* This must be committed to be visible */
isc_commit_transaction(status, &cntry_trans);
}
/*
* End transaction 2.
* Add the customer record, now with a reference.
*/
if (isc_dsql_execute_immediate(status, &db, &cust_trans, 0, cust_str,
1, NULL))
{
ERREXIT(status, 1)
}
/* Commit to make this reference visible */
if (isc_commit_transaction(status, &cust_trans))
{
ERREXIT(status, 1)
}
/* Lookup the new cust_no for this record */
if (isc_dsql_execute(status, &trans, &stmt0, 1, NULL))
{
ERREXIT(status, 1)
}
if (!isc_dsql_fetch(status, &stmt0, 1, sqlda1))
printf("New customer number: %ld\n", cust_no);
/* Then try to add the sales record again */
if (isc_dsql_execute(status, &sales_trans, &stmt1, 1, sqlda3))
{
ERREXIT(status, 1)
}
}
if (isc_commit_transaction(status, &sales_trans))
{
ERREXIT (status, 1)
}
printf("Added sales record for V88055\n");
isc_commit_transaction(status, &trans);
isc_dsql_free_statement(status, &stmt0, DSQL_close);
isc_dsql_free_statement(status, &stmt1, DSQL_close);
isc_dsql_free_statement(status, &stmt2, DSQL_close);
free(sqlda1);
free(sqlda2);
free(sqlda3);
return 0;
}
/* Cleanup removes all updates that might have been done
* Make sure to cleanup in reverse order to avoid primary
* key violations
*/
int cleanup (void)
{
char del_str[100];
printf ("Cleaning up...\n");
if (isc_start_transaction(status, &trans, 1, &db, 0, NULL))
{
ERREXIT(status, 1)
}
strcpy(del_str, "DELETE FROM SALES WHERE PO_NUMBER = \"V88005\"");
if (isc_dsql_execute_immediate(status, &db, &trans, 0, del_str, 1, NULL))
{
ERREXIT(status, 1)
}
strcpy (del_str, "DELETE FROM CUSTOMER WHERE COUNTRY LIKE \"Cayman%\"");
if (isc_dsql_execute_immediate(status, &db, &trans, 0, del_str, 1, NULL))
{
ERREXIT (status, 1)
}
strcpy (del_str, "DELETE FROM COUNTRY WHERE COUNTRY LIKE \"Cayman%\"");
if (isc_dsql_execute_immediate(status, &db, &trans, 0, del_str, 1, NULL))
{
ERREXIT(status, 1)
}
if (isc_commit_transaction(status, &trans))
{
ERREXIT(status, 1)
}
return 0;
}
/*
* Return the order number for the next sales order to be entered.
*/
char *more_orders (void)
{
return Sales[Inp_ptr++];
}

197
src/v5_examples/api13.c Normal file
View File

@ -0,0 +1,197 @@
/*
* Program type: API Interface
*
* Description:
* This program performs a multi-database transaction
* with a two-phase commit. A 'currency' field is updated
* in database 1 for table country, and corresponding
* 'from_currency' or 'to_currency' fields are updated in
* database 2 for table cross_rate. The transaction is
* committed only if all instances of the string are
* changed successfully in both databases.
* The contents of this file are subject to the Interbase Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy
* of the License at http://www.Inprise.com/IPL.html
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code was created by Inprise Corporation
* and its predecessors. Portions created by Inprise Corporation are
* Copyright (C) Inprise Corporation.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/
#include <stdlib.h>
#include <string.h>
#include <ibase.h>
#include <stdio.h>
#include "example.h"
#define BUFLEN 512
#define CURRENLEN 10
char *sel_str1 =
"SELECT currency FROM country WHERE country = 'Canada'";
int main (ARG(int, argc), ARG(char **, argv))
ARGLIST(int argc)
ARGLIST(char **argv)
{
char *country = "Canada"; /* passed as a parameter */
char *new_name = "CdnDollar"; /* passed as a parameter */
char orig_name[CURRENLEN + 1];
char buf[BUFLEN + 1];
isc_db_handle db1 = NULL, /* handle for database 1 */
db2 = NULL; /* handle for database 2 */
isc_tr_handle trans1 = NULL; /* transaction handle */
long status[20];
XSQLDA ISC_FAR * sel_sqlda;
isc_stmt_handle stmt = NULL;
long stat1, stat2, stat3;
char empdb[128], empdb2[128];
if (argc > 1)
strcpy(empdb, argv[1]);
else
strcpy(empdb, "employee.gdb");
if (argc > 2)
strcpy(empdb2, argv[2]);
else
strcpy(empdb2, "employe2.gdb");
/* Open database 1. */
printf("Attaching to database %s\n", empdb);
if (isc_attach_database(status, 0, empdb, &db1, 0, NULL))
{
ERREXIT(status, 1)
}
/* Open database 2. */
printf ("Attaching to database %s\n", empdb2);
if (isc_attach_database(status, 0, empdb2, &db2, 0, NULL))
{
ERREXIT(status, 1)
}
/* Start a two-database transaction. */
if (isc_start_transaction(status, &trans1, 2, &db1, 0, NULL, &db2, 0, NULL))
{
ERREXIT(status, 1)
}
/*
* Get the string, which is to be globally changed.
*/
sprintf(buf, "SELECT currency FROM country WHERE country = '%s'", country);
sel_sqlda = (XSQLDA ISC_FAR *) malloc(XSQLDA_LENGTH(1));
sel_sqlda->sqln = 1;
sel_sqlda->version = 1;
if (isc_dsql_allocate_statement(status, &db1, &stmt))
{
ERREXIT(status, 1)
}
if (isc_dsql_prepare(status, &trans1, &stmt, 0, sel_str1, 1, sel_sqlda))
{
ERREXIT(status, 1)
}
sel_sqlda->sqlvar[0].sqldata = orig_name;
sel_sqlda->sqlvar[0].sqltype = SQL_TEXT;
sel_sqlda->sqlvar[0].sqllen = CURRENLEN;
if (isc_dsql_execute(status, &trans1, &stmt, 1, NULL))
{
ERREXIT(status, 1)
}
if (isc_dsql_fetch(status, &stmt, 1, sel_sqlda))
{
ERREXIT(status, 1)
}
orig_name[CURRENLEN] = '\0';
printf("Modifying currency string: %s\n", orig_name);
/*
* Change the string in database 1.
*/
sprintf(buf, "UPDATE country SET currency = '%s' WHERE country = 'Canada'",
new_name);
stat1 = 0L;
if (isc_dsql_execute_immediate(status, &db1, &trans1, 0, buf, 1, NULL))
{
isc_print_status(status);
stat1 = isc_sqlcode(status);
}
/*
* Change all corresponding occurences of the string in database 2.
*/
sprintf(buf, "UPDATE cross_rate SET from_currency = '%s' WHERE \
from_currency = '%s'", new_name, orig_name);
stat2 = 0L;
if (isc_dsql_execute_immediate(status, &db2, &trans1, 0, buf, 1, NULL))
{
isc_print_status(status);
stat2 = isc_sqlcode(status);
}
sprintf(buf, "UPDATE cross_rate SET to_currency = '%s' WHERE \
to_currency = '%s'", new_name, orig_name);
stat3 = 0L;
if (isc_dsql_execute_immediate(status, &db2, &trans1, 0, buf, 1, NULL))
{
isc_print_status(status);
stat3 = isc_sqlcode(status);
}
if (isc_dsql_free_statement(status, &stmt, DSQL_close))
isc_print_status(status);
/*
* If all statements executed successfully, commit the transaction.
* Otherwise, undo all work.
*/
if (!stat1 && !stat2 && !stat3)
{
if (isc_commit_transaction (status, &trans1))
isc_print_status(status);
printf("Changes committed.\n");
}
else
{
printf("update1: %d\n", stat1);
printf("update2: %d\n", stat2);
printf("update3: %d\n", stat3);
if (isc_rollback_transaction(status, &trans1))
isc_print_status(status);
printf("Changes undone.\n");
}
/* Close database 1. */
if (isc_detach_database(status, &db1))
isc_print_status(status);
/* Close database 2. */
if (isc_detach_database(status, &db2))
isc_print_status(status);
free(sel_sqlda);
return 0;
}

249
src/v5_examples/api14.e Normal file
View File

@ -0,0 +1,249 @@
/*
* Program type: API Interface
*
* Description:
* This program combines the three programming styles:
* static SQL, dynamic SQL, and the API interface.
*
* Employee information is retrieved and printed for some set
* of employees. A predefined set of columns is always printed.
* However, the 'where' clause, defining which employees the report
* is to be printed for, is unknown.
*
* Dynamic SQL is utilized to construct the select statement.
* The 'where' clause is assumed to be passed as a parameter.
*
* Static SQL is used for known SQL statements.
*
* The API interface is used to access the two databases, and
* to control most transactions. The database and transaction
* handles are shared between the three interfaces.
* The contents of this file are subject to the Interbase Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy
* of the License at http://www.Inprise.com/IPL.html
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code was created by Inprise Corporation
* and its predecessors. Portions created by Inprise Corporation are
* Copyright (C) Inprise Corporation.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "example.h"
#define BUFLEN 1024
char *sel_str =
"SELECT full_name, dept_no, salary, job_code, job_grade, job_country \
FROM employee";
char *where_str =
"WHERE job_code = 'SRep' AND dept_no IN (110, 140, 115, 125, 123, 121)";
/* This macro is used to declare structures representing SQL VARCHAR types */
#define SQL_VARCHAR(len) struct {short vary_length; char vary_string[(len)+1];}
char Db_name[128];
EXEC SQL
SET DATABASE db1 = "employee.gdb" RUNTIME :Db_name;
int main(ARG(int, argc), ARG(char **, argv))
ARGLIST(int argc)
ARGLIST(char **argv)
{
BASED_ON employee.salary salary;
SQL_VARCHAR(5) job_code;
BASED_ON employee.job_grade job_grade;
SQL_VARCHAR(15) job_country;
SQL_VARCHAR(37) full_name;
BASED_ON country.currency currency;
BASED_ON department.dept_no dept_no;
BASED_ON department.department department;
char buf[BUFLEN + 1];
float rate;
void *trans1 = NULL; /* transaction handle */
void *trans2 = NULL; /* transaction handle */
long status[20];
XSQLDA *sqlda;
char empdb2[128];
if (argc > 1)
strcpy(Db_name, argv[1]);
else
strcpy(Db_name, "employee.gdb");
if (argc > 2)
strcpy(empdb2, argv[2]);
else
strcpy(empdb2, "employe2.gdb");
EXEC SQL
WHENEVER SQLERROR GO TO Error;
/*
* Set-up the select query. The select portion of the query is
* static, while the 'where' clause is determined elsewhere and
* passed as a parameter.
*/
sprintf(buf, "%s %s", sel_str, where_str);
/*
* Open the employee database.
*/
if (isc_attach_database(status, 0, Db_name, &db1, 0, NULL))
isc_print_status(status);
/*
* Prepare the select query.
*/
sqlda = (XSQLDA *) malloc(XSQLDA_LENGTH(6));
sqlda->sqln = 6;
sqlda->sqld = 6;
sqlda->version = 1;
EXEC SQL
SET TRANSACTION USING db1;
EXEC SQL
PREPARE q INTO SQL DESCRIPTOR sqlda FROM :buf;
EXEC SQL
COMMIT ;
sqlda->sqlvar[0].sqldata = (char *)&full_name;
sqlda->sqlvar[0].sqltype = SQL_VARYING;
sqlda->sqlvar[1].sqldata = dept_no;
sqlda->sqlvar[1].sqltype = SQL_TEXT;
sqlda->sqlvar[2].sqldata = (char *) &salary;
sqlda->sqlvar[2].sqltype = SQL_DOUBLE;
sqlda->sqlvar[3].sqldata = (char *)&job_code;
sqlda->sqlvar[3].sqltype = SQL_VARYING;
sqlda->sqlvar[4].sqldata = (char *) &job_grade;
sqlda->sqlvar[4].sqltype = SQL_SHORT;
sqlda->sqlvar[5].sqldata = (char *)&job_country;
sqlda->sqlvar[5].sqltype = SQL_VARYING;
/*
* Open the second database.
*/
EXEC SQL
SET DATABASE db2 = "employe2.gdb";
if (isc_attach_database(status, 0, empdb2, &db2, 0, NULL))
isc_print_status(status);
/*
* Select the employees, using the dynamically allocated SQLDA.
*/
EXEC SQL
DECLARE emp CURSOR FOR q;
if (isc_start_transaction(status, &trans1, 1, &db1, 0, NULL))
isc_print_status(status);
EXEC SQL
OPEN TRANSACTION trans1 emp;
while (SQLCODE == 0)
{
EXEC SQL
FETCH emp USING SQL DESCRIPTOR sqlda;
if (SQLCODE == 100)
break;
/*
* Get the department name, using a static SQL statement.
*/
EXEC SQL
SELECT TRANSACTION trans1 department
INTO :department
FROM department
WHERE dept_no = :dept_no;
/*
* If the job country is not USA, access the second database
* in order to get the conversion rate between different money
* types. Even though the conversion rate may fluctuate, all
* salaries will be presented in US dollars for relative comparison.
*/
job_country.vary_string[job_country.vary_length] = '\0';
if (strcmp(job_country.vary_string, "USA"))
{
EXEC SQL
SELECT TRANSACTION trans1 currency
INTO :currency
FROM country
WHERE country = :job_country.vary_string :job_country.vary_length;
if (isc_start_transaction(status, &trans2, 1, &db2, 0, NULL))
isc_print_status(status);
EXEC SQL
SELECT TRANSACTION trans2 conv_rate
INTO :rate
FROM cross_rate
WHERE from_currency = 'Dollar'
AND to_currency = :currency;
if (!SQLCODE)
salary = salary / rate;
if (isc_commit_transaction (status, &trans2))
isc_print_status(status);
}
/*
* Print the results.
*/
printf("%-20.*s ", full_name.vary_length, full_name.vary_string);
fflush (stdout);
printf("%8.2f ", salary);
fflush (stdout);
printf(" %-5.*s %d", job_code.vary_length, job_code.vary_string, job_grade);
fflush (stdout);
printf(" %-20s\n", department);
fflush (stdout);
}
EXEC SQL
CLOSE emp;
if (isc_commit_transaction (status, &trans1))
isc_print_status(status);
isc_detach_database(status, &db1);
isc_detach_database(status, &db2);
return(0);
Error:
printf("\n");
isc_print_sqlerror(SQLCODE, isc_status);
return(1);
}

220
src/v5_examples/api15.c Normal file
View File

@ -0,0 +1,220 @@
/*
* Program type: API
*
* Description:
* This program demonstrates constructing a database
* parameter buffer and attaching to a database.
* First manually set sweep interval, then
* The user and password is set to "guest" with expand_dpb
* Then get back the sweep interval and other useful numbers
* with an info call.
* This program will accept up to 4 args. All are positional:
* api15 <db_name> <user> <password> <sweep_interval>
*
* Note: The system administrator needs to create the account
* "guest" with password "guest" on the server before this
* example can be run.
* The contents of this file are subject to the Interbase Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy
* of the License at http://www.Inprise.com/IPL.html
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code was created by Inprise Corporation
* and its predecessors. Portions created by Inprise Corporation are
* Copyright (C) Inprise Corporation.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "example.h"
#include <ibase.h>
int main (ARG(int, argc), ARG(char **, argv))
ARGLIST(int argc)
ARGLIST(char **argv)
{
isc_db_handle db = NULL; /* database handle */
isc_tr_handle trans = NULL; /* transaction handle */
isc_stmt_handle stmt = NULL;
long status[20]; /* status vector */
char dbname[128];
char user_name[31], uname[81];
short nullind;
char password[31];
/* Query to find current user name */
static char ISC_FAR *query = "SELECT USER FROM RDB$DATABASE";
char ISC_FAR * dpb = NULL, /* DB parameter buffer */
*d, *p, *copy;
XSQLDA ISC_FAR *sqlda;
short dpb_length = 0;
long l,sweep_interval = 16384;
/* All needed for analyzing an info packet */
char buffer[100]; /* Buffer for db info */
char item;
short length;
long value_out;
/* List of items for db_info call */
static char db_items [] = {
isc_info_page_size,
isc_info_allocation,
isc_info_sweep_interval,
isc_info_end
};
strcpy(user_name, "guest");
strcpy(password, "guest");
strcpy(dbname, "employee.gdb");
if (argc > 1)
strcpy(dbname, argv[1]);
if (argc > 2)
strcpy(user_name, argv[2]);
if (argc > 3)
strcpy(password, argv[3]);
if (argc > 4)
sweep_interval = atoi(argv[4]);
/* Adding sweep interval will be done by hand
** First byte is a version (1), next byte is the isc_dpb_sweep
** byte, then a length (4) then the byte-swapped int we want
** to provide -- 7 bytes total
*/
copy = dpb = (char *) malloc(7);
p = dpb;
*p++ = '\1';
*p++ = isc_dpb_sweep_interval;
*p++ = '\4';
l = isc_vax_integer((char ISC_FAR *) &sweep_interval, 4);
d = (char *) &l;
*p++ = *d++;
*p++ = *d++;
*p++ = *d++;
*p = *d;
dpb_length = 7;
/* Add user and password to dpb, much easier. The dpb will be
** new memory.
*/
isc_expand_dpb(&dpb, (short ISC_FAR *) &dpb_length,
isc_dpb_user_name, user_name,
isc_dpb_password, password, NULL);
/*
** Connect to the database with the given user and pw.
*/
printf("Attaching to %s with user name: %s, password: %s\n",
dbname, user_name, password);
printf("Resetting sweep interval to %ld\n", sweep_interval);
if (isc_attach_database(status, 0, dbname, &db, dpb_length, dpb))
isc_print_status(status);
/* Prove we are "guest" . Query a single row with the
** key word "USER" to find out who we are
*/
if (isc_start_transaction(status, &trans, 1, &db, 0, NULL))
isc_print_status(status);
/* Prepare sqlda for singleton fetch */
sqlda = (XSQLDA ISC_FAR *) malloc(XSQLDA_LENGTH(1));
sqlda->sqln = sqlda->sqld = 1;
sqlda->version = 1;
sqlda->sqlvar[0].sqldata = uname;
sqlda->sqlvar[0].sqlind = &nullind;
/* Yes, it is possible to execute a singleton select without
** a cursor. You must prepare the sqlda by hand.
*/
isc_dsql_allocate_statement(status, &db, &stmt);
if (isc_dsql_prepare(status, &trans, &stmt, 0, query, 1, sqlda))
{
ERREXIT(status, 1)
}
/* Force to type sql_text */
sqlda->sqlvar[0].sqltype = SQL_TEXT;
if (isc_dsql_execute(status, &trans, &stmt, 1, NULL))
{
ERREXIT(status, 1)
}
/* There will only be one row. If it isn't there, something is
** seriously wrong.
*/
if (isc_dsql_fetch(status, &stmt, 1, sqlda))
{
ERREXIT(status, 1)
}
isc_dsql_free_statement(status, &stmt, DSQL_close);
uname[sqlda->sqlvar[0].sqllen] = '\0';
printf ("New user = %s\n", uname);
if (isc_commit_transaction(status, &trans))
{
ERREXIT(status, 1)
}
/* Look at the database to see some parameters (like sweep
** The database_info call returns a buffer full of type, length,
** and value sets until info_end is reached
*/
if (isc_database_info(status, &db, sizeof(db_items), db_items,
sizeof (buffer), buffer))
{
ERREXIT(status, 1)
}
for (d = buffer; *d != isc_info_end;)
{
value_out = 0;
item = *d++;
length = (short) isc_vax_integer (d, 2);
d += 2;
switch (item)
{
case isc_info_end:
break;
case isc_info_page_size:
value_out = isc_vax_integer (d, length);
printf ("PAGE_SIZE %ld \n", value_out);
break;
case isc_info_allocation:
value_out = isc_vax_integer (d, length);
printf ("Number of DB pages allocated = %ld \n",
value_out);
break;
case isc_info_sweep_interval:
value_out = isc_vax_integer (d, length);
printf ("Sweep interval = %ld \n", value_out);
break;
}
d += length;
}
isc_detach_database(status, &db);
isc_free(dpb);
free(copy);
free(sqlda);
return 0;
}

239
src/v5_examples/api16.c Normal file
View File

@ -0,0 +1,239 @@
/********************************************************************8
**
** Program type: API
**
** Description: This program does an asynchronous event wait
** on a trigger set up in employee.sales.
** Somebody must add a new sales order to alert
** this program. That role can be accomplished
** by running programs stat12t or api16t at the
** same time.
**
** When the event is fired, this program selects
** back any new records and updates (current) those
** records to status "open". The entire program runs
** in a single read-committed (wait, no version)
** transaction, so transaction doesn't need to be started
** after an event.
* The contents of this file are subject to the Interbase Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy
* of the License at http://www.Inprise.com/IPL.html
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code was created by Inprise Corporation
* and its predecessors. Portions created by Inprise Corporation are
* Copyright (C) Inprise Corporation.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "example.h"
#include <ibase.h>
/* Sleep for Windows is a stupid loop with I/O */
#if defined __BORLANDC__ || defined _MSC_VER
#include <windows.h>
#define SLEEP(x) Sleep(x * 1000 )
#else
#define SLEEP(x) sleep(x)
#endif
short event_flag = 0;
isc_callback ast_routine (char ISC_FAR *, short, char ISC_FAR *);
int main(ARG(int, argc), ARG(char **, argv))
ARGLIST(int argc)
ARGLIST(char **argv)
{
isc_db_handle DB = NULL; /* database handle */
isc_tr_handle trans = NULL; /* transaction handle */
isc_stmt_handle stmt = NULL; /* transaction handle */
long status[20]; /* status vector */
char ISC_FAR * event_buffer;
char ISC_FAR * result_buffer;
long event_id;
short length;
char dbname[128];
char po_number[9];
XSQLDA ISC_FAR * sqlda;
short nullind = 0;
char query[128], update[128];
long count[2], i = 0;
unsigned long Vector[20];
char ids[2][15];
int first = 1;
int ret = 0;
/* Transaction parameter block for read committed */
static char isc_tpb[5] = {isc_tpb_version1,
isc_tpb_write,
isc_tpb_read_committed,
isc_tpb_wait,
isc_tpb_no_rec_version};
if (argc > 1)
strcpy(dbname, argv[1]);
else
strcpy(dbname, "employee.gdb");
strcpy (ids[0], "new_order");
strcpy (ids[1], "change_order");
count[0] = 0;
count[1] = 0;
sqlda = (XSQLDA ISC_FAR *) malloc(XSQLDA_LENGTH(1));
sqlda->sqln = 1;
sqlda->version = 1;
sqlda->sqlvar[0].sqldata = po_number;
sqlda->sqlvar[0].sqlind = &nullind;
if (isc_attach_database (status, 0, dbname, &DB, 0, NULL))
{ERREXIT(status, 1)};
/* SET TRANSACTION ISOLATION LEVEL READ COMMITTED */
if (isc_start_transaction (status, &trans, 1, &DB, 5, isc_tpb))
{ERREXIT(status, 1)};
/* Prepare the query to look at the result tables */
strcpy(query, " SELECT po_number FROM sales \
WHERE order_status = 'new' FOR UPDATE");
/* This is for the update where current of */
strcpy(update,
"UPDATE sales SET order_status = 'open' WHERE CURRENT OF C");
isc_dsql_allocate_statement(status, &DB, &stmt);
if (isc_dsql_prepare(status, &trans, &stmt, 0, query, 1, sqlda))
{ERREXIT(status, 1)};
/* Call the cursor "C" */
isc_dsql_set_cursor_name(status, &stmt, "C", 0);
/* Allocate an event block and initialize its values
** This will wait on two named events
*/
length = (short) isc_event_block((char ISC_FAR * ISC_FAR *) &event_buffer,
(char ISC_FAR * ISC_FAR *) &result_buffer,
2, ids[0], ids[1], 0);
/* Request the server to notify us of our events of interest.
** When one of the two named events is triggered, the ast_routine
** will be called with event_buffer, an updated buffer and length
** que_events returns ast_returns value
*/
if(isc_que_events(status, &DB, &event_id, length,
event_buffer, (isc_callback) ast_routine, result_buffer))
{ERREXIT(status, 1)};
while (!ret)
{
i++;
/* If the event was triggered, reset the buffer and re-queue */
if (event_flag)
{
/* Check for first ast_call. isc_que_events fires
each event to get processing started */
if ( first )
{
first = 0;
event_flag = 0;
}
else
{
event_flag = 0;
/* event_counts will compare the various events
** listed in the two buffers and update the
** appropriate count_array elements with the difference
** in the counts in the two buffers.
*/
isc_event_counts(Vector, length, (char ISC_FAR *) event_buffer,
(char ISC_FAR *) result_buffer);
/* Look through the count array */
count[0] += Vector[0];
count[1] += Vector[1];
/* Select query to look at triggered events */
if (isc_dsql_execute(status, &trans, &stmt, 1, NULL))
{ERREXIT(status, 1)};
while (!isc_dsql_fetch(status, &stmt, 1, sqlda))
{
po_number[8] = 0;
printf("api16: %s\n", po_number);
/* exit on processing the last example record*/
if (!strncmp(po_number, "VNEW4", 5))
ret = 1;
/* Update current row */
if(isc_dsql_execute_immediate(status, &DB,
&trans, 0, update, 1, NULL))
{ERREXIT(status, 1)};
}
/* Close cursor */
isc_dsql_free_statement(status, &stmt, DSQL_close);
}
/* Re-queue for the next event */
if (isc_que_events(status, &DB, &event_id, length,
event_buffer, (isc_callback) ast_routine, result_buffer))
{ERREXIT(status, 1)};
}
/* This does not block, but as a sample program there is nothing
** else for us to do, so we will take a nap
*/
SLEEP(1);
}
isc_commit_transaction(status, &trans);
isc_detach_database (status, &DB);
printf("Event complete, exiting\n");
free( sqlda);
return 0;
}
/*
** The called routine is always called with these three buffers. Any
** event will land us here . PLus we get called once when the
** program first starts.
*/
isc_callback ast_routine(ARG(char ISC_FAR *, result),
ARG(short, length),
ARG(char ISC_FAR *, updated))
ARGLIST(char *result)
ARGLIST(char *updated)
ARGLIST(short length)
{
/* Set the global event flag */
event_flag++;
printf("ast routine was called\n");
/* Copy the updated buffer to the result buffer */
while (length--)
*result++ = *updated++;
return 0;
}

181
src/v5_examples/api16t.c Normal file
View File

@ -0,0 +1,181 @@
/*
* Program type: API
*
* Description:
* If run from a Windows 3.1 Client, the winevent program
* should be started before running this program and should
* be terminated upon the completion of this program.
* For other platforms, this program should be run in
* conjunction with api16.
*
* This Program adds some sales records, in order to trigger
* the event that api16 or winevent is waiting for.
* The contents of this file are subject to the Interbase Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy
* of the License at http://www.Inprise.com/IPL.html
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code was created by Inprise Corporation
* and its predecessors. Portions created by Inprise Corporation are
* Copyright (C) Inprise Corporation.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "example.h"
#include <ibase.h>
int main (ARG(int, argc), ARG(char **, argv))
ARGLIST(int argc)
ARGLIST(char **argv)
{
struct {
short len;
char data [9];
} po_number;
short nullind = 0;
isc_stmt_handle stmt = NULL; /* statement handle */
isc_db_handle DB = NULL; /* database handle */
isc_tr_handle trans = NULL; /* transaction handle */
long status[20]; /* status vector */
XSQLDA ISC_FAR * sqlda;
char empdb[128];
char *delete_str =
"DELETE FROM sales WHERE po_number LIKE 'VNEW%'";
char *insert_str =
"INSERT INTO sales (po_number, cust_no, order_status, total_value) \
VALUES (?, 1015, 'new', 0)";
if (argc > 1)
strcpy(empdb, argv[1]);
else
strcpy(empdb, "employee.gdb");
if (isc_attach_database(status, 0, empdb, &DB, 0, NULL))
{
ERREXIT(status, 1)
}
if (isc_start_transaction(status, &trans, 1, &DB, 0, NULL))
{
ERREXIT(status, 1)
}
/* Allocate an input SQLDA for po_number in insert string. */
sqlda = (XSQLDA ISC_FAR *) malloc(XSQLDA_LENGTH(1));
sqlda->sqln = 1;
sqlda->sqld = 1;
sqlda->version = 1;
/* Allocate a statement. */
if (isc_dsql_allocate_statement(status, &DB, &stmt))
{
ERREXIT(status, 1)
}
/* Start out by deleting any existing records */
if (isc_dsql_execute_immediate(status, &DB, &trans, 0, delete_str,
1, NULL))
{
ERREXIT(status, 2)
}
if (isc_commit_transaction(status, &trans))
{
ERREXIT(status, 2)
}
if (isc_start_transaction(status, &trans, 1, &DB, 0, NULL))
{
ERREXIT(status, 3)
}
/* Insert three records in one transaction */
if (isc_dsql_prepare(status, &trans, &stmt, 0, insert_str, 1, NULL))
{
ERREXIT(status, 4)
}
if (isc_dsql_describe_bind(status, &stmt, 1, sqlda))
{
ERREXIT(status, 5)
}
sqlda->sqlvar[0].sqltype = SQL_VARYING + 1;
sqlda->sqlvar[0].sqllen = sizeof (po_number.data);
sqlda->sqlvar[0].sqldata = (char *) &po_number;
sqlda->sqlvar[0].sqlind = &nullind;
/* Add batch 1. */
po_number.len = strlen("VNEW1");
strncpy(po_number.data, "VNEW1", sizeof (po_number.data));
printf("api16t: Adding %s\n", po_number.data);
if (isc_dsql_execute(status, &trans, &stmt, 1, sqlda))
{
ERREXIT(status, 6)
}
po_number.len = strlen("VNEW2");
strncpy(po_number.data, "VNEW2", sizeof (po_number.data));
printf("api16t: Adding %s\n", po_number.data);
if (isc_dsql_execute(status, &trans, &stmt, 1, sqlda))
{
ERREXIT(status, 6)
}
po_number.len = strlen("VNEW3");
strncpy(po_number.data, "VNEW3", sizeof (po_number.data));
printf("api16t: Adding %s\n", po_number.data);
if (isc_dsql_execute(status, &trans, &stmt, 1, sqlda))
{
ERREXIT(status, 6)
}
/* This will fire the triggers for the first three records */
if (isc_commit_transaction(status, &trans))
{
ERREXIT(status, 7)
}
/* Add batch 2. */
if (isc_start_transaction(status, &trans, 1, &DB, 0, NULL))
{
ERREXIT(status, 8)
}
po_number.len = strlen("VNEW4");
strncpy(po_number.data, "VNEW4", sizeof (po_number.data));
printf("api16t: Adding %s\n", po_number.data);
if (isc_dsql_execute(status, &trans, &stmt, 1, sqlda))
{
ERREXIT(status, 9)
}
if (isc_dsql_free_statement(status, &stmt, DSQL_drop))
{
ERREXIT(status, 10)
}
/* This will fire the triggers for the fourth record */
if (isc_commit_transaction(status, &trans))
{
ERREXIT(status, 11)
}
isc_detach_database(status, &DB);
free(sqlda);
return 0;
}

193
src/v5_examples/api2.c Normal file
View File

@ -0,0 +1,193 @@
/*
* Program type: API Interface
*
* Description:
* This program adds several departments with small default
* budgets, using 'execute immediate' statement.
* Then, a prepared statement, which doubles budgets for
* departments with low budgets, is executed.
* The contents of this file are subject to the Interbase Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy
* of the License at http://www.Inprise.com/IPL.html
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code was created by Inprise Corporation
* and its predecessors. Portions created by Inprise Corporation are
* Copyright (C) Inprise Corporation.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "example.h"
#include <ibase.h>
#define MAXLEN 256
#define DNAMELEN 25
#define DNOLEN 3
int getline (char ISC_FAR *, int);
int cleanup (void);
isc_db_handle DB = NULL; /* database handle */
isc_tr_handle trans = NULL; /* transaction handle */
long status[20]; /* status vector */
char Db_name[128];
int main (ARG(int, argc), ARG(char **, argv))
ARGLIST(int argc)
ARGLIST(char **argv)
{
int n = 0;
char exec_str[MAXLEN];
char prep_str[MAXLEN];
isc_stmt_handle double_budget = NULL; /* statement handle */
if (argc > 1)
strcpy(Db_name, argv[1]);
else
strcpy(Db_name, "employee.gdb");
if (isc_attach_database(status, 0, Db_name, &DB, 0, NULL))
{
ERREXIT(status, 1)
}
cleanup();
/*
* Prepare a statement, which may be executed more than once.
*/
strcpy(prep_str,
"UPDATE DEPARTMENT SET budget = budget * 2 WHERE budget < 100000");
/* Allocate a statement. */
if (isc_dsql_allocate_statement(status, &DB, &double_budget))
{
ERREXIT(status, 1)
}
if (isc_start_transaction(status, &trans, 1, &DB, 0, NULL))
{
ERREXIT(status, 1)
}
/* Prepare the statement. */
if (isc_dsql_prepare(status, &trans, &double_budget, 0, prep_str, 1, NULL))
{
ERREXIT(status, 1)
}
/*
* Add new departments, using 'execute immediate'.
* Build each 'insert' statement, using the supplied parameters.
* Since these statements will not be needed after they are executed,
* use 'execute immediate'.
*/
while (getline(exec_str, n++))
{
printf("\nExecuting statement:\n%d:\t%s;\n", n, exec_str);
if (isc_dsql_execute_immediate(status, &DB, &trans, 0, exec_str, 1, NULL))
{
ERREXIT(status, 1)
}
}
/*
* Execute a previously prepared statement.
*/
printf("\nExecuting a prepared statement:\n\t%s;\n\n", prep_str);
if (isc_dsql_execute(status, &trans, &double_budget, 1, NULL))
{
ERREXIT(status, 1)
}
if (isc_dsql_free_statement(status, &double_budget, DSQL_drop))
{
ERREXIT(status, 1)
}
if (isc_commit_transaction(status, &trans))
{
ERREXIT(status, 1)
}
if (isc_detach_database(status, &DB))
{
ERREXIT(status, 1)
}
return 0;
}
/*
* Construct an 'insert' statement from the supplied parameters.
*/
int getline (ARG(char ISC_FAR*, line), ARG(int, line_no))
ARGLIST(char ISC_FAR* line)
ARGLIST(int line_no)
{
static char ISC_FAR * Dept_data[] =
{
"117", "Field Office: Hong Kong", "110",
"118", "Field Office: Australia", "110",
"119", "Field Office: New Zealand", "110",
0
};
char dept_no[4];
char department[30];
char dept_head[4];
if (Dept_data[3 * line_no] == 0)
return 0;
strcpy(dept_no, Dept_data[3 * line_no]);
strcpy(department, Dept_data[3 * line_no + 1]);
strcpy(dept_head, Dept_data[3 * line_no + 2]);
sprintf(line, "INSERT INTO DEPARTMENT (dept_no, department, head_dept) \
VALUES ('%s', '%s', '%s')", dept_no, department, dept_head);
return 1;
}
/*
* Delete old data.
*/
int cleanup (void)
{
if (isc_start_transaction(status, &trans, 1, &DB, 0, NULL))
{
ERREXIT(status, 1)
}
if (isc_dsql_execute_immediate(status, &DB, &trans, 0,
"DELETE FROM department WHERE dept_no IN ('117', '118', '119')", 1, 0L))
{
ERREXIT(status, 1)
}
if (isc_commit_transaction(status, &trans))
{
ERREXIT(status, 1)
}
return 0;
}

159
src/v5_examples/api3.c Normal file
View File

@ -0,0 +1,159 @@
/*
* Program type: API Interface
*
* Description:
* This program displays employee names and phone extensions.
*
* It allocates an output SQLDA, prepares and executes a statement,
* and loops fetching multiple rows.
*
* The SQLCODE returned by fetch is checked.
* The contents of this file are subject to the Interbase Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy
* of the License at http://www.Inprise.com/IPL.html
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code was created by Inprise Corporation
* and its predecessors. Portions created by Inprise Corporation are
* Copyright (C) Inprise Corporation.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <ibase.h>
#include "example.h"
#define LASTLEN 20
#define FIRSTLEN 15
#define EXTLEN 4
/* This macro is used to declare structures representing SQL VARCHAR types */
#define SQL_VARCHAR(len) struct {short vary_length; char vary_string[(len)+1];}
int main (ARG(int, argc), ARG(char **, argv))
ARGLIST(int argc)
ARGLIST(char **argv)
{
SQL_VARCHAR(LASTLEN) last_name;
SQL_VARCHAR(FIRSTLEN) first_name;
char phone_ext[EXTLEN + 2];
short flag0 = 0, flag1 = 0;
short flag2 = 0;
isc_stmt_handle stmt = NULL; /* statement handle */
isc_db_handle DB = NULL; /* database handle */
isc_tr_handle trans = NULL; /* transaction handle */
long status[20]; /* status vector */
XSQLDA ISC_FAR * sqlda;
long fetch_stat;
char empdb[128];
char *sel_str =
"SELECT last_name, first_name, phone_ext FROM phone_list \
WHERE location = 'Monterey' ORDER BY last_name, first_name;";
if (argc > 1)
strcpy(empdb, argv[1]);
else
strcpy(empdb, "employee.gdb");
if (isc_attach_database(status, 0, empdb, &DB, 0, NULL))
isc_print_status(status);
if (isc_start_transaction(status, &trans, 1, &DB, 0, NULL))
{
ERREXIT(status, 1)
}
/* Allocate an output SQLDA. */
sqlda = (XSQLDA ISC_FAR *) malloc(XSQLDA_LENGTH(3));
sqlda->sqln = 3;
sqlda->sqld = 3;
sqlda->version = 1;
/* Allocate a statement. */
if (isc_dsql_allocate_statement(status, &DB, &stmt))
{
ERREXIT(status, 1)
}
/* Prepare the statement. */
if (isc_dsql_prepare(status, &trans, &stmt, 0, sel_str, 1, sqlda))
{
ERREXIT(status, 1)
}
/*
* Although all three selected columns are of type varchar, the
* third field's type is changed and printed as type TEXT.
*/
sqlda->sqlvar[0].sqldata = (char *)&last_name;
sqlda->sqlvar[0].sqltype = SQL_VARYING + 1;
sqlda->sqlvar[0].sqlind = &flag0;
sqlda->sqlvar[1].sqldata = (char *)&first_name;
sqlda->sqlvar[1].sqltype = SQL_VARYING + 1;
sqlda->sqlvar[1].sqlind = &flag1;
sqlda->sqlvar[2].sqldata = (char ISC_FAR *) phone_ext;
sqlda->sqlvar[2].sqltype = SQL_TEXT + 1;
sqlda->sqlvar[2].sqlind = &flag2;
printf("\n%-20s %-15s %-10s\n\n", "LAST NAME", "FIRST NAME", "EXTENSION");
/* Execute the statement. */
if (isc_dsql_execute(status, &trans, &stmt, 1, NULL))
{
ERREXIT(status, 1)
}
/*
* Fetch and print the records.
* Status is 100 after the last row is fetched.
*/
while ((fetch_stat = isc_dsql_fetch(status, &stmt, 1, sqlda)) == 0)
{
printf("%-20.*s ", last_name.vary_length, last_name.vary_string);
printf("%-15.*s ", first_name.vary_length, first_name.vary_string);
phone_ext[sqlda->sqlvar[2].sqllen] = '\0';
printf("%s\n", phone_ext);
}
if (fetch_stat != 100L)
{
ERREXIT(status, 1)
}
/* Free statement handle. */
if (isc_dsql_free_statement(status, &stmt, DSQL_close))
{
ERREXIT(status, 1)
}
if (isc_commit_transaction(status, &trans))
{
ERREXIT(status, 1)
}
if (isc_detach_database(status, &DB))
{
ERREXIT(status, 1)
}
free( sqlda);
return 0;
}

168
src/v5_examples/api4.c Normal file
View File

@ -0,0 +1,168 @@
/*
* Program type: API Interface
*
* Desription:
* This program updates departments' budgets, given
* the department and the new budget information parameters.
*
* An input SQLDA is allocated for the update query
* with parameter markers.
* Note that all updates are rolled back in this version.
* The contents of this file are subject to the Interbase Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy
* of the License at http://www.Inprise.com/IPL.html
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code was created by Inprise Corporation
* and its predecessors. Portions created by Inprise Corporation are
* Copyright (C) Inprise Corporation.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/
#include <stdlib.h>
#include <string.h>
#include <ibase.h>
#include <stdio.h>
#include "example.h"
int get_input (char* , double*);
static char *Dept_data[] =
{"622", "100", "116", "900", 0};
static double Percent_data[] =
{0.05, 1.00, 0.075, 0.10, 0};
int Input_ptr = 0;
char *updstr =
"UPDATE department SET budget = ? * budget + budget WHERE dept_no = ?";
isc_db_handle DB = NULL; /* database handle */
isc_tr_handle trans = NULL; /* transaction handle */
long status[20]; /* status vector */
int main (ARG(int, argc), ARG(char **, argv))
ARGLIST(int argc)
ARGLIST(char **argv)
{
char dept_no[4];
double percent_inc;
short flag0 = 0, flag1 = 0;
XSQLDA ISC_FAR *sqlda;
long sqlcode;
char empdb[128];
if (argc > 1)
strcpy(empdb, argv[1]);
else
strcpy(empdb, "employee.gdb");
if (isc_attach_database(status, 0, empdb, &DB, 0, NULL))
{
ERREXIT(status, 1)
}
/* Allocate an input SQLDA. There are two unknown parameters. */
sqlda = (XSQLDA ISC_FAR *) malloc(XSQLDA_LENGTH(2));
sqlda->sqln = 2;
sqlda->sqld = 2;
sqlda->version = 1;
sqlda->sqlvar[0].sqldata = (char ISC_FAR *) &percent_inc;
sqlda->sqlvar[0].sqltype = SQL_DOUBLE + 1;
sqlda->sqlvar[0].sqllen = sizeof(percent_inc);
sqlda->sqlvar[0].sqlind = &flag0;
flag0 = 0;
sqlda->sqlvar[1].sqldata = dept_no;
sqlda->sqlvar[1].sqltype = SQL_TEXT + 1;
sqlda->sqlvar[1].sqllen = 3;
sqlda->sqlvar[1].sqlind = &flag1;
flag1 = 0;
/*
* Get the next department-percent increase input pair.
*/
while (get_input(dept_no, &percent_inc))
{
printf("\nIncreasing budget for department: %s by %5.2lf percent.\n",
dept_no, percent_inc);
if (isc_start_transaction(status, &trans, 1, &DB, 0, NULL))
{
ERREXIT(status, 1)
}
/* Update the budget. */
isc_dsql_execute_immediate(status, &DB, &trans, 0, updstr, 1, sqlda);
sqlcode = isc_sqlcode(status);
if (sqlcode)
{
/* Don't save the update, if the new budget exceeds the limit. */
if (sqlcode == -625)
{
printf("\tExceeded budget limit -- not updated.\n");
if (isc_rollback_transaction(status, &trans))
{
ERREXIT(status, 1)
}
continue;
}
/* Undo all changes, in case of an error. */
else
{
isc_print_status(status);
printf("SQLCODE=%d\n", sqlcode);
isc_rollback_transaction(status, &trans);
ERREXIT(status, 1)
}
}
/* Save each department's update independently.
** Change to isc_commit_transaction to see changes
*/
if (isc_rollback_transaction (status, &trans))
{
ERREXIT(status, 1)
}
}
if (isc_detach_database(status, &DB))
{
ERREXIT(status, 1)
}
free(sqlda);
return 0;
}
/*
* Get the department and percent parameters.
*/
int get_input (ARG(char *,dept_no), ARG(double *,percent))
ARGLIST(char *dept_no)
ARGLIST(double *percent)
{
if (Dept_data[Input_ptr] == 0)
return 0;
strcpy(dept_no, Dept_data[Input_ptr]);
if ((*percent = Percent_data[Input_ptr++]) == 0)
return 0;
return 1;
}

142
src/v5_examples/api5.c Normal file
View File

@ -0,0 +1,142 @@
/*
* Program type: API Interface
*
* Desription:
* This program demonstrates the reallocation of SQLDA
* and the 'isc_dsql_describe' statement. After a query
* is examined with 'isc_dsql_describe', an SQLDA of correct
* size is reallocated, and some information is printed about
* the query: its type (select, non-select), the number
* of columns, etc.
* The contents of this file are subject to the Interbase Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy
* of the License at http://www.Inprise.com/IPL.html
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code was created by Inprise Corporation
* and its predecessors. Portions created by Inprise Corporation are
* Copyright (C) Inprise Corporation.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/
#include <stdlib.h>
#include <string.h>
#include <ibase.h>
#include <stdio.h>
#include "example.h"
char *sel_str =
"SELECT department, mngr_no, location, head_dept \
FROM department WHERE head_dept in ('100', '900', '600')";
isc_db_handle DB = 0; /* database handle */
isc_tr_handle trans = 0; /* transaction handle */
long status[20]; /* status vector */
int main (ARG(int, argc), ARG(char **, argv))
ARGLIST(int argc)
ARGLIST(char **argv)
{
int num_cols, i;
isc_stmt_handle stmt = NULL;
XSQLDA ISC_FAR *sqlda;
char empdb[128];
if (argc > 1)
strcpy(empdb, argv[1]);
else
strcpy(empdb, "employee.gdb");
if (isc_attach_database(status, 0, empdb, &DB, 0, NULL))
{
ERREXIT(status, 1)
}
/* Allocate SQLDA of an arbitrary size. */
sqlda = (XSQLDA ISC_FAR *) malloc(XSQLDA_LENGTH(3));
sqlda->sqln = 3;
sqlda->version = 1;
if (isc_start_transaction(status, &trans, 1, &DB, 0, NULL))
{
ERREXIT(status, 1)
}
/* Allocate a statement. */
if (isc_dsql_allocate_statement(status, &DB, &stmt))
{
ERREXIT(status, 1)
}
/* Prepare the statement. */
if (isc_dsql_prepare(status, &trans, &stmt, 0, sel_str, 1, sqlda))
{
ERREXIT(status, 1)
}
/* Describe the statement. */
if (isc_dsql_describe(status, &stmt, 1, sqlda))
{
ERREXIT(status, 1)
}
/* This is a select statement, print more information about it. */
printf("Query Type: SELECT\n\n");
num_cols = sqlda->sqld;
printf("Number of columns selected: %d\n", num_cols);
/* Reallocate SQLDA if necessary. */
if (sqlda->sqln < sqlda->sqld)
{
sqlda = (XSQLDA ISC_FAR *) malloc(XSQLDA_LENGTH(num_cols));
sqlda->sqln = num_cols;
sqlda->version = 1;
/* Re-describe the statement. */
if (isc_dsql_describe(status, &stmt, 1, sqlda))
{
ERREXIT(status, 1)
}
num_cols = sqlda->sqld;
}
/* List column names, types, and lengths. */
for (i = 0; i < num_cols; i++)
{
printf("\nColumn name: %s\n", sqlda->sqlvar[i].sqlname);
printf("Column type: %d\n", sqlda->sqlvar[i].sqltype);
printf("Column length: %d\n", sqlda->sqlvar[i].sqllen);
}
if (isc_dsql_free_statement(status, &stmt, DSQL_drop))
{
ERREXIT(status, 1)
}
if (isc_commit_transaction(status, &trans))
{
ERREXIT(status, 1)
}
if (isc_detach_database(status, &DB))
{
ERREXIT (status, 1)
}
free(sqlda);
return 0;
}

263
src/v5_examples/api6.c Normal file
View File

@ -0,0 +1,263 @@
/*
* Program type: API Interface
*
* Description:
* This program performs a positioned update.
* Department budgets are examined and updated using some
* percent increase factor, determined at run-time.
*
* The update statement is constructed using a dynamic cursor
* name. The statement handle is freed and re-used by the
* update cursor, after being used by another statement.
* The contents of this file are subject to the Interbase Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy
* of the License at http://www.Inprise.com/IPL.html
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code was created by Inprise Corporation
* and its predecessors. Portions created by Inprise Corporation are
* Copyright (C) Inprise Corporation.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/
#include <stdlib.h>
#include <string.h>
#include <ibase.h>
#include <stdio.h>
#include "example.h"
#define DEPTLEN 3
#define PROJLEN 5
#define BUFLEN 256
float increase_factor (double budget);
/*
* A cursor is declared on this select statement, allowing for
* the update of projected_budget field.
*/
char *sel_str =
"SELECT proj_id, dept_no, projected_budget \
FROM proj_dept_budget WHERE fiscal_year = 1994 \
FOR UPDATE OF projected_budget";
/* This query is executed prior to the positioned update. */
char *tot_str =
"SELECT SUM(projected_budget) FROM proj_dept_budget WHERE fiscal_year = 1994";
int main (ARG(int, argc), ARG(char **,argv))
ARGLIST(int argc)
ARGLIST(char **argv)
{
char dept_no[DEPTLEN + 2];
char proj_id[PROJLEN + 2];
char upd_str[BUFLEN];
double budget;
double tot_budget;
short flag0 = 0,
flag1 = 0,
flag2 = 0,
flag3 = 0;
isc_db_handle DB = NULL; /* Database handle */
isc_tr_handle trans = NULL; /* transaction handle */
long status[20]; /* status vector */
char *cursor = "budget"; /* dynamic cursor name */
isc_stmt_handle stmt = NULL; /* statement handle */
XSQLDA ISC_FAR * osqlda; /* output SQLDA */
XSQLDA ISC_FAR * isqlda; /* input SQLDA */
long fetch_stat;
char empdb[128];
if (argc > 1)
strcpy(empdb, argv[1]);
else
strcpy(empdb, "employee.gdb");
if (isc_attach_database(status, 0, empdb, &DB, 0, NULL))
{
ERREXIT(status, 1)
}
/*
* Prepare and execute the first select statement.
* Free the statement handle, when done.
*/
if (isc_dsql_allocate_statement(status, &DB, &stmt))
{
ERREXIT(status, 1)
}
osqlda = (XSQLDA *) malloc(XSQLDA_LENGTH(1));
osqlda->sqln = 1;
osqlda->sqld = 1;
osqlda->version = 1;
if (isc_start_transaction(status, &trans, 1, &DB, 0, NULL))
{
ERREXIT(status, 1)
}
if (isc_dsql_prepare(status, &trans, &stmt, 0, tot_str, 1, osqlda))
isc_print_status(status);
osqlda->sqlvar[0].sqldata = (char *) &tot_budget;
osqlda->sqlvar[0].sqltype = SQL_DOUBLE + 1;
osqlda->sqlvar[0].sqllen = sizeof(budget);
osqlda->sqlvar[0].sqlind = &flag3;
if (isc_dsql_execute(status, &trans, &stmt, 1, NULL))
{
ERREXIT(status, 1)
}
fetch_stat = isc_dsql_fetch(status, &stmt, 1, osqlda);
printf("\nTotal budget: %16.2f\n\n", tot_budget);
if (isc_dsql_free_statement(status, &stmt, DSQL_close))
{
ERREXIT(status, 1)
}
if (isc_commit_transaction(status, &trans))
{
ERREXIT(status, 1)
}
/*
* Prepare and execute the positioned update.
* Re-use the statement handle as the select cursor.
*/
sprintf(upd_str, "UPDATE proj_dept_budget SET projected_budget = ? \
WHERE CURRENT OF %s", cursor);
/* Allocate an input SQLDA for the update statement. */
isqlda = (XSQLDA ISC_FAR *) malloc(XSQLDA_LENGTH(1));
isqlda->sqln = isqlda->sqld = 1;
isqlda->version = 1;
isqlda->sqlvar[0].sqldata = (char ISC_FAR *) &budget;
isqlda->sqlvar[0].sqltype = SQL_DOUBLE + 1;
isqlda->sqlvar[0].sqllen = sizeof(budget);
isqlda->sqlvar[0].sqlind = &flag3;
/* Free the output SQLDA, which was used previously. */
free(osqlda);
/* Re-allocate the output SQLDA. */
osqlda = (XSQLDA ISC_FAR*) malloc(XSQLDA_LENGTH(3));
osqlda->sqln = 3;
osqlda->sqld = 3;
osqlda->version = 1;
osqlda->sqlvar[0].sqldata = proj_id;
osqlda->sqlvar[0].sqlind = &flag0;
osqlda->sqlvar[1].sqldata = dept_no;
osqlda->sqlvar[1].sqlind = &flag1;
osqlda->sqlvar[2].sqldata = (char ISC_FAR *) &budget;
osqlda->sqlvar[2].sqlind = &flag2;
if (isc_start_transaction(status, &trans, 1, &DB, 0, NULL))
{
ERREXIT(status, 1)
}
/* Zero the statement handle. */
stmt = NULL;
if (isc_dsql_allocate_statement(status, &DB, &stmt))
isc_print_status(status);
if (isc_dsql_prepare(status, &trans, &stmt, 0, sel_str, 1, osqlda))
isc_print_status(status);
/* Declare the cursor. */
isc_dsql_set_cursor_name(status, &stmt, cursor, 0);
if (isc_dsql_execute(status, &trans, &stmt, 1, NULL))
{
ERREXIT(status, 1)
}
printf("\n%-15s%-10s%-18s%-18s\n\n",
"PROJ", "DEPT", " CURRENT BUDGET", " CHANGED TO");
/*
* Fetch and update department budgets.
*/
while ((fetch_stat = isc_dsql_fetch(status, &stmt, 1, osqlda)) == 0)
{
/* Determine the increase percentage. */
proj_id[PROJLEN] = '\0';
dept_no[DEPTLEN] = '\0';
printf("%-15s%-10s%15.2f", proj_id, dept_no, budget);
budget = budget + budget * increase_factor(budget);
printf("%15.2f\n", budget);
/* Increase the budget. */
isc_dsql_exec_immed2(status, &DB, &trans, 0, upd_str, 1, isqlda, NULL);
if (isc_sqlcode(status) == -625)
{
printf("\tExceeded budget limit -- not updated.\n");
continue;
}
else
isc_print_status(status);
}
if (fetch_stat != 100L)
{
ERREXIT(status, 1)
}
if (isc_dsql_free_statement(status, &stmt, DSQL_close))
{
ERREXIT(status, 1)
}
if (isc_rollback_transaction(status, &trans))
{
ERREXIT(status, 1)
}
if (isc_detach_database(status, &DB))
{
ERREXIT(status, 1)
}
free(osqlda);
free(isqlda);
return 0;
}
/*
* Determine a percent increase for the department's budget.
*/
float increase_factor (ARG(double, budget))
ARGLIST(double budget)
{
if (budget < 100000L)
return (float)0.15;
else if (budget < 500000L)
return (float)0.10;
else
return (float)0.5;
}

183
src/v5_examples/api7.c Normal file
View File

@ -0,0 +1,183 @@
/*
* Program type: API Interface
*
* Description:
* This program selects a blob data type.
* A set of project descriptions is printed.
* The contents of this file are subject to the Interbase Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy
* of the License at http://www.Inprise.com/IPL.html
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code was created by Inprise Corporation
* and its predecessors. Portions created by Inprise Corporation are
* Copyright (C) Inprise Corporation.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/
#include <stdlib.h>
#include <string.h>
#include <ibase.h>
#include <stdio.h>
#include "example.h"
#define TYPELEN 12
#define PROJLEN 20
#define BUFLEN 512
/* This macro is used to declare structures representing SQL VARCHAR types */
#define SQL_VARCHAR(len) struct {short vary_length; char vary_string[(len)+1];}
int main (ARG(int, argc), ARG(char **, argv))
ARGLIST(int argc)
ARGLIST(char **argv)
{
SQL_VARCHAR(PROJLEN + 2) proj_name;
char prod_type[TYPELEN + 2];
char sel_str[BUFLEN + 1];
ISC_QUAD blob_id;
isc_blob_handle blob_handle = NULL;
short blob_seg_len;
char blob_segment[11];
isc_db_handle DB = NULL; /* database handle */
isc_tr_handle trans = NULL; /* transaction handle */
long status[20]; /* status vector */
isc_stmt_handle stmt = NULL; /* statement handle */
XSQLDA ISC_FAR * sqlda;
long fetch_stat, blob_stat;
short flag0 = 0,
flag1 = 0,
flag2 = 0;
char empdb[128];
if (argc > 1)
strcpy(empdb, argv[1]);
else
strcpy(empdb, "employee.gdb");
strcpy(sel_str, "SELECT proj_name, proj_desc, product FROM project WHERE \
product IN ('software', 'hardware', 'other') ORDER BY proj_name");
if (isc_attach_database(status, 0, empdb, &DB, 0, NULL))
{
ERREXIT(status, 1)
}
if (isc_start_transaction(status, &trans, 1, &DB, 0, NULL))
{
ERREXIT(status, 1)
}
/*
* Allocate and prepare the select statement.
*/
if (isc_dsql_allocate_statement(status, &DB, &stmt))
{
ERREXIT(status, 1)
}
sqlda = (XSQLDA ISC_FAR *) malloc(XSQLDA_LENGTH(3));
sqlda->sqln = 3;
sqlda->version = 1;
if (isc_dsql_prepare(status, &trans, &stmt, 0, sel_str, 1, sqlda))
{
ERREXIT(status, 1)
}
sqlda->sqlvar[0].sqldata = (char *)&proj_name;
sqlda->sqlvar[0].sqltype = SQL_VARYING + 1;
sqlda->sqlvar[0].sqlind = &flag0;
sqlda->sqlvar[1].sqldata = (char ISC_FAR *) &blob_id;
sqlda->sqlvar[1].sqltype = SQL_BLOB + 1;
sqlda->sqlvar[1].sqlind = &flag1;
sqlda->sqlvar[2].sqldata = prod_type;
sqlda->sqlvar[2].sqltype = SQL_TEXT + 1;
sqlda->sqlvar[2].sqlind = &flag2;
if (isc_dsql_execute(status, &trans, &stmt, 1, NULL))
{
ERREXIT(status, 1)
}
/*
* For each project in the select statement, get and display
* project descriptions.
*/
while ((fetch_stat = isc_dsql_fetch(status, &stmt, 1, sqlda)) == 0)
{
prod_type[TYPELEN] = '\0';
printf("\nPROJECT: %-20.*s TYPE: %-15s\n\n",
proj_name.vary_length, proj_name.vary_string, prod_type);
/* Open the blob with the fetched blob_id. Notice that the
* segment length is shorter than the average segment fetched.
* Each partial fetch should return isc_segment.
*/
if (isc_open_blob(status, &DB, &trans, &blob_handle, &blob_id))
{
ERREXIT(status, 1)
}
/* Get blob segments and their lengths and print each segment. */
blob_stat = isc_get_segment(status, &blob_handle,
(unsigned short ISC_FAR *) &blob_seg_len,
sizeof(blob_segment), blob_segment);
while (blob_stat == 0 || status[1] == isc_segment)
{
printf("%*.*s", blob_seg_len, blob_seg_len, blob_segment);
blob_stat = isc_get_segment(status, &blob_handle,
(unsigned short ISC_FAR *)&blob_seg_len,
sizeof(blob_segment), blob_segment);
}
/* Close the blob. Should be blob_stat to check */
if (status[1] == isc_segstr_eof)
{
if (isc_close_blob(status, &blob_handle))
{
ERREXIT(status, 1)
}
}
else
isc_print_status(status);
printf("\n");
}
if (fetch_stat != 100L)
{
ERREXIT(status, 1)
}
if (isc_dsql_free_statement(status, &stmt, DSQL_close))
{
ERREXIT(status, 1)
}
if (isc_commit_transaction (status, &trans))
{
ERREXIT(status, 1)
}
if (isc_detach_database(status, &DB))
{
ERREXIT(status, 1)
}
free(sqlda);
return 0;
}

182
src/v5_examples/api8.c Normal file
View File

@ -0,0 +1,182 @@
/*
* Program type: API Interface
*
* Description:
* This program updates a blob data type.
* Project descriptions are added for a set of projects.
* The contents of this file are subject to the Interbase Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy
* of the License at http://www.Inprise.com/IPL.html
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code was created by Inprise Corporation
* and its predecessors. Portions created by Inprise Corporation are
* Copyright (C) Inprise Corporation.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/
#include <stdlib.h>
#include <string.h>
#include <ibase.h>
#include <stdio.h>
#include "example.h"
#define PROJLEN 5
#define BUFLEN 512
char ISC_FAR* get_line (void);
static char *Proj_data[] =
{
"VBASE",
"Design a video data base management system for ",
"controlling on-demand video distribution.",
0,
"DGPII",
"Develop second generation digital pizza maker ",
"with flash-bake heating element and ",
"digital ingredient measuring system.",
0,
"GUIDE",
"Develop a prototype for the automobile version of ",
"the hand-held map browsing device.",
0,
"MAPDB",
"Port the map browsing database software to run ",
"on the automobile model.",
0,
"HWRII",
"Integrate the hand-writing recognition module into the ",
"universal language translator.",
0,
0
};
int Inp_ptr = 0;
int main (ARG(int, argc), ARG(char **, argv))
ARGLIST(int argc)
ARGLIST(char **argv)
{
char proj_id[PROJLEN + 1];
char upd_stmt[BUFLEN + 1];
ISC_QUAD blob_id;
isc_blob_handle blob_handle = NULL;
isc_db_handle DB = NULL; /* database handle */
isc_tr_handle trans = NULL; /* transaction handle */
long status[20]; /* status vector */
XSQLDA ISC_FAR * sqlda;
unsigned short len;
char ISC_FAR* line;
int rec_cnt = 0;
char empdb[128];
if (argc > 1)
strcpy(empdb, argv[1]);
else
strcpy(empdb, "employee.gdb");
strcpy(upd_stmt, "UPDATE project SET proj_desc = ? WHERE proj_id = ?");
if (isc_attach_database(status, 0, empdb, &DB, 0, NULL))
isc_print_status(status);
/*
* Set-up the SQLDA for the update statement.
*/
sqlda = (XSQLDA ISC_FAR *) malloc(XSQLDA_LENGTH(2));
sqlda->sqln = 2;
sqlda->sqld = 2;
sqlda->version = 1;
sqlda->sqlvar[0].sqldata = (char ISC_FAR *) &blob_id;
sqlda->sqlvar[0].sqltype = SQL_BLOB;
sqlda->sqlvar[0].sqllen = sizeof(ISC_QUAD);
sqlda->sqlvar[1].sqldata = proj_id;
sqlda->sqlvar[1].sqltype = SQL_TEXT;
sqlda->sqlvar[1].sqllen = 5;
if (isc_start_transaction(status, &trans, 1, &DB, 0, NULL))
isc_print_status(status);
/*
* Get the next project id and update the project description.
*/
line = get_line();
while (line)
{
strcpy(proj_id, line);
printf("\nUpdating description for project: %s\n\n", proj_id);
blob_handle = 0;
if (isc_create_blob(status, &DB, &trans, &blob_handle, &blob_id))
{
ERREXIT(status, 1)
}
line = get_line();
while (line)
{
printf(" Inserting segment: %s\n", line);
len = (unsigned short)strlen(line);
if (isc_put_segment(status, &blob_handle, len, line))
{
ERREXIT (status, 1)
}
line = get_line();
}
if (isc_close_blob(status, &blob_handle))
{
ERREXIT(status, 1)
}
if (isc_dsql_execute_immediate(status, &DB, &trans, 0, upd_stmt, 1,
sqlda))
{
ERREXIT (status, 1)
}
if (isc_sqlcode(status) == 0)
rec_cnt++;
else
printf("Input error -- no project record with key: %s\n", proj_id);
line = get_line();
}
if (isc_rollback_transaction (status, &trans))
{
ERREXIT(status, 1)
}
printf("\n\nAdded %d project descriptions.\n", rec_cnt);
if (isc_detach_database(status, &DB))
{
ERREXIT(status, 1)
}
free(sqlda);
return 0;
}
/*
* Get the next input line, which is either a project id
* or a project description segment.
*/
char *get_line (void)
{
return Proj_data[Inp_ptr++];
}

180
src/v5_examples/api9.c Normal file
View File

@ -0,0 +1,180 @@
/*
* Program type: API Interface
*
* Description:
* This program uses a filter to display a blob data type.
* Job descriptions are read through a filter, which formats
* the text into 40-character-wide paragraphs.
*
* IMPORTANT NOTE!
* The server side file, api9f.c, must have been compiled
* and linked and must be running on the server before
* this example can be run.
* The contents of this file are subject to the Interbase Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy
* of the License at http://www.Inprise.com/IPL.html
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code was created by Inprise Corporation
* and its predecessors. Portions created by Inprise Corporation are
* Copyright (C) Inprise Corporation.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <ibase.h>
#include "example.h"
#define COUNTRYLEN 15
#define CODELEN 5
char *sel_str =
"SELECT job_requirement, job_code, job_grade, job_country \
FROM job WHERE job_code = 'SRep'";
/* Blob parameter buffer. */
char bpb[] = {1,2,2,-4,-1,1,2,1,0};
int main (ARG(int, argc), ARG(char **, argv))
ARGLIST(int argc)
ARGLIST(char **argv)
{
char job_code[CODELEN + 2];
short job_grade;
char job_country[COUNTRYLEN + 2];
short flag0 = 0, flag1 = 0,
flag2 = 0, flag3 = 0;
ISC_QUAD blob_id;
isc_blob_handle blob_handle = NULL;
short blob_seg_len;
char blob_segment[401];
isc_db_handle DB = NULL;
isc_tr_handle trans = NULL;
long status[20];
isc_stmt_handle stmt = NULL;
XSQLDA ISC_FAR * sqlda;
long fetch_stat;
char empdb[128];
if (argc > 1)
strcpy(empdb, argv[1]);
else
strcpy(empdb, "employee.gdb");
if (isc_attach_database(status, 0, empdb, &DB, 0, NULL))
{
ERREXIT(status, 1)
}
if (isc_start_transaction(status, &trans, 1, &DB, 0, NULL))
{
ERREXIT(status, 1)
}
/*
* Allocate and prepare the select statement.
*/
if (isc_dsql_allocate_statement(status, &DB, &stmt))
{
ERREXIT(status, 1)
}
sqlda = (XSQLDA ISC_FAR *) malloc(XSQLDA_LENGTH(4));
sqlda->sqln = 4;
sqlda->version = 1;
if (isc_dsql_prepare(status, &trans, &stmt, 0, sel_str, 1, sqlda))
{
ERREXIT(status, 1)
}
sqlda->sqlvar[0].sqldata = (char ISC_FAR *) &blob_id;
sqlda->sqlvar[0].sqltype = SQL_BLOB + 1;
sqlda->sqlvar[0].sqlind = &flag0;
sqlda->sqlvar[1].sqldata = (char ISC_FAR *) job_code;
sqlda->sqlvar[1].sqltype = SQL_TEXT + 1;
sqlda->sqlvar[1].sqlind = &flag1;
sqlda->sqlvar[2].sqldata = (char ISC_FAR *) &job_grade;
sqlda->sqlvar[2].sqltype = SQL_SHORT + 1;
sqlda->sqlvar[2].sqlind = &flag2;
sqlda->sqlvar[3].sqldata = (char ISC_FAR *) job_country;
sqlda->sqlvar[3].sqltype = SQL_TEXT + 1;
sqlda->sqlvar[3].sqlind = &flag3;
if (isc_dsql_execute(status, &trans, &stmt, 1, NULL))
{
ERREXIT(status, 1)
}
/*
* Display job descriptions.
*/
while ((fetch_stat = isc_dsql_fetch(status, &stmt, 1, sqlda)) == 0)
{
job_code[CODELEN] = '\0';
job_country[COUNTRYLEN] = '\0';
printf("\nJOB CODE: %5s GRADE: %d", job_code, job_grade);
printf(" COUNTRY: %-20s\n\n", job_country);
/* Open the blob with the fetched blob_id. */
if (isc_open_blob2(status, &DB, &trans, &blob_handle, &blob_id, 9, bpb))
{
ERREXIT(status, 1)
}
/* Get blob segments and their lengths and print each segment. */
while (isc_get_segment(status, &blob_handle,
(unsigned short ISC_FAR *) &blob_seg_len, sizeof(blob_segment),
blob_segment) == 0)
printf(" %*.*s", blob_seg_len, blob_seg_len, blob_segment);
/* Close the blob. */
if (status[1] == isc_segstr_eof)
{
if (isc_close_blob(status, &blob_handle))
{
ERREXIT(status, 1)
}
}
else
isc_print_status(status);
printf("\n");
}
if (fetch_stat != 100L)
isc_print_status(status);
if (isc_dsql_free_statement(status, &stmt, DSQL_drop))
{
ERREXIT(status, 1)
}
if (isc_commit_transaction(status, &trans))
{
ERREXIT(status, 1)
}
if (isc_detach_database(status, &DB))
{
ERREXIT(status, 1)
}
free(sqlda);
return 0;
}

339
src/v5_examples/api9f.c Normal file
View File

@ -0,0 +1,339 @@
/*
* The contents of this file are subject to the Interbase Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy
* of the License at http://www.Inprise.com/IPL.html
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code was created by Inprise Corporation
* and its predecessors. Portions created by Inprise Corporation are
* Copyright (C) Inprise Corporation.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/
#include <stdio.h>
#include <ibase.h>
#include "example.h"
#ifndef CHAR
#define CHAR unsigned char
#endif
#ifndef SHORT
#define SHORT unsigned short
#endif
static void set_statistics (char*, ISC_BLOB_CTL);
static int read_text (SHORT, ISC_BLOB_CTL);
static int dump_text (SHORT, ISC_BLOB_CTL);
static int caller (SHORT, ISC_BLOB_CTL, SHORT, CHAR*, SHORT*);
#define ACTION_open 0
#define ACTION_get_segment 1
#define ACTION_close 2
#define ACTION_put_segment 3
#define ACTION_create 4
#define SUCCESS 0
#define FAILURE 1
#define BUFFER_LENGTH 512
#ifdef SHLIB_DEFS
#define system (*_libfun_system)
#define fopen (*_libfun_fopen)
#define unlink (*_libfun_unlink)
#define fprintf (*_libfun_fprintf)
#define fclose (*_libfun_fclose)
#define fgetc (*_libfun_fgetc)
extern int system();
extern FILE *fopen();
extern int unlink();
extern int fprintf();
extern int fclose();
extern int fgetc();
#endif
static char prevbuf[BUFFER_LENGTH + 1];
static int width = 40;
int EXPORT desc_filter (ARG(SHORT, action), ARG(ISC_BLOB_CTL, control))
ARGLIST(SHORT action)
ARGLIST(ISC_BLOB_CTL control)
{
/**************************************
*
* d e s c _ f i l t e r
*
**************************************
*
* Functional description
* Format a blob into 40-character-wide
* paragraphs.
* Read the blob into a file and process
* it on open, then read it back line by
* line in the get_segment loop.
*
**************************************/
int status;
FILE *text_file;
char *out_buffer;
switch (action)
{
case ACTION_open:
prevbuf[0] = '\0';
if (status = dump_text (action, control))
return status;
set_statistics("desc.txt", control); /* set up stats in ctl struct */
break;
case ACTION_get_segment:
/* open the file first time through and save the file pointer */
if (!control->ctl_data [0])
{
text_file = fopen ("desc.txt", "r");
control->ctl_data[0] = (long) text_file;
}
if (status = read_text (action, control))
return status;
break;
case ACTION_close:
/* don't need the temp files any more, so clean them up */
/*unlink("desc.txt");*/
break;
case ACTION_create:
case ACTION_put_segment:
return isc_uns_ext;
}
return SUCCESS;
}
static int caller (ARG(SHORT, action), ARG(ISC_BLOB_CTL, control),
ARG(SHORT, buffer_length), ARG(CHAR*, buffer),
ARG(SHORT*, return_length))
ARGLIST(SHORT action)
ARGLIST(ISC_BLOB_CTL control)
ARGLIST(SHORT buffer_length)
ARGLIST(CHAR *buffer)
ARGLIST(SHORT *return_length)
{
/**************************************
*
* c a l l e r
*
**************************************
*
* Functional description
* Call next source filter. This
* is a useful service routine for
* all blob filters.
*
**************************************/
int status;
ISC_BLOB_CTL source;
source = control->ctl_source_handle;
source->ctl_status = control->ctl_status;
source->ctl_buffer = buffer;
source->ctl_buffer_length = buffer_length;
status = (*source->ctl_source) (action, source);
if (return_length)
*return_length = source->ctl_segment_length;
return status;
}
static int dump_text (ARG(SHORT, action), ARG(ISC_BLOB_CTL, control))
ARGLIST(SHORT action)
ARGLIST(ISC_BLOB_CTL control)
{
/**************************************
*
* d u m p _ t e x t
*
**************************************
*
* Functional description
* Open a blob and write the
* contents to a file
*
**************************************/
FILE *text_file;
CHAR buffer [BUFFER_LENGTH + 1];
SHORT length;
int status;
int i, j;
CHAR tbuf [BUFFER_LENGTH + 1];
if (!(text_file = fopen ("desc.txt", "w")))
return FAILURE;
while (!(status = caller (ACTION_get_segment, control, sizeof(buffer) - 1,
buffer, &length)))
{
buffer[length] = 0;
sprintf(tbuf, "%s%s", prevbuf, buffer);
length = strlen(tbuf);
/* replace any new-lines with space */
for (i = 0; i < length; i++) {
if (tbuf[i] == '\n')
tbuf[i] = ' ';
}
i = 0;
/* break the line up into width-length pieces */
for (; i < length; i++)
{
/* save the remainder */
if (strlen(&tbuf[i]) <= 40) {
sprintf(prevbuf, "%s ", &tbuf[i]);
break;
}
/* find end-of-word to break the line at */
for (j = width - 1; j >= 0; j--) {
if (isspace(tbuf[i + j]))
break;
}
if (j < 0)
j = width;
fprintf (text_file, "%*.*s\n", j, j, &tbuf[i]);
i = i + j;
}
}
/* print the remainder */
fprintf(text_file, "%s\n", prevbuf);
fclose (text_file);
if (status != isc_segstr_eof)
return status;
return SUCCESS;
}
static void set_statistics (ARG(char*, filename), ARG(ISC_BLOB_CTL, control))
ARGLIST(char filename)
ARGLIST(ISC_BLOB_CTL control)
{
/*************************************
*
* s e t _ s t a t i s t i c s
*
*************************************
*
* Functional description
* Sets up the statistical fields
* in the passed in ctl structure.
* These fields are:
* ctl_max_segment - length of
* longest seg in blob (in
* bytes)
* ctl_number_segments - # of
* segments in blob
* ctl_total_length - total length
* of blob in bytes.
* we should reset the
* ctl structure, so that
* blob_info calls get the right
* values.
*
*************************************/
register int max_seg_length;
register int length;
register int num_segs;
register int cur_length;
FILE *file;
char *p;
char c;
num_segs = 0;
length = 0;
max_seg_length = 0;
cur_length = 0;
file = fopen ("desc.txt", "r");
while (1)
{
c = fgetc (file);
if (feof (file))
break;
length++;
cur_length++;
if (c == '\n') /* that means we are at end of seg */
{
if (cur_length > max_seg_length)
max_seg_length = cur_length;
num_segs++;
cur_length = 0;
}
}
control->ctl_max_segment = max_seg_length;
control->ctl_number_segments = num_segs;
control->ctl_total_length = length;
}
static int read_text (ARG(SHORT, action), ARG(ISC_BLOB_CTL, control))
ARGLIST(SHORT action)
ARGLIST(ISC_BLOB_CTL control)
{
/**************************************
*
* r e a d _ t e x t
*
**************************************
*
* Functional description
* Reads a file one line at a time
* and puts the data out as if it
* were coming from a blob.
*
**************************************/
CHAR *p;
FILE *file;
SHORT length;
int c, status;
p = control->ctl_buffer;
length = control->ctl_buffer_length;
file = (FILE *)control->ctl_data [0];
for (;;)
{
c = fgetc (file);
if (feof (file))
break;
*p++ = c;
if ((c == '\n') || p >= control->ctl_buffer + length)
{
control->ctl_segment_length = p - control->ctl_buffer;
if (c == '\n')
return SUCCESS;
else
return isc_segment;
}
}
return isc_segstr_eof;
}

21
src/v5_examples/api9f.def Normal file
View File

@ -0,0 +1,21 @@
; The contents of this file are subject to the Interbase Public
; License Version 1.0 (the "License"); you may not use this file
; except in compliance with the License. You may obtain a copy
; of the License at http://www.Inprise.com/IPL.html
;
; Software distributed under the License is distributed on an
; "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
; or implied. See the License for the specific language governing
; rights and limitations under the License.
;
; The Original Code was created by Inprise Corporation
; and its predecessors. Portions created by Inprise Corporation are
; Copyright (C) Inprise Corporation.
;
; All Rights Reserved.
; Contributor(s): ______________________________________.
LIBRARY api9f
DESCRIPTION 'api9f.dll'
DATA READ WRITE
EXPORTS
desc_filter

31
src/v5_examples/api9f.sql Normal file
View File

@ -0,0 +1,31 @@
/*
* The contents of this file are subject to the Interbase Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy
* of the License at http://www.Inprise.com/IPL.html
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code was created by Inprise Corporation
* and its predecessors. Portions created by Inprise Corporation are
* Copyright (C) Inprise Corporation.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/
/*--------------------------------------------------------------
** User Defined Filter definition for example databases
**--------------------------------------------------------------
*/
DECLARE FILTER desc_filter
INPUT_TYPE 1
OUTPUT_TYPE -4
ENTRY_POINT "desc_filter"
MODULE_NAME "api9f";

548
src/v5_examples/apifull.c Normal file
View File

@ -0,0 +1,548 @@
/*
* Program type: API Interface
*
* Description:
* This program prompts for and executes unknown SQL statements.
* The contents of this file are subject to the Interbase Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy
* of the License at http://www.Inprise.com/IPL.html
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code was created by Inprise Corporation
* and its predecessors. Portions created by Inprise Corporation are
* Copyright (C) Inprise Corporation.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/
/*
$Id: apifull.c,v 1.1 2001-07-23 16:05:46 skywalker Exp $
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <time.h>
#include <ctype.h>
#include <ibase.h>
#include "align.h"
#include "example.h"
#define MAXLEN 1024
process_statement (XSQLDA ISC_FAR * ISC_FAR * sqlda, char ISC_FAR *query);
void print_column (XSQLVAR ISC_FAR * var);
int get_statement (char ISC_FAR * buf);
typedef struct vary {
short vary_length;
char vary_string [1];
} VARY;
isc_db_handle db = NULL;
isc_tr_handle trans = NULL;
isc_stmt_handle stmt = NULL;
long status[20];
int ret;
#ifndef ISC_INT64_FORMAT
/* Define a format string for printf. Printing of 64-bit integers
is not standard between platforms */
#if (defined(_MSC_VER) && defined(WIN32)) || (defined(__BORLANDC__) && defined(__WIN32__))
#define ISC_INT64_FORMAT "I64"
#else
#define ISC_INT64_FORMAT "ll"
#endif
#endif
int main (ARG(int, argc), ARG(char **, argv))
ARGLIST(int argc)
ARGLIST(char **argv)
{
long query[MAXLEN];
XSQLDA ISC_FAR * sqlda;
char db_name[128];
if (argc < 2)
{
printf("Enter the database name: ");
gets(db_name);
}
else
{
strcpy(db_name, argv[1]);
}
if (isc_attach_database(status, 0, db_name, &db, 0, NULL))
{
printf("Could not open database %s\n", db_name);
ERREXIT(status, 1);
}
/*
* Allocate enough space for 20 fields.
* If more fields get selected, re-allocate SQLDA later.
*/
sqlda = (XSQLDA ISC_FAR *) malloc(XSQLDA_LENGTH (20));
sqlda->sqln = 20;
sqlda->version = 1;
/* Allocate a global statement */
if (isc_dsql_allocate_statement(status, &db, &stmt))
{
free (sqlda);
ERREXIT(status,1)
}
/*
* Process SQL statements.
*/
ret = get_statement((char ISC_FAR *) query);
/* Use break on error or exit */
while (ret != 1)
{
/* We must pass the address of sqlda, in case it
** gets re-allocated
*/
ret = process_statement((XSQLDA ISC_FAR * ISC_FAR *) &sqlda,
(char ISC_FAR *) query);
if (ret == 1)
break;
ret = get_statement((char ISC_FAR *) query);
}
free (sqlda);
if (trans)
if (isc_commit_transaction(status, &trans))
{
ERREXIT(status,1);
};
if (isc_detach_database(status, &db))
{
ERREXIT(status,1);
};
return ret;
}
/*
** Function: process_statement
** Process submitted statement. On any fundamental error, return status 1,
** which will do an isc_print_status and exit the program.
** On user errors, found in parsing or executing go to status 2,
** which will print the error and continue.
*/
process_statement (ARG(XSQLDA ISC_FAR * ISC_FAR *, sqldap),
ARG(char ISC_FAR *, query))
ARGLIST(XSQLDA **sqldap)
ARGLIST(char *query)
{
long buffer[MAXLEN];
XSQLDA ISC_FAR *sqlda;
XSQLVAR ISC_FAR *var;
short num_cols, i;
short length, alignment, type, offset;
long fetch_stat;
static char stmt_info[] = { isc_info_sql_stmt_type };
char info_buffer[20];
short l;
long statement_type;
sqlda = *sqldap;
/* Start a transaction if we are not in one */
if (!trans)
if (isc_start_transaction(status, &trans, 1, &db, 0, NULL))
{
ERREXIT(status, 1)
}
if (isc_dsql_prepare(status, &trans, &stmt, 0, query, SQL_DIALECT_V6, sqlda))
{
ERREXIT(status,2)
}
/* What is the statement type of this statement?
**
** stmt_info is a 1 byte info request. info_buffer is a buffer
** large enough to hold the returned info packet
** The info_buffer returned contains a isc_info_sql_stmt_type in the first byte,
** two bytes of length, and a statement_type token.
*/
if (!isc_dsql_sql_info(status, &stmt, sizeof (stmt_info), stmt_info,
sizeof (info_buffer), info_buffer))
{
l = (short) isc_vax_integer((char ISC_FAR *) info_buffer + 1, 2);
statement_type = isc_vax_integer((char ISC_FAR *) info_buffer + 3, l);
}
/*
* Execute a non-select statement.
*/
if (!sqlda->sqld)
{
if (isc_dsql_execute(status, &trans, &stmt, SQL_DIALECT_V6, NULL))
{
ERREXIT(status,2)
}
/* Commit DDL statements if that is what sql_info says */
if (trans && (statement_type == isc_info_sql_stmt_ddl))
{
printf ("\tCommitting...\n");
if (isc_commit_transaction(status, &trans))
{
ERREXIT(status, 2)
}
}
return 0;
}
/*
* Process select statements.
*/
num_cols = sqlda->sqld;
/* Need more room. */
if (sqlda->sqln < num_cols)
{
*sqldap = sqlda = (XSQLDA ISC_FAR *) realloc(sqlda,
XSQLDA_LENGTH (num_cols));
sqlda->sqln = num_cols;
sqlda->version = 1;
if (isc_dsql_describe(status, &stmt, SQL_DIALECT_V6, sqlda))
{
ERREXIT(status,2)
}
num_cols = sqlda->sqld;
}
/*
* Set up SQLDA.
*/
for (var = sqlda->sqlvar, offset = 0, i = 0; i < num_cols; var++, i++)
{
length = alignment = var->sqllen;
type = var->sqltype & ~1;
if (type == SQL_TEXT)
alignment = 1;
else if (type == SQL_VARYING)
{
length += sizeof (short) + 1;
alignment = sizeof (short);
}
/* RISC machines are finicky about word alignment
** So the output buffer values must be placed on
** word boundaries where appropriate
*/
offset = FB_ALIGN(offset, alignment);
var->sqldata = (char ISC_FAR *) buffer + offset;
offset += length;
offset = FB_ALIGN(offset, sizeof (short));
var->sqlind = (short*) ((char ISC_FAR *) buffer + offset);
offset += sizeof (short);
}
if (isc_dsql_execute(status, &trans, &stmt, SQL_DIALECT_V6, NULL))
{
ERREXIT(status,2)
}
/*
* Print rows.
*/
while ((fetch_stat = isc_dsql_fetch(status, &stmt, SQL_DIALECT_V6, sqlda)) == 0)
{
for (i = 0; i < num_cols; i++)
{
print_column((XSQLVAR ISC_FAR *) &sqlda->sqlvar[i]);
}
printf("\n");
}
/* Close cursor */
if (isc_dsql_free_statement(status, &stmt, DSQL_close))
{
ERREXIT (status,2);
};
if (fetch_stat != 100L)
{
ERREXIT(status,2)
}
return 0;
}
/*
* Print column's data.
*/
void print_column (ARG(XSQLVAR ISC_FAR *, var))
ARGLIST(XSQLVAR *var)
{
short dtype;
char data[MAXLEN], *p;
char blob_s[20], date_s[25];
VARY *vary;
short len;
struct tm times;
ISC_QUAD bid;
dtype = var->sqltype & ~1;
p = data;
/* Null handling. If the column is nullable and null */
if ((var->sqltype & 1) && (*var->sqlind < 0))
{
switch (dtype)
{
case SQL_TEXT:
case SQL_VARYING:
len = var->sqllen;
break;
case SQL_SHORT:
len = 6;
if (var->sqlscale > 0) len += var->sqlscale;
break;
case SQL_LONG:
len = 11;
if (var->sqlscale > 0) len += var->sqlscale;
break;
case SQL_INT64:
len = 21;
if (var->sqlscale > 0) len += var->sqlscale;
break;
case SQL_FLOAT:
len = 15;
break;
case SQL_DOUBLE:
len = 24;
break;
case SQL_TIMESTAMP:
len = 24;
break;
case SQL_TYPE_DATE:
len = 10;
break;
case SQL_TYPE_TIME:
len = 13;
break;
case SQL_BLOB:
case SQL_ARRAY:
default:
len = 17;
break;
}
if ((dtype == SQL_TEXT) || (dtype == SQL_VARYING))
sprintf(p, "%-*s ", len, "NULL");
else
sprintf(p, "%*s ", len, "NULL");
}
else
{
switch (dtype)
{
case SQL_TEXT:
sprintf(p, "%.*s ", var->sqllen, var->sqldata);
break;
case SQL_VARYING:
vary = (VARY*) var->sqldata;
vary->vary_string[vary->vary_length] = '\0';
sprintf(p, "%-*s ", var->sqllen, vary->vary_string);
break;
case SQL_SHORT:
case SQL_LONG:
case SQL_INT64:
{
ISC_INT64 value;
short field_width;
short dscale;
switch (dtype)
{
case SQL_SHORT:
value = (ISC_INT64) *(short ISC_FAR *) var->sqldata;
field_width = 6;
break;
case SQL_LONG:
value = (ISC_INT64) *(long ISC_FAR *) var->sqldata;
field_width = 11;
break;
case SQL_INT64:
value = (ISC_INT64) *(ISC_INT64 ISC_FAR *) var->sqldata;
field_width = 21;
break;
}
dscale = var->sqlscale;
if (dscale < 0)
{
ISC_INT64 tens;
short i;
tens = 1;
for (i = 0; i > dscale; i--)
tens *= 10;
if (value >= 0)
sprintf (p, "%*" ISC_INT64_FORMAT "d.%0*" ISC_INT64_FORMAT "d",
field_width - 1 + dscale,
(ISC_INT64) value / tens,
-dscale,
(ISC_INT64) value % tens);
else if ((value / tens) != 0)
sprintf (p, "%*" ISC_INT64_FORMAT "d.%0*" ISC_INT64_FORMAT "d",
field_width - 1 + dscale,
(ISC_INT64) (value / tens),
-dscale,
(ISC_INT64) -(value % tens));
else
sprintf (p, "%*s.%0*" ISC_INT64_FORMAT "d",
field_width - 1 + dscale,
"-0",
-dscale,
(ISC_INT64) -(value % tens));
}
else if (dscale)
sprintf (p, "%*" ISC_INT64_FORMAT "d%0*d",
field_width,
(ISC_INT64) value,
dscale, 0);
else
sprintf (p, "%*" ISC_INT64_FORMAT "d%",
field_width,
(ISC_INT64) value);
};
break;
case SQL_FLOAT:
sprintf(p, "%15g ", *(float ISC_FAR *) (var->sqldata));
break;
case SQL_DOUBLE:
sprintf(p, "%24f ", *(double ISC_FAR *) (var->sqldata));
break;
case SQL_TIMESTAMP:
isc_decode_timestamp((ISC_TIMESTAMP ISC_FAR *)var->sqldata, &times);
sprintf(date_s, "%04d-%02d-%02d %02d:%02d:%02d.%04d",
times.tm_year + 1900,
times.tm_mon+1,
times.tm_mday,
times.tm_hour,
times.tm_min,
times.tm_sec,
((ISC_TIMESTAMP *)var->sqldata)->timestamp_time % 10000);
sprintf(p, "%*s ", 24, date_s);
break;
case SQL_TYPE_DATE:
isc_decode_sql_date((ISC_DATE ISC_FAR *)var->sqldata, &times);
sprintf(date_s, "%04d-%02d-%02d",
times.tm_year + 1900,
times.tm_mon+1,
times.tm_mday);
sprintf(p, "%*s ", 10, date_s);
break;
case SQL_TYPE_TIME:
isc_decode_sql_time((ISC_TIME ISC_FAR *)var->sqldata, &times);
sprintf(date_s, "%02d:%02d:%02d.%04d",
times.tm_hour,
times.tm_min,
times.tm_sec,
(*((ISC_TIME *)var->sqldata)) % 10000);
sprintf(p, "%*s ", 13, date_s);
break;
case SQL_BLOB:
case SQL_ARRAY:
/* Print the blob id on blobs or arrays */
bid = *(ISC_QUAD ISC_FAR *) var->sqldata;
sprintf(blob_s, "%08x:%08x", bid.isc_quad_high, bid.isc_quad_low);
sprintf(p, "%17s ", blob_s);
break;
default:
break;
}
}
while (*p)
{
putchar(*p++);
}
}
/*
* Prompt for and get input.
* Statements are terminated by a semicolon.
*/
int get_statement (ARG(char ISC_FAR *,buf))
ARGLIST(char *buf)
{
short c;
char *p;
int cnt;
p = buf;
cnt = 0;
printf("SQL> ");
for (;;)
{
if ((c = getchar()) == EOF)
return 1;
if (c == '\n')
{
/* accept "quit" or "exit" to terminate application */
if (!strncmp(buf, "exit", 4))
return 1;
if (!strncmp(buf, "quit", 4))
return 1;
/* Search back through white space looking for ';'.*/
while (cnt && isspace(*(p - 1)))
{
p--;
cnt--;
}
if (*(p - 1) == ';')
{
*p++ = '\0';
return 0;
}
*p++ = ' ';
printf("CON> ");
}
else
{
*p++ = (char)c;
}
cnt++;
}
}

147
src/v5_examples/dyn1.e Normal file
View File

@ -0,0 +1,147 @@
/*
* Program type: Embedded Dynamic SQL
*
* Description:
* This program creates a new database, using a static SQL string.
* The newly created database is accessed after its creation,
* and a sample table is added.
* The contents of this file are subject to the Interbase Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy
* of the License at http://www.Inprise.com/IPL.html
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code was created by Inprise Corporation
* and its predecessors. Portions created by Inprise Corporation are
* Copyright (C) Inprise Corporation.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/
#include "example.h"
#include <stdlib.h>
#include <string.h>
void pr_error (char *operation);
char *new_dbname = "new.gdb";
char *create_tbl = "CREATE TABLE dbinfo (when_created DATE)";
char *insert_date = "INSERT INTO dbinfo VALUES ('NOW')";
/*
* Declare a database handle, which will be used by the new database.
*/
EXEC SQL
SET DATABASE db = COMPILETIME "employee.gdb";
int main(ARG(int, argc), ARG(char **, argv))
ARGLIST(int argc)
ARGLIST(char **argv)
{
db = NULL;
/*
* Create a new database, establishing a connection
* as well.
*/
EXEC SQL
EXECUTE IMMEDIATE "CREATE DATABASE 'new.gdb'";
if (SQLCODE)
{
/* Print a descriptive message, if the database exists. */
if (SQLCODE == -902)
{
printf("\nDatabase already exists.\n");
printf("Remove %s before running this program.\n\n", new_dbname);
}
pr_error("create database");
return 1;
}
EXEC SQL
COMMIT RELEASE;
if (SQLCODE)
{
pr_error("commit & release");
return 1;
}
printf("Created database '%s'.\n\n", new_dbname);
/*
* Connect to the new database and create a sample table.
*/
/* Use the database handle declared above. */
EXEC SQL
CONNECT :new_dbname AS db;
if (SQLCODE)
{
pr_error("connect database");
return 1;
}
/* Create a sample table. */
EXEC SQL
SET TRANSACTION;
EXEC SQL
EXECUTE IMMEDIATE :create_tbl;
if (SQLCODE)
{
pr_error("create table");
return 1;
}
EXEC SQL
COMMIT RETAIN;
/* Insert 1 row into the new table. */
EXEC SQL
SET TRANSACTION;
EXEC SQL
EXECUTE IMMEDIATE :insert_date;
if (SQLCODE)
{
pr_error("insert into");
return 1;
}
EXEC SQL
COMMIT RELEASE;
printf("Successfully accessed the newly created database.\n\n");
EXEC SQL
DISCONNECT db;
return 0;
}
/*
* Print the status, the SQLCODE, and exit.
* Also, indicate which operation the error occured on.
*/
void pr_error(ARG(char *, operation))
ARGLIST(char *operation)
{
printf("[\n");
printf("PROBLEM ON \"%s\".\n", operation);
isc_print_status(gds__status);
printf("SQLCODE = %d\n", SQLCODE);
printf("]\n");
}

174
src/v5_examples/dyn2.e Normal file
View File

@ -0,0 +1,174 @@
/*
* Program type: Embedded Dynamic SQL
*
* Description:
* This program adds several departments with small default
* budgets, using 'execute immediate' statement.
* Then, a prepared statement, which doubles budgets for
* departments with low budgets, is executed.
* The contents of this file are subject to the Interbase Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy
* of the License at http://www.Inprise.com/IPL.html
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code was created by Inprise Corporation
* and its predecessors. Portions created by Inprise Corporation are
* Copyright (C) Inprise Corporation.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/
#include "example.h"
#include <stdlib.h>
#include <string.h>
#define MAXLEN 256
int get_line (char *line);
void clean_up (void);
static char *Dept_data[] =
{
"117", "Field Office: Hong Kong", "110",
"118", "Field Office: Australia", "110",
"119", "Field Office: New Zealand", "110",
0
};
int Dept_ptr = 0;
char Db_name[128];
EXEC SQL
SET DATABASE empdb = "employee.gdb" RUNTIME :Db_name;
int main(ARG(int, argc), ARG(char **, argv))
ARGLIST(int argc)
ARGLIST(char **argv)
{
BASED_ON department.department dept_name;
BASED_ON department.dept_no dept_id;
char exec_str[MAXLEN], prep_str[MAXLEN];
if (argc > 1)
strcpy(Db_name, argv[1]);
else
strcpy(Db_name, "employee.gdb");
EXEC SQL
WHENEVER SQLERROR GO TO MainError;
EXEC SQL
CONNECT empdb;
clean_up();
EXEC SQL
SET TRANSACTION;
/*
* Prepare a statement, which may be executed more than once.
*/
strcpy(prep_str,
"UPDATE DEPARTMENT SET budget = budget * 2 WHERE budget < 100000");
EXEC SQL
PREPARE double_small_budget FROM :prep_str;
/*
* Add new departments, using 'execute immediate'.
* Build each 'insert' statement, using the supplied parameters.
* Since these statements will not be needed after they are executed,
* use 'execute immediate'.
*/
while (get_line(exec_str))
{
printf("\nExecuting statement:\n\t%s;\n", exec_str);
EXEC SQL
EXECUTE IMMEDIATE :exec_str;
}
EXEC SQL
COMMIT RETAIN;
/*
* Execute a previously prepared statement.
*/
printf("\nExecuting a prepared statement:\n\t%s;\n\n", prep_str);
EXEC SQL
EXECUTE double_small_budget;
EXEC SQL
COMMIT;
EXEC SQL
DISCONNECT empdb;
exit(0);
MainError:
EXEC SQL
WHENEVER SQLERROR CONTINUE;
isc_print_status(gds__status);
printf("SQLCODE=%d\n", SQLCODE);
EXEC SQL ROLLBACK;
exit(1);
}
/*
* Construct an 'insert' statement from the supplied parameters.
*/
int get_line(ARG(char *, line))
ARGLIST(char *line)
{
if (Dept_data[Dept_ptr] == 0)
return 0;
if (Dept_data[Dept_ptr + 1] == 0)
return 0;
if (Dept_data[Dept_ptr + 2] == 0)
return 0;
sprintf(line, "INSERT INTO DEPARTMENT (dept_no, department, head_dept) \
VALUES ('%s', '%s', '%s')", Dept_data[Dept_ptr],
Dept_data[Dept_ptr + 1], Dept_data[Dept_ptr + 2]);
Dept_ptr += 3;
return(1);
}
/*
* Delete old data.
*/
void clean_up (void)
{
EXEC SQL WHENEVER SQLERROR GO TO CleanErr;
EXEC SQL SET TRANSACTION;
EXEC SQL EXECUTE IMMEDIATE
"DELETE FROM department WHERE dept_no IN ('117', '118', '119')";
EXEC SQL COMMIT;
return;
CleanErr:
isc_print_status(gds__status);
printf("SQLCODE=%d\n", SQLCODE);
exit(1);
}

146
src/v5_examples/dyn3.e Normal file
View File

@ -0,0 +1,146 @@
/*
* Program type: Embedded Dynamic SQL
*
* Description:
* This program displays employee names and phone extensions.
*
* It allocates an output SQLDA, declares and opens a cursor,
* and loops fetching multiple rows.
* The contents of this file are subject to the Interbase Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy
* of the License at http://www.Inprise.com/IPL.html
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code was created by Inprise Corporation
* and its predecessors. Portions created by Inprise Corporation are
* Copyright (C) Inprise Corporation.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/
#include "example.h"
#include <stdlib.h>
#include <string.h>
void print_error (void);
char *sel_str =
"SELECT last_name, first_name, phone_ext FROM phone_list \
WHERE location = 'Monterey' ORDER BY last_name, first_name;";
/* This macro is used to declare structures representing SQL VARCHAR types */
#define SQL_VARCHAR(len) struct {short vary_length; char vary_string[(len)+1];}
char Db_name[128];
EXEC SQL
SET DATABASE empdb = "employee.gdb" RUNTIME :Db_name;
int main(ARG(int, argc), ARG(char **, argv))
ARGLIST(int argc)
ARGLIST(char **argv)
{
SQL_VARCHAR(15) first_name;
SQL_VARCHAR(20) last_name;
char phone_ext[6];
XSQLDA *sqlda;
short flag0 = 0, flag1 = 0, flag2 = 0;
if (argc > 1)
strcpy(Db_name, argv[1]);
else
strcpy(Db_name, "employee.gdb");
EXEC SQL
WHENEVER SQLERROR GO TO Error;
EXEC SQL
CONNECT empdb;
EXEC SQL
SET TRANSACTION;
/* Allocate an output SQLDA. */
sqlda = (XSQLDA *) malloc(XSQLDA_LENGTH(3));
sqlda->sqln = 3;
sqlda->version = 1;
/* Prepare the query. */
EXEC SQL
PREPARE q INTO SQL DESCRIPTOR sqlda FROM :sel_str;
/*
* Although, all three selected columns are of type varchar, the
* third field's type is changed and printed as type TEXT.
*/
sqlda->sqlvar[0].sqldata = (char *)&last_name;
sqlda->sqlvar[0].sqltype = SQL_VARYING + 1;
sqlda->sqlvar[0].sqlind = &flag0;
sqlda->sqlvar[1].sqldata = (char *)&first_name;
sqlda->sqlvar[1].sqltype = SQL_VARYING + 1;
sqlda->sqlvar[1].sqlind = &flag1;
sqlda->sqlvar[2].sqldata = phone_ext;
sqlda->sqlvar[2].sqltype = SQL_TEXT + 1;
sqlda->sqlvar[2].sqlind = &flag2;
/* Declare the cursor for the prepared query. */
EXEC SQL
DECLARE s CURSOR FOR q;
EXEC SQL
OPEN s;
printf("\n%-20s %-15s %-10s\n\n", "LAST NAME", "FIRST NAME", "EXTENSION");
/*
* Fetch and print the records.
*/
while (SQLCODE == 0)
{
EXEC SQL
FETCH s USING SQL DESCRIPTOR sqlda;
if (SQLCODE == 100)
break;
printf("%-20.*s ", last_name.vary_length, last_name.vary_string);
printf("%-15.*s ", first_name.vary_length, first_name.vary_string);
phone_ext[sqlda->sqlvar[2].sqllen] = '\0';
printf("%-10s\n", phone_ext);
}
EXEC SQL
CLOSE s;
EXEC SQL
COMMIT;
EXEC SQL
DISCONNECT empdb;
free( sqlda);
return(0);
Error:
print_error();
}
void print_error (void)
{
isc_print_status(gds__status);
printf("SQLCODE=%d\n", SQLCODE);
}

164
src/v5_examples/dyn4.e Normal file
View File

@ -0,0 +1,164 @@
/*
* Program type: Embedded Dynamic SQL
*
* Description:
* This program updates departments' budgets, given
* the department and the new budget information parameters.
*
* An input SQLDA is allocated for the update query
* with parameter markers.
* The contents of this file are subject to the Interbase Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy
* of the License at http://www.Inprise.com/IPL.html
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code was created by Inprise Corporation
* and its predecessors. Portions created by Inprise Corporation are
* Copyright (C) Inprise Corporation.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/
#include "example.h"
#include <stdlib.h>
#include <string.h>
int get_input (char *dept_no, double *percent);
static char *Dept_data[] =
{"622", "100", "116", "900", 0};
static double Percent_data[] =
{0.05, 1.00, 0.075, 0.10, 0};
int Input_ptr = 0;
char Db_name[128];
EXEC SQL
SET DATABASE empdb = "employee.gdb" RUNTIME :Db_name;
char *upd_str =
"UPDATE department SET budget = ? * budget + budget WHERE dept_no = ?";
int main(ARG(int, argc), ARG(char **, argv))
ARGLIST(int argc)
ARGLIST(char **argv)
{
BASED_ON department.dept_no dept_no;
double percent_inc;
short nullind = 0;
XSQLDA *sqlda;
if (argc > 1)
strcpy(Db_name, argv[1]);
else
strcpy(Db_name, "employee.gdb");
EXEC SQL
WHENEVER SQLERROR GO TO Error;
EXEC SQL
CONNECT empdb;
EXEC SQL
SET TRANSACTION USING empdb;
/* Allocate an input SQLDA. There are two unknown parameters. */
sqlda = (XSQLDA *) malloc(XSQLDA_LENGTH(2));
sqlda->sqln = 2;
sqlda->sqld = 2;
sqlda->version = 1;
/* Prepare the query. */
EXEC SQL
PREPARE q FROM :upd_str;
/* Prepare the input sqlda, only data and indicator to set */
EXEC SQL
DESCRIBE INPUT q USING SQL DESCRIPTOR sqlda;
sqlda->sqlvar[0].sqldata = (char *) &percent_inc;
sqlda->sqlvar[0].sqlind = &nullind;
sqlda->sqlvar[1].sqldata = dept_no;
/* FOrce the type to char instead of varchar */
sqlda->sqlvar[1].sqltype = SQL_TEXT +1;
sqlda->sqlvar[1].sqlind = &nullind;
/* Expect an error, trap it */
EXEC SQL WHENEVER SQLERROR CONTINUE;
/*
* Get the next department-percent increase input pair.
*/
while (get_input(dept_no, &percent_inc))
{
printf("\nIncreasing budget for department: %s by %5.2f percent.\n",
dept_no, percent_inc);
/* Update the budget. */
EXEC SQL
EXECUTE q USING SQL DESCRIPTOR sqlda;
/* Don't save the update, if the new budget exceeds
** the limit. Detect an integrity violation
*/
if (SQLCODE == -625)
{
printf("\tExceeded budget limit -- not updated.\n");
continue;
}
/* Undo all changes, in case of an error. */
else if (SQLCODE)
goto Error;
/* Save each department's update independently. */
EXEC SQL
COMMIT RETAIN;
}
EXEC SQL
COMMIT RELEASE;
return (0);
Error:
isc_print_status(gds__status);
printf("SQLCODE=%d\n", SQLCODE);
EXEC SQL
ROLLBACK RELEASE;
EXEC SQL
DISCONNECT empdb;
free( sqlda);
return(1);
}
/*
* Get the department and percent parameters.
*/
int get_input(ARG(char *, dept_no), ARG(double *, percent))
ARGLIST(char *dept_no)
ARGLIST(double *percent)
{
if (Dept_data[Input_ptr] == 0)
return 0;
strcpy(dept_no, Dept_data[Input_ptr]);
if ((*percent = Percent_data[Input_ptr++]) == 0)
return 0;
return(1);
}

127
src/v5_examples/dyn5.e Normal file
View File

@ -0,0 +1,127 @@
/*
* Program type: Embedded Dynamic SQL
*
* Description:
* This program demonstrates the reallocation of SQLDA and
* the 'describe' statement. After a query is examined with
* 'describe', an SQLDA of correct size is reallocated, and some
* information is printed about the query: its type (select,
* non-select), the number of columns, etc.
* The contents of this file are subject to the Interbase Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy
* of the License at http://www.Inprise.com/IPL.html
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code was created by Inprise Corporation
* and its predecessors. Portions created by Inprise Corporation are
* Copyright (C) Inprise Corporation.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/
#include "example.h"
#include <stdlib.h>
#include <string.h>
char *sel_str =
"SELECT department, mngr_no, location, head_dept \
FROM department WHERE head_dept in ('100', '900', '600')";
char Db_name[128];
EXEC SQL
SET DATABASE empdb = "employee.gdb" RUNTIME :Db_name;
int main(ARG(int, argc), ARG(char **, argv))
ARGLIST(int argc)
ARGLIST(char **argv)
{
short num_cols, i;
XSQLDA *sqlda;
if (argc > 1)
strcpy(Db_name, argv[1]);
else
strcpy(Db_name, "employee.gdb");
EXEC SQL
WHENEVER SQLERROR GO TO Error;
EXEC SQL
CONNECT empdb;
EXEC SQL
SET TRANSACTION;
/* Allocate SQLDA of an arbitrary size. */
sqlda = (XSQLDA *) malloc(XSQLDA_LENGTH(4));
sqlda->sqln = 4;
sqlda->sqld = 4;
sqlda->version = 1;
/* Prepare an unknown statement. */
EXEC SQL
PREPARE q INTO SQL DESCRIPTOR sqlda FROM :sel_str;
/* Describe the statement. */
EXEC SQL
DESCRIBE q INTO SQL DESCRIPTOR sqlda;
/* This is a non-select statement, which can now be executed. */
if (sqlda->sqld == 0)
return(0);
/* If this is a select statement, print more information about it. */
else
printf("Query Type: SELECT\n\n");
num_cols = sqlda->sqld;
printf("Number of columns selected: %d\n", num_cols);
/* Reallocate SQLDA if necessary. */
if (sqlda->sqln < sqlda->sqld)
{
free(sqlda);
sqlda = (XSQLDA *) malloc(XSQLDA_LENGTH(num_cols));
sqlda->sqln = num_cols;
sqlda->sqld = num_cols;
/* Re-describe the statement. */
EXEC SQL
DESCRIBE q INTO SQL DESCRIPTOR sqlda;
num_cols = sqlda->sqld;
}
/* List column names, types, and lengths. */
for (i = 0; i < num_cols; i++)
{
printf("\nColumn name: %s\n", sqlda->sqlvar[i].sqlname);
printf("Column type: %d\n", sqlda->sqlvar[i].sqltype);
printf("Column length: %d\n", sqlda->sqlvar[i].sqllen);
}
EXEC SQL
COMMIT;
EXEC SQL
DISCONNECT empdb;
free( sqlda);
return(0);
Error:
isc_print_status(gds__status);
printf("SQLCODE=%d\n", SQLCODE);
return(1);
}

499
src/v5_examples/dynfull.e Normal file
View File

@ -0,0 +1,499 @@
/*
* Program type: Embedded Dynamic SQL
*
* Description:
* This program prompts for and executes unknown SQL statements.
* The contents of this file are subject to the Interbase Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy
* of the License at http://www.Inprise.com/IPL.html
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code was created by Inprise Corporation
* and its predecessors. Portions created by Inprise Corporation are
* Copyright (C) Inprise Corporation.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/
/*
$Id: dynfull.e,v 1.1 2001-07-23 16:05:46 skywalker Exp $
*/
#include "example.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <ctype.h>
#include <ibase.h>
#include "align.h"
#define MAXLEN 1024
#define EOF -1
void process_statement (XSQLDA **sqlda, char *query);
void print_column (XSQLVAR *var);
int get_statement (char *buf);
typedef struct vary {
short vary_length;
char vary_string [1];
} VARY;
#ifndef ISC_INT64_FORMAT
/* Define a format string for printf. Printing of 64-bit integers
is not standard between platforms */
#if (defined(_MSC_VER) && defined(WIN32)) || (defined(__BORLANDC__) && defined(__WIN32__))
#define ISC_INT64_FORMAT "I64"
#else
#define ISC_INT64_FORMAT "ll"
#endif
#endif
EXEC SQL
SET SQL DIALECT 3;
EXEC SQL
SET DATABASE db = COMPILETIME "employee.gdb";
int main(ARG(int, argc), ARG(char **, argv))
ARGLIST(int argc)
ARGLIST(char **argv)
{
char query[MAXLEN];
XSQLDA *sqlda;
char db_name[128];
if (argc < 2)
{
printf("Enter the database name: ");
gets(db_name);
}
else
strcpy(db_name, *(++argv));
EXEC SQL
CONNECT :db_name AS db;
if (SQLCODE)
{
printf("Could not open database %s\n", db_name);
return(1);
}
/*
* Allocate enough space for 20 fields.
* If more fields get selected, re-allocate SQLDA later.
*/
sqlda = (XSQLDA *) malloc(XSQLDA_LENGTH (20));
sqlda->sqln = 20;
sqlda->version = 1;
/*
* Process SQL statements.
*/
while (get_statement(query))
{
process_statement(&sqlda, query);
}
EXEC SQL
DISCONNECT db;
return(0);
}
void process_statement(ARG(XSQLDA ISC_FAR * ISC_FAR *, sqldap),
ARG(char ISC_FAR *, query))
ARGLIST(XSQLDA **sqldap)
ARGLIST(char *query)
{
long buffer[MAXLEN];
XSQLVAR *var;
XSQLDA *sqlda;
short num_cols, i;
short length, alignment, type, offset;
sqlda = *sqldap;
EXEC SQL
WHENEVER SQLERROR GO TO Error;
/* Start a transaction for each statement */
EXEC SQL
SET TRANSACTION;
EXEC SQL
PREPARE q INTO SQL DESCRIPTOR sqlda FROM :query;
EXEC SQL
DESCRIBE q INTO SQL DESCRIPTOR sqlda;
/*
* Execute a non-select statement.
*/
if (!sqlda->sqld)
{
EXEC SQL
EXECUTE q;
EXEC SQL
COMMIT;
return ;
}
/*
* Process select statements.
*/
num_cols = sqlda->sqld;
/* Need more room. */
if (sqlda->sqln < num_cols)
{
free(sqlda);
sqlda = (XSQLDA *) malloc(XSQLDA_LENGTH (num_cols));
sqlda->sqln = num_cols;
sqlda->sqld = num_cols;
sqlda->version = 1;
EXEC SQL
DESCRIBE q INTO SQL DESCRIPTOR sqlda;
num_cols = sqlda->sqld;
}
/* Open the cursor. */
EXEC SQL
DECLARE c CURSOR FOR q;
EXEC SQL
OPEN c;
/*
* Set up SQLDA.
*/
for (var = sqlda->sqlvar, offset = 0, i = 0; i < num_cols; var++, i++)
{
length = alignment = var->sqllen;
type = var->sqltype & ~1;
if (type == SQL_TEXT)
alignment = 1;
else if (type == SQL_VARYING)
{
/* Allow space for vary's strlen & space to insert
a null byte for printing */
length += sizeof (short) + 1;
alignment = sizeof (short);
}
offset = FB_ALIGN(offset, alignment);
var->sqldata = (char*) buffer + offset;
offset += length;
offset = FB_ALIGN(offset, sizeof (short));
var->sqlind = (short*) ((char*) buffer + offset);
offset += sizeof (short);
}
/*
* Print rows.
*/
while (SQLCODE == 0)
{
EXEC SQL
FETCH c USING SQL DESCRIPTOR sqlda;
if (SQLCODE == 100)
break;
for (i = 0; i < num_cols; i++)
{
print_column(&sqlda->sqlvar[i]);
}
printf("\n");
}
EXEC SQL
CLOSE c;
EXEC SQL
COMMIT;
return;
Error:
EXEC SQL
WHENEVER SQLERROR CONTINUE;
printf("Statement failed. SQLCODE = %d\n", SQLCODE);
fflush (stdout);
isc_print_status(gds__status);
EXEC SQL
ROLLBACK;
return;
}
/*
* Print column's data.
*/
void print_column(ARG(XSQLVAR ISC_FAR *, var))
ARGLIST(XSQLVAR *var)
{
short dtype;
char data[MAXLEN], *p;
char blob_s[20], date_s[25];
VARY *vary;
short len;
struct tm times;
ISC_QUAD bid;
dtype = var->sqltype & ~1;
p = data;
if ((var->sqltype & 1) && (*var->sqlind < 0))
{
switch (dtype)
{
case SQL_TEXT:
case SQL_VARYING:
len = var->sqllen;
break;
case SQL_SHORT:
len = 6;
if (var->sqlscale > 0) len += var->sqlscale;
break;
case SQL_LONG:
len = 11;
if (var->sqlscale > 0) len += var->sqlscale;
break;
case SQL_INT64:
len = 21;
if (var->sqlscale > 0) len += var->sqlscale;
break;
case SQL_FLOAT:
len = 15;
break;
case SQL_DOUBLE:
len = 24;
break;
case SQL_TIMESTAMP:
len = 24;
break;
case SQL_TYPE_DATE:
len = 10;
break;
case SQL_TYPE_TIME:
len = 13;
break;
case SQL_BLOB:
case SQL_ARRAY:
default:
len = 17;
break;
}
if ((dtype == SQL_TEXT) || (dtype == SQL_VARYING))
sprintf(p, "%-*s ", len, "NULL");
else
sprintf(p, "%*s ", len, "NULL");
}
else
{
switch (dtype)
{
case SQL_TEXT:
sprintf(p, "%.*s ", var->sqllen, var->sqldata);
break;
case SQL_VARYING:
vary = (VARY*) var->sqldata;
vary->vary_string[vary->vary_length] = '\0';
sprintf(p, "%-*s ", var->sqllen, vary->vary_string);
break;
case SQL_SHORT:
case SQL_LONG:
case SQL_INT64:
{
ISC_INT64 value;
short field_width;
short dscale;
switch (dtype)
{
case SQL_SHORT:
value = (ISC_INT64) *(short *) var->sqldata;
field_width = 6;
break;
case SQL_LONG:
value = (ISC_INT64) *(long *) var->sqldata;
field_width = 11;
break;
case SQL_INT64:
value = (ISC_INT64) *(ISC_INT64 *) var->sqldata;
field_width = 21;
break;
}
dscale = var->sqlscale;
if (dscale < 0)
{
ISC_INT64 tens;
short i;
tens = 1;
for (i = 0; i > dscale; i--)
tens *= 10;
if (value >= 0)
sprintf (p, "%*" ISC_INT64_FORMAT "d.%0*" ISC_INT64_FORMAT "d",
field_width - 1 + dscale,
(ISC_INT64) value / tens,
-dscale,
(ISC_INT64) value % tens);
else if ((value / tens) != 0)
sprintf (p, "%*" ISC_INT64_FORMAT "d.%0*" ISC_INT64_FORMAT "d",
field_width - 1 + dscale,
(ISC_INT64) (value / tens),
-dscale,
(ISC_INT64) -(value % tens));
else
sprintf (p, "%*s.%0*" ISC_INT64_FORMAT "d",
field_width - 1 + dscale,
"-0",
-dscale,
(ISC_INT64) -(value % tens));
}
else if (dscale)
sprintf (p, "%*" ISC_INT64_FORMAT "d%0*d",
field_width,
(ISC_INT64) value,
dscale, 0);
else
sprintf (p, "%*" ISC_INT64_FORMAT "d%",
field_width,
(ISC_INT64) value);
};
break;
case SQL_FLOAT:
sprintf(p, "%15g ", *(float *) (var->sqldata));
break;
case SQL_DOUBLE:
sprintf(p, "%24g ", *(double *) (var->sqldata));
break;
case SQL_TIMESTAMP:
isc_decode_timestamp((ISC_TIMESTAMP *)var->sqldata, &times);
sprintf(date_s, "%04d-%02d-%02d %02d:%02d:%02d.%04d",
times.tm_year + 1900,
times.tm_mon+1,
times.tm_mday,
times.tm_hour,
times.tm_min,
times.tm_sec,
((ISC_TIMESTAMP *)var->sqldata)->timestamp_time % 10000);
sprintf(p, "%*s ", 24, date_s);
break;
case SQL_TYPE_DATE:
isc_decode_sql_date((ISC_DATE *)var->sqldata, &times);
sprintf(date_s, "%04d-%02d-%02d",
times.tm_year + 1900,
times.tm_mon+1,
times.tm_mday);
sprintf(p, "%*s ", 10, date_s);
break;
case SQL_TYPE_TIME:
isc_decode_sql_time((ISC_TIME *)var->sqldata, &times);
sprintf(date_s, "%02d:%02d:%02d.%04d",
times.tm_hour,
times.tm_min,
times.tm_sec,
(*((ISC_TIME *)var->sqldata)) % 10000);
sprintf(p, "%*s ", 13, date_s);
break;
case SQL_BLOB:
case SQL_ARRAY:
bid = *(ISC_QUAD *) var->sqldata;
sprintf(blob_s, "%08x:%08x", bid.gds_quad_high, bid.gds_quad_low);
sprintf(p, "%17s ", blob_s);
break;
default:
break;
}
}
while (*p)
{
putchar(*p++);
}
}
/*
* Prompt for and get input.
* Statements are terminated by a semicolon.
*/
int get_statement(ARG(char ISC_FAR *, buf))
ARGLIST(char *buf)
{
short c;
char *p;
int cnt;
p = buf;
cnt = 0;
printf("SQL> ");
for (;;)
{
if ((c = getchar()) == EOF)
return 0;
if (c == '\n')
{
/* accept "quit" or "exit" to terminate application */
if (!strncmp(buf, "exit;", 5))
return 0;
if (!strncmp(buf, "quit;", 5))
return 0;
/* Search back through any white space looking for ';'.*/
while (cnt && isspace(*(p - 1)))
{
p--;
cnt--;
}
if (*(p - 1) == ';')
{
*p++ = '\0';
return 1;
}
*p++ = ' ';
printf("CON> ");
}
else
*p++ = c;
cnt++;
}
}

View File

@ -0,0 +1,23 @@
/*
* The contents of this file are subject to the Interbase Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy
* of the License at http://www.Inprise.com/IPL.html
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code was created by Inprise Corporation
* and its predecessors. Portions created by Inprise Corporation are
* Copyright (C) Inprise Corporation.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/
set sql dialect 1;
create database 'employee.gdb';
show version;
input empddl.sql;
quit;

783
src/v5_examples/empbuild.c Normal file
View File

@ -0,0 +1,783 @@
/*********** Preprocessed module -- do not edit ***************/
/*********** Preprocessed module -- do not edit ***************/
/*********** Preprocessed module -- do not edit ***************/
/*********** Preprocessed module -- do not edit ***************/
/*********** Preprocessed module -- do not edit ***************/
/***************** gpre version LI-T0.9.4.34 Firebird Test1 **********************/
/*
* The contents of this file are subject to the Interbase Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy
* of the License at http://www.Inprise.com/IPL.html
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code was created by Inprise Corporation
* and its predecessors. Portions created by Inprise Corporation are
* Copyright (C) Inprise Corporation.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "../jrd/common.h"
#include "../jrd/gds.h"
/*
** Empbuild.e GPRE with manual switch, since it creates the database
** This program then calls isql with various input files
** It installs the blobs and arrays.
** Usage: empbuild <db name>
*/
static int addlang (void);
static int addjob (void);
static int addproj (void);
static int addqtr (void);
static TEXT Db_name[128];
static FILE *Fp;
/*EXEC SQL INCLUDE SQLCA;*/
/**** GDS Preprocessor Definitions ****/
#ifndef JRD_IBASE_H
#include <ibase.h>
#endif
static ISC_QUAD
isc_blob_null = {0,0}; /* initializer for blobs */
static long *gds__null = 0; /* dummy status vector */
isc_db_handle
DB = 0; /* database handle */
isc_tr_handle
gds__trans = 0; /* default transaction handle */
long
isc_status [20], /* status vector */
isc_status2 [20]; /* status vector */
long
isc_array_length, /* array return size */
SQLCODE; /* SQL status code */
static char
isc_tpb_6 [4] = {1,9,2,6};
static char
isc_tpb_5 [4] = {1,9,2,6};
static char
isc_tpb_4 [4] = {1,9,2,6};
static char
isc_tpb_1 [4] = {1,9,2,6};
static char
isc_tpb_0 [4] = {1,9,2,6};
static isc_req_handle
isc_9 = 0; /* request handle */
static short
isc_10l = 163;
static char
isc_10 [] = {
4,2,4,1,1,0,8,0,4,0,4,0,9,0,40,4,0,8,0,40,6,0,12,0,14,1,2,1,
21,8,0,0,0,0,0,25,1,0,0,7,'C',1,'J',16,'P','R','O','J','_','D',
'E','P','T','_','B','U','D','G','E','T',0,'G',58,47,23,0,11,
'F','I','S','C','A','L','_','Y','E','A','R',25,0,2,0,58,47,23,
0,7,'P','R','O','J','_','I','D',25,0,3,0,47,23,0,7,'D','E','P',
'T','_','N','O',25,0,1,0,-1,2,10,0,1,2,1,25,0,0,0,23,1,14,'Q',
'U','A','R','T','_','H','E','A','D','_','C','N','T',-1,1,34,
21,8,0,1,0,0,0,25,1,0,0,25,1,0,0,-1,-1,-1,'L'
}; /* end of blr string for request isc_10 */
static short
isc_18l = 51;
static char
isc_18 [] = {
1,6,1,8,0,2,16,'P','R','O','J','_','D','E','P','T','_','B','U',
'D','G','E','T',4,14,'Q','U','A','R','T','_','H','E','A','D',
'_','C','N','T',35,0,9,4,'$',1,8,0,1,7,0,-1
}; /* end of sdl string for request isc_18 */
static isc_req_handle
isc_20 = 0; /* request handle */
static short
isc_21l = 108;
static char
isc_21 [] = {
4,2,4,1,1,0,8,0,4,0,2,0,9,0,40,6,0,12,0,14,1,2,1,21,8,0,0,0,
0,0,25,1,0,0,7,'C',1,'J',7,'P','R','O','J','E','C','T',0,'G',
47,23,0,7,'P','R','O','J','_','I','D',25,0,1,0,-1,2,10,0,1,2,
1,25,0,0,0,23,1,9,'P','R','O','J','_','D','E','S','C',-1,1,34,
21,8,0,1,0,0,0,25,1,0,0,25,1,0,0,-1,-1,-1,'L'
}; /* end of blr string for request isc_21 */
static isc_stmt_handle
isc_28s; /* sql statement handle */
static isc_req_handle
isc_34 = 0; /* request handle */
static short
isc_35l = 154;
static char
isc_35 [] = {
4,2,4,1,1,0,8,0,4,0,4,0,40,16,0,9,0,7,0,40,6,0,12,0,14,1,2,1,
21,8,0,0,0,0,0,25,1,0,0,7,'C',1,'J',3,'J','O','B',0,'G',58,47,
23,0,8,'J','O','B','_','C','O','D','E',25,0,3,0,58,47,23,0,9,
'J','O','B','_','G','R','A','D','E',25,0,2,0,47,23,0,11,'J',
'O','B','_','C','O','U','N','T','R','Y',25,0,0,0,-1,2,10,0,1,
2,1,25,0,1,0,23,1,15,'J','O','B','_','R','E','Q','U','I','R',
'E','M','E','N','T',-1,1,34,21,8,0,1,0,0,0,25,1,0,0,25,1,0,0,
-1,-1,-1,'L'
}; /* end of blr string for request isc_35 */
static isc_stmt_handle
isc_44s; /* sql statement handle */
static isc_req_handle
isc_50 = 0; /* request handle */
static short
isc_51l = 151;
static char
isc_51 [] = {
4,2,4,1,1,0,8,0,4,0,4,0,40,16,0,9,0,7,0,40,6,0,12,0,14,1,2,1,
21,8,0,0,0,0,0,25,1,0,0,7,'C',1,'J',3,'J','O','B',0,'G',58,47,
23,0,8,'J','O','B','_','C','O','D','E',25,0,3,0,58,47,23,0,9,
'J','O','B','_','G','R','A','D','E',25,0,2,0,47,23,0,11,'J',
'O','B','_','C','O','U','N','T','R','Y',25,0,0,0,-1,2,10,0,1,
2,1,25,0,1,0,23,1,12,'L','A','N','G','U','A','G','E','_','R',
'E','Q',-1,1,34,21,8,0,1,0,0,0,25,1,0,0,25,1,0,0,-1,-1,-1,'L'
}; /* end of blr string for request isc_51 */
static short
isc_59l = 37;
static char
isc_59 [] = {
1,6,1,40,16,0,2,3,'J','O','B',4,12,'L','A','N','G','U','A','G',
'E','_','R','E','Q',35,0,9,5,'$',1,8,0,1,7,0,-1
}; /* end of sdl string for request isc_59 */
#define gds__blob_null isc_blob_null /* compatibility symbols */
#define gds__status isc_status
#define gds__status2 isc_status2
#define gds__array_length isc_array_length
#define gds__count isc_count
#define gds__slack isc_slack
#define gds__utility isc_utility /* end of compatibility symbols */
#ifndef isc_version4
Generate a compile-time error.
Picking up a V3 include file after preprocessing with V4 GPRE.
#endif
/**** end of GPRE definitions ****/
/*EXEC SQL SET DATABASE DB = COMPILETIME "empbuild.gdb" RUNTIME :Db_name;*/
main (
int argc,
char *argv[])
{
/**************************************
*
* m a i n
*
**************************************
*
* Functional description
*
**************************************/
TEXT cmd [140];
if (argc > 1)
strcpy (Db_name, argv[1]);
else
strcpy (Db_name, "employee.gdb");
/* Create the database */
printf ("creating database %s\n", Db_name);
sprintf (cmd, "CREATE DATABASE \"%s\"", Db_name);
gds__trans = 0;
/*EXEC SQL EXECUTE IMMEDIATE :cmd;*/
{
isc_embed_dsql_execute_immed (isc_status, &DB, &gds__trans, 0, cmd, 1, (XSQLDA*) 0L);
SQLCODE = isc_sqlcode (isc_status);
}
if (SQLCODE)
{
isc_print_status (gds__status);
exit (FINI_ERROR);
}
gds__trans = 0;
/*EXEC SQL DISCONNECT ALL;*/
{
if (DB)
isc_detach_database (isc_status, &DB);
SQLCODE = isc_sqlcode (isc_status);
}
if (SQLCODE)
{
isc_print_status (gds__status);
exit (FINI_ERROR);
}
printf ("Creating tables\n");
sprintf (cmd, "isql %s -q -i empddl.sql", Db_name);
if (system (cmd))
{
printf ("Couldn't create tables \n");
exit (FINI_ERROR);
}
printf ("Turning off indices and triggers \n");
sprintf (cmd, "isql %s -i indexoff.sql", Db_name);
system (cmd);
printf ("Loading column data\n");
sprintf (cmd, "isql %s -i empdml.sql", Db_name);
system (cmd);
printf ("Turning on indices and triggers \n");
sprintf (cmd, "isql %s -i indexon.sql", Db_name);
system (cmd);
/*EXEC SQL CONNECT DB;*/
{
isc_attach_database (isc_status, 0, Db_name, &DB, 0, (char*) 0);
SQLCODE = isc_sqlcode (isc_status);
}
if (SQLCODE)
{
isc_print_status (gds__status);
exit (FINI_ERROR);
}
/*EXEC SQL SET TRANSACTION;*/
{
isc_start_transaction (isc_status, (void**) &gds__trans, (short) 1, &DB, (short) 4, isc_tpb_0);
SQLCODE = isc_sqlcode (isc_status);
}
printf ("Loading Language blobs\n");
addlang();
printf ("Loading Job blobs\n");
addjob();
printf ("Loading project blobs \n");
addproj();
printf ("Loading quarter arrays \n");
addqtr();
exit (FINI_OK);
}
static int addlang (void)
{
struct {
long isc_58; /* isc_count */
} isc_57;
struct {
char isc_53 [16]; /* JOB_COUNTRY */
ISC_QUAD isc_54; /* LANGUAGE_REQ */
short isc_55; /* JOB_GRADE */
char isc_56 [6]; /* JOB_CODE */
} isc_52;
/**************************************
*
* a d d l a n g
*
**************************************
*
* Functional description
* Add language array to 'job' table.
*
**************************************/
TEXT job_code[6], job_country[16];
TEXT line[81];
TEXT lang_array[5][16];
int i, job_grade, rec_cnt = 0;
/*EXEC SQL SET TRANSACTION;*/
{
isc_start_transaction (isc_status, (void**) &gds__trans, (short) 1, &DB, (short) 4, isc_tpb_1);
SQLCODE = isc_sqlcode (isc_status);
}
/*EXEC SQL WHENEVER SQLERROR GO TO Error;*/
Fp = fopen ("lang.inp", "r");
while (fgets (line, 100, Fp) != NULL)
{
sscanf (line, "%s %d %s", job_code, &job_grade, job_country);
for (i = 0; i < 5; i++)
{
if (fgets (line, 100, Fp) == NULL)
break;
strcpy (lang_array [i], line);
}
/*EXEC SQL
UPDATE job
SET language_req = :lang_array
WHERE job_code = :job_code AND
job_grade = :job_grade AND
job_country = :job_country;*/
{
if (!isc_50)
isc_compile_request2 (isc_status, (void**) &DB, (void**) &isc_50, (short) sizeof (isc_51), (char ISC_FAR *) isc_51);
isc_vtov ((char*)job_country, (char*)isc_52.isc_53, 16);
isc_52.isc_54 = isc_blob_null;
isc_put_slice (isc_status, &DB, &gds__trans, &isc_52.isc_54, (short) 37, (char ISC_FAR *) isc_59, 0, (long*) 0, (long) 80, (void ISC_FAR *)lang_array);
SQLCODE = isc_sqlcode (isc_status);
if (SQLCODE < 0) goto Error;
isc_52.isc_55 = job_grade;
isc_vtov ((char*)job_code, (char*)isc_52.isc_56, 6);
if (isc_50)
isc_start_and_send (isc_status, (void**) &isc_50, (void**) &gds__trans, (short) 0, (short) 32, &isc_52, (short) 0);
SQLCODE = isc_sqlcode (isc_status);
if (!SQLCODE)
{
isc_receive (isc_status, (void**) &isc_50, (short) 1, (short) 4, &isc_57, (short) 0);
SQLCODE = isc_sqlcode (isc_status);
if (!SQLCODE && !isc_57.isc_58)
SQLCODE = 100;
}
if (SQLCODE < 0) goto Error;
}
if (SQLCODE == 0)
rec_cnt++;
else
{
printf ("Input error -- no job record with key: %s %d %s\n",
job_code, job_grade, job_country);
}
}
/*EXEC SQL COMMIT;*/
{
isc_commit_transaction (isc_status, (void**) &gds__trans);
SQLCODE = isc_sqlcode (isc_status);
if (SQLCODE < 0) goto Error;
}
printf ("Added %d language arrays.\n", rec_cnt);
fclose (Fp);
return (0);
Error:
printf ("SQLCODE=%d\n", SQLCODE);
isc_print_status (gds__status);
return (1);
}
static int addjob (void)
{
struct {
long isc_42; /* isc_count */
} isc_41;
struct {
char isc_37 [16]; /* JOB_COUNTRY */
ISC_QUAD isc_38; /* JOB_REQUIREMENT */
short isc_39; /* JOB_GRADE */
char isc_40 [6]; /* JOB_CODE */
} isc_36;
struct {
ISC_QUAD isc_49; /* JOB_REQUIREMENT */
} isc_48;
isc_blob_handle isc_45; /* blob handle */
char isc_46 [400]; /* blob segment */
unsigned short isc_47; /* segment length */
/**************************************
*
* a d d j o b
*
**************************************
*
* Functional description
* Add job description blobs.
*
**************************************/
TEXT job_code[6];
TEXT line[82], job_country[16];
int len;
ISC_QUAD job_blob;
int job_grade, rec_cnt = 0;
/*EXEC SQL SET TRANSACTION;*/
{
isc_start_transaction (isc_status, (void**) &gds__trans, (short) 1, &DB, (short) 4, isc_tpb_4);
SQLCODE = isc_sqlcode (isc_status);
if (SQLCODE < 0) goto Error;
}
/*EXEC SQL WHENEVER SQLERROR GO TO Error;*/
/*EXEC SQL DECLARE be CURSOR FOR
INSERT BLOB job_requirement INTO job;*/
isc_45 = 0;
Fp = fopen ("job.inp", "r");
while (fgets (line, 100, Fp) != NULL)
{
/*EXEC SQL OPEN be INTO :job_blob;*/
{
{
if (!isc_44s)
isc_dsql_alloc_statement2 (isc_status, &DB, &isc_44s);
if (isc_44s)
{
if (!isc_dsql_set_cursor_name (isc_status, &isc_44s, "BE", 0) &&
!isc_dsql_execute_m (isc_status, &gds__trans, &isc_44s, 0, (char *)0, -1, 0, (char *)0))
{
isc_create_blob2 (isc_status, &DB, &gds__trans, &isc_45, &isc_48.isc_49, (short) 0, (char*) 0);
}
}
}
SQLCODE = isc_sqlcode (isc_status);
if (!SQLCODE)
job_blob = isc_48.isc_49;
if (SQLCODE < 0) goto Error;
}
sscanf (line, "%s %d %s", job_code, &job_grade, job_country);
while (fgets (line, 100, Fp) != NULL)
{
if (*line == '\n')
break;
len = strlen (line);
/*EXEC SQL INSERT CURSOR be VALUES (:line INDICATOR :len);*/
{
{
isc_47 = len;
isc_ftof (line, isc_47, isc_46, isc_47);
isc_put_segment (isc_status, &isc_45, isc_47, isc_46);
SQLCODE = isc_sqlcode (isc_status);
}
if (SQLCODE < 0) goto Error;
}
}
/*EXEC SQL CLOSE be;*/
{
if (isc_44s && !isc_dsql_free_statement (isc_status, &isc_44s, 1))
{
isc_close_blob (isc_status, &isc_45);
}
SQLCODE = isc_sqlcode (isc_status);
if (SQLCODE < 0) goto Error;
}
/*EXEC SQL
UPDATE job
SET job_requirement = :job_blob
WHERE job_code = :job_code AND
job_grade = :job_grade AND
job_country = :job_country;*/
{
if (!isc_34)
isc_compile_request2 (isc_status, (void**) &DB, (void**) &isc_34, (short) sizeof (isc_35), (char ISC_FAR *) isc_35);
isc_vtov ((char*)job_country, (char*)isc_36.isc_37, 16);
isc_36.isc_38 = job_blob;
isc_36.isc_39 = job_grade;
isc_vtov ((char*)job_code, (char*)isc_36.isc_40, 6);
if (isc_34)
isc_start_and_send (isc_status, (void**) &isc_34, (void**) &gds__trans, (short) 0, (short) 32, &isc_36, (short) 0);
SQLCODE = isc_sqlcode (isc_status);
if (!SQLCODE)
{
isc_receive (isc_status, (void**) &isc_34, (short) 1, (short) 4, &isc_41, (short) 0);
SQLCODE = isc_sqlcode (isc_status);
if (!SQLCODE && !isc_41.isc_42)
SQLCODE = 100;
}
if (SQLCODE < 0) goto Error;
}
if (SQLCODE == 0)
rec_cnt++;
else
{
printf ("Input error -- no job record with key: %s %d %s\n",
job_code, job_grade, job_country);
}
}
/*EXEC SQL COMMIT;*/
{
isc_commit_transaction (isc_status, (void**) &gds__trans);
SQLCODE = isc_sqlcode (isc_status);
if (SQLCODE < 0) goto Error;
}
printf ("Added %d job requirement descriptions.\n", rec_cnt);
fclose (Fp);
return (0);
Error:
printf ("SQLCODE=%d\n", SQLCODE);
isc_print_status (gds__status);
return (1);
}
static int addproj (void)
{
struct {
long isc_26; /* isc_count */
} isc_25;
struct {
ISC_QUAD isc_23; /* PROJ_DESC */
char isc_24 [6]; /* PROJ_ID */
} isc_22;
struct {
ISC_QUAD isc_33; /* PROJ_DESC */
} isc_32;
isc_blob_handle isc_29; /* blob handle */
char isc_30 [800]; /* blob segment */
unsigned short isc_31; /* segment length */
/**************************************
*
* a d d p r o j
*
**************************************
*
* Functional description
* Add project description blobs.
*
**************************************/
TEXT proj_id[6];
TEXT line[82];
int len;
ISC_QUAD proj_blob;
int rec_cnt = 0;
/*EXEC SQL SET TRANSACTION;*/
{
isc_start_transaction (isc_status, (void**) &gds__trans, (short) 1, &DB, (short) 4, isc_tpb_5);
SQLCODE = isc_sqlcode (isc_status);
if (SQLCODE < 0) goto Error;
}
/*EXEC SQL WHENEVER SQLERROR GO TO Error;*/
/*EXEC SQL DECLARE bd CURSOR FOR
INSERT BLOB proj_desc INTO project;*/
isc_29 = 0;
Fp = fopen ("proj.inp", "r");
while (fgets (line, 100, Fp) != NULL)
{
/*EXEC SQL OPEN bd INTO :proj_blob;*/
{
{
if (!isc_28s)
isc_dsql_alloc_statement2 (isc_status, &DB, &isc_28s);
if (isc_28s)
{
if (!isc_dsql_set_cursor_name (isc_status, &isc_28s, "BD", 0) &&
!isc_dsql_execute_m (isc_status, &gds__trans, &isc_28s, 0, (char *)0, -1, 0, (char *)0))
{
isc_create_blob2 (isc_status, &DB, &gds__trans, &isc_29, &isc_32.isc_33, (short) 0, (char*) 0);
}
}
}
SQLCODE = isc_sqlcode (isc_status);
if (!SQLCODE)
proj_blob = isc_32.isc_33;
if (SQLCODE < 0) goto Error;
}
sscanf (line, "%s", proj_id);
while (fgets (line, 100, Fp) != NULL)
{
if (*line == '\n')
break;
len = strlen (line);
/*EXEC SQL INSERT CURSOR bd VALUES (:line INDICATOR :len);*/
{
{
isc_31 = len;
isc_ftof (line, isc_31, isc_30, isc_31);
isc_put_segment (isc_status, &isc_29, isc_31, isc_30);
SQLCODE = isc_sqlcode (isc_status);
}
if (SQLCODE < 0) goto Error;
}
}
/*EXEC SQL CLOSE bd;*/
{
if (isc_28s && !isc_dsql_free_statement (isc_status, &isc_28s, 1))
{
isc_close_blob (isc_status, &isc_29);
}
SQLCODE = isc_sqlcode (isc_status);
if (SQLCODE < 0) goto Error;
}
/*EXEC SQL
UPDATE project
SET proj_desc = :proj_blob
WHERE proj_id = :proj_id;*/
{
if (!isc_20)
isc_compile_request2 (isc_status, (void**) &DB, (void**) &isc_20, (short) sizeof (isc_21), (char ISC_FAR *) isc_21);
isc_22.isc_23 = proj_blob;
isc_vtov ((char*)proj_id, (char*)isc_22.isc_24, 6);
if (isc_20)
isc_start_and_send (isc_status, (void**) &isc_20, (void**) &gds__trans, (short) 0, (short) 14, &isc_22, (short) 0);
SQLCODE = isc_sqlcode (isc_status);
if (!SQLCODE)
{
isc_receive (isc_status, (void**) &isc_20, (short) 1, (short) 4, &isc_25, (short) 0);
SQLCODE = isc_sqlcode (isc_status);
if (!SQLCODE && !isc_25.isc_26)
SQLCODE = 100;
}
if (SQLCODE < 0) goto Error;
}
if (SQLCODE == 0)
rec_cnt++;
else
{
printf ("Input error -- no project record with key: %s\n", proj_id);
}
}
/*EXEC SQL COMMIT;*/
{
isc_commit_transaction (isc_status, (void**) &gds__trans);
SQLCODE = isc_sqlcode (isc_status);
if (SQLCODE < 0) goto Error;
}
printf ("Added %d project descriptions.\n", rec_cnt);
fclose (Fp);
return (0);
Error:
printf ("SQLCODE=%d\n", SQLCODE);
isc_print_status (gds__status);
return (1);
}
static int addqtr (void)
{
struct {
long isc_17; /* isc_count */
} isc_16;
struct {
ISC_QUAD isc_12; /* QUART_HEAD_CNT */
char isc_13 [4]; /* DEPT_NO */
long isc_14; /* FISCAL_YEAR */
char isc_15 [6]; /* PROJ_ID */
} isc_11;
/**************************************
*
* a d d q t r
*
**************************************
*
* Functional description
* Add project quarterly head-count array to 'proj_dept_budget' table.
*
**************************************/
TEXT proj_id[6], dept_no[4];
int yr;
TEXT line[81];
int hcnt[4];
int rec_cnt = 0;
/*EXEC SQL SET TRANSACTION;*/
{
isc_start_transaction (isc_status, (void**) &gds__trans, (short) 1, &DB, (short) 4, isc_tpb_6);
SQLCODE = isc_sqlcode (isc_status);
if (SQLCODE < 0) goto Error;
}
/*EXEC SQL WHENEVER SQLERROR GO TO Error;*/
Fp = fopen ("qtr.inp", "r");
while (fgets (line, 100, Fp) != NULL)
{
sscanf (line, "%d %s %s %d %d %d %d", &yr, proj_id, dept_no,
&hcnt[0], &hcnt[1], &hcnt[2], &hcnt[3]);
/*EXEC SQL
UPDATE proj_dept_budget
SET quart_head_cnt = :hcnt
WHERE fiscal_year = :yr AND proj_id = :proj_id AND dept_no = :dept_no;*/
{
if (!isc_9)
isc_compile_request2 (isc_status, (void**) &DB, (void**) &isc_9, (short) sizeof (isc_10), (char ISC_FAR *) isc_10);
isc_11.isc_12 = isc_blob_null;
isc_put_slice (isc_status, &DB, &gds__trans, &isc_11.isc_12, (short) 51, (char ISC_FAR *) isc_18, 0, (long*) 0, (long) 16, (void ISC_FAR *)hcnt);
SQLCODE = isc_sqlcode (isc_status);
if (SQLCODE < 0) goto Error;
isc_vtov ((char*)dept_no, (char*)isc_11.isc_13, 4);
isc_11.isc_14 = yr;
isc_vtov ((char*)proj_id, (char*)isc_11.isc_15, 6);
if (isc_9)
isc_start_and_send (isc_status, (void**) &isc_9, (void**) &gds__trans, (short) 0, (short) 22, &isc_11, (short) 0);
SQLCODE = isc_sqlcode (isc_status);
if (!SQLCODE)
{
isc_receive (isc_status, (void**) &isc_9, (short) 1, (short) 4, &isc_16, (short) 0);
SQLCODE = isc_sqlcode (isc_status);
if (!SQLCODE && !isc_16.isc_17)
SQLCODE = 100;
}
if (SQLCODE < 0) goto Error;
}
if (SQLCODE == 0)
rec_cnt++;
else
{
printf ("Input error -- no job record with key: %d %s %s\n",
yr, proj_id, dept_no);
}
}
/*EXEC SQL COMMIT RELEASE;*/
{
if (gds__trans)
isc_commit_transaction (isc_status, (void**) &gds__trans);
if (DB)
isc_detach_database (isc_status, &DB);
SQLCODE = isc_sqlcode (isc_status);
if (SQLCODE < 0) goto Error;
}
printf ("Added %d quarter arrays.\n", rec_cnt);
fclose (Fp);
return (0);
Error:
printf ("SQLCODE=%d\n", SQLCODE);
isc_print_status (gds__status);
return (1);
}

393
src/v5_examples/empbuild.e Normal file
View File

@ -0,0 +1,393 @@
/*
* The contents of this file are subject to the Interbase Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy
* of the License at http://www.Inprise.com/IPL.html
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code was created by Inprise Corporation
* and its predecessors. Portions created by Inprise Corporation are
* Copyright (C) Inprise Corporation.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
//#include "../jrd/common.h"
#include "gds.h"
/* Some #defines that are used in the program - they actually come from
jrd/common.h but should not be exposed externally with those name so
are reproduced here MOD 15-07-2001
*/
/* typedef char TEXT; */
#define FINI_OK 0
#define FINI_ERROR 44
/*
** Empbuild.e GPRE with manual switch, since it creates the database
** This program then calls isql with various input files
** It installs the blobs and arrays.
** Usage: empbuild <db name>
*/
static int addlang (void);
static int addjob (void);
static int addproj (void);
static int addqtr (void);
static TEXT Db_name[128];
static FILE *Fp;
EXEC SQL INCLUDE SQLCA;
EXEC SQL SET DATABASE DB = COMPILETIME "empbuild.gdb" RUNTIME :Db_name;
int main (
int argc,
char *argv[])
{
/**************************************
*
* m a i n
*
**************************************
*
* Functional description
*
**************************************/
TEXT cmd [140];
if (argc > 1)
strcpy (Db_name, argv[1]);
else
strcpy (Db_name, "employee.gdb");
/* Create the database */
printf ("creating database %s\n", Db_name);
sprintf (cmd, "CREATE DATABASE \"%s\"", Db_name);
gds__trans = 0;
EXEC SQL EXECUTE IMMEDIATE :cmd;
if (SQLCODE)
{
isc_print_status (gds__status);
exit (FINI_ERROR);
}
gds__trans = 0;
EXEC SQL DISCONNECT ALL;
if (SQLCODE)
{
isc_print_status (gds__status);
exit (FINI_ERROR);
}
printf ("Creating tables\n");
sprintf (cmd, "isql %s -q -i empddl.sql", Db_name);
if (system (cmd))
{
printf ("Couldn't create tables \n");
exit (FINI_ERROR);
}
printf ("Turning off indices and triggers \n");
sprintf (cmd, "isql %s -i indexoff.sql", Db_name);
system (cmd);
printf ("Loading column data\n");
sprintf (cmd, "isql %s -i empdml.sql", Db_name);
system (cmd);
printf ("Turning on indices and triggers \n");
sprintf (cmd, "isql %s -i indexon.sql", Db_name);
system (cmd);
EXEC SQL CONNECT DB;
if (SQLCODE)
{
isc_print_status (gds__status);
exit (FINI_ERROR);
}
EXEC SQL SET TRANSACTION;
printf ("Loading Language blobs\n");
addlang();
printf ("Loading Job blobs\n");
addjob();
printf ("Loading project blobs \n");
addproj();
printf ("Loading quarter arrays \n");
addqtr();
exit (FINI_OK);
}
static int addlang (void)
{
/**************************************
*
* a d d l a n g
*
**************************************
*
* Functional description
* Add language array to 'job' table.
*
**************************************/
TEXT job_code[6], job_country[16];
TEXT line[81];
TEXT lang_array[5][16];
int i, job_grade, rec_cnt = 0;
EXEC SQL SET TRANSACTION;
EXEC SQL WHENEVER SQLERROR GO TO Error;
Fp = fopen ("lang.inp", "r");
while (fgets (line, 100, Fp) != NULL)
{
sscanf (line, "%s %d %s", job_code, &job_grade, job_country);
for (i = 0; i < 5; i++)
{
if (fgets (line, 100, Fp) == NULL)
break;
strcpy (lang_array [i], line);
}
EXEC SQL
UPDATE job
SET language_req = :lang_array
WHERE job_code = :job_code AND
job_grade = :job_grade AND
job_country = :job_country;
if (SQLCODE == 0)
rec_cnt++;
else
{
printf ("Input error -- no job record with key: %s %d %s\n",
job_code, job_grade, job_country);
}
}
EXEC SQL COMMIT;
printf ("Added %d language arrays.\n", rec_cnt);
fclose (Fp);
return (0);
Error:
printf ("SQLCODE=%d\n", SQLCODE);
isc_print_status (gds__status);
return (1);
}
static int addjob (void)
{
/**************************************
*
* a d d j o b
*
**************************************
*
* Functional description
* Add job description blobs.
*
**************************************/
TEXT job_code[6];
TEXT line[82], job_country[16];
int len;
ISC_QUAD job_blob;
int job_grade, rec_cnt = 0;
EXEC SQL SET TRANSACTION;
EXEC SQL WHENEVER SQLERROR GO TO Error;
EXEC SQL DECLARE be CURSOR FOR
INSERT BLOB job_requirement INTO job;
Fp = fopen ("job.inp", "r");
while (fgets (line, 100, Fp) != NULL)
{
EXEC SQL OPEN be INTO :job_blob;
sscanf (line, "%s %d %s", job_code, &job_grade, job_country);
while (fgets (line, 100, Fp) != NULL)
{
if (*line == '\n')
break;
len = strlen (line);
EXEC SQL INSERT CURSOR be VALUES (:line INDICATOR :len);
}
EXEC SQL CLOSE be;
EXEC SQL
UPDATE job
SET job_requirement = :job_blob
WHERE job_code = :job_code AND
job_grade = :job_grade AND
job_country = :job_country;
if (SQLCODE == 0)
rec_cnt++;
else
{
printf ("Input error -- no job record with key: %s %d %s\n",
job_code, job_grade, job_country);
}
}
EXEC SQL COMMIT;
printf ("Added %d job requirement descriptions.\n", rec_cnt);
fclose (Fp);
return (0);
Error:
printf ("SQLCODE=%d\n", SQLCODE);
isc_print_status (gds__status);
return (1);
}
static int addproj (void)
{
/**************************************
*
* a d d p r o j
*
**************************************
*
* Functional description
* Add project description blobs.
*
**************************************/
TEXT proj_id[6];
TEXT line[82];
int len;
ISC_QUAD proj_blob;
int rec_cnt = 0;
EXEC SQL SET TRANSACTION;
EXEC SQL WHENEVER SQLERROR GO TO Error;
EXEC SQL DECLARE bd CURSOR FOR
INSERT BLOB proj_desc INTO project;
Fp = fopen ("proj.inp", "r");
while (fgets (line, 100, Fp) != NULL)
{
EXEC SQL OPEN bd INTO :proj_blob;
sscanf (line, "%s", proj_id);
while (fgets (line, 100, Fp) != NULL)
{
if (*line == '\n')
break;
len = strlen (line);
EXEC SQL INSERT CURSOR bd VALUES (:line INDICATOR :len);
}
EXEC SQL CLOSE bd;
EXEC SQL
UPDATE project
SET proj_desc = :proj_blob
WHERE proj_id = :proj_id;
if (SQLCODE == 0)
rec_cnt++;
else
{
printf ("Input error -- no project record with key: %s\n", proj_id);
}
}
EXEC SQL COMMIT;
printf ("Added %d project descriptions.\n", rec_cnt);
fclose (Fp);
return (0);
Error:
printf ("SQLCODE=%d\n", SQLCODE);
isc_print_status (gds__status);
return (1);
}
static int addqtr (void)
{
/**************************************
*
* a d d q t r
*
**************************************
*
* Functional description
* Add project quarterly head-count array to 'proj_dept_budget' table.
*
**************************************/
TEXT proj_id[6], dept_no[4];
int yr;
TEXT line[81];
int hcnt[4];
int rec_cnt = 0;
EXEC SQL SET TRANSACTION;
EXEC SQL WHENEVER SQLERROR GO TO Error;
Fp = fopen ("qtr.inp", "r");
while (fgets (line, 100, Fp) != NULL)
{
sscanf (line, "%d %s %s %d %d %d %d", &yr, proj_id, dept_no,
&hcnt[0], &hcnt[1], &hcnt[2], &hcnt[3]);
EXEC SQL
UPDATE proj_dept_budget
SET quart_head_cnt = :hcnt
WHERE fiscal_year = :yr AND proj_id = :proj_id AND dept_no = :dept_no;
if (SQLCODE == 0)
rec_cnt++;
else
{
printf ("Input error -- no job record with key: %d %s %s\n",
yr, proj_id, dept_no);
}
}
EXEC SQL COMMIT RELEASE;
printf ("Added %d quarter arrays.\n", rec_cnt);
fclose (Fp);
return (0);
Error:
printf ("SQLCODE=%d\n", SQLCODE);
isc_print_status (gds__status);
return (1);
}

951
src/v5_examples/empddl.sql Normal file
View File

@ -0,0 +1,951 @@
/*
* The contents of this file are subject to the Interbase Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy
* of the License at http://www.Inprise.com/IPL.html
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code was created by Inprise Corporation
* and its predecessors. Portions created by Inprise Corporation are
* Copyright (C) Inprise Corporation.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/
/*create database "employee.gdb";*/
/**
** Create a sample employee database.
**
** This database keeps track of employees, departments, projects, and sales
** for a small company.
**
**/
/*
* Define domains.
*/
CREATE DOMAIN firstname AS VARCHAR(15);
CREATE DOMAIN lastname AS VARCHAR(20);
CREATE DOMAIN phonenumber AS VARCHAR(20);
CREATE DOMAIN countryname AS VARCHAR(15);
CREATE DOMAIN addressline AS VARCHAR(30);
CREATE DOMAIN empno
AS SMALLINT;
CREATE DOMAIN deptno
AS CHAR(3)
CHECK (VALUE = '000' OR (VALUE > '0' AND VALUE <= '999') OR VALUE IS NULL);
CREATE DOMAIN projno
AS CHAR(5)
CHECK (VALUE = UPPER (VALUE));
CREATE DOMAIN custno
AS INTEGER
CHECK (VALUE > 1000);
/* must begin with a letter */
CREATE DOMAIN jobcode
AS VARCHAR(5)
CHECK (VALUE > '99999');
CREATE DOMAIN jobgrade
AS SMALLINT
CHECK (VALUE BETWEEN 0 AND 6);
/* salary is in any currency type */
CREATE DOMAIN salary
AS NUMERIC(10,2)
DEFAULT 0
CHECK (VALUE > 0);
/* budget is in US dollars */
CREATE DOMAIN budget
AS DECIMAL(12,2)
DEFAULT 50000
CHECK (VALUE > 10000 AND VALUE <= 2000000);
CREATE DOMAIN prodtype
AS VARCHAR(12)
DEFAULT 'software' NOT NULL
CHECK (VALUE IN ('software', 'hardware', 'other', 'N/A'));
CREATE DOMAIN PONUMBER
AS CHAR(8)
CHECK (VALUE STARTING WITH 'V');
/*
* Create generators.
*/
CREATE GENERATOR emp_no_gen;
CREATE GENERATOR cust_no_gen;
SET GENERATOR cust_no_gen to 1000;
COMMIT;
/*
* Create tables.
*/
/*
* Country name, currency type.
*/
CREATE TABLE country
(
country COUNTRYNAME NOT NULL PRIMARY KEY,
currency VARCHAR(10) NOT NULL
);
/*
* Job id, job title, minimum and maximum salary, job description,
* and required languages.
*
* A job is defined by a multiple key, consisting of a job_code
* (a 5-letter job abbreviation), a job grade, and a country name
* indicating the salary currency type.
*
* The salary range is expressed in the appropriate country's currency.
*
* The job requirement is a text blob.
*
* The job may also require some knowledge of foreign languages,
* stored in a character array.
*/
CREATE TABLE job
(
job_code JOBCODE NOT NULL,
job_grade JOBGRADE NOT NULL,
job_country COUNTRYNAME NOT NULL,
job_title VARCHAR(25) NOT NULL,
min_salary SALARY NOT NULL,
max_salary SALARY NOT NULL,
job_requirement BLOB(400,1),
language_req VARCHAR(15) [5],
PRIMARY KEY (job_code, job_grade, job_country),
FOREIGN KEY (job_country) REFERENCES country (country),
CHECK (min_salary < max_salary)
);
CREATE ASCENDING INDEX minsalx ON job (job_country, min_salary);
CREATE DESCENDING INDEX maxsalx ON job (job_country, max_salary);
/*
* Department number, name, head department, manager id,
* budget, location, department phone number.
*
* Each department is a sub-department in some department, determined
* by head_dept. The head of this tree is the company.
* This information is used to produce a company organization chart.
*
* Departments have managers; however, manager id can be null to allow
* for temporary situations where a manager needs to be hired.
*
* Budget is allocated in U.S. dollars for all departments.
*
* Foreign key mngr_no is added after the employee table is created,
* using 'alter table'.
*/
CREATE TABLE department
(
dept_no DEPTNO NOT NULL,
department VARCHAR(25) NOT NULL UNIQUE,
head_dept DEPTNO,
mngr_no EMPNO,
budget BUDGET,
location VARCHAR(15),
phone_no PHONENUMBER DEFAULT '555-1234',
PRIMARY KEY (dept_no),
FOREIGN KEY (head_dept) REFERENCES department (dept_no)
);
CREATE DESCENDING INDEX budgetx ON department (budget);
/*
* Employee id, name, phone extension, date of hire, department id,
* job and salary information.
*
* Salary can be entered in any country's currency.
* Therefore, some of the salaries can appear magnitudes larger than others,
* depending on the currency type. Ex. Italian lira vs. U.K. pound.
* The currency type is determined by the country code.
*
* job_code, job_grade, and job_country reference employee's job information,
* illustrating two tables related by referential constraints on multiple
* columns.
*
* The employee salary is verified to be in the correct salary range
* for the given job title.
*/
CREATE TABLE employee
(
emp_no EMPNO NOT NULL,
first_name FIRSTNAME NOT NULL,
last_name LASTNAME NOT NULL,
phone_ext VARCHAR(4),
hire_date DATE DEFAULT 'NOW' NOT NULL,
dept_no DEPTNO NOT NULL,
job_code JOBCODE NOT NULL,
job_grade JOBGRADE NOT NULL,
job_country COUNTRYNAME NOT NULL,
salary SALARY NOT NULL,
full_name COMPUTED BY (last_name || ', ' || first_name),
PRIMARY KEY (emp_no),
FOREIGN KEY (dept_no) REFERENCES
department (dept_no),
FOREIGN KEY (job_code, job_grade, job_country) REFERENCES
job (job_code, job_grade, job_country),
CHECK ( salary >= (SELECT min_salary FROM job WHERE
job.job_code = employee.job_code AND
job.job_grade = employee.job_grade AND
job.job_country = employee.job_country) AND
salary <= (SELECT max_salary FROM job WHERE
job.job_code = employee.job_code AND
job.job_grade = employee.job_grade AND
job.job_country = employee.job_country))
);
CREATE INDEX namex ON employee (last_name, first_name);
CREATE VIEW phone_list AS SELECT
emp_no, first_name, last_name, phone_ext, location, phone_no
FROM employee, department
WHERE employee.dept_no = department.dept_no;
COMMIT;
SET TERM !! ;
CREATE TRIGGER set_emp_no FOR employee
BEFORE INSERT AS
BEGIN
new.emp_no = gen_id(emp_no_gen, 1);
END !!
SET TERM ; !!
/*
* Add an additional constraint to department: check manager numbers
* in the employee table.
*/
ALTER TABLE department ADD FOREIGN KEY (mngr_no) REFERENCES employee (emp_no);
/*
* Project id, project name, description, project team leader,
* and product type.
*
* Project description is a text blob.
*/
CREATE TABLE project
(
proj_id PROJNO NOT NULL,
proj_name VARCHAR(20) NOT NULL UNIQUE,
proj_desc BLOB(800,1),
team_leader EMPNO,
product PRODTYPE,
PRIMARY KEY (proj_id),
FOREIGN KEY (team_leader) REFERENCES employee (emp_no)
);
CREATE UNIQUE INDEX prodtypex ON project (product, proj_name);
/*
* Employee id, project id, employee's project duties.
*
* Employee duties is a text blob.
*/
CREATE TABLE employee_project
(
emp_no EMPNO NOT NULL,
proj_id PROJNO NOT NULL,
PRIMARY KEY (emp_no, proj_id),
FOREIGN KEY (emp_no) REFERENCES employee (emp_no),
FOREIGN KEY (proj_id) REFERENCES project (proj_id)
);
/*
* Fiscal year, project id, department id, projected head count by
* fiscal quarter, projected budget.
*
* Tracks head count and budget planning by project by department.
*
* Quarterly head count is an array of integers.
*/
CREATE TABLE proj_dept_budget
(
fiscal_year INTEGER NOT NULL CHECK (FISCAL_YEAR >= 1993),
proj_id PROJNO NOT NULL,
dept_no DEPTNO NOT NULL,
quart_head_cnt INTEGER [4],
projected_budget BUDGET,
PRIMARY KEY (fiscal_year, proj_id, dept_no),
FOREIGN KEY (dept_no) REFERENCES department (dept_no),
FOREIGN KEY (proj_id) REFERENCES project (proj_id)
);
/*
* Employee number, salary change date, updater's user id, old salary,
* and percent change between old and new salary.
*/
CREATE TABLE salary_history
(
emp_no EMPNO NOT NULL,
change_date DATE DEFAULT 'NOW' NOT NULL,
updater_id VARCHAR(20) NOT NULL,
old_salary SALARY NOT NULL,
percent_change DOUBLE PRECISION
DEFAULT 0
NOT NULL
CHECK (percent_change between -50 and 50),
new_salary COMPUTED BY
(old_salary + old_salary * percent_change / 100),
PRIMARY KEY (emp_no, change_date, updater_id),
FOREIGN KEY (emp_no) REFERENCES employee (emp_no)
);
CREATE INDEX updaterx ON salary_history (updater_id);
CREATE DESCENDING INDEX changex ON salary_history (change_date);
COMMIT;
SET TERM !! ;
CREATE TRIGGER save_salary_change FOR employee
AFTER UPDATE AS
BEGIN
IF (old.salary <> new.salary) THEN
INSERT INTO salary_history
(emp_no, change_date, updater_id, old_salary, percent_change)
VALUES (
old.emp_no,
'NOW',
user,
old.salary,
(new.salary - old.salary) * 100 / old.salary);
END !!
SET TERM ; !!
COMMIT;
/*
* Customer id, customer name, contact first and last names,
* phone number, address lines, city, state or province, country,
* postal code or zip code, and customer status.
*/
CREATE TABLE customer
(
cust_no CUSTNO NOT NULL,
customer VARCHAR(25) NOT NULL,
contact_first FIRSTNAME,
contact_last LASTNAME,
phone_no PHONENUMBER,
address_line1 ADDRESSLINE,
address_line2 ADDRESSLINE,
city VARCHAR(25),
state_province VARCHAR(15),
country COUNTRYNAME,
postal_code VARCHAR(12),
on_hold CHAR
DEFAULT NULL
CHECK (on_hold IS NULL OR on_hold = '*'),
PRIMARY KEY (cust_no),
FOREIGN KEY (country) REFERENCES country (country)
);
CREATE INDEX custnamex ON customer (customer);
CREATE INDEX custregion ON customer (country, city);
SET TERM !! ;
CREATE TRIGGER set_cust_no FOR customer
BEFORE INSERT AS
BEGIN
new.cust_no = gen_id(cust_no_gen, 1);
END !!
SET TERM ; !!
COMMIT;
/*
* Purchase order number, customer id, sales representative, order status,
* order date, date shipped, date need to ship by, payment received flag,
* quantity ordered, total order value, type of product ordered,
* any percent discount offered.
*
* Tracks customer orders.
*
* sales_rep is the ID of the employee handling the sale.
*
* Number of days passed since the order date is a computed field.
*
* Several checks are performed on this table, among them:
* - A sale order must have a status: open, shipped, waiting.
* - The ship date must be entered, if order status is 'shipped'.
* - New orders can't be shipped to customers with 'on_hold' status.
* - Sales rep
*/
CREATE TABLE sales
(
po_number PONUMBER NOT NULL,
cust_no CUSTNO NOT NULL,
sales_rep EMPNO,
order_status VARCHAR(7)
DEFAULT 'new'
NOT NULL
CHECK (order_status in
('new', 'open', 'shipped', 'waiting')),
order_date DATE
DEFAULT 'NOW'
NOT NULL,
ship_date DATE
CHECK (ship_date >= order_date OR ship_date IS NULL),
date_needed DATE
CHECK (date_needed > order_date OR date_needed IS NULL),
paid CHAR
DEFAULT 'n'
CHECK (paid in ('y', 'n')),
qty_ordered INTEGER
DEFAULT 1
NOT NULL
CHECK (qty_ordered >= 1),
total_value DECIMAL(9,2)
NOT NULL
CHECK (total_value >= 0),
discount FLOAT
DEFAULT 0
NOT NULL
CHECK (discount >= 0 AND discount <= 1),
item_type PRODTYPE,
aged COMPUTED BY
(ship_date - order_date),
PRIMARY KEY (po_number),
FOREIGN KEY (cust_no) REFERENCES customer (cust_no),
FOREIGN KEY (sales_rep) REFERENCES employee (emp_no),
CHECK (NOT (order_status = 'shipped' AND ship_date IS NULL)),
CHECK (NOT (order_status = 'shipped' AND
EXISTS (SELECT on_hold FROM customer
WHERE customer.cust_no = sales.cust_no
AND customer.on_hold = '*')))
);
CREATE INDEX needx ON sales (date_needed);
CREATE INDEX salestatx ON sales (order_status, paid);
CREATE DESCENDING INDEX qtyx ON sales (item_type, qty_ordered);
SET TERM !! ;
CREATE TRIGGER post_new_order FOR sales
AFTER INSERT AS
BEGIN
POST_EVENT 'new_order';
END !!
SET TERM ; !!
COMMIT;
/****************************************************************************
*
* Create stored procedures.
*
*****************************************************************************/
SET TERM !! ;
/*
* Get employee's projects.
*
* Parameters:
* employee number
* Returns:
* project id
*/
CREATE PROCEDURE get_emp_proj (emp_no SMALLINT)
RETURNS (proj_id CHAR(5)) AS
BEGIN
FOR SELECT proj_id
FROM employee_project
WHERE emp_no = :emp_no
INTO :proj_id
DO
SUSPEND;
END !!
/*
* Add an employee to a project.
*
* Parameters:
* employee number
* project id
* Returns:
* --
*/
CREATE EXCEPTION unknown_emp_id 'Invalid employee number or project id.' !!
CREATE PROCEDURE add_emp_proj (emp_no SMALLINT, proj_id CHAR(5)) AS
BEGIN
BEGIN
INSERT INTO employee_project (emp_no, proj_id) VALUES (:emp_no, :proj_id);
WHEN SQLCODE -530 DO
EXCEPTION unknown_emp_id;
END
SUSPEND;
END !!
/*
* Select one row.
*
* Compute total, average, smallest, and largest department budget.
*
* Parameters:
* department id
* Returns:
* total budget
* average budget
* min budget
* max budget
*/
CREATE PROCEDURE sub_tot_budget (head_dept CHAR(3))
RETURNS (tot_budget DECIMAL(12, 2), avg_budget DECIMAL(12, 2),
min_budget DECIMAL(12, 2), max_budget DECIMAL(12, 2))
AS
BEGIN
SELECT SUM(budget), AVG(budget), MIN(budget), MAX(budget)
FROM department
WHERE head_dept = :head_dept
INTO :tot_budget, :avg_budget, :min_budget, :max_budget;
SUSPEND;
END !!
/*
* Delete an employee.
*
* Parameters:
* employee number
* Returns:
* --
*/
CREATE EXCEPTION reassign_sales
'Reassign the sales records before deleting this employee.' !!
CREATE PROCEDURE delete_employee (emp_num INTEGER)
AS
DECLARE VARIABLE any_sales INTEGER;
BEGIN
any_sales = 0;
/*
* If there are any sales records referencing this employee,
* can't delete the employee until the sales are re-assigned
* to another employee or changed to NULL.
*/
SELECT count(po_number)
FROM sales
WHERE sales_rep = :emp_num
INTO :any_sales;
IF (any_sales > 0) THEN
BEGIN
EXCEPTION reassign_sales;
SUSPEND;
END
/*
* If the employee is a manager, update the department.
*/
UPDATE department
SET mngr_no = NULL
WHERE mngr_no = :emp_num;
/*
* If the employee is a project leader, update project.
*/
UPDATE project
SET team_leader = NULL
WHERE team_leader = :emp_num;
/*
* Delete the employee from any projects.
*/
DELETE FROM employee_project
WHERE emp_no = :emp_num;
/*
* Delete old salary records.
*/
DELETE FROM salary_history
WHERE emp_no = :emp_num;
/*
* Delete the employee.
*/
DELETE FROM employee
WHERE emp_no = :emp_num;
SUSPEND;
END !!
/*
* Recursive procedure.
*
* Compute the sum of all budgets for a department and all the
* departments under it.
*
* Parameters:
* department id
* Returns:
* total budget
*/
CREATE PROCEDURE dept_budget (dno CHAR(3))
RETURNS (tot decimal(12,2)) AS
DECLARE VARIABLE sumb DECIMAL(12, 2);
DECLARE VARIABLE rdno CHAR(3);
DECLARE VARIABLE cnt INTEGER;
BEGIN
tot = 0;
SELECT budget FROM department WHERE dept_no = :dno INTO :tot;
SELECT count(budget) FROM department WHERE head_dept = :dno INTO :cnt;
IF (cnt = 0) THEN
SUSPEND;
FOR SELECT dept_no
FROM department
WHERE head_dept = :dno
INTO :rdno
DO
BEGIN
EXECUTE PROCEDURE dept_budget :rdno RETURNING_VALUES :sumb;
tot = tot + sumb;
END
SUSPEND;
END !!
/*
* Display an org-chart.
*
* Parameters:
* --
* Returns:
* parent department
* department name
* department manager
* manager's job title
* number of employees in the department
*/
CREATE PROCEDURE org_chart
RETURNS (head_dept CHAR(25), department CHAR(25),
mngr_name CHAR(20), title CHAR(5), emp_cnt INTEGER)
AS
DECLARE VARIABLE mngr_no INTEGER;
DECLARE VARIABLE dno CHAR(3);
BEGIN
FOR SELECT h.department, d.department, d.mngr_no, d.dept_no
FROM department d
LEFT OUTER JOIN department h ON d.head_dept = h.dept_no
ORDER BY d.dept_no
INTO :head_dept, :department, :mngr_no, :dno
DO
BEGIN
IF (:mngr_no IS NULL) THEN
BEGIN
mngr_name = '--TBH--';
title = '';
END
ELSE
SELECT full_name, job_code
FROM employee
WHERE emp_no = :mngr_no
INTO :mngr_name, :title;
SELECT COUNT(emp_no)
FROM employee
WHERE dept_no = :dno
INTO :emp_cnt;
SUSPEND;
END
END !!
/*
* Generate a 6-line mailing label for a customer.
* Some of the lines may be blank.
*
* Parameters:
* customer number
* Returns:
* 6 address lines
*/
CREATE PROCEDURE mail_label (cust_no INTEGER)
RETURNS (line1 CHAR(40), line2 CHAR(40), line3 CHAR(40),
line4 CHAR(40), line5 CHAR(40), line6 CHAR(40))
AS
DECLARE VARIABLE customer VARCHAR(25);
DECLARE VARIABLE first VARCHAR(15);
DECLARE VARIABLE last VARCHAR(20);
DECLARE VARIABLE addr1 VARCHAR(30);
DECLARE VARIABLE addr2 VARCHAR(30);
DECLARE VARIABLE city VARCHAR(25);
DECLARE VARIABLE state VARCHAR(15);
DECLARE VARIABLE country VARCHAR(15);
DECLARE VARIABLE postcode VARCHAR(12);
DECLARE VARIABLE cnt INTEGER;
BEGIN
line1 = '';
line2 = '';
line3 = '';
line4 = '';
line5 = '';
line6 = '';
SELECT customer, contact_first, contact_last, address_line1,
address_line2, city, state_province, country, postal_code
FROM CUSTOMER
WHERE cust_no = :cust_no
INTO :customer, :first, :last, :addr1, :addr2,
:city, :state, :country, :postcode;
IF (customer IS NOT NULL) THEN
line1 = customer;
IF (first IS NOT NULL) THEN
line2 = first || ' ' || last;
ELSE
line2 = last;
IF (addr1 IS NOT NULL) THEN
line3 = addr1;
IF (addr2 IS NOT NULL) THEN
line4 = addr2;
IF (country = 'USA') THEN
BEGIN
IF (city IS NOT NULL) THEN
line5 = city || ', ' || state || ' ' || postcode;
ELSE
line5 = state || ' ' || postcode;
END
ELSE
BEGIN
IF (city IS NOT NULL) THEN
line5 = city || ', ' || state;
ELSE
line5 = state;
line6 = country || ' ' || postcode;
END
SUSPEND;
END !!
/*
* Ship a sales order.
* First, check if the order is already shipped, if the customer
* is on hold, or if the customer has an overdue balance.
*
* Parameters:
* purchase order number
* Returns:
* --
*
*/
CREATE EXCEPTION order_already_shipped 'Order status is "shipped."' !!
CREATE EXCEPTION customer_on_hold 'This customer is on hold.' !!
CREATE EXCEPTION customer_check 'Overdue balance -- can not ship.' !!
CREATE PROCEDURE ship_order (po_num CHAR(8))
AS
DECLARE VARIABLE ord_stat CHAR(7);
DECLARE VARIABLE hold_stat CHAR(1);
DECLARE VARIABLE cust_no INTEGER;
DECLARE VARIABLE any_po CHAR(8);
BEGIN
SELECT s.order_status, c.on_hold, c.cust_no
FROM sales s, customer c
WHERE po_number = :po_num
AND s.cust_no = c.cust_no
INTO :ord_stat, :hold_stat, :cust_no;
/* This purchase order has been already shipped. */
IF (ord_stat = 'shipped') THEN
BEGIN
EXCEPTION order_already_shipped;
SUSPEND;
END
/* Customer is on hold. */
ELSE IF (hold_stat = '*') THEN
BEGIN
EXCEPTION customer_on_hold;
SUSPEND;
END
/*
* If there is an unpaid balance on orders shipped over 2 months ago,
* put the customer on hold.
*/
FOR SELECT po_number
FROM sales
WHERE cust_no = :cust_no
AND order_status = 'shipped'
AND paid = 'n'
AND ship_date < CAST('NOW' AS DATE) - 60
INTO :any_po
DO
BEGIN
EXCEPTION customer_check;
UPDATE customer
SET on_hold = '*'
WHERE cust_no = :cust_no;
SUSPEND;
END
/*
* Ship the order.
*/
UPDATE sales
SET order_status = 'shipped', ship_date = 'NOW'
WHERE po_number = :po_num;
SUSPEND;
END !!
CREATE PROCEDURE show_langs (code VARCHAR(5), grade SMALLINT, cty VARCHAR(15))
RETURNS (languages VARCHAR(15))
AS
DECLARE VARIABLE i INTEGER;
BEGIN
i = 1;
WHILE (i <= 5) DO
BEGIN
SELECT language_req[:i] FROM joB
WHERE ((job_code = :code) AND (job_grade = :grade) AND (job_country = :cty)
AND (language_req IS NOT NULL))
INTO :languages;
IF (languages = ' ') THEN /* Prints 'NULL' instead of blanks */
languages = 'NULL';
i = i +1;
SUSPEND;
END
END!!
CREATE PROCEDURE all_langs RETURNS
(code VARCHAR(5), grade VARCHAR(5),
country VARCHAR(15), LANG VARCHAR(15)) AS
BEGIN
FOR SELECT job_code, job_grade, job_country FROM job
INTO :code, :grade, :country
DO
BEGIN
FOR SELECT languages FROM show_langs
(:code, :grade, :country) INTO :lang DO
SUSPEND;
/* Put nice separators between rows */
code = '=====';
grade = '=====';
country = '===============';
lang = '==============';
SUSPEND;
END
END!!
SET TERM ; !!
/* Privileges */
GRANT ALL PRIVILEGES ON country TO PUBLIC WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON job TO PUBLIC WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON department TO PUBLIC WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON employee TO PUBLIC WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON phone_list TO PUBLIC WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON project TO PUBLIC WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON employee_project TO PUBLIC WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON proj_dept_budget TO PUBLIC WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON salary_history TO PUBLIC WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON customer TO PUBLIC WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON sales TO PUBLIC WITH GRANT OPTION;
GRANT EXECUTE ON PROCEDURE get_emp_proj TO PUBLIC WITH GRANT OPTION;
GRANT EXECUTE ON PROCEDURE add_emp_proj TO PUBLIC WITH GRANT OPTION;
GRANT EXECUTE ON PROCEDURE sub_tot_budget TO PUBLIC WITH GRANT OPTION;
GRANT EXECUTE ON PROCEDURE delete_employee TO PUBLIC WITH GRANT OPTION;
GRANT EXECUTE ON PROCEDURE dept_budget TO PUBLIC WITH GRANT OPTION;
GRANT EXECUTE ON PROCEDURE org_chart TO PUBLIC WITH GRANT OPTION;
GRANT EXECUTE ON PROCEDURE mail_label TO PUBLIC WITH GRANT OPTION;
GRANT EXECUTE ON PROCEDURE ship_order TO PUBLIC WITH GRANT OPTION;
GRANT EXECUTE ON PROCEDURE show_langs TO PUBLIC WITH GRANT OPTION;
GRANT EXECUTE ON PROCEDURE all_langs TO PUBLIC WITH GRANT OPTION;

1037
src/v5_examples/empdml.sql Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,50 @@
/*
* The contents of this file are subject to the Interbase Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy
* of the License at http://www.Inprise.com/IPL.html
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code was created by Inprise Corporation
* and its predecessors. Portions created by Inprise Corporation are
* Copyright (C) Inprise Corporation.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/
set sql dialect 1;
create database "employe2.gdb";
/*
* Currency cross rates: convert one currency type into another.
*
* Ex. 5 U.S. Dollars = 5 * 1.3273 Canadian Dollars
*/
CREATE TABLE cross_rate
(
from_currency VARCHAR(10) NOT NULL,
to_currency VARCHAR(10) NOT NULL,
conv_rate FLOAT NOT NULL,
update_date DATE,
PRIMARY KEY (from_currency, to_currency)
);
INSERT INTO cross_rate VALUES ('Dollar', 'CdnDlr', 1.3273, '11/22/93');
INSERT INTO cross_rate VALUES ('Dollar', 'FFranc', 5.9193, '11/22/93');
INSERT INTO cross_rate VALUES ('Dollar', 'D-Mark', 1.7038, '11/22/93');
INSERT INTO cross_rate VALUES ('Dollar', 'Lira', 1680.0, '11/22/93');
INSERT INTO cross_rate VALUES ('Dollar', 'Yen', 108.43, '11/22/93');
INSERT INTO cross_rate VALUES ('Dollar', 'Guilder', 1.9115, '11/22/93');
INSERT INTO cross_rate VALUES ('Dollar', 'SFranc', 1.4945, '11/22/93');
INSERT INTO cross_rate VALUES ('Dollar', 'Pound', 0.67774, '11/22/93');
INSERT INTO cross_rate VALUES ('Pound', 'FFranc', 8.734, '11/22/93');
INSERT INTO cross_rate VALUES ('Pound', 'Yen', 159.99, '11/22/93');
INSERT INTO cross_rate VALUES ('Yen', 'Pound', 0.00625, '11/22/93');
INSERT INTO cross_rate VALUES ('CdnDlr', 'Dollar', 0.75341, '11/22/93');
INSERT INTO cross_rate VALUES ('CdnDlr', 'FFranc', 4.4597, '11/22/93');

View File

@ -0,0 +1,25 @@
; The contents of this file are subject to the Interbase Public
; License Version 1.0 (the "License"); you may not use this file
; except in compliance with the License. You may obtain a copy
; of the License at http://www.Inprise.com/IPL.html
;
; Software distributed under the License is distributed on an
; "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
; or implied. See the License for the specific language governing
; rights and limitations under the License.
;
; The Original Code was created by Inprise Corporation
; and its predecessors. Portions created by Inprise Corporation are
; Copyright (C) Inprise Corporation.
;
; All Rights Reserved.
; Contributor(s): ______________________________________.
;-------------------------------------
; example.DEF module definition file
;-------------------------------------
EXETYPE WINDOWS
CODE PRELOAD MOVEABLE DISCARDABLE
DATA PRELOAD MOVEABLE MULTIPLE
HEAPSIZE 4096
STACKSIZE 15000

35
src/v5_examples/example.h Normal file
View File

@ -0,0 +1,35 @@
/*
* The contents of this file are subject to the Interbase Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy
* of the License at http://www.Inprise.com/IPL.html
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code was created by Inprise Corporation
* and its predecessors. Portions created by Inprise Corporation are
* Copyright (C) Inprise Corporation.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/
#if defined __STDC__ || defined __BORLANDC__ || defined _MSC_VER
#define args args
#define ARG(type, arg) type arg
#define ARGLIST(arg)
#else
#define args ()
#define ARG(type, arg) arg
#define ARGLIST(arg) arg;
#endif
#if defined __BORLANDC__ && defined __WIN32__
#define EXPORT _export
#else
#define EXPORT
#endif
#define ERREXIT(status, rc) {isc_print_status(status); return rc;}

143
src/v5_examples/example.mak Normal file
View File

@ -0,0 +1,143 @@
# The contents of this file are subject to the Interbase Public
# License Version 1.0 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy
# of the License at http://www.Inprise.com/IPL.html
#
# Software distributed under the License is distributed on an
# "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
# or implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code was created by Inprise Corporation
# and its predecessors. Portions created by Inprise Corporation are
# Copyright (C) Inprise Corporation.
#
# All Rights Reserved.
# Contributor(s): ______________________________________.
#------------------------------------------------------------------------
# EXAMPLES make file
#
# To use Borland C 3.x or 4.x type the following on the command line:
# "make -fexample.mak <example program>"
# e.g. make -fexample.mak api1.exe
#
# To use MicroSoft C 7.0 type the following on the command line:
# "nmake MSFT= /f example.mak <example program>"
# e.g. nmake MSFT= /f example.mak api1.exe
#
#------------------------------------------------------------------------
INC_PATH=..\include
!ifdef MSFT
CC=cl
LINK=link
RC=rc
#------------------------------------------------------------------------
# MicroSoft C compiler and link flags
# The QCFLAGS and QWINLIB macros exist because a console app in MicroSoft
# C requires a special compile flag, /Mq (Quick Win app), and a special
# link library, llibcewq.
#------------------------------------------------------------------------
QCFLAGS=/c /AL /Ge /Zi /Mq /Od /G2 /Zp1 /W3 /I$(INC_PATH)
CFLAGS=/c /AL /Ge /Zi /Od /GA /G2 /Zp1 /W3 /I$(INC_PATH)
LFLAGS=/M /NOD /CO
QWINLIB=..\lib\gds libw llibcewq
WINLIB=..\lib\gds libw llibcew
!else
CC=bcc
LINK=tlink
RC=brc
#------------------------------------------------------------------------
# Borland C compiler and link flags
# The QCFLAGS and QWINLIB macros exist because a console app in MicroSoft
# C requires a special compile flag, /Mq (Quick Win app), and a special
# link library, llibcewq.
#------------------------------------------------------------------------
CFLAGS=-c -ml -N -v -Od -WE -2 -I$(INC_PATH)
QCFLAGS=$(CFLAGS)
LFLAGS=/n /m /Twe /v c0wl
WINLIB=..\lib\gds import mathwl cwl
QWINLIB=$(WINLIB)
!endif
.c.obj:
$(CC) $(QCFLAGS) $<
TARGETS = winevent.exe api1.exe api2.exe api3.exe api4.exe api5.exe \
api6.exe api7.exe api8.exe api9.exe api10.exe api11.exe api12.exe \
api13.exe api15.exe api16t.exe apifull.exe
all: $(TARGETS)
winevent.obj : winevent.c $(INC_PATH)\ibase.h
$(CC) $(CFLAGS) winevent.c
winevent.exe : winevent.obj winevent.def winevent.res
$(LINK) $(LFLAGS) winevent.obj, winevent.exe,, $(WINLIB), winevent.def
$(RC) winevent.res
winevent.res : winevent.rc
$(RC) -r winevent.rc
api1.exe: api1.obj example.def example.h $(INC_PATH)\ibase.h
$(LINK) $(LFLAGS) $*.obj, $*.exe,, $(QWINLIB), example.def
api2.exe: api2.obj example.def example.h $(INC_PATH)\ibase.h
$(LINK) $(LFLAGS) $*.obj, $*.exe,, $(QWINLIB), example.def
api3.exe: api3.obj example.def example.h $(INC_PATH)\ibase.h
$(LINK) $(LFLAGS) $*.obj, $*.exe,, $(QWINLIB), example.def
api4.exe: api4.obj example.def example.h $(INC_PATH)\ibase.h
$(LINK) $(LFLAGS) $*.obj, $*.exe,, $(QWINLIB), example.def
api5.exe: api5.obj example.def example.h $(INC_PATH)\ibase.h
$(LINK) $(LFLAGS) $*.obj, $*.exe,, $(QWINLIB), example.def
api6.exe: api6.obj example.def example.h $(INC_PATH)\ibase.h
$(LINK) $(LFLAGS) $*.obj, $*.exe,, $(QWINLIB), example.def
api7.exe: api7.obj example.def example.h $(INC_PATH)\ibase.h
$(LINK) $(LFLAGS) $*.obj, $*.exe,, $(QWINLIB), example.def
api8.exe: api8.obj example.def example.h $(INC_PATH)\ibase.h
$(LINK) $(LFLAGS) $*.obj, $*.exe,, $(QWINLIB), example.def
api9.exe: api9.obj example.def example.h $(INC_PATH)\ibase.h
$(LINK) $(LFLAGS) $*.obj, $*.exe,, $(QWINLIB), example.def
api10.exe: api10.obj example.def example.h $(INC_PATH)\ibase.h
$(LINK) $(LFLAGS) $*.obj, $*.exe,, $(QWINLIB), example.def
api11.exe: api11.obj example.def example.h $(INC_PATH)\ibase.h
$(LINK) $(LFLAGS) $*.obj, $*.exe,, $(QWINLIB), example.def
api12.exe: api12.obj example.def example.h $(INC_PATH)\ibase.h
$(LINK) $(LFLAGS) $*.obj, $*.exe,, $(QWINLIB), example.def
api13.exe: api13.obj example.def example.h $(INC_PATH)\ibase.h
$(LINK) $(LFLAGS) $*.obj, $*.exe,, $(QWINLIB), example.def
api15.exe: api15.obj example.def example.h $(INC_PATH)\ibase.h
$(LINK) $(LFLAGS) $*.obj, $*.exe,, $(QWINLIB), example.def
api16t.exe: api16t.obj example.def example.h $(INC_PATH)\ibase.h
$(LINK) $(LFLAGS) api16t.obj, api16t.exe,, $(QWINLIB), example.def
apifull.exe: apifull.obj align.h example.def example.h $(INC_PATH)\ibase.h
$(LINK) $(LFLAGS) $*.obj, $*.exe,, $(QWINLIB), example.def
clean:
del *.obj
del *.exe
del *.res
del *.map

149
src/v5_examples/functions.c Normal file
View File

@ -0,0 +1,149 @@
/*
* PROGRAM: InterBase Access Method
* MODULE: functions.c
* DESCRIPTION: External entrypoint definitions
*
* The contents of this file are subject to the Interbase Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy
* of the License at http://www.Inprise.com/IPL.html
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code was created by Inprise Corporation
* and its predecessors. Portions created by Inprise Corporation are
* Copyright (C) Inprise Corporation.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/
typedef int (*FUN_PTR)();
typedef struct {
char *fn_module;
char *fn_entrypoint;
FUN_PTR fn_function;
} FN;
static test();
extern char *fn_lower_c();
extern char *fn_strcat();
extern char *fn_substr();
extern char *fn_trim();
extern char *fn_trunc();
extern long fn_doy();
extern short *fn_moy();
extern char *fn_dow();
extern char *fn_sysdate();
extern long fn_add2();
extern double fn_mul();
extern double fn_fact();
extern double fn_abs();
extern double fn_max();
extern double fn_sqrt();
extern long fn_blob_linecount();
extern long fn_blob_bytecount();
extern char *fn_blob_substr();
static FN isc_functions [] = {
"test_module", "test_function", test,
"FUNCLIB", "fn_lower_c", (FUN_PTR) fn_lower_c,
"FUNCLIB", "fn_strcat", (FUN_PTR) fn_strcat,
"FUNCLIB", "fn_substr", (FUN_PTR) fn_substr,
"FUNCLIB", "fn_trim", (FUN_PTR) fn_trim,
"FUNCLIB", "fn_trunc", (FUN_PTR) fn_trunc,
"FUNCLIB", "fn_doy", (FUN_PTR) fn_doy,
"FUNCLIB", "fn_moy", (FUN_PTR) fn_moy,
"FUNCLIB", "fn_dow", (FUN_PTR) fn_dow,
"FUNCLIB", "fn_sysdate", (FUN_PTR) fn_sysdate,
"FUNCLIB", "fn_add2", (FUN_PTR) fn_add2,
"FUNCLIB", "fn_mul", (FUN_PTR) fn_mul,
"FUNCLIB", "fn_fact", (FUN_PTR) fn_fact,
"FUNCLIB", "fn_abs", (FUN_PTR) fn_abs,
"FUNCLIB", "fn_max", (FUN_PTR) fn_max,
"FUNCLIB", "fn_sqrt", (FUN_PTR) fn_sqrt,
"FUNCLIB", "fn_blob_linecount", (FUN_PTR) fn_blob_linecount,
"FUNCLIB", "fn_blob_bytecount", (FUN_PTR) fn_blob_bytecount,
"FUNCLIB", "fn_blob_substr", (FUN_PTR) fn_blob_substr,
0, 0, 0};
#ifdef SHLIB_DEFS
#define strcmp (*_libfun_strcmp)
#define sprintf (*_libfun_sprintf)
extern int strcmp();
extern int sprintf();
#endif
FUN_PTR FUNCTIONS_entrypoint (module, entrypoint)
char *module;
char *entrypoint;
{
/**************************************
*
* F U N C T I O N S _ e n t r y p o i n t
*
**************************************
*
* Functional description
* Lookup function in hardcoded table. The module and
* entrypoint names are null terminated, but may contain
* insignificant trailing blanks.
*
**************************************/
FN *function;
char *p, temp [64], *ep;
p = temp;
while (*module && *module != ' ')
*p++ = *module++;
*p++ = 0;
ep = p;
while (*entrypoint && *entrypoint != ' ')
*p++ = *entrypoint++;
*p = 0;
for (function = isc_functions; function->fn_module; ++function)
if (!strcmp (temp, function->fn_module) && !strcmp (ep, function->fn_entrypoint))
return function->fn_function;
return 0;
}
static test (n, result)
int n;
char *result;
{
/**************************************
*
* t e s t
*
**************************************
*
* Functional description
* Sample extern function. Defined in database by:
*
* define function test module_name "test_module" entry_point "test_function"
* long by value,
* char [20] by reference return_argument;
*
**************************************/
char *end;
sprintf (result, "%d is a number", n);
end = result + 20;
while (*result)
result++;
while (result < end)
*result++ = ' ';
}

View File

@ -0,0 +1,33 @@
/*
* The contents of this file are subject to the Interbase Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy
* of the License at http://www.Inprise.com/IPL.html
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code was created by Inprise Corporation
* and its predecessors. Portions created by Inprise Corporation are
* Copyright (C) Inprise Corporation.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/
alter index CUSTNAMEX inactive;
alter index CUSTREGION inactive;
alter index BUDGETX inactive;
alter index NAMEX inactive;
alter index MAXSALX inactive;
alter index MINSALX inactive;
alter index PRODTYPEX inactive;
alter index CHANGEX inactive;
alter index UPDATERX inactive;
alter index NEEDX inactive;
alter index QTYX inactive;
alter index SALESTATX inactive;
ALTER TRIGGER set_emp_no INACTIVE;
ALTER TRIGGER set_cust_no INACTIVE;
ALTER TRIGGER post_new_order INACTIVE;

View File

@ -0,0 +1,33 @@
/*
* The contents of this file are subject to the Interbase Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy
* of the License at http://www.Inprise.com/IPL.html
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code was created by Inprise Corporation
* and its predecessors. Portions created by Inprise Corporation are
* Copyright (C) Inprise Corporation.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/
alter index CUSTNAMEX active;
alter index CUSTREGION active;
alter index BUDGETX active;
alter index NAMEX active;
alter index MAXSALX active;
alter index MINSALX active;
alter index PRODTYPEX active;
alter index CHANGEX active;
alter index UPDATERX active;
alter index NEEDX active;
alter index QTYX active;
alter index SALESTATX active;
ALTER TRIGGER set_emp_no ACTIVE;
ALTER TRIGGER set_cust_no ACTIVE;
ALTER TRIGGER post_new_order ACTIVE;

395
src/v5_examples/intlbld.e Normal file
View File

@ -0,0 +1,395 @@
/*
* The contents of this file are subject to the Interbase Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy
* of the License at http://www.Inprise.com/IPL.html
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code was created by Inprise Corporation
* and its predecessors. Portions created by Inprise Corporation are
* Copyright (C) Inprise Corporation.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
//#include "../jrd/common.h"
#include "gds.h"
/* typedef char TEXT; */
#define FINI_OK 0
#define FINI_ERROR 44
/*
** Intlbld.e International version of Empbuild.e. Default database
** name was changed to 'intlemp.gdb'. Two of the files
** executed as ISQL input files were modified: intlddl.sql
** and intldml.sql are used by this program.
**
** GPRE with manual switch, since it creates the database
** This program then calls isql with various input files
** It installs the blobs and arrays.
** Usage: empbuild <db name>
*/
static int addlang (void);
static int addjob (void);
static int addproj (void);
static int addqtr (void);
static TEXT Db_name[128];
static FILE *Fp;
EXEC SQL INCLUDE SQLCA;
EXEC SQL SET DATABASE DB = COMPILETIME "intlbuild.gdb" RUNTIME :Db_name;
int main (
int argc,
char *argv[])
{
/**************************************
*
* m a i n
*
**************************************
*
* Functional description
*
**************************************/
TEXT cmd [140];
if (argc > 1)
strcpy (Db_name, argv[1]);
else
strcpy (Db_name, "intlemp.gdb");
/* Create the database */
printf ("creating database %s\n", Db_name);
sprintf (cmd, "CREATE DATABASE \"%s\" DEFAULT CHARACTER SET ISO8859_1", Db_name);
gds__trans = 0;
EXEC SQL EXECUTE IMMEDIATE :cmd;
if (SQLCODE)
{
isc_print_status (gds__status);
exit (FINI_ERROR);
}
gds__trans = 0;
EXEC SQL DISCONNECT ALL;
if (SQLCODE)
{
isc_print_status (gds__status);
exit (FINI_ERROR);
}
/* ddl and dml file names are different for international */
printf ("Creating tables\n");
sprintf (cmd, "isql %s -q -i intlddl.sql", Db_name);
if (system (cmd))
{
printf ("Couldn't create tables \n");
exit (FINI_ERROR);
}
printf ("Turning off indices and triggers \n");
sprintf (cmd, "isql %s -i indexoff.sql", Db_name);
system (cmd);
printf ("Loading column data\n");
sprintf (cmd, "isql %s -i intldml.sql", Db_name);
system (cmd);
printf ("Turning on indices and triggers \n");
sprintf (cmd, "isql %s -i indexon.sql", Db_name);
system (cmd);
EXEC SQL CONNECT DB;
if (SQLCODE)
{
isc_print_status (gds__status);
exit (FINI_ERROR);
}
EXEC SQL SET TRANSACTION;
printf ("Loading Language blobs\n");
addlang();
printf ("Loading Job blobs\n");
addjob();
printf ("Loading project blobs \n");
addproj();
printf ("Loading quarter arrays \n");
addqtr();
exit (FINI_OK);
}
static int addlang (void)
{
/**************************************
*
* a d d l a n g
*
**************************************
*
* Functional description
* Add language array to 'job' table.
*
**************************************/
TEXT job_code[6], job_country[16];
TEXT line[81];
TEXT lang_array[5][16];
int i, job_grade, rec_cnt = 0;
EXEC SQL SET TRANSACTION;
EXEC SQL WHENEVER SQLERROR GO TO Error;
Fp = fopen ("lang.inp", "r");
while (fgets (line, 100, Fp) != NULL)
{
sscanf (line, "%s %d %s", job_code, &job_grade, job_country);
for (i = 0; i < 5; i++)
{
if (fgets (line, 100, Fp) == NULL)
break;
strcpy (lang_array [i], line);
}
EXEC SQL
UPDATE job
SET language_req = :lang_array
WHERE job_code = :job_code AND
job_grade = :job_grade AND
job_country = :job_country;
if (SQLCODE == 0)
rec_cnt++;
else
{
printf ("Input error -- no job record with key: %s %d %s\n",
job_code, job_grade, job_country);
}
}
EXEC SQL COMMIT;
printf ("Added %d language arrays.\n", rec_cnt);
fclose (Fp);
return (0);
Error:
printf ("SQLCODE=%d\n", SQLCODE);
isc_print_status (gds__status);
return (1);
}
static int addjob (void)
{
/**************************************
*
* a d d j o b
*
**************************************
*
* Functional description
* Add job description blobs.
*
**************************************/
TEXT job_code[6];
TEXT line[82], job_country[16];
int len;
ISC_QUAD job_blob;
int job_grade, rec_cnt = 0;
EXEC SQL SET TRANSACTION;
EXEC SQL WHENEVER SQLERROR GO TO Error;
EXEC SQL DECLARE be CURSOR FOR
INSERT BLOB job_requirement INTO job;
Fp = fopen ("job.inp", "r");
while (fgets (line, 100, Fp) != NULL)
{
EXEC SQL OPEN be INTO :job_blob;
sscanf (line, "%s %d %s", job_code, &job_grade, job_country);
while (fgets (line, 100, Fp) != NULL)
{
if (*line == '\n')
break;
len = strlen (line);
EXEC SQL INSERT CURSOR be VALUES (:line INDICATOR :len);
}
EXEC SQL CLOSE be;
EXEC SQL
UPDATE job
SET job_requirement = :job_blob
WHERE job_code = :job_code AND
job_grade = :job_grade AND
job_country = :job_country;
if (SQLCODE == 0)
rec_cnt++;
else
{
printf ("Input error -- no job record with key: %s %d %s\n",
job_code, job_grade, job_country);
}
}
EXEC SQL COMMIT;
printf ("Added %d job requirement descriptions.\n", rec_cnt);
fclose (Fp);
return (0);
Error:
printf ("SQLCODE=%d\n", SQLCODE);
isc_print_status (gds__status);
return (1);
}
static int addproj (void)
{
/**************************************
*
* a d d p r o j
*
**************************************
*
* Functional description
* Add project description blobs.
*
**************************************/
TEXT proj_id[6];
TEXT line[82];
int len;
ISC_QUAD proj_blob;
int rec_cnt = 0;
EXEC SQL SET TRANSACTION;
EXEC SQL WHENEVER SQLERROR GO TO Error;
EXEC SQL DECLARE bd CURSOR FOR
INSERT BLOB proj_desc INTO project;
Fp = fopen ("proj.inp", "r");
while (fgets (line, 100, Fp) != NULL)
{
EXEC SQL OPEN bd INTO :proj_blob;
sscanf (line, "%s", proj_id);
while (fgets (line, 100, Fp) != NULL)
{
if (*line == '\n')
break;
len = strlen (line);
EXEC SQL INSERT CURSOR bd VALUES (:line INDICATOR :len);
}
EXEC SQL CLOSE bd;
EXEC SQL
UPDATE project
SET proj_desc = :proj_blob
WHERE proj_id = :proj_id;
if (SQLCODE == 0)
rec_cnt++;
else
{
printf ("Input error -- no project record with key: %s\n", proj_id);
}
}
EXEC SQL COMMIT;
printf ("Added %d project descriptions.\n", rec_cnt);
fclose (Fp);
return (0);
Error:
printf ("SQLCODE=%d\n", SQLCODE);
isc_print_status (gds__status);
return (1);
}
static int addqtr (void)
{
/**************************************
*
* a d d q t r
*
**************************************
*
* Functional description
* Add project quarterly head-count array to 'proj_dept_budget' table.
*
**************************************/
TEXT proj_id[6], dept_no[4];
int yr;
TEXT line[81];
int hcnt[4];
int rec_cnt = 0;
EXEC SQL SET TRANSACTION;
EXEC SQL WHENEVER SQLERROR GO TO Error;
Fp = fopen ("qtr.inp", "r");
while (fgets (line, 100, Fp) != NULL)
{
sscanf (line, "%d %s %s %d %d %d %d", &yr, proj_id, dept_no,
&hcnt[0], &hcnt[1], &hcnt[2], &hcnt[3]);
EXEC SQL
UPDATE proj_dept_budget
SET quart_head_cnt = :hcnt
WHERE fiscal_year = :yr AND proj_id = :proj_id AND dept_no = :dept_no;
if (SQLCODE == 0)
rec_cnt++;
else
{
printf ("Input error -- no job record with key: %d %s %s\n",
yr, proj_id, dept_no);
}
}
EXEC SQL COMMIT RELEASE;
printf ("Added %d quarter arrays.\n", rec_cnt);
fclose (Fp);
return (0);
Error:
printf ("SQLCODE=%d\n", SQLCODE);
isc_print_status (gds__status);
return (1);
}

View File

@ -0,0 +1,23 @@
/*
* The contents of this file are subject to the Interbase Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy
* of the License at http://www.Inprise.com/IPL.html
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code was created by Inprise Corporation
* and its predecessors. Portions created by Inprise Corporation are
* Copyright (C) Inprise Corporation.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/
set sql dialect 1;
create database 'intlemp.gdb' default character set iso8859_1;
show version;
input intlddl.sql;
quit;

1013
src/v5_examples/intlddl.sql Normal file

File diff suppressed because it is too large Load Diff

1398
src/v5_examples/intldml.sql Normal file

File diff suppressed because it is too large Load Diff

156
src/v5_examples/job.inp Normal file
View File

@ -0,0 +1,156 @@
CEO 1 USA
No specific requirements.
CFO 1 USA
15+ years in finance or 5+ years as a CFO
with a proven track record.
MBA or J.D. degree.
Finan 3 USA
5-10 years of accounting and financial experience.
Strong analytical skills.
CPA/MBA required.
Accnt 4 USA
CPA with 3-5 years experience.
Spreadsheet, data entry, and word processing knowledge required.
Accnt 4 USA
CPA with 3-5 years experience.
Spreadsheet, data entry, and word processing knowledge required.
Dir 2 USA
5-10 years as a director in computer or electronics industries.
An advanced degree.
VP 2 USA
No specific requirements.
Admin 4 USA
3-5 years experience in executive environment.
Strong organizational and communication skills required.
BA degree preferred.
Admin 5 USA
2-4 years clerical experience.
Facility with word processing and data entry.
AA degree preferred.
Mktg 3 USA
MBA required.
10+ years experience in high tech environment.
Mktg 4 USA
BA/BS required. MBA preferred.
3-5 years experience.
Knowledgeable with spreadsheets and databases.
Eng 2 USA
Distinguished engineer.
Ph.D/MS/BS or equivalent experience.
Eng 3 USA
5+ years experience.
BA/BS required.
MS degree preferred.
Eng 3 Japan
5+ years experience.
BA/BS and/or MS degrees required.
Customer support experience desired.
Knowledge of Japanese and English.
Eng 4 USA
BA/BS and 3-5 years experience.
Eng 4 England
BA/BS and
2-4 years experience in technical support.
Knowledge of several European languages helpful.
Eng 5 USA
BA/BS preferred.
2-4 years technical experience.
Doc 3 USA
4+ years writing highly technical
software documentation.
A bachelor's degree or equivalent.
Programming experience required.
Excellent language skills.
Doc 5 USA
BA in English/journalism or excellent language skills.
Some programming experience required.
2-4 years of technical writing.
Mngr 3 USA
BA/BS required.
3-5 years in management,
plus 2-4 years engineering experience.
Mngr 4 USA
5+ years office management experience.
Sales 3 USA
Experience in sales and public relations
in a high tech environment.
Excellent communication skills.
BA or equivalent.
Sales 3 England
Experience in sales and public relations
in a high tech environment.
Excellent communication skills.
BA or equivalent.
Knowledge of several European languages helpful.
SRep 4 USA
Computer/electronics industry sales experience.
Excellent communications, negotiation, and analytical skills.
Experience in establishing long term customer relationships.
Some knowledge of Spanish required.
Travel required.
SRep 4 England
Computer/electronics industry sales experience.
Excellent communications, negotiation, and analytical skills.
Experience in establishing long term customer relationships.
Knowledge of several European languages helpful.
Travel required.
SRep 4 Canada
Computer/electronics industry sales experience.
Excellent communications, negotiation, and analytical skills.
Experience in establishing long term customer relationships.
Travel required.
English plus speaking knowledge of French required.
SRep 4 Switzerland
Computer/electronics industry sales experience.
Excellent communications, negotiation, and analytical skills.
Experience in establishing long term customer relationships.
Knowledge of German required; one or more other European language helpful.
Travel required.
SRep 4 Japan
Computer/electronics industry sales experience.
Excellent communications, negotiation, and analytical skills.
Experience in establishing long term customer relationships.
Knowledge of Japanese required.
Travel required.
SRep 4 Italy
Computer/electronics industry sales experience.
Excellent communications, negotiation, and analytical skills.
Experience in establishing long term customer relationships.
Fluency in Italian; some knowledge of German helpful.
Travel required.
SRep 4 France
Computer/electronics industry sales experience.
Excellent communications, negotiation, and analytical skills.
Experience in establishing long term customer relationships.
Fluency in French; some knowledge of German/Spanish helpful.
Travel required.

60
src/v5_examples/lang.inp Normal file
View File

@ -0,0 +1,60 @@
Eng 3 Japan
Japanese
Mandarin
English
Eng 4 England
English
German
French
Sales 3 England
English
German
French
SRep 4 USA
English
Spanish
SRep 4 England
English
German
French
SRep 4 Canada
English
French
SRep 4 Switzerland
German
French
English
Italian
SRep 4 Japan
Japanese
English
SRep 4 Italy
Italian
German
French
SRep 4 France
English
French
Spanish

View File

@ -0,0 +1,64 @@
# The contents of this file are subject to the Interbase Public
# License Version 1.0 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy
# of the License at http://www.Inprise.com/IPL.html
#
# Software distributed under the License is distributed on an
# "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
# or implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code was created by Inprise Corporation
# and its predecessors. Portions created by Inprise Corporation are
# Copyright (C) Inprise Corporation.
#
# All Rights Reserved.
# Contributor(s): ______________________________________.
# The contents of this file are subject to the Interbase Public
# License Version 1.0 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy
# of the License at http://www.Inprise.com/IPL.html
#
# Software distributed under the License is distributed on an
# "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
# or implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code was created by Inprise Corporation
# and its predecessors. Portions created by Inprise Corporation are
# Copyright (C) Inprise Corporation.
#
# All Rights Reserved.
# Contributor(s): ______________________________________.
#--------------------------- PC EXAMPLES MAKEFILE ----------------------------
ROOT=..
.path.c=$(ROOT)\example4
!include $(ROOT)\std.mk
#--------------------------- SOURCE COMPONENTS -----------------------------
H1 = example.h align.h
HDRS=$(H1)
S1 = api1.c api2.c api3.c api4.c api5.c api6.c api7.c api8.c api9.c api9F
S2 = api10.c api11.c api12.c api13.c api15.c api16t.c apifull.c create2.sql
S3 = winevent.c winevent.rc winevent.def example.mak example.def readme
SRCS = $(S1) $(S2) $(S3)
# Extra files which are used to build the product
XFILES = makefile.mak
#---------------------------- TARGET LIST --------------------------------
#---------------------------- UTILITIES ---------------------------------
# Refresh all the source & header files from the DEVSRC directory
srcs::
for %i in ($(H1)) do copy $(DEVSRC)\example4\%i
for %i in ($(S1)) do copy $(DEVSRC)\example4\%i
for %i in ($(S2)) do copy $(DEVSRC)\example4\%i
for %i in ($(S3)) do copy $(DEVSRC)\example4\%i
for %i in ($(XFILES)) do copy $(DEVSRC)\example4\%i

View File

@ -0,0 +1,325 @@
# The contents of this file are subject to the Interbase Public
# License Version 1.0 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy
# of the License at http://www.Inprise.com/IPL.html
#
# Software distributed under the License is distributed on an
# "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
# or implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code was created by Inprise Corporation
# and its predecessors. Portions created by Inprise Corporation are
# Copyright (C) Inprise Corporation.
#
# All Rights Reserved.
# Contributor(s): ______________________________________.
# Start of file prefix.linux: DEV $(PLATFORM)
#$Id: makefile.old,v 1.1 2001-07-23 16:05:46 skywalker Exp $
#Revision 1.6 2000/12/01 11:20:31 fsg
#Added SHRLIB_EXT to prefix.linux
#
.SUFFIXES: .c .e
.e.c:
$(GPRE) $(GPRE_FLAGS) $<
.SUFFIXES: .bin .o .c
.c.o:
$(CC) -c $(CFLAGS) $(VERSION_FLAG) $<
.c.bin:
$(CC) -c $(PIC_FLAGS) $(VERSION_FLAG) -o $*.bin $<
PROD_DEBUG_OBJECTS= nodebug.o
PROD_SHRLIB_DIR= -Lsource/jrd -Lsource/interbase/lib
PROD_VERSION_FLAG= -DPROD_BUILD
PROD_CFLAGS= -O3 -m486 -fpic -DFLINTSTONE
DEV_DEBUG_OBJECTS= grammar.o dbg.o dbt.o dmp.o
DEV_SHRLIB_DIR= -Lsource/jrd -Lsource/interbase/lib
DEV_VERSION_FLAG= -DDEV_BUILD
DEV_CFLAGS= -ggdb
DEBUG_OBJECTS= $(DEV_DEBUG_OBJECTS)
SHRLIB_DIR= $(DEV_SHRLIB_DIR)
VERSION_FLAG= $(DEV_VERSION_FLAG)
CFLAGS_COMMON= $(DEV_CFLAGS) -DLINUX -Wall -fwritable-strings -I$(INTERBASE)/include
CFLAGS= $(CFLAGS_COMMON)
PIC_J_CFLAGS= $(CFLAGS_COMMON) -DPIPE_IS_SHRLIB -fPIC
SPECIAL_OBJECTS= j
UDF_LINK_CMD= gcc
UDF_CFLAGS= -fPIC -mieee-fp
UDF_LFLAGS= -shared
UDF_SHRLIBS= -L$(INTERBASE)/lib -lgds -lm -lc -mieee-fp -ldl -lcrypt
#NOTE: PIC_J_CFLAGS is special CFLAGS used to build PIPD_IS_SHRLIB modules
# to workaround the Solaris threading problems with signals
#NOTE: -Xt is ANSI C transition mode (default)
# -DBDS_COMP is for BSD Compatibility package and is used in <sys/ioctl.h>
ACCESS_METHOD= gdslib.linux pipe
BACKEND_BRIDGE_MISC= head5.o allp.o
BIN_PATH= /usr/isc/bin
BRIDGE_MISC= head5.o allp.o
CHMOD_VAL= 666
#NOTE: I removed CURSES_LIB= -lbsd because it breaks the build on SuSE systems
# and isn't necessary anymore.
#FSG 091500
CURSES_LIB=
DSQL_P_OBJS= dsql_p_objects
FORM_OBJECTS= form.o
FORM_TRN_OBJECTS= form_trn.o
FUNCTIONS= functions.bin
FUNCSHR= source/interbase/lib/gdsf.so
GDS_LINK= $(GDSSHR_LINK)
GDS_PYXIS= gds_pyxis.a
GDSLIB_BACKEND= source/interbase/lib/gds_b.a
GDSLIB_LINK= -Lsource/jrd -lgds_b -lc -ldl -lcrypt
GDSSHR= source/interbase/lib/gds.so
LINUX_GDSSHR= $(GDSSHR)
GDSSHR_LINK= $(SHRLIB_DIR) -lgds -ldl -lgds_pyxis -lcrypt -lncurses
#PIPE_GDSSHR= source/interbase/lib/gds.so.0
PIPE_GDSSHR_LINK= $(SHRLIB_DIR) -lgds -lgds_pyxis
HLPDIR= source/qli/
HOSTNAME= `hostname | cut -d'.' -f1`
INCLUDES= include_so include_so_ada
INTL= intl
INTL_CFLAGS= $(CFLAGS)
INTL_LD_LINE= ld -G -o gdsintl
INTL_PIC_FLAGS= $(PIC_FLAGS)
INTL_TARGET= intl_shr_objs
IO_OBJECTS= unix.o
IO_P_OBJECTS= unix.bin
JRD_MISC_OBJECTS= source/jrd/sun_ftn.o
JRD_J_MISC_OBJECTS= source/jrd/sun_ftn.j
JRD_P_MISC_OBJECTS= source/jrd/sun_ftn.bin source/jrd/nodebug.bin
LANG_OBJECTS= ada.o ftn.o cob.o
LANGUAGES= cc cxx ada microfocus_cob make16 gdl1 sun_ftn
LD_LIBS= -lc
LD_LIBS_J= -lc
LD_OPTS= -shared
LOCK_JRD_MISC= source/jrd/thd.o
LOCK_MANAGER= manager
MARION_DB= -d source/marion.gdb
MUISQL= muisql
MUISQL_MU_LIB= -L /usr/gds.$(HOSTNAME)/qa_tools/lib -lmu
MUISQL_LINK_OPTS= $(MUISQL_MU_LIB) $(PIPE_GDSSHR_LINK) -lm
PIC_FLAGS= $(CFLAGS) -fPIC
PIPE= gds.a gds_pipe
PYXIS= pyxis
PYXIS_MISC_OBJS= $(PYXIS_MISC)
PYXIS_P_MISC_OBJS= $(PYXIS_P_MISC)
PYXIS_OBJECTS= pyxis_objects
PYXIS_MISC_OBJECTS= $(PYXDIR)cdm.o $(PYXDIR)vt100.o $(PYXDIR)sun_ftn_pyxis.o
REG_HELP= isc_ins_hlp.dat
REMOTE_GDSSHR= $(GDSSHR)
REMOTE_GDSSHR_LINK= $(SERVER_LINK)
REMOTE_P_OBJS= rem_p_objects
SCREEN_LIBS= -lncurses
SERVER_LINK= $(GDSSHR_LINK)
SETUP_ISC= ISC_USER=sysdba; ISC_PASSWORD=masterkey; export ISC_USER ISC_PASSWORD;
SPECIAL_OPT= source/special_opt
NETWORK_LIB=
SOCKET_LIB= -lc
THREAD_LIB= -lpthread
SUN_FUNCSHR= $(FUNCSHR)
LX_SUPER_GDSSHR= source/interbase/lib/gds.so.1
SUPER_CLIENT_GDSSHR= $(LX_SUPER_GDSSHR)
SUPER_BACKEND= source/jrd/gds_ss.a
SUPER_LINK= -Lsource/jrd -lgds_ss -lc -ldl -lcrypt -lpthread
SUPER_SERVER=
UTILITIES=
WAL_P_OBJS= wal_p_objects
SUPER_SERVER_DEST= source/interbase/bin/ibserver
INET_SERVER_DEST= source/interbase/bin/gds_inet_server
DNET_SERVER_DEST= source/interbase/bin/gds_dnet_server
AMBX_SERVER_DEST= source/interbase/bin/gds_server
INET_LIB_DEST= source/interbase/lib/gds_inet_server.a
DNET_LIB_DEST= source/interbase/lib/gds_dnet_server.a
SH= sh -c
RM= rm -f
CHMOD= chmod
CHMOD_6= chmod 666
CHMOD_7= chmod 777
CHMOD_S7= chmod 06777
MV= mv -f
TOUCH= touch
CP= cp
ECHO= echo
QUIET_ECHO= @echo
CD= cd
CAT= cat
AR= ar r
EXPAND_DBNAME= @echo No need to expand...
COMPRESS_DBNAME= @echo No need to compress...
ARCH_EXT= .a
EXEC_EXT=
# FSG 1.Dez.2000
SHRLIB_EXT= .so
V3PRINTER= source/lock/printv3.o
# Forces library build for linux TMC 082100
PYXIS_LIBRARY= libpyxis.a
# End of file prefix.linux: DEV $(PLATFORM)
# The contents of this file are subject to the Interbase Public
# License Version 1.0 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy
# of the License at http://www.Inprise.com/IPL.html
#
# Software distributed under the License is distributed on an
# "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
# or implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code was created by Inprise Corporation
# and its predecessors. Portions created by Inprise Corporation are
# Copyright (C) Inprise Corporation.
#
# All Rights Reserved.
# Contributor(s): ______________________________________.
GBAK= source/interbase/bin/gbak
GPRE= source/interbase/bin/gpre
ISQL= source/interbase/bin/isql
GPRE_FLAGS= -r -m -z -n
EXAMPLES_DEST= source/interbase/examples/v5/
EXAMPLES_SRC= source/example5/
EMPBLD_OBJ= empbuild.o
INTLBLD_OBJ= intlbld.o
INPUT_FILES= empddl.sql empdml.sql indexoff.sql indexon.sql \
job.inp lang.inp proj.inp qtr.inp
INTL_FILES= intlddl.sql intldml.sql indexoff.sql indexon.sql \
job.inp lang.inp proj.inp qtr.inp
v5_examples: employee.gdb intlemp.gdb $(NT_EXAMPLES) makefile.example
$(CP) $(EXAMPLES_SRC)readme $(EXAMPLES_DEST)README
$(CP) $(EXAMPLES_SRC)align.h $(EXAMPLES_DEST)align.h
$(CP) $(EXAMPLES_SRC)api1.c $(EXAMPLES_DEST)api1.c
$(CP) $(EXAMPLES_SRC)api10.c $(EXAMPLES_DEST)api10.c
$(CP) $(EXAMPLES_SRC)api11.c $(EXAMPLES_DEST)api11.c
$(CP) $(EXAMPLES_SRC)api12.c $(EXAMPLES_DEST)api12.c
$(CP) $(EXAMPLES_SRC)api13.c $(EXAMPLES_DEST)api13.c
$(CP) $(EXAMPLES_SRC)api14.e $(EXAMPLES_DEST)api14.e
$(CP) $(EXAMPLES_SRC)api15.c $(EXAMPLES_DEST)api15.c
$(CP) $(EXAMPLES_SRC)api16.c $(EXAMPLES_DEST)api16.c
$(CP) $(EXAMPLES_SRC)api16t.c $(EXAMPLES_DEST)api16t.c
$(CP) $(EXAMPLES_SRC)api2.c $(EXAMPLES_DEST)api2.c
$(CP) $(EXAMPLES_SRC)api3.c $(EXAMPLES_DEST)api3.c
$(CP) $(EXAMPLES_SRC)api4.c $(EXAMPLES_DEST)api4.c
$(CP) $(EXAMPLES_SRC)api5.c $(EXAMPLES_DEST)api5.c
$(CP) $(EXAMPLES_SRC)api6.c $(EXAMPLES_DEST)api6.c
$(CP) $(EXAMPLES_SRC)api7.c $(EXAMPLES_DEST)api7.c
$(CP) $(EXAMPLES_SRC)api8.c $(EXAMPLES_DEST)api8.c
$(CP) $(EXAMPLES_SRC)api9.c $(EXAMPLES_DEST)api9.c
$(CP) $(EXAMPLES_SRC)api9f.c $(EXAMPLES_DEST)api9f.c
$(CP) $(EXAMPLES_SRC)apifull.c $(EXAMPLES_DEST)apifull.c
$(CP) $(EXAMPLES_SRC)employe2.sql $(EXAMPLES_DEST)employe2.sql
$(CP) $(EXAMPLES_SRC)dyn1.e $(EXAMPLES_DEST)dyn1.e
$(CP) $(EXAMPLES_SRC)dyn2.e $(EXAMPLES_DEST)dyn2.e
$(CP) $(EXAMPLES_SRC)dyn3.e $(EXAMPLES_DEST)dyn3.e
$(CP) $(EXAMPLES_SRC)dyn4.e $(EXAMPLES_DEST)dyn4.e
$(CP) $(EXAMPLES_SRC)dyn5.e $(EXAMPLES_DEST)dyn5.e
$(CP) $(EXAMPLES_SRC)dynfull.e $(EXAMPLES_DEST)dynfull.e
$(SETUP_ISC_LOCAL) \
$(GBAK) $(EXAMPLES_SRC)employee.gdb $(EXAMPLES_DEST)employee.gbk
-$(RM) $(EXAMPLES_DEST)employee.gdb
$(SETUP_ISC_LOCAL) \
$(GBAK) -r $(EXAMPLES_DEST)employee.gbk $(EXAMPLES_DEST)employee.gdb
$(CP) $(EXAMPLES_SRC)example.h $(EXAMPLES_DEST)example.h
$(CP) $(EXAMPLES_SRC)api9f.sql $(EXAMPLES_DEST)api9f.sql
$(SETUP_ISC_LOCAL) \
$(GBAK) $(EXAMPLES_SRC)intlemp.gdb $(EXAMPLES_DEST)intlemp.gbk
-$(RM) $(EXAMPLES_DEST)intlemp.gdb
$(SETUP_ISC_LOCAL) \
$(GBAK) -r $(EXAMPLES_DEST)intlemp.gbk $(EXAMPLES_DEST)intlemp.gdb
$(CP) $(EXAMPLES_SRC)stat1.e $(EXAMPLES_DEST)stat1.e
$(CP) $(EXAMPLES_SRC)stat10.e $(EXAMPLES_DEST)stat10.e
$(CP) $(EXAMPLES_SRC)stat11.e $(EXAMPLES_DEST)stat11.e
$(CP) $(EXAMPLES_SRC)stat12.e $(EXAMPLES_DEST)stat12.e
$(CP) $(EXAMPLES_SRC)stat12t.e $(EXAMPLES_DEST)stat12t.e
$(CP) $(EXAMPLES_SRC)stat2.e $(EXAMPLES_DEST)stat2.e
$(CP) $(EXAMPLES_SRC)stat3.e $(EXAMPLES_DEST)stat3.e
$(CP) $(EXAMPLES_SRC)stat4.e $(EXAMPLES_DEST)stat4.e
$(CP) $(EXAMPLES_SRC)stat5.e $(EXAMPLES_DEST)stat5.e
$(CP) $(EXAMPLES_SRC)stat6.e $(EXAMPLES_DEST)stat6.e
$(CP) $(EXAMPLES_SRC)stat7.e $(EXAMPLES_DEST)stat7.e
$(CP) $(EXAMPLES_SRC)stat8.e $(EXAMPLES_DEST)stat8.e
$(CP) $(EXAMPLES_SRC)stat9.e $(EXAMPLES_DEST)stat9.e
$(CP) $(EXAMPLES_SRC)udf.sql $(EXAMPLES_DEST)udf.sql
$(CP) $(EXAMPLES_SRC)udflib.c $(EXAMPLES_DEST)udflib.c
$(CP) $(EXAMPLES_SRC)makefile.example $(EXAMPLES_DEST)makefile
nt_examples:
$(CP) $(EXAMPLES_SRC)api9f.def $(EXAMPLES_DEST)api9f.def
$(CP) $(EXAMPLES_SRC)udflib.def $(EXAMPLES_DEST)udflib.def
$(CP) $(EXAMPLES_SRC)makefile.bc $(EXAMPLES_DEST)Makefile.bc
$(CP) $(EXAMPLES_SRC)makefile.msc $(EXAMPLES_DEST)Makefile.msc
employee.gdb: empbuild$(EXEC_EXT) $(INPUT_FILES)
-$(RM) employee.gdb
$(SETUP_ISC_LOCAL) \
empbuild employee.gdb
-$(CHMOD_6) employee.gdb
intlemp.gdb: intlbld$(EXEC_EXT) $(INTL_FILES)
-$(RM) intlemp.gdb
$(SETUP_ISC_LOCAL) \
intlbld intlemp.gdb
-$(CHMOD_6) intlemp.gdb
empbuild: $(EMPBLD_OBJ)
-$(RM) empbuild
$(CC) $(LINK_OPTS) empbuild.o -o empbuild $(GDS_LINK)
$(CHMOD_7) empbuild
empbuild.exe: $(EMPBLD_OBJ)
-$(RM) empbuild.exe
$(CC) $(O_EXE_SWITCH)empbuild $(LINK_OPTS) empbuild.o $(GDS_LINK)
dbs: empddl.sql empbld.sql intlddl.sql intlbld.sql
-$(RM) employee.gdb
-$(RM) intlemp.gdb
$(ISQL) -i empbld.sql
$(ISQL) -i intlbld.sql
$(TOUCH) dbs
intlbld: $(INTLBLD_OBJ)
-$(RM) intlbld
$(CC) $(LINK_OPTS) intlbld.o -o intlbld $(GDS_LINK)
$(CHMOD_7) intlbld
intlbld.exe: $(INTLBLD_OBJ)
-$(RM) intlbld.exe
$(CC) $(O_EXE_SWITCH)intlbld $(LINK_OPTS) intlbld.o $(GDS_LINK)
empbuild.c: dbs empbuild.e
empbuild.o: empbuild.c
intlbld.c: dbs intlbld.e
intlbld.o: intlbld.c
makefile.example:
$(CHMOD_7) build_make
$(SH) "build_make"

View File

@ -0,0 +1,76 @@
# The contents of this file are subject to the Interbase Public
# License Version 1.0 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy
# of the License at http://www.Inprise.com/IPL.html
#
# Software distributed under the License is distributed on an
# "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
# or implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code was created by Inprise Corporation
# and its predecessors. Portions created by Inprise Corporation are
# Copyright (C) Inprise Corporation.
#
# All Rights Reserved.
# Contributor(s): ______________________________________.
# -------------------------- makefile ----------------------------
#
# This makefile will build the examples supplied with InterBase 5.0.
# See the Programmer's Guide for information about the example
# databases and example programs.
#
# You should edit the IBASE definition in this file to point to the
# directory where InterBase was installed. Or you can specify the
# definition on the command-line of make.
#
# To build all the examples use the 'all' target, by issuing the
# following command:
#
# make all
# or
# make IBASE=/usr/interbase all
#
# To build any one individual target, use the following command:
#
# make 'target'
# or
# make IBASE=/usr/interbase 'target'
#
# where 'target' is one of the following:
# employe2.gdb, api1, api2, api3, api4, api5, api6, api7,
# api8, api9, api9f, api10, api11, api12, api13, api14,
# api15, api16, api16t, apifull, dyn1, dyn2, dyn3, dyn4,
# dyn5, dynfull, stat1, stat2, stat3, stat4, stat5,
# stat6, stat7, stat8, stat9, stat10, stat11, stat12,
# stat12t, udflib
#
# ---------------------------------------------------------------------
# ---------------------------------------------------------------------
# InterBase Installation Directory
#
# CHANGE this definition to point to your InterBase installation directory
# ---------------------------------------------------------------------
IBASE= /usr/interbase
# ---------------------------------------------------------------------
# General InterBase Defines for HP-UX
# ---------------------------------------------------------------------
GPRE= $(IBASE)/bin/gpre -c -n
GPRE_M= $(IBASE)/bin/gpre -c -n -m
ISQL= $(IBASE)/bin/isql
DB= employee.gdb
# ---------------------------------------------------------------------
# General Compiler and linker Defines for HP-UX
# ---------------------------------------------------------------------
CC= cc
LINK= cc
LIB_LINK= ld
CFLAGS= -O -c -w -I$(IBASE)/include
LIB_CFLAGS= +z -Aa $(CFLAGS)
LINK_FLAGS= -lgds -ldld
LIB_LINK_FLAGS= -b -lgds -lm
RM= rm -f

View File

@ -0,0 +1,77 @@
# The contents of this file are subject to the Interbase Public
# License Version 1.0 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy
# of the License at http://www.Inprise.com/IPL.html
#
# Software distributed under the License is distributed on an
# "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
# or implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code was created by Inprise Corporation
# and its predecessors. Portions created by Inprise Corporation are
# Copyright (C) Inprise Corporation.
#
# All Rights Reserved.
# Contributor(s): ______________________________________.
# -------------------------- makefile ----------------------------
#
# This makefile will build the examples supplied with InterBase 5.0.
# See the Programmer's Guide for information about the example
# databases and example programs.
#
# You should edit the IBASE definition in this file to point to the
# directory where InterBase was installed. Or you can specify the
# definition on the command-line of make.
#
# To build all the examples use the 'all' target, by issuing the
# following command:
#
# make all
# or
# make IBASE=/usr/interbase all
#
# To build any one individual target, use the following command:
#
# make 'target'
# or
# make IBASE=/usr/interbase 'target'
#
# where target 'target' is one of the following:
# employe2.gdb, api1, api2, api3, api4, api5, api6, api7,
# api8, api9, api9f, api10, api11, api12, api13, api14,
# api15, api16, api16t, apifull, dyn1, dyn2, dyn3, dyn4,
# dyn5, dynfull, stat1, stat2, stat3, stat4, stat5,
# stat6, stat7, stat8, stat9, stat10, stat11, stat12,
# stat12t, udflib
#
# ---------------------------------------------------------------------
# ---------------------------------------------------------------------
# InterBase Installation Directory
#
# CHANGE this definition to point to your InterBase installation directory
# ---------------------------------------------------------------------
IBASE= /usr/interbase
# ---------------------------------------------------------------------
# General InterBase Defines for Linux
# ---------------------------------------------------------------------
GPRE= $(IBASE)/bin/gpre -c -n
GPRE_M= $(IBASE)/bin/gpre -c -n -m
ISQL= $(IBASE)/bin/isql
DB= employee.gdb
# ---------------------------------------------------------------------
# General Compiler and linker Defines for Linux
# ---------------------------------------------------------------------
CC= gcc
LINK= gcc
LIB_LINK= ld
CFLAGS= -c -w -I$(IBASE)/include
LIB_CFLAGS= -fPIC $(CFLAGS)
LINK_FLAGS= -lgds -ldl -lcrypt
LIB_LINK_FLAGS= -shared -lgds
RM= rm -f

View File

@ -0,0 +1,77 @@
# The contents of this file are subject to the Interbase Public
# License Version 1.0 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy
# of the License at http://www.Inprise.com/IPL.html
#
# Software distributed under the License is distributed on an
# "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
# or implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code was created by Inprise Corporation
# and its predecessors. Portions created by Inprise Corporation are
# Copyright (C) Inprise Corporation.
#
# All Rights Reserved.
# Contributor(s): ______________________________________.
# -------------------------- makefile ----------------------------
#
# This makefile will build the examples supplied with InterBase 5.0.
# See the Programmer's Guide for information about the example
# databases and example programs.
#
# You should edit the IBASE definition in this file to point to the
# directory where InterBase was installed. Or you can specify the
# definition on the command-line of make.
#
# To build all the examples use the 'all' target, by issuing the
# following command:
#
# make all
# or
# make IBASE=/usr/interbase all
#
# To build any one individual target, use the following command:
#
# make 'target'
# or
# make IBASE=/usr/interbase 'target'
#
# where target 'target' is one of the following:
# employe2.gdb, api1, api2, api3, api4, api5, api6, api7,
# api8, api9, api9f, api10, api11, api12, api13, api14,
# api15, api16, api16t, apifull, dyn1, dyn2, dyn3, dyn4,
# dyn5, dynfull, stat1, stat2, stat3, stat4, stat5,
# stat6, stat7, stat8, stat9, stat10, stat11, stat12,
# stat12t, udflib
#
# ---------------------------------------------------------------------
# ---------------------------------------------------------------------
# InterBase Installation Directory
#
# CHANGE this definition to point to your InterBase installation directory
# ---------------------------------------------------------------------
IBASE= /usr/interbase
# ---------------------------------------------------------------------
# General InterBase Defines for SCO Superserver
# ---------------------------------------------------------------------
GPRE= $(IBASE)/bin/gpre -c -n
GPRE_M= $(IBASE)/bin/gpre -c -n -m
ISQL= $(IBASE)/bin/isql
DB= employee.gdb
# ---------------------------------------------------------------------
# General Compiler and linker Defines for SCO Superserver
# ---------------------------------------------------------------------
CC= gcc
LINK= gcc
LIB_LINK= ld
CFLAGS= -c -w -I$(IBASE)/include -o
LIB_CFLAGS= -fPIC -melf $(CFLAGS)
LINK_FLAGS= -melf -lgds -lsocket
LIB_LINK_FLAGS= -G -belf -Bsymbolic -lgds -lsocket -lc -lcrypt -lm
RM= rm -f

View File

@ -0,0 +1,77 @@
# The contents of this file are subject to the Interbase Public
# License Version 1.0 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy
# of the License at http://www.Inprise.com/IPL.html
#
# Software distributed under the License is distributed on an
# "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
# or implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code was created by Inprise Corporation
# and its predecessors. Portions created by Inprise Corporation are
# Copyright (C) Inprise Corporation.
#
# All Rights Reserved.
# Contributor(s): ______________________________________.
# -------------------------- makefile ----------------------------
#
# This makefile will build the examples supplied with InterBase 5.0.
# See the Programmer's Guide for information about the example
# databases and example programs.
#
# You should edit the IBASE definition in this file to point to the
# directory where InterBase was installed. Or you can specify the
# definition on the command-line of make.
#
# To build all the examples use the 'all' target, by issuing the
# following command:
#
# make all
# or
# make IBASE=/usr/interbase all
#
# To build any one individual target, use the following command:
#
# make 'target'
# or
# make IBASE=/usr/interbase 'target'
#
# where target 'target' is one of the following:
# employe2.gdb, api1, api2, api3, api4, api5, api6, api7,
# api8, api9, api9f, api10, api11, api12, api13, api14,
# api15, api16, api16t, apifull, dyn1, dyn2, dyn3, dyn4,
# dyn5, dynfull, stat1, stat2, stat3, stat4, stat5,
# stat6, stat7, stat8, stat9, stat10, stat11, stat12,
# stat12t, udflib
#
# ---------------------------------------------------------------------
# ---------------------------------------------------------------------
# InterBase Installation Directory
#
# CHANGE this definition to point to your InterBase installation directory
# ---------------------------------------------------------------------
IBASE= /usr/interbase
# ---------------------------------------------------------------------
# General InterBase Defines for SOLARIS
# ---------------------------------------------------------------------
GPRE= $(IBASE)/bin/gpre -c -n
GPRE_M= $(IBASE)/bin/gpre -c -n -m
ISQL= $(IBASE)/bin/isql
DB= employee.gdb
# ---------------------------------------------------------------------
# General Compiler and linker Defines for SOLARIS
# ---------------------------------------------------------------------
CC= cc
LINK= cc
LIB_LINK= ld
CFLAGS= -O -c -mt -w -I$(IBASE)/include
LIB_CFLAGS= -K PIC $(CFLAGS)
LINK_FLAGS= -lgdsmt -lsocket -lthread -lnsl -ldl
LIB_LINK_FLAGS= -G -Bsymbolic -lgdsmt -lm -lc
RM= rm -f

View File

@ -0,0 +1,203 @@
# The contents of this file are subject to the Interbase Public
# License Version 1.0 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy
# of the License at http://www.Inprise.com/IPL.html
#
# Software distributed under the License is distributed on an
# "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
# or implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code was created by Inprise Corporation
# and its predecessors. Portions created by Inprise Corporation are
# Copyright (C) Inprise Corporation.
#
# All Rights Reserved.
# Contributor(s): ______________________________________.
# -------------------------- makefile.bc -------------------------
#
# This makefile will build the examples supplied with InterBase 5.0.
# See the Programmer's Guide for information about the example
# databases and example programs.
#
# You MUST edit the IBASE definition in this file to point to the
# directory where InterBase was installed. As well as the BCDIR
# definition to point to the installations directory of your
# Borland C/C++ Compiler.
#
# To build all the examples use the 'all' target, by issuing the
# following command:
#
# make -f makefile.bc all
#
# To build any one individual target, use the following command:
#
# make -f makefile.bc 'target'
#
# where target 'target' is one of the following:
# employe2.gdb, api1.exe, api2.exe, api3.exe, api4.exe,
# api5.exe, api6.exe, api7.exe, api8.exe, api9.exe,
# api9f.dll, api10.exe, api11.exe, api12.exe, api13.exe,
# api14.exe, api15.exe, api16.exe, api16t.exe, apifull.exe,
# dyn1.exe, dyn2.exe, dyn3.exe, dyn4.exe, dyn5.exe,
# dynfull.exe, stat1.exe, stat2.exe, stat3.exe, stat4.exe,
# stat5.exe, stat6.exe, stat7.exe, stat8.exe, stat9.exe,
# stat10.exe, stat11.exe, stat12.exe, stat12t.exe,
# udflib.dll
#
# ---------------------------------------------------------------------
# ---------------------------------------------------------------------
# InterBase Installation Directory
#
# CHANGE this definition to point to your InterBase installation directory
# ---------------------------------------------------------------------
IBASE= d:\interbase
# ---------------------------------------------------------------------
# Borland C/C++ Installation Directory
#
# CHANGE this definition to point to your compiler's installation directory
# ---------------------------------------------------------------------
BCDIR= d:\bc5
# ---------------------------------------------------------------------
# General InterBase Defines for Microsoft Windows 95/NT
# ---------------------------------------------------------------------
GPRE= $(IBASE)\bin\gpre -c -n
GPRE_M= $(IBASE)\bin\gpre -c -n -m
ISQL= $(IBASE)\bin\isql
DB= employee.gdb
# ---------------------------------------------------------------------
# General Compiler and linker Defines for Borland C/C++ 5.0
# ---------------------------------------------------------------------
COMMON_FLAGS= -c -v -w- -a4 -tWM -DWIN32 $(INCLUDE)
CFLAGS= $(COMMON_FLAGS) -tWC
LIB_CFLAGS= $(COMMON_FLAGS) -tWCDE
INCLUDE= -I$(IBASE)\include -I$(BCDIR)\include
LFLAGS= /c /x /ap /Tpe
LIBS= $(IBASE)\lib\gds32.lib
CC= $(BCDIR)\bin\bcc32
LINK= $(BCDIR)\bin\tlink32
IMPLIB= $(BCDIR)\bin\implib
COPY= copy
RM= del
# ---------------------------------------------------------------------
# Generic Compilation Rules
#
# Do NOT change anything below this point.
# ---------------------------------------------------------------------
.SUFFIXES: .e .c .obj .exe
.e.c:
$(GPRE) $< -d $(DB)
.c.obj:
$(CC) $(CFLAGS) $<
.obj.exe:
@echo $(BCDIR)\lib\c0x32.obj+ > link.arg
@echo $< >> link.arg
@echo $@ >> link.arg
@echo $(LFLAGS) >> link.arg
@echo $(LIBS)+ >> link.arg
@echo $(BCDIR)\lib\import32.lib+ >> link.arg
@echo $(BCDIR)\lib\cw32mt.lib >> link.arg
$(LINK) @link.arg
-$(RM) link.arg
# ---------------------------------------------------------------------
# Specific targets to build
# ---------------------------------------------------------------------
cmt:
@echo "--------------------------- makefile.bc -------------------------
@echo "
@echo " This makefile will build the InterBase 5.0 examples.
@echo " See the Programmer's Guide for information about the example
@echo " databases and example programs.
@echo "
@echo " You MUST edit the IBASE definition in this file to point to the
@echo " directory where InterBase was installed. As well as the BCDIR
@echo " definition to point to the installations directory of your
@echo " Borland C/C++ Compiler.
@echo "
@echo " To build all the examples use the 'all' target, by issuing the
@echo " following command:
@echo "
@echo " make -f makefile.bc all
@echo "
@echo " To build any one individual target, use the command:
@echo "
@echo " make -f makefile.bc 'target'
@echo "
@echo " where target 'target' is one of the following:
@echo "
@echo " employe2.gdb, api1.exe, api2.exe, api3.exe, api4.exe,
@echo " api5.exe, api6.exe, api7.exe, api8.exe, api9.exe,
@echo " api9f.dll, api10.exe, api11.exe, api12.exe, api13.exe,
@echo " api14.exe, api15.exe, api16.exe, api16t.exe, apifull.exe,
@echo " dyn1.exe, dyn2.exe, dyn3.exe, dyn4.exe, dyn5.exe,
@echo " dynfull.exe, stat1.exe, stat2.exe, stat3.exe, stat4.exe,
@echo " stat5.exe, stat6.exe, stat7.exe, stat8.exe, stat9.exe,
@echo " stat10.exe, stat11.exe, stat12.exe, stat12t.exe,
@echo " udflib.dll
@echo "
@echo "-----------------------------------------------------------------
all: employe2.gdb api1.exe api2.exe api3.exe \
api4.exe api5.exe api6.exe api7.exe api8.exe \
api9.exe api9f.dll api10.exe api11.exe api12.exe api13.exe \
api14.exe api15.exe api16.exe api16t.exe \
apifull.exe dyn1.exe dyn2.exe dyn3.exe dyn4.exe \
dyn5.exe dynfull.exe stat1.exe stat2.exe stat3.exe \
stat4.exe stat5.exe stat6.exe stat7.exe stat8.exe stat9.exe \
stat10.exe stat11.exe stat12.exe stat12t.exe udflib.dll
employe2.gdb: employe2.sql
$(ISQL) -i $?
api9.obj: api9.c example.h api9f.sql
$(CC) $(CFLAGS) api9.c $(LIBS)
$(ISQL) employee.gdb -i api9f.sql
api9f.obj: api9f.c example.h
$(CC) $(LIB_CFLAGS) $?
api9f.dll: api9f.obj
# build a small argument file and use it
@echo $(BCDIR)\lib\c0d32.obj+ > link.arg
@echo $? >> link.arg
@echo $@ >> link.arg
@echo /x /Tpd >> link.arg
@echo $(LIBS)+ >> link.arg
@echo $(BCDIR)\lib\import32.lib+ >> link.arg
@echo $(BCDIR)\lib\cw32mt.lib >> link.arg
$(LINK) @link.arg
@echo -----------------------------------------------------------
@echo You need to copy api9f.dll to the interbase lib directory
@echo in order for api9.exe to work correctly.
@echo -----------------------------------------------------------
udflib.obj: udflib.c example.h
$(CC) $(LIB_CFLAGS) udflib.c
udflib.dll: udflib.obj
# build a small argument file and use it
@echo $(BCDIR)\lib\c0d32.obj+ > link.arg
@echo $? >> link.arg
@echo $@ >> link.arg
@echo /x /Tpd >> link.arg
@echo $(LIBS)+ >> link.arg
@echo $(BCDIR)\lib\import32.lib+ >> link.arg
@echo $(BCDIR)\lib\cw32mt.lib >> link.arg
$(LINK) @link.arg
@echo -----------------------------------------------------------
@echo You need to copy udflib.dll to the interbase lib directory
@echo in order for the server to load it.
@echo -----------------------------------------------------------

View File

@ -0,0 +1,193 @@
# The contents of this file are subject to the Interbase Public
# License Version 1.0 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy
# of the License at http://www.Inprise.com/IPL.html
#
# Software distributed under the License is distributed on an
# "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
# or implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code was created by Inprise Corporation
# and its predecessors. Portions created by Inprise Corporation are
# Copyright (C) Inprise Corporation.
#
# All Rights Reserved.
# Contributor(s): ______________________________________.
# -------------------------- makefile.msc ------------------------
#
# This makefile will build the examples supplied with InterBase 5.0.
# See the Programmer's Guide for information about the example
# databases and example programs.
#
# You MUST edit the IBASE definition in this file to point to the
# directory where InterBase was installed. As well as the MSCDIR
# definition to point to the installations directory of your
# Microsoft C/C++ Compiler.
#
# To build all the examples use the 'all' target, by issuing the
# following command:
#
# nmake -f makefile.msc all
#
# To build any one individual target, use the following command:
#
# nmake -f makefile.msc 'target'
#
# where target 'target' is one of the following:
# employe2.gdb, api1.exe, api2.exe, api3.exe, api4.exe,
# api5.exe, api6.exe, api7.exe, api8.exe, api9.exe,
# api9f.dll, api10.exe, api11.exe, api12.exe, api13.exe,
# api14.exe, api15.exe, api16.exe, api16t.exe, apifull.exe,
# dyn1.exe, dyn2.exe, dyn3.exe, dyn4.exe, dyn5.exe,
# dynfull.exe, stat1.exe, stat2.exe, stat3.exe, stat4.exe,
# stat5.exe, stat6.exe, stat7.exe, stat8.exe, stat9.exe,
# stat10.exe, stat11.exe, stat12.exe, stat12t.exe,
# udflib.dll
#
# ---------------------------------------------------------------------
# ---------------------------------------------------------------------
# InterBase Installation Directory
#
# CHANGE this definition to point to your InterBase installation directory
# ---------------------------------------------------------------------
IBASE= d:\interbase
# ---------------------------------------------------------------------
# Microsoft C/C++ Installation Directory
#
# CHANGE this definition to point to your compiler's installation directory
# ---------------------------------------------------------------------
MSCDIR= d:\DevStudio\VC
# ---------------------------------------------------------------------
# General InterBase Defines for Microsoft Windows 95/NT
# ---------------------------------------------------------------------
GPRE= $(IBASE)\bin\gpre -c -n
GPRE_M= $(IBASE)\bin\gpre -c -n -m
ISQL= $(IBASE)\bin\isql
DB= employee.gdb
# ---------------------------------------------------------------------
# General Compiler and linker Defines for Microsoft C/C++ 5.0
# ---------------------------------------------------------------------
CFLAGS= -c -Zi -w -MD -DWIN32 $(INCLUDE)
LIB_CFLAGS= $(CFLAGS) -LD
INCLUDE= -I$(IBASE)\include -I$(MSCDIR)\include
LIBS= $(MSCDIR)\lib\msvcrt.lib $(IBASE)\lib\gds32_ms.lib
CC= $(MSCDIR)\bin\cl
LINK= $(MSCDIR)\bin\link
LIBRARIAN= $(MSCDIR)\bin\lib
COPY= copy
# ---------------------------------------------------------------------
# Generic Compilation Rules
#
# Do NOT change anything below this point.
# ---------------------------------------------------------------------
.SUFFIXES: .e .c .obj .exe
.e.c:
$(GPRE) $< -d $(DB)
.c.obj:
$(CC) $(CFLAGS) $<
.obj.exe:
$(LINK) -out:$@ $< $(LIBS)
# ---------------------------------------------------------------------
# Specific targets to build
# ---------------------------------------------------------------------
cmt:
@echo "--------------------------- makefile.msc ------------------------
@echo "
@echo " This makefile will build the InterBase 5.0 examples.
@echo " See the Programmer's Guide for information about the example
@echo " databases and example programs.
@echo "
@echo " You MUST edit the IBASE definition this file to point to the
@echo " directory where InterBase was installed. As well as the MSCDIR
@echo " definition point to the installations directory of your
@echo " Microsoft C/C++ Compiler.
@echo "
@echo " To build all the examples use the 'all' target, by issuing the
@echo " following command:
@echo "
@echo " nmake -f makefile.msc all
@echo "
@echo " To build any one individual target, use the command:
@echo "
@echo " nmake -f makefile.msc 'target'
@echo "
@echo " where target 'target' is one of the following:
@echo "
@echo " employe2.gdb, api1.exe, api2.exe, api3.exe, api4.exe,
@echo " api5.exe, api6.exe, api7.exe, api8.exe, api9.exe,
@echo " api9f.dll, api10.exe, api11.exe, api12.exe, api13.exe,
@echo " api14.exe, api15.exe, api16.exe, api16t.exe, apifull.exe,
@echo " dyn1.exe, dyn2.exe, dyn3.exe, dyn4.exe, dyn5.exe,
@echo " dynfull.exe, stat1.exe, stat2.exe, stat3.exe, stat4.exe,
@echo " stat5.exe, stat6.exe, stat7.exe, stat8.exe, stat9.exe,
@echo " stat10.exe, stat11.exe, stat12.exe, stat12t.exe,
@echo " udflib.dll
@echo "
@echo "-----------------------------------------------------------------
all: employe2.gdb api1.exe api2.exe api3.exe \
api4.exe api5.exe api6.exe api7.exe api8.exe \
api9.exe api9f.dll api10.exe api11.exe api12.exe api13.exe \
api14.exe api15.exe api16.exe api16t.exe \
apifull.exe dyn1.exe dyn2.exe dyn3.exe dyn4.exe \
dyn5.exe dynfull.exe stat1.exe stat2.exe stat3.exe \
stat4.exe stat5.exe stat6.exe stat7.exe stat8.exe stat9.exe \
stat10.exe stat11.exe stat12.exe stat12t.exe udflib.dll
employe2.gdb: employe2.sql
$(ISQL) -i $?
api9.obj: api9.c example.h api9f.sql
$(CC) $(CFLAGS) api9.c $(LIBS)
$(ISQL) employee.gdb -i api9f.sql
api9f.obj: api9f.c example.h
$(CC) $(LIB_CFLAGS) $?
api9f.lib api9f.exp: api9f.obj api9f.def
$(LIBRARIAN) api9f.obj -out:api9f.lib -def:api9f.def -machine:i386 \
-subsystem:console
api9f.dll: api9f.lib api9f.exp api9f.obj
# build a small argument file and use it
@echo -entry:_DllMainCRTStartup@12 > link.arg
@echo -subsystem:console -DLL -DEBUG:FULL >> link.arg
@echo -out:api9f.dll >> link.arg
@echo api9f.exp api9f.obj $(LIBS) >> link.arg
$(LINK) @link.arg
@echo -----------------------------------------------------------
@echo You need to copy api9f.dll to the interbase lib directory
@echo in order for api9.exe to work correctly.
@echo -----------------------------------------------------------
udflib.obj: udflib.c example.h
$(CC) $(LIB_CFLAGS) udflib.c
udflib.lib udflib.exp: udflib.obj udflib.def
$(LIBRARIAN) udflib.obj -out:udflib.lib -def:udflib.def -machine:i386 \
-subsystem:console
udflib.dll: udflib.lib udflib.obj udflib.exp
# build a small argument file and use it
@echo -entry:_DllMainCRTStartup@12 > link.arg
@echo -subsystem:console -DLL >> link.arg
@echo -out:udflib.dll >> link.arg
@echo udflib.obj udflib.exp $(LIBS) >> link.arg
$(LINK) @link.arg
@echo -----------------------------------------------------------
@echo You need to copy udflib.dll to the interbase lib directory
@echo in order for the server to load it.
@echo -----------------------------------------------------------

25
src/v5_examples/proj.inp Normal file
View File

@ -0,0 +1,25 @@
VBASE
Design a video data base management system for
controlling on-demand video distribution.
DGPII
Develop second generation digital pizza maker
with flash-bake heating element and
digital ingredient measuring system.
GUIDE
Develop a prototype for the automobile version of
the hand-held map browsing device.
MAPDB
Port the map browsing database software to run
on the automobile model.
HWRII
Integrate the hand-writing recognition module into the
universal language translator.
MKTPR
Expand marketing and sales in the Pacific Rim.
Set up a field office in Australia and Singapore.

24
src/v5_examples/qtr.inp Normal file
View File

@ -0,0 +1,24 @@
1994 GUIDE 100 1 1 1 0
1994 GUIDE 671 3 2 1 0
1993 MAPDB 621 0 0 0 1
1994 MAPDB 621 2 1 0 0
1994 MAPDB 622 1 1 0 0
1994 MAPDB 671 1 1 0 0
1994 HWRII 670 1 1 1 1
1994 HWRII 621 2 3 2 1
1994 HWRII 622 1 1 2 2
1994 MKTPR 623 1 1 1 2
1994 MKTPR 672 1 1 1 2
1994 MKTPR 100 4 5 6 6
1994 MKTPR 110 2 2 0 3
1994 MKTPR 000 1 1 2 2
1995 MKTPR 623 7 7 4 4
1995 MKTPR 672 2 3 3 3
1995 MKTPR 100 4 5 6 6
1995 MKTPR 110 1 1 1 1
1994 VBASE 621 4 5 5 3
1995 VBASE 621 4 3 2 2
1994 VBASE 622 2 2 2 1
1994 VBASE 100 1 1 2 3
1995 VBASE 100 3 3 1 1
1996 VBASE 100 1 1 0 0

145
src/v5_examples/readme Normal file
View File

@ -0,0 +1,145 @@
/*
* The contents of this file are subject to the Interbase Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy
* of the License at http://www.Inprise.com/IPL.html
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code was created by Inprise Corporation
* and its predecessors. Portions created by Inprise Corporation are
* Copyright (C) Inprise Corporation.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/
The following example programs demonstrate a number of useful features of
the InterBase programming interface. Only the api<n>.c programs are
available on Windows 3.1 clients (except api9f.c and api16.c).
All others are available on all platforms.
Note that the following environment variables need to be set before running
the examples (before loading Windows for the InterBase Client for Windows):
ISC_USER - A valid username on the server.
ISC_PASSWORD - The password for the above user.
ISC_DATABASE - The path to the employee.gdb example database, including
server name. For example, to connect to the NT server
named "NTserver" via NetBEUI:
ISC_DATABASE=\\NTserver\c:\ibserver\examples
This assumes that InterBase was installed to the
default directory on the server, c:\ibserver.
In addition, a guest account should be created with the username "guest"
and password "guest" before running api15 and winevent.
Embedded Static SQL
Program Description
--------- ------------------------------------------------------------------
stat1.e Illustrates a simple update to an existing table, commit, rollback.
stat2.e Illustrates singleton select.
stat3.e Illustrates a simple cursor -- declare/open/close/fetch.
stat4.e Show 'declare table' and 'create table'.
stat5.e Demonstrate 'update where current of'.
stat6.e Select an array.
stat7.e Illustrate blob cursor for select.
stat8.e Illustrate blob cursor for insert.
stat9.e Execute and select from a stored procedure.
stat10.e Demonstrate 'set database', 'connect' and 'set transaction'.
stat11.e Demonstrate 'set transaction' with various isolation options.
stat12.e Event wait and signaling.
stat12t.e
WHENEVER SQLERROR and BASED_ON clause are illustrated by many programs.
^L
Embedded Dynamic SQL
Program Description
--------- ------------------------------------------------------------------
dyn1.e Execute 'create database' statement as a static string.
dyn2.e 'Execute immediate', and 'prepare' and 'execute'.
dyn3.e Dynamic cursor for select with output SQLDA allocated.
dyn4.e Execute an update query with parameter markers and input SQLDA.
dyn5.e Demonstrate dynamic reallocation of SQLDA and 'describe' statement.
dynfull.e A full_dsql program (process unknown statements).
VARY struct is used by dyn3.e, dynfull.e.
^L
API Interface
Program Description
--------- ------------------------------------------------------------------
api1.c Execute 'create dabatabase' statement as a static string.
Demonstrates zero database handle.
api2.c 'Execute immediate', and 'prepare' and 'execute'.
api3.c Dynamic cursor for select with output SQLDA allocated.
api4.c Execute an update query with parameter markers and input SQLDA.
api5.c Demonstrate dynamic reallocation of SQLDA and 'describe' statement.
apifull.c A full_dsql program (process unknown statements).
Demonstrates stmt_info calls and numeric scale.
api6.c Assemble an update current of statement, based on a dynamic
cursor name. Free a statement handle and re-use it as the cursor.
api7.c Demonstrate blob_open, get_segment.
api8.c Demonstrate create_blob, put_segment.
api9.c Demonstrate blob_open2 (using blob filter).
api9f.c Filter for api9.c. (Not part of Windows 3.1 clients)
api10.c Update an array using get_slice/put_slice.
api11.c Execute and select from a stored procedure.
api12.c A program with several active transactions.
api13.c A multi-database transaction with 2-phase commit.
api14.e Combine the three programming styles in one program.
api15.c Construct a database parameter buffer. db_info calls.
api16.c Demonstrate asynchronous event trapping
(Not available on Windows 3.1 clients)
winevent.c Demonstrate asynchronous event trapping
(Replacement for api16.c on Windows 3.1 Client)
api16t.c Identical to stat12t, this triggers the event for api16.
VARY struct is used by api3.c, apifull.c, and api14.e.
SQLCODE extraction from status is covered by several programs.
Zero transaction handle is covered in several programs, ex. api14.e.

View File

@ -0,0 +1,230 @@
# The contents of this file are subject to the Interbase Public
# License Version 1.0 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy
# of the License at http://www.Inprise.com/IPL.html
#
# Software distributed under the License is distributed on an
# "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
# or implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code was created by Inprise Corporation
# and its predecessors. Portions created by Inprise Corporation are
# Copyright (C) Inprise Corporation.
#
# All Rights Reserved.
# Contributor(s): ______________________________________.
# ---------------------------------------------------------------------
# Generic Compilation Rules
#
# Do NOT change anything below this point.
# ---------------------------------------------------------------------
.SUFFIXES: .o .c .e
.e.c:
$(GPRE) $< -d $(DB)
.c.o:
$(CC) $< $(CFLAGS) $@
.o:
$(LINK) -o $@ $< $(LINK_FLAGS)
# ---------------------------------------------------------------------
# Specific targets to build
# ---------------------------------------------------------------------
cmt:
@echo "--------------------------- makefile ----------------------------"
@echo " "
@echo " This makefile will build the InterBase 5.0 examples. "
@echo " See the Programmer's Guide for information about the example "
@echo " databases and example programs. "
@echo " "
@echo " You can edit the IBASE definition in this file to point to the "
@echo " directory where InterBase was installed. Or you can specify the "
@echo " defenition on the command-line of make. "
@echo " "
@echo " To build all the examples use the 'all' target, by issuing the "
@echo " following command: "
@echo " "
@echo " make all "
@echo " or "
@echo " make IBASE=/usr/interbase all "
@echo " "
@echo " To build any one individual target, use the command: "
@echo " "
@echo " make 'target' "
@echo " or "
@echo " make IBASE=/usr/interbase 'target' "
@echo " "
@echo " where 'target' is one of the following: "
@echo " "
@echo " employe2.gdb, api1, api2, api3, api4, api5, api6, api7, "
@echo " api8, api9, api9f, api10, api11, api12, api13, api14, "
@echo " api15, api16, api16t, apifull, dyn1, dyn2, dyn3, dyn4, "
@echo " dyn5, dynfull, stat1, stat2, stat3, stat4, stat5, "
@echo " stat6, stat7, stat8, stat9, stat10, stat11, stat12, "
@echo " stat12t, udflib "
@echo " "
@echo "-----------------------------------------------------------------"
all: employe2.gdb api1 api2 api3 api4 api5 api6 api7 \
api8 api9 api10 api11 api12 api13 api14 api15 \
api16 api16t apifull dyn1 dyn2 dyn3 dyn4 \
dyn5 dynfull stat1 stat2 stat3 stat4 stat5 \
stat6 stat7 stat8 stat9 stat10 stat11 stat12 \
stat12t udflib api9f
employe2.gdb: employe2.sql
$(ISQL) -i employe2.sql
api1.o: api1.c example.h
api2.o: api2.c example.h
api3.o: api3.c example.h
api4.o: api4.c example.h
api5.o: api5.c example.h
api6.o: api6.c example.h
api7.o: api7.c example.h
api8.o: api8.c example.h
api9.o: api9.c example.h
api9: api9.o api9f.sql
$(LINK) $@.o -o $@ $(LINK_FLAGS)
$(ISQL) $(DB) -i api9f.sql
api9f.o:api9f.c example.h
$(CC) $< $(LIB_CFLAGS) $@
api9f: api9f.o
$(LIB_LINK) $@.o -o $@ $(LIB_LINK_FLAGS)
@echo ------------------------------------------------------
@echo You need to copy api9f to the interbase lib directory
@echo in order for api9 to work correctly.
@echo ------------------------------------------------------
udflib.o:udflib.c example.h
$(CC) $< $(LIB_CFLAGS) $@
udflib: udflib.o
$(LIB_LINK) $@.o -o $@ $(LIB_LINK_FLAGS)
@echo ------------------------------------------------------
@echo You need to copy udflib to the interbase lib directory
@echo in order for the server to load it.
@echo ------------------------------------------------------
api10.o: api10.c example.h
api11.o: api11.c example.h
api12.o: api12.c example.h
api13.o: api13.c example.h
api14.c:api14.e
$(GPRE_M) $< -d $(DB)
api14.o: api14.c example.h
api15.o: api15.c example.h
api16.o: api16.c example.h
api16t.o: api16t.c example.h
apifull.o: apifull.c example.h align.h
stat1.c:stat1.e
stat1.o:stat1.c example.h
stat2.c:stat2.e
stat2.o:stat2.c example.h
stat3.c:stat3.e
stat3.o:stat3.c example.h
stat4.c:stat4.e
stat4.o:stat4.c example.h
stat5.c:stat5.e
stat5.o:stat5.c example.h
stat6.c:stat6.e
stat6.o:stat6.c example.h
stat7.c:stat7.e
stat7.o:stat7.c example.h
stat8.c:stat8.e
stat8.o:stat8.c example.h
stat9.c:stat9.e
stat9.o:stat9.c example.h
stat10.c:stat10.e
$(GPRE_M) $<
stat10.o:stat10.c example.h
stat11.c:stat11.e
$(GPRE_M) $<
stat11.o:stat11.c example.h
stat12.c:stat12.e
$(GPRE_M) $<
stat12.o:stat12.c example.h
stat12t.c:stat12t.e
$(GPRE_M) $<
stat12t.o:stat12t.c example.h
dyn1.c: dyn1.e
$(GPRE_M) $<
dyn1.o: dyn1.c example.h
dyn2.c: dyn2.e
$(GPRE_M) $<
dyn2.o: dyn2.c example.h
dyn3.c: dyn3.e
$(GPRE_M) $<
dyn3.o: dyn3.c example.h
dyn4.c: dyn4.e
$(GPRE_M) $<
dyn4.o: dyn4.c example.h
dyn5.c: dyn5.e
$(GPRE_M) $<
dyn5.o: dyn5.c example.h
dynfull.c:dynfull.e
$(GPRE_M) $<
dynfull.o:dynfull.c example.h align.h

View File

@ -0,0 +1,133 @@
# The contents of this file are subject to the Interbase Public
# License Version 1.0 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy
# of the License at http://www.Inprise.com/IPL.html
#
# Software distributed under the License is distributed on an
# "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
# or implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code was created by Inprise Corporation
# and its predecessors. Portions created by Inprise Corporation are
# Copyright (C) Inprise Corporation.
#
# All Rights Reserved.
# Contributor(s): ______________________________________.
api1.obj: api1.c example.h
api2.obj: api2.c example.h
api3.obj: api3.c example.h
api4.obj: api4.c example.h
api5.obj: api5.c example.h
api6.obj: api6.c example.h
api7.obj: api7.c example.h
api8.obj: api8.c example.h
api10.obj: api10.c example.h
api11.obj: api11.c example.h
api12.obj: api12.c example.h
api13.obj: api13.c example.h
api14.c: api14.e
api14.obj: api14.c example.h
apifull.obj: apifull.c example.h align.h
stat1.c: stat1.e
stat1.obj: stat1.c example.h
stat2.c: stat2.e
stat2.obj: stat2.c example.h
stat3.c: stat3.e
stat3.obj: stat3.c example.h
stat4.c: stat4.e
stat4.obj: stat4.c example.h
stat5.c: stat5.e
stat5.obj: stat5.c example.h
stat6.c: stat6.e
stat6.obj: stat6.c example.h
stat7.c: stat7.e
stat7.obj: stat7.c example.h
stat8.c: stat8.e
stat8.obj: stat8.c example.h
stat9.c: stat9.e
stat9.obj: stat9.c example.h
stat10.c: stat10.e
$(GPRE_M) $?
stat10.obj: stat10.c example.h
stat11.c: stat11.e
$(GPRE_M) $?
stat11.obj: stat11.c example.h
stat12.c: stat12.e
$(GPRE_M) $?
stat12.obj: stat12.c example.h
stat12t.c: stat12t.e
$(GPRE_M) $?
stat12t.obj: stat12t.c example.h
dyn1.c: dyn1.e
$(GPRE_M) $?
dyn1.obj: dyn1.c example.h
dyn2.c: dyn2.e
$(GPRE_M) $?
dyn2.obj: dyn2.c example.h
dyn3.c: dyn3.e
$(GPRE_M) $?
dyn3.obj: dyn3.c example.h
dyn4.c: dyn4.e
$(GPRE_M) $?
dyn4.obj: dyn4.c example.h
dyn5.c: dyn5.e
$(GPRE_M) $?
dyn5.obj: dyn5.c example.h
dynfull.c: dynfull.e
$(GPRE_M) $?
dynfull.obj: dynfull.c example.h align.h

101
src/v5_examples/stat1.e Normal file
View File

@ -0,0 +1,101 @@
/*
* Program type: Embedded Static SQL
*
* Description:
* This program performs a simple update to an existing
* table, asks the user whether to save the update, and
* commits or undoes the transaction accordingly.
* The contents of this file are subject to the Interbase Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy
* of the License at http://www.Inprise.com/IPL.html
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code was created by Inprise Corporation
* and its predecessors. Portions created by Inprise Corporation are
* Copyright (C) Inprise Corporation.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/
#include "example.h"
#include <stdio.h>
#include <stdlib.h>
int do_save (void);
void clean_up (void);
EXEC SQL
BEGIN DECLARE SECTION;
EXEC SQL
END DECLARE SECTION;
int main (void)
{
clean_up();
/* Insert a new row. */
EXEC SQL
INSERT INTO country (country, currency)
VALUES ('Mexico', 'Peso');
/* Check the SQLCODE directly */
if (SQLCODE)
{
isc_print_sqlerror((short)SQLCODE, gds__status);
exit(1);
}
printf("\nAdding: country = 'Mexico', currency = 'Peso'\n\n");
/* Confirm whether to commit the update. */
if (do_save())
{
EXEC SQL
COMMIT RELEASE;
printf("\nSAVED.\n\n");
}
else
{
EXEC SQL
ROLLBACK RELEASE;
printf("\nUNDONE.\n\n");
}
return 0;
}
/*
* Ask the user whether to save the newly added row.
*/
int do_save (void)
{
char answer[10];
printf("Save? Enter 'y' for yes, 'n' for no: ");
gets(answer);
return (*answer == 'y' ? 1 : 0);
}
/*
* If this is not the first time this program is run,
* the example row may already exist -- delete the example
* row in order to avoid a duplicate value error.
*/
void clean_up (void)
{
EXEC SQL
DELETE FROM country
WHERE country = 'Mexico';
EXEC SQL
COMMIT WORK;
}

234
src/v5_examples/stat10.e Normal file
View File

@ -0,0 +1,234 @@
/*
* Program type: Embedded Static SQL
*
* Description:
* This program demonstrates 'set database', 'connect',
* and 'set transaction' statements.
* Each time a database is connected to, a sample table
* is accessed as a test.
* The contents of this file are subject to the Interbase Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy
* of the License at http://www.Inprise.com/IPL.html
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code was created by Inprise Corporation
* and its predecessors. Portions created by Inprise Corporation are
* Copyright (C) Inprise Corporation.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/
#include "example.h"
#include <stdlib.h>
#include <stdio.h>
int count_types (void);
int count_records (void);
long pr_error (void);
char *dbname = "employee.gdb";
EXEC SQL INCLUDE SQLCA;
int main (void)
{
/*
* Declare 2 database handles for future use.
*/
EXEC SQL
SET DATABASE db1 = "employee.gdb";
EXEC SQL
SET DATABASE db2 = "employe2.gdb";
/*
* Open a single database.
*/
printf("\n1. Opening database employee.gdb.\n");
EXEC SQL
CONNECT db1;
if( pr_error())
return 1;;
EXEC SQL
SET TRANSACTION USING db1;
if (count_types())
return 1;
EXEC SQL
COMMIT RELEASE;
EXEC SQL
DISCONNECT db1;
/*
* Use a database name supplied at run-time.
* Connect to this database using an existing database handle.
*/
printf("\n2. Opening database with name: %s supplied at run-time.\n",
dbname);
EXEC SQL
CONNECT TO :dbname AS db1;
if( pr_error())
return 1;;
EXEC SQL
SET TRANSACTION USING db1;
if( count_types())
return 1;
EXEC SQL
COMMIT RELEASE;
EXEC SQL
DISCONNECT DEFAULT;
/*
* Open the second database within the same program,
* while the first database remains disconnected.
*/
printf("\n3. Opening a second database after closing the first one.\n");
EXEC SQL
CONNECT db2;
if( pr_error())
return 1;;
EXEC SQL
SET TRANSACTION USING db2;
if (count_records())
return 1;
EXEC SQL
COMMIT RELEASE;
EXEC SQL
DISCONNECT db2;
/*
* Open two databases simultaneously.
*/
printf("\n4. Opening two databases simultaneously.\n");
EXEC SQL
CONNECT TO db1, db2;
if( pr_error())
return 1;;
EXEC SQL
SET TRANSACTION USING db1, db2;
if (count_types())
return 1;;
if (count_records())
return 1;
EXEC SQL
COMMIT RELEASE;
EXEC SQL
DISCONNECT db1, db2;
/*
* Open all databases (in this case just two) at the same time.
*/
printf("\n5. Opening all databases.\n");
EXEC SQL
CONNECT TO ALL;
if( pr_error())
return 1;;
EXEC SQL
SET TRANSACTION;
if (count_types())
return 1;
if (count_records())
return 1;
EXEC SQL
COMMIT RELEASE;
EXEC SQL
DISCONNECT ALL;
return (0);
}
/*
* Access a table in database 1.
*/
int count_types (void)
{
long cnt;
EXEC SQL
SELECT COUNT(DISTINCT currency) INTO :cnt FROM country;
if (SQLCODE == 0)
printf("\tNumber of currency types : %d\n", cnt);
else
if( pr_error())
return 1;;
return (0);
}
/*
* Access a table in database 2.
*/
int count_records (void)
{
long cnt;
/* Use the database handle along with the table name. */
EXEC SQL
SELECT COUNT(DISTINCT to_currency) INTO :cnt FROM db2.cross_rate;
if (SQLCODE == 0)
printf("\tNumber of conversion records: %d\n", cnt);
else
if( pr_error())
return 1;;
return (0);
}
/*
* Print an error message.
*/
long pr_error (void)
{
if (SQLCODE)
{
isc_print_sqlerror(SQLCODE, isc_status);
printf("\n");
}
return (SQLCODE);
}

173
src/v5_examples/stat11.e Normal file
View File

@ -0,0 +1,173 @@
/*
* Program type: Embedded Static SQL
*
* Description:
* This program demonstrates 'set transaction' statements
* with the three isolation options:
*
* - snapshot
* - read committed
* - shapshot table stability.
* The contents of this file are subject to the Interbase Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy
* of the License at http://www.Inprise.com/IPL.html
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code was created by Inprise Corporation
* and its predecessors. Portions created by Inprise Corporation are
* Copyright (C) Inprise Corporation.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/
#include "example.h"
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
EXEC SQL
BEGIN DECLARE SECTION;
long *t1;
long *t2;
long *t3;
char Db_name[128];
EXEC SQL
SET DATABASE empdb = COMPILETIME "employee.gdb" RUNTIME :Db_name;
long cust_no;
long tot;
char ord_stat[8];
EXEC SQL
END DECLARE SECTION;
int main(ARG(int, argc), ARG(char **, argv))
ARGLIST(int argc)
ARGLIST(char **argv)
{
if (argc > 1)
strcpy (Db_name, argv[1]);
else
strcpy (Db_name, "employee.gdb");
/* Connect to the database. */
EXEC SQL
WHENEVER SQLERROR GOTO :err;
EXEC SQL
CONNECT empdb;
/*
* Start a transaction with SNAPSHOT isolation option.
* This transaction wants to see a stable, unchanging view
* of the sales orders, while it computes the totals.
* Name the transaction t1.
*/
printf("Starting a transaction with SNAPSHOT isolation option.\n\n");
EXEC SQL
SET TRANSACTION NAME t1 READ WRITE SNAPSHOT;
EXEC SQL
DECLARE s CURSOR FOR
SELECT cust_no, SUM(qty_ordered)
FROM sales GROUP BY cust_no;
EXEC SQL
OPEN TRANSACTION t1 s;
EXEC SQL
FETCH s INTO :cust_no, :tot; /* get the first row only */
if (!SQLCODE)
printf("\tCustomer: %ld Quantity Ordered: %ld\n\n", cust_no, tot);
EXEC SQL
CLOSE s;
EXEC SQL
COMMIT TRANSACTION t1;
/*
* Start a transaction with READ COMMITTED isolation option.
* This transaction wants to see changes for the order status
* as they come in.
* Name the transaction t2.
*/
printf("Starting a transaction with READ COMMITTED isolation option.\n\n");
EXEC SQL
SET TRANSACTION NAME t2 READ WRITE READ COMMITTED;
EXEC SQL
DECLARE c CURSOR FOR
SELECT cust_no, order_status
FROM sales
WHERE order_status IN ("open", "shipping");
EXEC SQL
OPEN TRANSACTION t2 c;
EXEC SQL
FETCH c INTO :cust_no, :ord_stat; /* get the first row only */
if (!SQLCODE)
printf("\tCustomer number: %ld Status: %s\n\n", cust_no, ord_stat);
EXEC SQL
CLOSE c;
EXEC SQL
COMMIT TRANSACTION t2;
/*
* Start a transaction with SNAPSHOT TABLE STABILITY isolation
* option. This transaction wants to lock out all other users
* from making any changes to the customer table, while it goes
* through and updates customer status.
* Name the transaction t3.
*/
printf("Starting a transaction with SNAPSHOT TABLE STABILITY.\n\n");
EXEC SQL
SET TRANSACTION NAME t3 READ WRITE SNAPSHOT TABLE STABILITY;
EXEC SQL
DECLARE h CURSOR FOR
SELECT cust_no
FROM customer
WHERE on_hold = '*'
FOR UPDATE OF on_hold;
EXEC SQL
OPEN TRANSACTION t3 h;
EXEC SQL
FETCH h INTO :cust_no; /* get the first row only */
if (!SQLCODE)
printf("\tCustomer on hold: %ld\n\n", cust_no);
EXEC SQL
CLOSE h;
EXEC SQL
COMMIT TRANSACTION t3;
EXEC SQL
DISCONNECT empdb;
return (0);
err:
isc_print_status(isc_status);
return 1;
}

143
src/v5_examples/stat12.e Normal file
View File

@ -0,0 +1,143 @@
/*
* Program type: Embedded Static SQL
*
* Description:
* This program utilizes the event mechanism for processing
* newly entered sales orders. It initializes an event called
* "new_order", and then loops waiting for and processing new
* orders as they come in.
*
* When a new sales order is entered, a trigger defined in the
* database posts the "new_order" event. When the program is
* notified of the event, it opens the cursor for selecting all
* orders with status "new". For each fetched order, a transaction
* is started, which changes the order status from "new" to "open
* and takes some action to initiate order processing. After all
* the new orders (if there were more than one) are processed, it
* goes back to waiting for new orders.
*
* To trigger the event, while running this program, run stat12t.
* The contents of this file are subject to the Interbase Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy
* of the License at http://www.Inprise.com/IPL.html
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code was created by Inprise Corporation
* and its predecessors. Portions created by Inprise Corporation are
* Copyright (C) Inprise Corporation.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/
#include "example.h"
#include <stdlib.h>
int process_order (char *);
EXEC SQL
BEGIN DECLARE SECTION;
EXEC SQL
SET DATABASE empdb = "employee.gdb";
long *t1;
long *t2;
EXEC SQL
END DECLARE SECTION;
int main(ARG(int, argc), ARG(char **, argv))
ARGLIST(int argc)
ARGLIST(char **argv)
{
int ret = 0;
BASED_ON sales.po_number pon;
EXEC SQL
WHENEVER SQLERROR GO TO Error;
EXEC SQL
CONNECT empdb;
/* Go with read committed to see updates */
EXEC SQL
SET TRANSACTION READ COMMITTED;
EXEC SQL
DECLARE get_order CURSOR FOR
SELECT po_number
FROM sales
WHERE order_status = "new"
FOR UPDATE OF order_status;
EXEC SQL
EVENT INIT order_wait empdb ("new_order");
while (!ret)
{
printf("\nStat 12 Waiting ...\n\n");
EXEC SQL
EVENT WAIT order_wait;
EXEC SQL
OPEN get_order;
for (;;)
{
EXEC SQL
FETCH get_order INTO :pon;
if (SQLCODE == 100)
break;
EXEC SQL
UPDATE sales
SET order_status = "open"
WHERE CURRENT OF get_order;
ret = process_order(pon);
}
EXEC SQL
CLOSE get_order;
}
EXEC SQL
COMMIT;
EXEC SQL
DISCONNECT empdb;
exit(0);
Error:
isc_print_sqlerror(SQLCODE, gds__status);
exit(1);
}
/*
* Initiate order processing for a newly received sales order.
*/
int process_order(ARG(char *, pon))
ARGLIST(char * pon)
{
/*
* This function would start a back-ground job, such as
* sending the new orders to the printer, or generating
* e-mail messages to the appropriate departments.
*/
printf("Stat12: Received order: %s\n", pon);
if (!strncmp(pon, "VNEW4", 5))
{
printf ("Stat12: exiting\n");
return 1;
}
return 0;
}

83
src/v5_examples/stat12t.e Normal file
View File

@ -0,0 +1,83 @@
/*
* Program type: Embedded Static SQL
*
* Description:
* This program should be run in conjunction with stat12.
* It adds some sales records, in order to trigger the event
* that stat12 is waiting for.
* The contents of this file are subject to the Interbase Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy
* of the License at http://www.Inprise.com/IPL.html
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code was created by Inprise Corporation
* and its predecessors. Portions created by Inprise Corporation are
* Copyright (C) Inprise Corporation.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/
#include "example.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
EXEC SQL
BEGIN DECLARE SECTION;
EXEC SQL
SET DATABASE empdb = "employee.gdb";
EXEC SQL
END DECLARE SECTION;
int main(ARG(int, argc), ARG(char **, argv))
ARGLIST(int argc)
ARGLIST(char **argv)
{
EXEC SQL
CONNECT empdb;
EXEC SQL
SET TRANSACTION;
/* Clean-up. */
EXEC SQL
DELETE FROM sales WHERE po_number LIKE "VNEW%";
EXEC SQL
COMMIT;
/* Add batch 1. */
EXEC SQL
SET TRANSACTION;
printf("Stat12t: Adding VNEW1\n");
EXEC SQL
INSERT INTO sales (po_number, cust_no, order_status, total_value)
VALUES ('VNEW1', 1015, 'new', 0);
printf("Stat12t: Adding VNEW2\n");
EXEC SQL
INSERT INTO sales (po_number, cust_no, order_status, total_value)
VALUES ('VNEW2', 1015, 'new', 0);
printf("Stat12t: Adding VNEW3\n");
EXEC SQL
INSERT INTO sales (po_number, cust_no, order_status, total_value)
VALUES ('VNEW3', 1015, 'new', 0);
EXEC SQL
COMMIT;
/* Add batch 2. */
EXEC SQL
SET TRANSACTION;
printf("Stat12t: Adding VNEW4\n");
EXEC SQL
INSERT INTO sales (po_number, cust_no, order_status, total_value)
VALUES ('VNEW4', 1015, 'new', 0);
EXEC SQL
COMMIT RELEASE;
exit(0);
}

90
src/v5_examples/stat2.e Normal file
View File

@ -0,0 +1,90 @@
/*
* Program type: Embedded Static SQL
*
* Description:
* This program demonstrates a singleton select.
* A full name and phone number are displayed for
* the CEO of the company.
* The contents of this file are subject to the Interbase Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy
* of the License at http://www.Inprise.com/IPL.html
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code was created by Inprise Corporation
* and its predecessors. Portions created by Inprise Corporation are
* Copyright (C) Inprise Corporation.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/
#include "example.h"
#include <stdlib.h>
#include <stdio.h>
#define FIRSTLEN 15
#define LASTLEN 20
#define EXTLEN 4
#define DEPTNO 3
#define PHONELEN 20
EXEC SQL
BEGIN DECLARE SECTION;
EXEC SQL
END DECLARE SECTION;
int main (void)
{
char first[FIRSTLEN + 1];
char last[LASTLEN + 1];
char ext[EXTLEN + 1];
char phone[PHONELEN + 1];
char dept[DEPTNO + 1];
/*
* Assume there's only one CEO.
* Select the name and phone extension.
*/
EXEC SQL
SELECT first_name, last_name, phone_ext, dept_no
INTO :first, :last, :ext, :dept
FROM employee
WHERE job_code = 'CEO';
/* Check the SQLCODE to make sure only 1 row was selected. */
if (SQLCODE)
{
isc_print_sqlerror((short)SQLCODE, gds__status);
exit(1);
}
/*
* Also, select the department phone number.
*/
EXEC SQL
SELECT phone_no
INTO :phone
FROM department
WHERE dept_no = :dept;
if (SQLCODE)
{
isc_print_sqlerror((short)SQLCODE, gds__status);
exit(1);
}
printf("President: %s %s\t\t", first, last);
printf("Phone #: %s x%s\n", phone, ext);
EXEC SQL
COMMIT RELEASE;
exit(0);
}

104
src/v5_examples/stat3.e Normal file
View File

@ -0,0 +1,104 @@
/*
* Program type: Embedded Static SQL
*
* Description:
* This program declares a cursor, opens the cursor, and loops
* fetching multiple rows. All departments that need to hire
* a manager are selected and displayed.
* The contents of this file are subject to the Interbase Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy
* of the License at http://www.Inprise.com/IPL.html
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code was created by Inprise Corporation
* and its predecessors. Portions created by Inprise Corporation are
* Copyright (C) Inprise Corporation.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/
#include "example.h"
#include <stdlib.h>
#include <stdio.h>
EXEC SQL
BEGIN DECLARE SECTION;
EXEC SQL
END DECLARE SECTION;
int main (void)
{
BASED_ON department.department department;
BASED_ON department.department parent_dept;
BASED_ON department.location location;
/* Trap all errors. */
EXEC SQL
WHENEVER SQLERROR GO TO Error;
/* Trap SQLCODE = -100 (end of file reached during a fetch). */
EXEC SQL
WHENEVER NOT FOUND GO TO AllDone;
/* Ignore all warnings. */
EXEC SQL
WHENEVER SQLWARNING CONTINUE;
/* Declare the cursor for selecting all departments without a manager. */
EXEC SQL
DECLARE to_be_hired CURSOR FOR
SELECT d.department, d.location, p.department
FROM department d, department p
WHERE d.mngr_no IS NULL
AND d.head_dept = p.dept_no;
/* Open the cursor. */
EXEC SQL
OPEN to_be_hired;
printf("\n%-25s %-15s %-25s\n\n",
"DEPARTMENT", "LOCATION", "HEAD DEPARTMENT");
/*
* Select and display all rows.
*/
while (SQLCODE == 0)
{
EXEC SQL
FETCH to_be_hired INTO :department, :location, :parent_dept;
/*
* If FETCH returns with -100, the processing will jump
* to AllDone before the following printf is executed.
*/
printf("%-25s %-15s %-25s\n", department, location, parent_dept);
}
/*
* Close the cursor and release all resources.
*/
AllDone:
EXEC SQL
CLOSE to_be_hired;
EXEC SQL
COMMIT RELEASE;
return 0;
/*
* Print the error, and exit.
*/
Error:
isc_print_sqlerror((short)SQLCODE, gds__status);
return 1;
}

173
src/v5_examples/stat4.e Normal file
View File

@ -0,0 +1,173 @@
/*
* Program type: Embedded Static SQL
*
* Description:
* This program declares and creates a new table.
* Some rows, describing a department structure,
* are added to the new table as a test.
*
* The table is created temporarily for figuring
* out which level in the department structure each
* department belongs too.
* The contents of this file are subject to the Interbase Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy
* of the License at http://www.Inprise.com/IPL.html
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code was created by Inprise Corporation
* and its predecessors. Portions created by Inprise Corporation are
* Copyright (C) Inprise Corporation.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/
#include "example.h"
#include <stdlib.h>
#include <stdio.h>
void build_tree (void);
void pr_error (void);
EXEC SQL
BEGIN DECLARE SECTION;
EXEC SQL
END DECLARE SECTION;
int main (void)
{
char dept[4];
long lvl = 1;
/* Describe the new table's structure. */
EXEC SQL
DECLARE tmp_dept_tree TABLE (
dept_no CHAR(3) NOT NULL PRIMARY KEY,
tree_level INTEGER);
/* Drop the table in case it exists. Ignore error */
EXEC SQL
DROP TABLE tmp_dept_tree;
EXEC SQL
WHENEVER SQLERROR GO TO Error1;
/* Create the new table. */
printf ("creating tmp_dept_tree\n");
EXEC SQL
CREATE TABLE tmp_dept_tree (
dept_no CHAR(3) NOT NULL PRIMARY KEY,
tree_level INTEGER);
/* Fill the new table. */
build_tree();
/* Look at it */
EXEC SQL DECLARE dc CURSOR FOR
SELECT dept_no, tree_level
FROM tmp_dept_tree;
EXEC SQL
OPEN dc;
EXEC SQL
FETCH dc INTO :dept, :lvl;
while (SQLCODE == 0)
{
printf ("Dept = %s: Level = %d\n", dept, lvl);
EXEC SQL
FETCH dc INTO :dept, :lvl;
}
EXEC SQL
COMMIT RELEASE;
return 0;
Error1:
pr_error();
return 1;
}
/*
* For each department find its sub-departments and mark them
* with the next level number.
*/
void build_tree (void)
{
char dept[4];
long lvl = 1;
EXEC SQL
WHENEVER SQLERROR GO TO Error2;
/* Initialize the department structure by adding the first level. */
EXEC SQL
INSERT INTO tmp_dept_tree VALUES ('000', :lvl);
/* Declare the cursor for selecting all departments with level 'lvl'. */
EXEC SQL
DECLARE ds CURSOR FOR
SELECT dept_no
FROM tmp_dept_tree
WHERE tree_level = :lvl;
/* For each department with level 'lvl', find its sub-departments. */
while (SQLCODE == 0)
{
EXEC SQL
OPEN ds;
/* Initialize the next level. */
lvl++;
/* Add all the sub-departments of the next level to the table. */
for (;;)
{
EXEC SQL
FETCH ds INTO :dept;
if (SQLCODE == 100)
break;
EXEC SQL
INSERT INTO tmp_dept_tree
SELECT dept_no, :lvl
FROM department
WHERE head_dept = :dept;
}
EXEC SQL
CLOSE ds;
EXEC SQL
COMMIT;
/* Done, if no next level was created by the INSERT above. */
EXEC SQL
SELECT tree_level
FROM tmp_dept_tree
WHERE tree_level = :lvl;
if (SQLCODE == 100)
return;
};
Error2:
pr_error();
return ;
}
/*
* Print any error and exit.
*/
void pr_error (void)
{
isc_print_sqlerror((short)SQLCODE, gds__status);
}

116
src/v5_examples/stat5.e Normal file
View File

@ -0,0 +1,116 @@
/*
* Program type: Embedded Static SQL
*
* Description:
* This program performs a positioned update.
* All job grades are selected, and the salary range
* for the job may be increased by some factor, if any
* of the employees have a salary close to the upper
* limit of their job grade.
* The contents of this file are subject to the Interbase Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy
* of the License at http://www.Inprise.com/IPL.html
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code was created by Inprise Corporation
* and its predecessors. Portions created by Inprise Corporation are
* Copyright (C) Inprise Corporation.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/
#include "example.h"
#include <stdlib.h>
#include <stdio.h>
EXEC SQL
BEGIN DECLARE SECTION;
BASED_ON job.job_code job;
BASED_ON job.job_grade grade;
BASED_ON job.job_country country;
BASED_ON job.max_salary max_salary;
EXEC SQL
END DECLARE SECTION;
int main (void)
{
char jobstr[25];
float mult_factor;
EXEC SQL
WHENEVER SQLERROR GO TO Error;
/* Declare the cursor, allowing for the update of max_salary field. */
EXEC SQL
DECLARE sal_range CURSOR FOR
SELECT job_grade, job_code, job_country, max_salary
FROM job
FOR UPDATE OF max_salary;
EXEC SQL
OPEN sal_range;
printf("\nIncreasing maximum salary limit for the following jobs:\n\n");
printf("%-25s%-22s%-22s\n\n", " JOB NAME", "CURRENT MAX", "NEW MAX");
for (;;)
{
EXEC SQL
FETCH sal_range INTO :grade, :job, :country, :max_salary;
if (SQLCODE == 100)
break;
/* Check if any of the employees in this job category are within
* 10% of the maximum salary.
*/
EXEC SQL
SELECT salary
FROM employee
WHERE job_grade = :grade
AND job_code = :job
AND job_country = :country
AND salary * 0.1 + salary > :max_salary;
/* If so, increase the maximum salary. */
if (SQLCODE == 0)
{
/* Determine the increase amount; for example, 5%. */
mult_factor = 0.05;
sprintf(jobstr, "%s %d (%s)", job, grade, country);
printf("%-25s%10.2f%20.2f\n", jobstr,
max_salary, max_salary * mult_factor + max_salary);
EXEC SQL
UPDATE job
SET max_salary = :max_salary + :max_salary * :mult_factor
WHERE CURRENT OF sal_range;
}
}
printf("\n");
EXEC SQL
CLOSE sal_range;
/* Don't actually save the changes. */
EXEC SQL
ROLLBACK RELEASE;
return 0;
Error:
isc_print_sqlerror(SQLCODE, gds__status);
return 1 ;
}

110
src/v5_examples/stat6.e Normal file
View File

@ -0,0 +1,110 @@
/*
* Program type: Embedded Static SQL
*
* Description:
* This program selects an array data type.
* Projected head count is displayed for the 4
* quarters of some fiscal year for some project,
* ordered by department name.
* The contents of this file are subject to the Interbase Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy
* of the License at http://www.Inprise.com/IPL.html
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code was created by Inprise Corporation
* and its predecessors. Portions created by Inprise Corporation are
* Copyright (C) Inprise Corporation.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/
#include "example.h"
#include <stdlib.h>
#include <stdio.h>
EXEC SQL
BEGIN DECLARE SECTION;
EXEC SQL
END DECLARE SECTION;
int main (void)
{
BASED_ON department.department department;
BASED_ON proj_dept_budget.quart_head_cnt hcnt;
BASED_ON proj_dept_budget.quart_head_cnt tot;
int fiscal_year = 1994; /* year parameter */
char *project = "VBASE"; /* project parameter */
short i;
EXEC SQL
WHENEVER SQLERROR GO TO Error;
/*
* Declare a cursor for selecting an array, given 2
* 2 parameters (year and project).
*/
EXEC SQL
DECLARE proj_cnt CURSOR FOR
SELECT department, quart_head_cnt[]
FROM proj_dept_budget p, department d
WHERE p.dept_no = d.dept_no
AND year = :fiscal_year
AND proj_id = :project
ORDER BY department;
printf("\n\t\t\tPROJECTED HEAD-COUNT REPORT\n");
printf("\t\t\t (by department)\n\n");
printf("FISCAL YEAR: %d\n", fiscal_year);
printf("PROJECT ID : %s\n\n\n", project);
printf("%-25s%10s%10s%10s%10s\n\n",
"DEPARTMENT", "QTR1", "QTR2", "QTR3", "QTR4");
/* Initialize quarterly totals. */
for (i = 0; i < 4; i++)
tot[i] = 0;
EXEC SQL
OPEN proj_cnt;
/* Get and display each department's counts. */
while (SQLCODE == 0)
{
EXEC SQL
FETCH proj_cnt INTO :department, :hcnt;
if (SQLCODE == 100)
break;
printf("%-25s%10ld%10ld%10ld%10ld\n",
department, hcnt[0], hcnt[1], hcnt[2], hcnt[3]);
for (i = 0; i < 4; i++)
tot[i] += hcnt[i];
}
/* Display quarterly totals. */
printf("\n%-25s%10ld%10ld%10ld%10ld\n\n",
"TOTAL", tot[0], tot[1], tot[2], tot[3]);
EXEC SQL
CLOSE proj_cnt;
EXEC SQL
COMMIT WORK;
return 0;
Error:
isc_print_sqlerror((short) SQLCODE, gds__status);
return 1;
}

114
src/v5_examples/stat7.e Normal file
View File

@ -0,0 +1,114 @@
/*
* Program type: Embedded Static SQL
*
* Description:
* This program selects a blob data type.
* A set of project descriptions is printed.
* The contents of this file are subject to the Interbase Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy
* of the License at http://www.Inprise.com/IPL.html
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code was created by Inprise Corporation
* and its predecessors. Portions created by Inprise Corporation are
* Copyright (C) Inprise Corporation.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/
#include "example.h"
#include <stdlib.h>
#include <stdio.h>
EXEC SQL
BEGIN DECLARE SECTION;
BASED ON project.proj_name proj_name;
BASED ON project.product prod_type;
BASED ON project.proj_desc blob_id;
BASED ON project.proj_desc.SEGMENT blob_segment;
unsigned short blob_seg_len;
EXEC SQL
END DECLARE SECTION;
int main (void)
{
EXEC SQL
WHENEVER SQLERROR GO TO Error;
/* Declare a table read cursor. */
EXEC SQL
DECLARE proj_cur CURSOR FOR
SELECT proj_name, proj_desc, product
FROM project
WHERE product IN ('software', 'hardware', 'other')
ORDER BY proj_name;
/* Declare a blob read cursor. */
EXEC SQL
DECLARE blob_cur CURSOR FOR
READ BLOB proj_desc
FROM project;
/* Open the table cursor. */
EXEC SQL
OPEN proj_cur;
/*
* For each project get and display project description.
*/
while (SQLCODE == 0)
{
/* Fetch the blob id along with some other columns. */
EXEC SQL
FETCH proj_cur INTO :proj_name, :blob_id, :prod_type;
if (SQLCODE == 100)
break;
printf("\nPROJECT: %-30s TYPE: %-15s\n\n", proj_name, prod_type);
/* Open the blob cursor. */
EXEC SQL
OPEN blob_cur USING :blob_id;
while (SQLCODE == 0)
{
/* Fetch a blob segment and a blob segment length. */
EXEC SQL FETCH blob_cur INTO :blob_segment :blob_seg_len;
if (SQLCODE == 100)
break;
printf(" %*.*s\n", blob_seg_len, blob_seg_len, blob_segment);
}
printf("\n");
/* Close the blob cursor. */
EXEC SQL
CLOSE blob_cur;
}
EXEC SQL
CLOSE proj_cur;
EXEC SQL
COMMIT;
return 0;
Error:
isc_print_sqlerror((short) SQLCODE, gds__status);
return 1;
}

145
src/v5_examples/stat8.e Normal file
View File

@ -0,0 +1,145 @@
/*
* Program type: Embedded Static SQL
*
* Description:
* This program updates a blob data type.
* Project descriptions are added for a set of projects.
* The contents of this file are subject to the Interbase Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy
* of the License at http://www.Inprise.com/IPL.html
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code was created by Inprise Corporation
* and its predecessors. Portions created by Inprise Corporation are
* Copyright (C) Inprise Corporation.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/
#include "example.h"
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
char *get_line (void);
static char *Proj_data[] =
{
"VBASE",
"Design a video data base management system for ",
"controlling on-demand video distribution.",
0,
"DGPII",
"Develop second generation digital pizza maker ",
"with flash-bake heating element and ",
"digital ingredient measuring system.",
0,
"GUIDE",
"Develop a prototype for the automobile version of ",
"the hand-held map browsing device.",
0,
"MAPDB",
"Port the map browsing database software to run ",
"on the automobile model.",
0,
"HWRII",
"Integrate the hand-writing recognition module into the ",
"universal language translator.",
0,
0
};
int Inp_ptr = 0;
EXEC SQL
BEGIN DECLARE SECTION;
EXEC SQL
END DECLARE SECTION;
int main (void)
{
BASED_ON project.proj_id proj_id;
ISC_QUAD blob_id;
int len;
char ISC_FAR * line;
int rec_cnt = 0;
EXEC SQL
WHENEVER SQLERROR GO TO Error;
/* Declare a blob insert cursor. */
EXEC SQL
DECLARE bc CURSOR FOR
INSERT BLOB proj_desc INTO project;
/*
* Get the next project id and update the project description.
*/
line = get_line();
while (line)
{
/* Open the blob cursor. */
EXEC SQL
OPEN bc INTO :blob_id;
strcpy(proj_id, line);
printf("\nUpdating description for project: %s\n\n", proj_id);
/* Get a project description segment. */
line = get_line();
while (line)
{
printf(" Inserting segment: %s\n", line);
/* Calculate the length of the segment. */
len = strlen(line);
/* Write the segment. */
EXEC SQL INSERT CURSOR bc VALUES (:line INDICATOR :len);
line = get_line();
}
/* Close the blob cursor. */
EXEC SQL
CLOSE bc;
/* Save the blob id in the project record. */
EXEC SQL
UPDATE project
SET proj_desc = :blob_id
WHERE proj_id = :proj_id;
if (SQLCODE == 0L)
rec_cnt++;
else
printf("Input error -- no project record with key: %s\n", proj_id);
line = get_line();
}
EXEC SQL
COMMIT RELEASE;
printf("\n\nAdded %d project descriptions.\n", rec_cnt);
return 0;
Error:
isc_print_sqlerror((short) SQLCODE, isc_status);
return 1;
}
/*
* Get the next input line, which is either a project id
* or a project description segment.
*/
char *get_line (void)
{
return Proj_data[Inp_ptr++];
}

173
src/v5_examples/stat9.e Normal file
View File

@ -0,0 +1,173 @@
/*
* Program type: Embedded Static SQL
*
* Description:
* This program executes a stored procedure and selects from
* a stored procedure. First, a list of projects an employee
* is involved in is printed. Then the employee is added to
* another project. The new list of projects is printed again.
* The contents of this file are subject to the Interbase Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy
* of the License at http://www.Inprise.com/IPL.html
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code was created by Inprise Corporation
* and its predecessors. Portions created by Inprise Corporation are
* Copyright (C) Inprise Corporation.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/
#include "example.h"
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
EXEC SQL INCLUDE SQLCA;
void select_projects (short emp_no);
void get_params (short *emp_no, char* proj_id);
void pr_error (long status);
int add_emp_proj (short emp_no,char * proj_id);
int main (void)
{
BASED_ON employee.emp_no emp_no;
BASED_ON project.proj_id proj_id;
/*
* Add employee with id 8 to project 'MAPDB'.
*/
get_params(&emp_no, proj_id);
/*
* Display employee's current projects.
*/
printf("\nCurrent projects for employee id: %d\n\n", emp_no);
select_projects(emp_no);
/*
* Insert a new employee project row.
*/
printf("\nAdd employee id: %d to project: %s\n", emp_no, proj_id);
add_emp_proj(emp_no, proj_id);
/*
* Display employee's new current projects.
*/
printf("\nCurrent projects for employee id: %d\n\n", emp_no);
select_projects(emp_no);
}
/*
* Select from a stored procedure.
* Procedure 'get_emp_proj' gets employee's projects.
*/
void select_projects(ARG(short, emp_no))
ARGLIST(short emp_no)
{
BASED_ON project.proj_id proj_id;
EXEC SQL
WHENEVER SQLERROR GO TO SelError;
/* Declare a cursor on the stored procedure. */
EXEC SQL
DECLARE projects CURSOR FOR
SELECT proj_id FROM get_emp_proj (:emp_no)
ORDER BY proj_id;
EXEC SQL
OPEN projects;
/* Print employee projects. */
while (SQLCODE == 0)
{
EXEC SQL
FETCH projects INTO :proj_id;
if (SQLCODE == 100)
break;
printf("\t%s\n", proj_id);
}
EXEC SQL
CLOSE projects;
EXEC SQL
COMMIT RETAIN;
SelError:
if (SQLCODE)
pr_error((long)gds__status);
}
/*
* Execute a stored procedure.
* Procedure 'add_emp_proj' adds an employee to a project.
*/
add_emp_proj(ARG(short, emp_no),
ARG(char *, proj_id))
ARGLIST(BASED_ON employee.emp_no emp_no)
ARGLIST(BASED_ON project.proj_id proj_id)
{
EXEC SQL
WHENEVER SQLERROR GO TO AddError;
EXEC SQL
EXECUTE PROCEDURE add_emp_proj :emp_no, :proj_id;
EXEC SQL
COMMIT;
AddError:
if (SQLCODE)
pr_error((long)gds__status);
}
/*
* Set-up procedure parameters and clean-up old data.
*/
void get_params(ARG(short *, emp_no),
ARG(char *, proj_id))
ARGLIST(BASED_ON employee.emp_no *emp_no)
ARGLIST(BASED_ON project.proj_id proj_id)
{
*emp_no = 8;
strcpy(proj_id, "MAPDB");
EXEC SQL
WHENEVER SQLERROR GO TO CleanupError;
/* Cleanup: delete row from the previous run. */
EXEC SQL
DELETE FROM employee_project
WHERE emp_no = 8 AND proj_id = "MAPDB";
CleanupError:
return;
}
/*
* Print an error message.
*/
void pr_error(ARG(long, status))
ARGLIST(long status)
{
isc_print_sqlerror(SQLCODE, gds__status);
}

111
src/v5_examples/udf.sql Normal file
View File

@ -0,0 +1,111 @@
/*
* The contents of this file are subject to the Interbase Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy
* of the License at http://www.Inprise.com/IPL.html
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code was created by Inprise Corporation
* and its predecessors. Portions created by Inprise Corporation are
* Copyright (C) Inprise Corporation.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/
/*--------------------------------------------------------------
** User Defined Function definitions for example databases
**--------------------------------------------------------------
*/
DECLARE EXTERNAL FUNCTION lower
VARCHAR (256)
RETURNS CSTRING(80) FREE_IT
ENTRY_POINT 'fn_lower_c' MODULE_NAME 'udflib';
DECLARE EXTERNAL FUNCTION substr
CSTRING(256), SMALLINT, SMALLINT
RETURNS CSTRING(80) FREE_IT
ENTRY_POINT 'fn_substr' MODULE_NAME 'udflib';
DECLARE EXTERNAL FUNCTION trim
CSTRING(256)
RETURNS CHAR (80) FREE_IT
ENTRY_POINT 'fn_trim' MODULE_NAME 'udflib';
DECLARE EXTERNAL FUNCTION trunc
CSTRING(256), SMALLINT
RETURNS VARCHAR (80) FREE_IT
ENTRY_POINT 'fn_trunc' MODULE_NAME 'udflib';
DECLARE EXTERNAL FUNCTION strcat
VARCHAR(255), VARCHAR (255)
RETURNS CSTRING(80) FREE_IT
ENTRY_POINT 'fn_strcat' MODULE_NAME 'udflib';
DECLARE EXTERNAL FUNCTION doy
RETURNS INTEGER BY VALUE
ENTRY_POINT 'fn_doy' MODULE_NAME 'udflib';
DECLARE EXTERNAL FUNCTION moy
RETURNS SMALLINT
ENTRY_POINT 'fn_moy' MODULE_NAME 'udflib';
DECLARE EXTERNAL FUNCTION dow
RETURNS CSTRING(12)
ENTRY_POINT 'fn_dow' MODULE_NAME 'udflib';
DECLARE EXTERNAL FUNCTION sysdate
RETURNS CSTRING(12) FREE_IT
ENTRY_POINT 'fn_sysdate' MODULE_NAME 'udflib';
DECLARE EXTERNAL FUNCTION fact
DOUBLE PRECISION
RETURNS DOUBLE PRECISION BY VALUE
ENTRY_POINT 'fn_fact' MODULE_NAME 'udflib';
DECLARE EXTERNAL FUNCTION add2
INTEGER,INTEGER
RETURNS INTEGER BY VALUE
ENTRY_POINT 'fn_add2' MODULE_NAME 'udflib';
DECLARE EXTERNAL FUNCTION mul
DOUBLE PRECISION, DOUBLE PRECISION
RETURNS DOUBLE PRECISION BY VALUE
ENTRY_POINT 'fn_mul' MODULE_NAME 'udflib';
DECLARE EXTERNAL FUNCTION abs
DOUBLE PRECISION
RETURNS DOUBLE PRECISION BY VALUE
ENTRY_POINT 'fn_abs' MODULE_NAME 'udflib';
DECLARE EXTERNAL FUNCTION maxnum
DOUBLE PRECISION, DOUBLE PRECISION
RETURNS DOUBLE PRECISION BY VALUE
ENTRY_POINT 'fn_max' MODULE_NAME 'udflib';
DECLARE EXTERNAL FUNCTION sqrt
DOUBLE PRECISION
RETURNS DOUBLE PRECISION
ENTRY_POINT 'fn_sqrt' MODULE_NAME 'udflib';
DECLARE EXTERNAL FUNCTION BLOB_BYTECOUNT
BLOB
RETURNS INTEGER BY VALUE
ENTRY_POINT 'fn_blob_bytecount' MODULE_NAME 'udflib';
DECLARE EXTERNAL FUNCTION BLOB_LINECOUNT
BLOB
RETURNS INTEGER BY VALUE
ENTRY_POINT 'fn_blob_linecount' MODULE_NAME 'udflib';
DECLARE EXTERNAL FUNCTION BLOB_SUBSTR
BLOB, INTEGER, INTEGER
RETURNS CSTRING(256) FREE_IT
ENTRY_POINT 'fn_blob_substr' MODULE_NAME 'udflib';

481
src/v5_examples/udflib.c Normal file
View File

@ -0,0 +1,481 @@
/*====================================================================
File Name: udflib.c
Description:
This module contains some user defined functions (UDF).
The test suite for UDF will use udf.sql
to define UDF to the database using SQL statements.
* The contents of this file are subject to the Interbase Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy
* of the License at http://www.Inprise.com/IPL.html
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code was created by Inprise Corporation
* and its predecessors. Portions created by Inprise Corporation are
* Copyright (C) Inprise Corporation.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
====================================================================== */
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <math.h>
#include <ibase.h>
#include "example.h"
#define BADVAL -9999L
#define MYBUF_LEN 15 /* number of chars to get for */
typedef struct blob {
short (*blob_get_segment) ();
void *blob_handle;
long blob_number_segments;
long blob_max_segment;
long blob_total_length;
void (*blob_put_segment) ();
} *BLOB;
time_t time();
char *ctime();
/* variable to return values in. Needs to be static so it doesn't go
away as soon as the function invocation is finished */
char buffer[256];
char buffer2[512]; /* for string concatenation */
char datebuf[12]; /* for date string */
long r_long;
double r_double;
float r_float;
short r_short;
struct tm *tbuf;
long time_sec;
ISC_QUAD newdate;
/*===============================================================
fn_lower_c() - Puts its argument longo lower case, for C programs
Input is of VARCHAR, output is of CSTRING.
Not international or non-ascii friendly.
================================================================= */
char* EXPORT fn_lower_c (ARG(char*, s))
ARGLIST(char *s) /* VARCHAR input */
{
char *buf;
short length = 0;
char *buffer = (char *)malloc(256);
length = (short)*s;
s += 2;
buf = buffer;
while (*s)
if (*s >= 'A' && *s <= 'Z')
*buf++ = *s++ - 'A' + 'a';
else
*buf++ = *s++;
*buf = '\0';
buffer [length] = '\0';
return buffer;
}
/*===============================================================
fn_strcat(s1, s2) - Returns concatenated string.
s1 and s2 are varchar to get a length count
================================================================= */
char* EXPORT fn_strcat(ARG(char*, s1), ARG(char*, s2))
ARGLIST(char *s1)
ARGLIST(char *s2)
{
short j = 0;
short length1, length2;
char *p;
char *buffer2 = (char *)malloc(512);
length1 = (short)*s1;
length2 = (short)*s2;
s1 += 2;
s2 += 2;
/* strip trailing blanks of s1 */
p = s1 + length1 - 1;
while (*p && *p == ' ')
p--;
p++;
*p = '\0';
p = buffer2;
while (*s1)
*p++ = *s1++;
for (j = 0; j < length2; j++)
if (*s2)
*p++ = *s2++;
*p = '\0';
return buffer2;
}
/*===============================================================
fn_substr(s, m, n) - Returns the substr starting m ending n in s.
================================================================= */
char* EXPORT fn_substr(ARG(char*, s), ARG(short*, m), ARG(short*, n))
ARGLIST(char *s)
ARGLIST(short *m) /* starting position */
ARGLIST(short *n) /* ending position */
{
short i = 0;
short j = 0;
char *buffer = (char *)malloc(256);
if (*m > *n || *m < 1 || *n < 1) return "Bad parameters in substring";
while (*s && i++ < *m-1) /* skip */
s++;
while (*s && i++ <= *n) /* copy */
buffer[j++] = *s++;
buffer[j] = '\0';
return buffer;
}
/*===============================================================
fn_trim(s) - Returns string that has leading blanks trimmed.
================================================================= */
char* EXPORT fn_trim(ARG(char*, s))
ARGLIST(char *s)
{
short j = 0;
char *buffer = (char *)malloc(256);
while (*s == ' ') /* skip leading blanks */
s++;
while (*s) /* copy the rest */
buffer[j++] = *s++;
buffer[j] = '\0';
return buffer;
}
/*===============================================================
fn_trunc(s, m) - Returns the string truncated at position m;
Input is of CSTRING, output is of VARCHAR.
================================================================= */
char* EXPORT fn_trunc(ARG(char*, s), ARG(short*, m))
ARGLIST(char *s)
ARGLIST(short *m)
{
short j = 2; /* leave 1st 2 bytes for VARCHAR output */
char *buffer = (char *)malloc(256);
while (*s && j < *m + 2) /* need to add 2 */
buffer[j++] = *s++;
buffer[j] = '\0';
buffer[0] = (unsigned short) strlen(s) + 2;
buffer[1] = ' '; /* anything other than \0 */
/*
*((unsigned short *)buffer) = (unsigned short) (strlen(buffer) + 2);
*/
return buffer; /* VARCHAR output */
}
/* ==============================================================
fn_doy() return the nth day of the year, by value.
============================================================== */
long EXPORT fn_doy()
{
char buf[4]; /* for day */
long i;
time (&time_sec);
tbuf = localtime(&time_sec);
i = strftime(buf, 4, "%j", tbuf);
return atoi (buf);
}
/* ==============================================================
fn_moy() return the nth month of the year. e.g. 1,2,3,...12.
Return by reference.
============================================================== */
short* EXPORT fn_moy()
{
time (&time_sec);
tbuf = localtime(&time_sec);
r_short = (short) tbuf->tm_mon + 1;
return &r_short;
}
/* ==============================================================
fn_dow() return the day of today. e.g., Monday, Friday. ...
============================================================== */
char* EXPORT fn_dow()
{
time (&time_sec);
tbuf = localtime(&time_sec);
switch (tbuf->tm_wday) {
case 1: return "Monday";
case 2: return "Tuesday";
case 3: return "Wednesday";
case 4: return "Thursday";
case 5: return "Friday";
case 6: return "Saturday";
case 7: return "Sunday";
default: return "Error in Date";
}
}
/*===============================================================
fn_sysdate() - Returns the system date in the "MMM-DD-YYYY" format.
================================================================= */
char* EXPORT fn_sysdate()
{
short len, i, j = 0;
char *time_str;
char *datebuf = (char *)malloc(12);
time (&time_sec);
time_str = ctime (&time_sec);
len = strlen(time_str);
for (i = 4; i <= 10; i++) {
if (*(time_str + i) != ' ')
datebuf[j++] = *(time_str+i);
else if (i == 7 || i == 10)
datebuf[j++] = '-';
else
datebuf[j++] = '0';
}
for (i = 20; i < len-1 ; i++)
datebuf[j++] = *(time_str+i);
datebuf[j] = '\0';
return datebuf;
}
/* ==============================================
fn_add2 (a, b) - returns a + b
=============================================== */
long EXPORT fn_add2 (ARG(long*, a), ARG(long*, b))
ARGLIST(long *a)
ARGLIST(long *b)
{
return (*a + *b);
}
/* ==================================================
fn_mul (a, b) - returns a * b
=================================================== */
double EXPORT fn_mul (ARG(double*, a), ARG(double*, b))
ARGLIST(double *a)
ARGLIST(double *b)
{
return (*a * *b);
}
/* ==============================================
fn_fact (n) - return factorial of n
================================================ */
double EXPORT fn_fact (ARG(double*, n))
ARGLIST(double *n)
{
double k;
if (*n > 100) return BADVAL;
if (*n < 0) return BADVAL;
if (*n == 0) return 1L;
else {
k = *n - 1L;
return (*n * fn_fact(&k));
}
}
/*===============================================================
fn_abs() - returns the absolute value of its argument.
================================================================= */
double EXPORT fn_abs(ARG(double*, x))
ARGLIST(double *x)
{
return (*x < 0.0) ? -*x : *x;
}
/*===============================================================
fn_max() - Returns the greater of its two arguments
================================================================ */
double EXPORT fn_max(ARG(double*, a), ARG(double*, b))
ARGLIST(double *a)
ARGLIST(double *b)
{
return (*a > *b) ? *a : *b;
}
/*===============================================================
fn_sqrt() - Returns square root of n
================================================================ */
double* EXPORT fn_sqrt(ARG(double*, n))
ARGLIST(double *n)
{
r_double = sqrt(*n);
return &r_double;
}
/*=============================================================
fn_blob_linecount() returns the number of lines in a blob
=============================================================*/
long EXPORT fn_blob_linecount (ARG(BLOB, b))
ARGLIST(BLOB b)
{
char *buf, *p;
short length, actual_length;
/* Null values */
if (!b->blob_handle)
return 0L;
length = b->blob_max_segment + 1L;
buf = (char *) malloc (length);
r_long = 0;
while ((*b->blob_get_segment) (b->blob_handle, buf, length, &actual_length))
{
buf [actual_length] = 0;
p = buf;
while (*p)
if (*p++ == '\n')
r_long++;
}
free (buf);
return r_long;
}
/*=============================================================
fn_blob_bytecount() returns the number of bytes in a blob
do not count newlines, so get rid of the newlines.
==============================================================*/
long EXPORT fn_blob_bytecount (ARG(BLOB, b))
ARGLIST(BLOB b)
{
/* Null values */
if (!b->blob_handle)
return 0L;
return (b->blob_total_length - fn_blob_linecount(b));
}
/*=============================================================
fn_substr_blob() returns portion of TEXT blob beginning at m th
character and ended at n th character.
Newlines are eliminated to make for better printing.
=============================================================*/
char* EXPORT fn_blob_substr(ARG(BLOB, b), ARG(long*, m), ARG(long*, n))
ARGLIST(BLOB b)
ARGLIST(long *m)
ARGLIST(long *n)
{
char *buf, *p, *q;
long i = 0;
long curr_bytecount = 0;
long begin, end;
short length, actual_length;
char *buffer = (char *)malloc(256);
if (!b->blob_handle)
return "<null>";
length = b->blob_max_segment + 1L;
buf = (char *) malloc (length);
if (*m > *n || *m < 1L || *n < 1L)
return "";
if (b->blob_total_length < (long)*m)
return "";
begin = *m; /* beginning position */
if (b->blob_total_length < (long)*n)
end = b->blob_total_length; /* ending position */
else
end = *n;
/* Limit the return string to 255 bytes */
if (end - begin + 1L > 255L)
end = begin + 254L;
q = buffer;
while ((*b->blob_get_segment) (b->blob_handle, buf, length,
&actual_length))
{
buf [actual_length] = 0;
p = buf;
while (*p && (curr_bytecount <= end))
{
curr_bytecount++;
if (*p == '\n')
*p = ' ';
if (curr_bytecount >= begin)
*q++ = *p;
p++;
}
if (curr_bytecount >= end)
{
*q = 0;
break;
}
}
free (buf);
return buffer;
}

View File

@ -0,0 +1,39 @@
; The contents of this file are subject to the Interbase Public
; License Version 1.0 (the "License"); you may not use this file
; except in compliance with the License. You may obtain a copy
; of the License at http://www.Inprise.com/IPL.html
;
; Software distributed under the License is distributed on an
; "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
; or implied. See the License for the specific language governing
; rights and limitations under the License.
;
; The Original Code was created by Inprise Corporation
; and its predecessors. Portions created by Inprise Corporation are
; Copyright (C) Inprise Corporation.
;
; All Rights Reserved.
; Contributor(s): ______________________________________.
LIBRARY udflib
DESCRIPTION 'udflib.dll'
DATA READ WRITE
EXPORTS
fn_abs
fn_add2
fn_blob_bytecount
fn_blob_linecount
fn_blob_substr
fn_dow
fn_doy
fn_fact
fn_lower_c
fn_max
fn_moy
fn_mul
fn_sqrt
fn_strcat
fn_substr
fn_sysdate
fn_trim
fn_trunc

426
src/v5_examples/winevent.c Normal file
View File

@ -0,0 +1,426 @@
/*
* Program type: API
*
* EVENTS.C -- Example events program
*
* Description: This program does an asynchronous event wait
* on a trigger set up in the sales table of
* employee.gdb.
* Somebody must add a new sales order to alert
* this program. That role can be accomplished
* by running the api16t example program
* after starting this program.
*
* Note: The system administrator needs to create the account
* "guest" with password "guest" on the server before this
* example can be run.
* The contents of this file are subject to the Interbase Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy
* of the License at http://www.Inprise.com/IPL.html
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code was created by Inprise Corporation
* and its predecessors. Portions created by Inprise Corporation are
* Copyright (C) Inprise Corporation.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/
#include <windows.h>
#include <windowsx.h>
#include <ibase.h>
#include <stdio.h>
#include <string.h>
/*
** Local Defines
*/
#define USER "guest"
#define PASSWORD "guest"
#define DATABASE "employee.gdb"
#define IDM_EXIT 1
#define WM_DB_EVENT WM_USER + 1
/*
** This is an event block defined to keep track of all the parameters
** used to queue and proecess events. A pointer to this structure
** will be passed as the user argument to gds_que_events.
*/
typedef struct _EventBlk {
char *EventBuf;
char *ResultBuf;
short length;
long EventId;
char *EventName;
isc_callback lpAstProc;
isc_db_handle DB;
HWND hWnd;
struct _EventBlk *NextBlk;
} EVENTBLK;
/*
** GLOBAL VARIABLES
*/
char szAppName [] = "Events";
HINSTANCE hInstance;
long status[20];
/*
** FUNCTION PROTOTYPES
*/
#ifdef BORLANDC
#pragma argsused
#endif
long FAR PASCAL _export WndProc (HWND, UINT, UINT, LONG) ;
HWND InitApplication(int nCmdShow, HINSTANCE hPrevInstance);
int InitEvent(EVENTBLK *lpEvent, long *DB,
HWND hWnd, char *event);
void ReleaseEvents(EVENTBLK *lpEvent);
#ifdef __cplusplus
extern "C" { /* Assume C declarations for C++ */
#endif /* __cplusplus */
void AstRoutine(EVENTBLK *result, short length,
char *updated);
#ifdef __cplusplus
}
#endif /* __cplusplus */
void WinPrint(char*);
int CHK_ERR(long *gds__status);
/*****************************************************************
*
* WinMain
*
*****************************************************************
*
* Functional description
* Description: Setup the dpb with the username and password
* and attach to the database, employee.gdb.
* If the attach was successful, allocate an event
* control block and register interest in the
* event "new_order".
*
*
****************************************************************/
int PASCAL WinMain (HINSTANCE hInst, HINSTANCE hPrevInstance,
LPSTR lpszCmdLine, int nCmdShow)
{
MSG msg;
isc_db_handle DB = NULL;
HWND hWnd;
EVENTBLK *lpEventNewOrder = NULL;
char dpb[48];
int i = 0, len;
hInstance = hInst;
hWnd = InitApplication(nCmdShow, hPrevInstance);
if (!hWnd)
{
WinPrint("Unable to initialize main window");
/* Get rid of warning for both Borland and Microsoft */
lpszCmdLine = lpszCmdLine;
return FALSE;
}
/* Format the dpb with the user name a password */
dpb[i++] = isc_dpb_version1;
dpb[i++] = isc_dpb_user_name;
len = strlen (USER);
dpb[i++] = (char) len;
strncpy(&(dpb[i]), USER, len);
i += len;
dpb[i++] = isc_dpb_password;
len = strlen (PASSWORD);
dpb[i++] = len;
strncpy(&(dpb[i]), PASSWORD, len);
i += len;
isc_attach_database(status, 0, DATABASE, &(DB), i, dpb);
/* If the attach was successful, initialize the event handlers */
if (!CHK_ERR(status))
{
/* Allocate our event control block to hold all the event parameters */
lpEventNewOrder = (EVENTBLK *) GlobalAllocPtr(
GMEM_MOVEABLE | GMEM_ZEROINIT,
sizeof(EVENTBLK));
/* Register interest in the "new_order" event */
InitEvent(lpEventNewOrder, (long *)DB, hWnd, "new_order");
}
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
isc_detach_database(status, &DB);
/* Release the allocated event blocks */
ReleaseEvents(lpEventNewOrder);
return msg.wParam;
}
/*****************************************************************
*
* InitApplication
*
*****************************************************************
*
* Functional description:
* Registers the window class and displays the main window.
* Returns:
* window handle on success, FALSE otherwise
*
*****************************************************************/
HWND InitApplication (int nCmdShow, HINSTANCE hPrevInstance)
{
WNDCLASS wndclass;
HWND hWnd;
if (!hPrevInstance)
{
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)GetStockObject (WHITE_BRUSH);
wndclass.lpszMenuName = szAppName;
wndclass.lpszClassName = szAppName;
if (!RegisterClass(&wndclass))
return NULL;
}
if ((hWnd = CreateWindow(szAppName, "Event Test",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL)) == NULL )
return NULL;
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
return hWnd;
}
/*****************************************************************
*
* InitEvents
*
*****************************************************************
*
* Functional description:
* Initialize the event_block, and queue interest in a particular
* event.
* Returns:
* TRUE if success, FALSE if que_events failed.
*
*****************************************************************/
int InitEvent (EVENTBLK *lpEvent, long *DB, HWND hWnd, char *event)
{
/* Allocate the event buffers and initialize the events of interest */
lpEvent->length = (short)isc_event_block(&(lpEvent->EventBuf),
&(lpEvent->ResultBuf),
1, event);
/* Store any necessary parameters in the event block */
lpEvent->lpAstProc = (isc_callback) MakeProcInstance((FARPROC) AstRoutine,
hInstance);
lpEvent->DB = DB;
lpEvent->hWnd = hWnd;
lpEvent->EventName = event;
/* Request the server to notify when any of our events occur */
isc_que_events(status, &(lpEvent->DB),
&(lpEvent->EventId), lpEvent->length, lpEvent->EventBuf,
lpEvent->lpAstProc, lpEvent);
if (CHK_ERR(status))
return FALSE;
return TRUE;
}
/*****************************************************************
*
* ReleaseEvents
*
*****************************************************************
*
* Functional description:
* Releases the event buffers allocated by isc_event_block
* and releases the main event block.
* Returns:
* none
*
*****************************************************************/
void ReleaseEvents (EVENTBLK *lpEvent)
{
if (lpEvent == NULL)
return;
isc_free(lpEvent->EventBuf);
isc_free(lpEvent->ResultBuf);
(VOID)GlobalFreePtr(lpEvent);
}
/*****************************************************************
*
* WndProc
*
*****************************************************************
*
* Functional description:
* Main window processing function.
* Returns:
* 0 if the message was handled,
* results from DefWindowProc otherwise
*
*****************************************************************/
long FAR PASCAL _export WndProc (HWND hWnd, UINT message, UINT wParam,
LONG lParam)
{
EVENTBLK *lpEvent;
unsigned long Vector[20];
char msgbuf[200];
switch (message)
{
case WM_COMMAND:
switch (wParam)
{
case IDM_EXIT:
SendMessage(hWnd, WM_CLOSE, 0, 0L);
return 0;
}
break;
case WM_DB_EVENT:
/* The event block is passed in lParam by the ast */
lpEvent = (EVENTBLK *)lParam;
/*
** isc_event_counts will update Vector with the number
** of times each event occurred. It will then copy
** ResultBuf into EventBuf to prepare for the next que_events.
*/
isc_event_counts(Vector, lpEvent->length, lpEvent->EventBuf,
lpEvent->ResultBuf);
sprintf(msgbuf, "Event %s triggered with count %ld\n...Resetting"
" count and calling gds_que_events again",
lpEvent->EventName, Vector[0]);
WinPrint(msgbuf);
/* Re-queue the event, so we can do this all over again */
isc_que_events(status, &(lpEvent->DB), &(lpEvent->EventId),
lpEvent->length, lpEvent->EventBuf,
lpEvent->lpAstProc, lpEvent);
CHK_ERR(status);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hWnd, message, wParam, lParam);
}
/*****************************************************************
*
* AstRoutine
*
*****************************************************************
*
* Functional description:
* This is the callback routine which is called by the
* gds library when an event occurs in the database.
* The event block which was passed as an argument to
* gds_que_events is received as the first argument,
* along with the updated event buffer and its length.
* Returns:
* none
*
*****************************************************************/
void far AstRoutine (EVENTBLK *lpEvent, short length, char *updated)
{
char *ResultBuf = lpEvent->ResultBuf;
/* Update the result buffer with the new values */
while (length--)
*ResultBuf++ = *updated++;
/* Let the parent window know the event triggered */
PostMessage(lpEvent->hWnd, WM_DB_EVENT, 0, (LPARAM) lpEvent);
}
/*****************************************************************
*
* WinPrint
*
*****************************************************************
*
* Functional description:
* Print a message in a message box.
* Returns:
* none
*
*****************************************************************/
void WinPrint (char *line)
{
MessageBox(NULL, line, szAppName, MB_ICONINFORMATION | MB_OK);
}
/*****************************************************************
*
* CHK_ERR
*
*****************************************************************
*
* Functional description:
* If an error was returned in the status vector, print it
* and the post a quit message to terminate the app.
* Returns:
* TRUE if there was error, FALSE otherwise
*
*****************************************************************/
int CHK_ERR (long *status)
{
if (status[1])
{
isc_print_status(status);
PostQuitMessage(1);
return TRUE;
}
return FALSE;
}

View File

@ -0,0 +1,33 @@
; The contents of this file are subject to the Interbase Public
; License Version 1.0 (the "License"); you may not use this file
; except in compliance with the License. You may obtain a copy
; of the License at http://www.Inprise.com/IPL.html
;
; Software distributed under the License is distributed on an
; "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
; or implied. See the License for the specific language governing
; rights and limitations under the License.
;
; The Original Code was created by Inprise Corporation
; and its predecessors. Portions created by Inprise Corporation are
; Copyright (C) Inprise Corporation.
;
; All Rights Reserved.
; Contributor(s): ______________________________________.
;-------------------------------------
; EVENTS.DEF module definition file
;-------------------------------------
NAME EVENTS
DESCRIPTION 'Event Test Program'
EXETYPE WINDOWS
STUB 'WINSTUB.EXE'
CODE PRELOAD MOVEABLE DISCARDABLE
DATA PRELOAD MOVEABLE MULTIPLE
HEAPSIZE 1024
STACKSIZE 15000
EXPORTS
; This needs an "_" prefix since it is a cdecl function
_AstRoutine

View File

@ -0,0 +1,28 @@
/*
* The contents of this file are subject to the Interbase Public
* License Version 1.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy
* of the License at http://www.Inprise.com/IPL.html
*
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
* or implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code was created by Inprise Corporation
* and its predecessors. Portions created by Inprise Corporation are
* Copyright (C) Inprise Corporation.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/
/*-----------------------------
EVENTS.RC resource script
-----------------------------*/
Events MENU
{
POPUP "&File"
{
MENUITEM "E&xit", 1
}
}