// **************************************************************************** // // // // Northgate Information Solutions // // ------------------------------- // // // // Source File: RealDbTest.c // // // // Description: This is a sample 'C' program (unsupported) designed to test // // an ODBC connection to a Reality database. // // SQL statements are executed and the results displayed. // // // // To establish a connection there must be a valid PCSNI // // system entry (winsni.ini) pointing to a Reality database // // i.e. // // // // [DBASE90] // // protocol=DDATCP // // host=magpie // // dbase=dbase9.0 // // port=1203 // // // // The user must also supply either... // // // // (a) A USER or SYSTEM DSN (Data Source Name). // // (b) A CONSTR (ConnectString). // // // // Only one type maybe supplied. // // // // Note // // ---- // // File DSN's are not regonised. // // The CONSTR allows a connection to be tested without // // having an ODBC Data Source (DSN) defined. // // // // Date : 4th July 2001 // // // // **************************************************************************** // #include #include #include #include #define REALSQL_DRIVER "DRIVER=RealSQL Driver 32bit" #define CREATE_TABLE "CREATE TABLE" #define DROP_TABLE "DROP TABLE" #define INSERT_ROW "INSERT INTO" #define UPDATE_COLUMN "UPDATE" #define DELETE_ROW "DELETE FROM" #define MAX_ERRMSG_LEN 255 #define VERBOSE if (dBase.bVerbose == true) printf #define TRACE printf #define SKIP_WHITE_SPACE(x) while (*x == '\0') x++ #define ISALPHA(x) if (isalnum(*x) != 1) usage() #define CHECK_OPT(x, y) if (x == true) usage(); else y = true; #define SET_PARAM(x) x = &argv[i][2] // Structure containing column info returned in result set. struct COLUMN { SWORD iColumnNo; SDWORD iColumnWidth; SWORD pcbDesc; PTR rgbDesc[BUFSIZ]; }; // Structure containing database connection and execution details. struct DATABASE { HENV hEnv; HDBC hDbc; HSTMT hStmt; SWORD iColumnCount; SDWORD iRowCount; RETCODE retCode; COLUMN *pColumns; CHAR *szDsn; CHAR *szStmt; CHAR *szConStr; CHAR *szUserId; CHAR *szUserPwd; CHAR *szAccount; CHAR *szAccountPwd; bool bDsn; bool bConStr; bool bVerbose; bool bCreate; bool bDrop; bool bInsert; bool bUpdate; bool bDelete; bool bProperties; } dBase; // **************************************************************************** // // Method : usage // // Description: display program usage and exit. // // **************************************************************************** // void usage() { TRACE("\nUsage: RealDbTest -v -p [-d \"DSN\" | -c \"CONSTR\"] -s \"SQL statement\"\n"); TRACE("\n"); TRACE("where -v - Verbose output.\n"); TRACE("where -p - Driver and database properties.\n"); TRACE(" -d DSN - ODBC Data Source Name (USER or SYSTEM).\n"); TRACE(" -c CONSTR - A full connection string using the format\n"); TRACE(" \"System=sss;Account=aaa;UID=uuu;PWD=ppp;{Logoption=[1|2|3]}\"\n"); TRACE(" sss=system name in winsni.ini\n"); TRACE(" aaa=Reality account name\n"); TRACE(" uuu=Database userid\n"); TRACE(" ppp=User password\n"); TRACE(" lll=Host logging option\n"); exit(0); } // **************************************************************************** // // Method : getparams // // Description: initialise connection parameters. // parse command line arguments. // // Parameters : argc - number of command lind arguments. // argv - pointer to command line arguments. // // Return : none. // // **************************************************************************** // void getparams(int argc, char *argv[]) { // Initialisation dBase.bDsn = false; dBase.bConStr = false; dBase.bVerbose = false; dBase.bCreate = false; dBase.bDrop = false; dBase.bInsert = false; dBase.bUpdate = false; dBase.bDelete = false; dBase.iRowCount = 0; dBase.iColumnCount = 0; // Parse command line for (int i=1; i