home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
cppsql.zip
/
SQL.ZIP
/
SQLTAB.HPP
< prev
next >
Wrap
C/C++ Source or Header
|
1992-09-11
|
10KB
|
273 lines
// :H1 SQLTAB.HPP: START OF SPECIFICATIONS
//----------------------------------------------------------------------
//
// Module Name: SQLTAB.HPP
//
// Description: SQL Table Interface.
//
// Product Classification:
// IBM Internal Use Only
// Copyright IBM Corp. 1992
//
// Status: New
//
// Initial Author: George L. Havens
//
// Function: To provide an interface for tables to SQL databases.
//
// Notes: None.
//
// Dependencies: Requires PORTABLE.H include.
// Requires SQLDA.H include.
//
// Restrictions: None.
//
// Compiler: Zortech C++
//
// Change Activity -----------------------------------------------------
//
// $MOD(module) COMP(component) PROD(product): Description...
//
// FLAG REASON VERS DATE WHO DESCRIPTION
// ---- -------- ---- ------ --- -----------
// V100 920224 GLH : Initial level
//
// END-OF-SPECIFICATIONS -----------------------------------------------
#ifndef XX_SQLTAB
#define XX_SQLTAB
class Table
{
public:
//----------------------------------------------------------------------
//
// Function Name: Table constructor
//
// Purpose: This method will create an SQL table object.
//
// Description: This method will create an SQL table object. It
// will create a SQLDA structure for the table
// format specified.
//
// Input:
// name Table name
// format table format
// format must be a string using %d, %ld, or %#s
// where # is the string length not including the 0 terminator
// col column names seperated by ','
// Output:
// none
//
//----------------------------------------------------------------------
Table (const CHAR *name, const CHAR *format, const CHAR *col);
//----------------------------------------------------------------------
//
// Function Name: Create
//
// Purpose: This method will create an SQL table.
//
// Description: This method will create an SQL table by using
// dynamic SQL.
//
// Input:
// none
//
// Output:
// return code 0 = successful, not 0 = error
//
//----------------------------------------------------------------------
SHORT Create (VOID);
//----------------------------------------------------------------------
//
// Function Name: Insert
//
// Purpose: This method will insert data into an SQL table.
//
// Description: This method will insert a variable data into the
// table columns.
//
// Input:
// num_cols number of colums to insert (must match number of columns
// in the table description)
// variable data to be inserted
//
// Output:
// return code 0 = successful, not 0 = error
//
//----------------------------------------------------------------------
SHORT Insert (SHORT num_cols, ...);
//----------------------------------------------------------------------
//
// Function Name: Search
//
// Purpose: This method will search an SQL table for a specified value(s).
//
// Description: This method will search for a match on the specified
// value(s). This is done by building a SELECT record
// for the specified values. If multiple conditions
// are specified they are AND'ed together.
//
// Input:
// initial initial search with this format?
// format table format
// format must be a string using %d, %ld, or %#s for
// fields to be searched and %*d, %*ld, and %*#s for
// those not being searched.
// # is the string length to search not including the
// 0 terminator. If no fields to be searched are specified
// the next row will be returned.
//
// variable pointers where to store EVERY field in the row
// variable data to be seached for match
// Output:
// return code 0 = successful, not 0 = error
//
//----------------------------------------------------------------------
SHORT Search (BOOLEAN beginning, const CHAR *, ...);
//----------------------------------------------------------------------
//
// Function Name: Delete
//
// Purpose: This method will search an SQL table for a specified value(s)
// and delete the rows found.
//
// Description: This method will search for a match on the specified
// value(s). This is done by building a DELETE record
// for the specified values. If multiple conditions
// are specified they are AND'ed together.
//
// Input:
// format table format
// format must be a string using %d, %ld, or %#s for
// fields to be searched and %*d, %*ld, and %*#s for
// those not being searched.
// # is the string length to search not including the
// 0 terminator. If no fields to be searched are specified
// all the rows will be deleted.
// variable data to be seached for match
// Output:
// return code 0 = successful, not 0 = error
//
//----------------------------------------------------------------------
SHORT Delete (const CHAR *, ...);
//----------------------------------------------------------------------
//
// Function Name: DeleteCurrent
//
// Purpose: This method will delete the current row found by using the
// search statement.
//
// Description: This method will delete the current row that was found using
// the search statement. This is done by building a DELETE
// current record.
//
// Input:
// none
//
// Output:
// return code 0 = successful, not 0 = error
//
//----------------------------------------------------------------------
SHORT DeleteCurrent (VOID);
//----------------------------------------------------------------------
//
// Function Name: Index
//
// Purpose: This method will create an index for the specified columns.
//
// Description: This method will create an index for the specified
// columns using the SQL create index command. Only one index
// can be created per table.
//
// Input:
// format table format
// format must be a string using %d, %ld, or %#s for
// fields to be searched and %*d, %*ld, and %*#s for
// those not being indexed.
// # is the string length to search not including the
// 0 terminator. If no fields to be indexed are specified
// an error will be returned.
// Output:
// return code 0 = successful, not 0 = error
//
//----------------------------------------------------------------------
SHORT Index (const CHAR *);
//----------------------------------------------------------------------
//
// Function Name: Error
//
// Purpose: This method will return the last error that occurred.
//
// Description: This method will return the internal error codes
// to the caller.
//
// Input:
// rc_a where to return last return code
// id_a where to return last statement that had error
//
// Output:
// none
//
//----------------------------------------------------------------------
inline VOID Error (SHORT& rc_a, SHORT& id_a)
{
// set current return code and location
rc_a = rc;
id_a = (rc == 0) ? 0 : id;
}
//----------------------------------------------------------------------
//
// Function Name: Table destructor
//
// Purpose: This method will delete an table object.
//
// Description: This method will delete the table object and
// release the table name.
//
// Input:
// none
//
// Output:
// none
//
//----------------------------------------------------------------------
~Table ();
private:
CHAR *table; // table name
CHAR *columns; // column names
struct sqlda *var; // sqlda variables
SHORT cols; // number of columns in table
BOOLEAN record_found; // record was found during search
SHORT rc; // return code
#define SQLTAB_MEMORY_ERROR -10001
#define SQLTAB_NO_PERCENT_ERROR -10002
#define SQLTAB_INVALID_NUMBER_OF_COLUMNS -10003
#define SQLTAB_INVALID_FORMAT_STRING -10004
#define SQLTAB_NO_SEARCH_DONE -10005
#define SQLTAB_NO_RECORD 100 // SQL error code
SHORT id; // id of where last error occurred
#define SQLTAB_ID_1 1
#define SQLTAB_ID_2 2
#define SQLTAB_ID_3 3
#define SQLTAB_ID_4 4
#define SQLTAB_ID_5 5
#define SQLTAB_ID_6 6
#define SQLTAB_ID_7 7
#define SQLTAB_ID_8 8
#define SQLTAB_ID_9 9
#define SQLTAB_ID_10 10
#define SQLTAB_ID_11 11
#define SQLTAB_ID_12 12
#define SQLTAB_ID_13 13
#define SQLTAB_ID_14 14
#define SQLTAB_ID_15 15
#define SQLTAB_ID_16 16
// #define SQLTAB_ID_17 17 // available for use
#define SQLTAB_ID_18 18
#define SQLTAB_ID_19 19
#define SQLTAB_ID_20 20
};
#endif