Updated the Remstar ODBC files, got the db sample compiling; added Freq and SubString
to wxString git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1283 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -5,6 +5,8 @@
|
||||
// source such as opening and closing the data source.
|
||||
// Author: Doug Card
|
||||
// Modified by:
|
||||
// Mods: Dec, 1998: Added support for SQL statement logging and database
|
||||
// cataloging
|
||||
// Created: 9.96
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) 1996 Remstar International, Inc.
|
||||
@@ -20,17 +22,17 @@
|
||||
// the wxWindows GUI development toolkit.
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/*
|
||||
// SYNOPSIS START
|
||||
// SYNOPSIS STOP
|
||||
*/
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "db.h"
|
||||
#endif
|
||||
|
||||
/*
|
||||
#ifdef _CONSOLE
|
||||
// SYNOPSIS START
|
||||
// SYNOPSIS STOP
|
||||
*/
|
||||
|
||||
/*
|
||||
#ifdef DBDEBUG_CONSOLE
|
||||
#include <iostream.h>
|
||||
#endif
|
||||
*/
|
||||
@@ -47,11 +49,10 @@
|
||||
|
||||
#if wxUSE_ODBC
|
||||
|
||||
#include <wx/db.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include "wx/db.h"
|
||||
|
||||
DbList *PtrBegDbList = 0;
|
||||
|
||||
@@ -59,6 +60,9 @@ DbList *PtrBegDbList = 0;
|
||||
wxDB::wxDB(HENV &aHenv)
|
||||
{
|
||||
int i;
|
||||
|
||||
fpSqlLog = 0; // Sql Log file pointer
|
||||
sqlLogState = sqlLogOFF; // By default, logging is turned off
|
||||
|
||||
strcpy(sqlState,"");
|
||||
strcpy(errorMsg,"");
|
||||
@@ -112,7 +116,7 @@ wxDB::wxDB(HENV &aHenv)
|
||||
/********** wxDB::Open() **********/
|
||||
bool wxDB::Open(char *Dsn, char *Uid, char *AuthStr)
|
||||
{
|
||||
assert(Dsn);
|
||||
assert(Dsn && strlen(Dsn));
|
||||
dsn = Dsn;
|
||||
uid = Uid;
|
||||
authStr = AuthStr;
|
||||
@@ -125,7 +129,7 @@ bool wxDB::Open(char *Dsn, char *Uid, char *AuthStr)
|
||||
// specified before the connection is made.
|
||||
retcode = SQLSetConnectOption(hdbc, SQL_ODBC_CURSORS, SQL_CUR_USE_IF_NEEDED);
|
||||
|
||||
#ifdef _CONSOLE
|
||||
#ifdef DBDEBUG_CONSOLE
|
||||
if (retcode == SQL_SUCCESS)
|
||||
cout << "SQLSetConnectOption(CURSOR_LIB) successful" << endl;
|
||||
else
|
||||
@@ -240,7 +244,7 @@ bool wxDB::Open(char *Dsn, char *Uid, char *AuthStr)
|
||||
else
|
||||
typeInfDate.FsqlType = SQL_TIMESTAMP;
|
||||
|
||||
#ifdef _CONSOLE
|
||||
#ifdef DBDEBUG_CONSOLE
|
||||
cout << "VARCHAR DATA TYPE: " << typeInfVarchar.TypeName << endl;
|
||||
cout << "INTEGER DATA TYPE: " << typeInfInteger.TypeName << endl;
|
||||
cout << "FLOAT DATA TYPE: " << typeInfFloat.TypeName << endl;
|
||||
@@ -262,7 +266,7 @@ bool wxDB::setConnectionOptions(void)
|
||||
SQLSetConnectOption(hdbc, SQL_OPT_TRACE, SQL_OPT_TRACE_OFF);
|
||||
|
||||
// Display the connection options to verify them
|
||||
#ifdef _CONSOLE
|
||||
#ifdef DBDEBUG_CONSOLE
|
||||
long l;
|
||||
cout << ">>>>> CONNECTION OPTIONS <<<<<<" << endl;
|
||||
|
||||
@@ -394,7 +398,7 @@ bool wxDB::getDbInfo(void)
|
||||
if (SQLGetInfo(hdbc, SQL_LOGIN_TIMEOUT, &dbInf.loginTimeout, sizeof(dbInf.loginTimeout), &cb) != SQL_SUCCESS)
|
||||
return(DispAllErrors(henv, hdbc));
|
||||
|
||||
#ifdef _CONSOLE
|
||||
#ifdef DBDEBUG_CONSOLE
|
||||
cout << ">>>>> DATA SOURCE INFORMATION <<<<<" << endl;
|
||||
cout << "SERVER Name: " << dbInf.serverName << endl;
|
||||
cout << "DBMS Name: " << dbInf.dbmsName << "; DBMS Version: " << dbInf.dbmsVer << endl;
|
||||
@@ -612,7 +616,7 @@ bool wxDB::getDataTypeInfo(SWORD fSqlType, SqlTypeInfo &structSQLTypeInfo)
|
||||
// Fetch the record
|
||||
if ((retcode = SQLFetch(hstmt)) != SQL_SUCCESS)
|
||||
{
|
||||
#ifdef _CONSOLE
|
||||
#ifdef DBDEBUG_CONSOLE
|
||||
if (retcode == SQL_NO_DATA_FOUND)
|
||||
cout << "SQL_NO_DATA_FOUND fetching inf. about data type." << endl;
|
||||
#endif
|
||||
@@ -647,6 +651,13 @@ bool wxDB::getDataTypeInfo(SWORD fSqlType, SqlTypeInfo &structSQLTypeInfo)
|
||||
/********** wxDB::Close() **********/
|
||||
void wxDB::Close(void)
|
||||
{
|
||||
// Close the Sql Log file
|
||||
if (fpSqlLog)
|
||||
{
|
||||
fclose(fpSqlLog);
|
||||
fpSqlLog = 0; //glt
|
||||
}
|
||||
|
||||
// Free statement handle
|
||||
if (dbIsOpen)
|
||||
{
|
||||
@@ -699,7 +710,7 @@ bool wxDB::DispAllErrors(HENV aHenv, HDBC aHdbc, HSTMT aHstmt)
|
||||
logError(odbcErrMsg, sqlState);
|
||||
if (!silent)
|
||||
{
|
||||
#ifdef _CONSOLE
|
||||
#ifdef DBDEBUG_CONSOLE
|
||||
// When run in console mode, use standard out to display errors.
|
||||
cout << odbcErrMsg << endl;
|
||||
cout << "Press any key to continue..." << endl;
|
||||
@@ -733,7 +744,7 @@ void wxDB::DispNextError(void)
|
||||
if (silent)
|
||||
return;
|
||||
|
||||
#ifdef _CONSOLE
|
||||
#ifdef DBDEBUG_CONSOLE
|
||||
// When run in console mode, use standard out to display errors.
|
||||
cout << odbcErrMsg << endl;
|
||||
cout << "Press any key to continue..." << endl;
|
||||
@@ -994,10 +1005,12 @@ bool wxDB::Grant(int privileges, char *tableName, char *userList)
|
||||
strcat(sqlStmt, " TO ");
|
||||
strcat(sqlStmt, userList);
|
||||
|
||||
#ifdef _CONSOLE
|
||||
#ifdef DBDEBUG_CONSOLE
|
||||
cout << endl << sqlStmt << endl;
|
||||
#endif
|
||||
|
||||
WriteSqlLog(sqlStmt);
|
||||
|
||||
return(ExecSql(sqlStmt));
|
||||
|
||||
} // wxDB::Grant()
|
||||
@@ -1025,7 +1038,9 @@ bool wxDB::CreateView(char *viewName, char *colList, char *pSqlStmt)
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef _CONSOLE
|
||||
WriteSqlLog(sqlStmt);
|
||||
|
||||
#ifdef DBDEBUG_CONSOLE
|
||||
cout << endl << sqlStmt << endl;
|
||||
#endif
|
||||
|
||||
@@ -1043,7 +1058,9 @@ bool wxDB::CreateView(char *viewName, char *colList, char *pSqlStmt)
|
||||
strcat(sqlStmt, " AS ");
|
||||
strcat(sqlStmt, pSqlStmt);
|
||||
|
||||
#ifdef _CONSOLE
|
||||
WriteSqlLog(sqlStmt);
|
||||
|
||||
#ifdef DBDEBUG_CONSOLE
|
||||
cout << sqlStmt << endl;
|
||||
#endif
|
||||
|
||||
@@ -1161,6 +1178,101 @@ CcolInf *wxDB::GetColumns(char *tableName[])
|
||||
} // wxDB::GetColumns()
|
||||
|
||||
|
||||
/********** wxDB::Catalog() **********/
|
||||
bool wxDB::Catalog(char *userID, char *fileName)
|
||||
{
|
||||
assert(userID && strlen(userID));
|
||||
assert(fileName && strlen(fileName));
|
||||
|
||||
RETCODE retcode;
|
||||
SDWORD cb;
|
||||
char tblName[DB_MAX_TABLE_NAME_LEN+1];
|
||||
char tblNameSave[DB_MAX_TABLE_NAME_LEN+1];
|
||||
char colName[DB_MAX_COLUMN_NAME_LEN+1];
|
||||
SWORD sqlDataType;
|
||||
char typeName[16];
|
||||
SWORD precision, length;
|
||||
|
||||
FILE *fp = fopen(fileName,"wt");
|
||||
if (fp == NULL)
|
||||
return(FALSE);
|
||||
|
||||
SQLFreeStmt(hstmt, SQL_CLOSE);
|
||||
|
||||
int i = 0;
|
||||
char userIdUC[81];
|
||||
for (char *p = userID; *p; p++)
|
||||
userIdUC[i++] = toupper(*p);
|
||||
userIdUC[i] = 0;
|
||||
|
||||
retcode = SQLColumns(hstmt,
|
||||
NULL, 0, // All qualifiers
|
||||
(UCHAR *) userIdUC, SQL_NTS, // User specified
|
||||
NULL, 0, // All tables
|
||||
NULL, 0); // All columns
|
||||
if (retcode != SQL_SUCCESS)
|
||||
{
|
||||
DispAllErrors(henv, hdbc, hstmt);
|
||||
fclose(fp);
|
||||
return(FALSE);
|
||||
}
|
||||
|
||||
SQLBindCol(hstmt, 3, SQL_C_CHAR, tblName, DB_MAX_TABLE_NAME_LEN+1, &cb);
|
||||
SQLBindCol(hstmt, 4, SQL_C_CHAR, colName, DB_MAX_COLUMN_NAME_LEN+1, &cb);
|
||||
SQLBindCol(hstmt, 5, SQL_C_SSHORT, &sqlDataType, 0, &cb);
|
||||
SQLBindCol(hstmt, 6, SQL_C_CHAR, typeName, 16, &cb);
|
||||
SQLBindCol(hstmt, 7, SQL_C_SSHORT, &precision, 0, &cb);
|
||||
SQLBindCol(hstmt, 8, SQL_C_SSHORT, &length, 0, &cb);
|
||||
|
||||
char outStr[256];
|
||||
strcpy(tblNameSave,"");
|
||||
int cnt = 0;
|
||||
|
||||
while ((retcode = SQLFetch(hstmt)) == SQL_SUCCESS)
|
||||
{
|
||||
if (strcmp(tblName,tblNameSave))
|
||||
{
|
||||
if (cnt)
|
||||
fputs("\n", fp);
|
||||
fputs("================================ ", fp);
|
||||
fputs("================================ ", fp);
|
||||
fputs("===================== ", fp);
|
||||
fputs("========= ", fp);
|
||||
fputs("=========\n", fp);
|
||||
sprintf(outStr, "%-32s %-32s %-21s %9s %9s\n",
|
||||
"TABLE NAME", "COLUMN NAME", "DATA TYPE", "PRECISION", "LENGTH");
|
||||
fputs(outStr, fp);
|
||||
fputs("================================ ", fp);
|
||||
fputs("================================ ", fp);
|
||||
fputs("===================== ", fp);
|
||||
fputs("========= ", fp);
|
||||
fputs("=========\n", fp);
|
||||
strcpy(tblNameSave,tblName);
|
||||
}
|
||||
sprintf(outStr, "%-32s %-32s (%04d)%-15s %9d %9d\n",
|
||||
tblName, colName, sqlDataType, typeName, precision, length);
|
||||
if (fputs(outStr, fp) == EOF)
|
||||
{
|
||||
fclose(fp);
|
||||
return(FALSE);
|
||||
}
|
||||
cnt++;
|
||||
}
|
||||
|
||||
if (retcode != SQL_NO_DATA_FOUND)
|
||||
{
|
||||
DispAllErrors(henv, hdbc, hstmt);
|
||||
fclose(fp);
|
||||
return(FALSE);
|
||||
}
|
||||
|
||||
SQLFreeStmt(hstmt, SQL_CLOSE);
|
||||
fclose(fp);
|
||||
return(TRUE);
|
||||
|
||||
} // wxDB::Catalog()
|
||||
|
||||
|
||||
// Table name can refer to a table, view, alias or synonym. Returns true
|
||||
// if the object exists in the database. This function does not indicate
|
||||
// whether or not the user has privleges to query or perform other functions
|
||||
@@ -1190,6 +1302,54 @@ bool wxDB::TableExists(char *tableName)
|
||||
} // wxDB::TableExists()
|
||||
|
||||
|
||||
/********** wxDB::SqlLog() **********/
|
||||
bool wxDB::SqlLog(enum sqlLog state, char *filename, bool append)
|
||||
{
|
||||
assert(state == sqlLogON || state == sqlLogOFF);
|
||||
assert(state == sqlLogOFF || filename);
|
||||
|
||||
if (state == sqlLogON)
|
||||
{
|
||||
if (fpSqlLog == 0)
|
||||
{
|
||||
fpSqlLog = fopen(filename, (append ? "at" : "wt"));
|
||||
if (fpSqlLog == NULL)
|
||||
return(FALSE);
|
||||
}
|
||||
}
|
||||
else // sqlLogOFF
|
||||
{
|
||||
if (fpSqlLog)
|
||||
{
|
||||
if (fclose(fpSqlLog))
|
||||
return(FALSE);
|
||||
fpSqlLog = 0;
|
||||
}
|
||||
}
|
||||
|
||||
sqlLogState = state;
|
||||
return(TRUE);
|
||||
|
||||
} // wxDB::SqlLog()
|
||||
|
||||
|
||||
/********** wxDB::WriteSqlLog() **********/
|
||||
bool wxDB::WriteSqlLog(char *logMsg)
|
||||
{
|
||||
assert(logMsg);
|
||||
|
||||
if (fpSqlLog == 0 || sqlLogState == sqlLogOFF)
|
||||
return(FALSE);
|
||||
|
||||
if (fputs("\n", fpSqlLog) == EOF) return(FALSE);
|
||||
if (fputs(logMsg, fpSqlLog) == EOF) return(FALSE);
|
||||
if (fputs("\n", fpSqlLog) == EOF) return(FALSE);
|
||||
|
||||
return(TRUE);
|
||||
|
||||
} // wxDB::WriteSqlLog()
|
||||
|
||||
|
||||
/********** GetDbConnection() **********/
|
||||
wxDB *GetDbConnection(DbStuff *pDbStuff)
|
||||
{
|
||||
@@ -1319,4 +1479,5 @@ bool GetDataSource(HENV henv, char *Dsn, SWORD DsnMax, char *DsDesc, SWORD DsDes
|
||||
} // GetDataSource()
|
||||
|
||||
#endif
|
||||
// wxUSE_ODBC
|
||||
// wxUSE_ODBC
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: table.cpp
|
||||
// Name: dbtable.cpp
|
||||
// Purpose: Implementation of the wxTable class.
|
||||
// Author: Doug Card
|
||||
// Modified by:
|
||||
@@ -18,6 +18,10 @@
|
||||
// the wxWindows GUI development toolkit.
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "dbtable.h"
|
||||
#endif
|
||||
|
||||
/*
|
||||
// SYNOPSIS START
|
||||
// SYNOPSIS STOP
|
||||
@@ -46,14 +50,15 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
#ifdef __WXUNIX__
|
||||
#ifdef __UNIX__
|
||||
// The HPUX preprocessor lines below were commented out on 8/20/97
|
||||
// because macros.h currently redefines DEBUG and is unneeded.
|
||||
// # ifdef HPUX
|
||||
// # include <macros.h>
|
||||
// # endif
|
||||
# ifdef __WXLINUX__
|
||||
# ifdef LINUX
|
||||
# include <sys/minmax.h>
|
||||
# endif
|
||||
#endif
|
||||
@@ -63,16 +68,22 @@ wxTable::wxTable(wxDB *pwxDB, const char *tblName, const int nCols, const char *
|
||||
{
|
||||
// Assign member variables
|
||||
pDb = pwxDB; // Pointer to the wxDB object
|
||||
|
||||
strcpy(tableName, tblName); // Table Name
|
||||
if (qryTblName) // Name of the table/view to query
|
||||
strcpy(queryTableName, qryTblName);
|
||||
else
|
||||
strcpy(queryTableName, tblName);
|
||||
|
||||
noCols = nCols; // No. of cols in the table
|
||||
where = 0; // Where clause
|
||||
orderBy = 0; // Order By clause
|
||||
selectForUpdate = FALSE; // SELECT ... FOR UPDATE; Indicates whether to include the FOR UPDATE phrase
|
||||
assert(pDb); // Assert is placed after table name is assigned for error reporting reasons
|
||||
if (!pDb)
|
||||
return;
|
||||
|
||||
noCols = nCols; // No. of cols in the table
|
||||
where = 0; // Where clause
|
||||
orderBy = 0; // Order By clause
|
||||
from = 0; // From clause
|
||||
selectForUpdate = FALSE; // SELECT ... FOR UPDATE; Indicates whether to include the FOR UPDATE phrase
|
||||
|
||||
// Grab the HENV and HDBC from the wxDB object
|
||||
henv = pDb->henv;
|
||||
@@ -214,15 +225,18 @@ wxTable::~wxTable()
|
||||
/********** wxTable::Open() **********/
|
||||
bool wxTable::Open(void)
|
||||
{
|
||||
if (!pDb)
|
||||
return FALSE;
|
||||
|
||||
int i;
|
||||
char sqlStmt[DB_MAX_STATEMENT_LEN];
|
||||
|
||||
// Verify that the table exists in the database
|
||||
if (!pDb->TableExists(tableName))
|
||||
{
|
||||
wxString s;
|
||||
s.Printf("Error opening '%s', table/view does not exist in the database.", tableName);
|
||||
pDb->LogError(WXSTRINGCAST(s));
|
||||
char s[128];
|
||||
sprintf(s, "Error opening '%s', table/view does not exist in the database.", tableName);
|
||||
pDb->LogError(s);
|
||||
return(FALSE);
|
||||
}
|
||||
|
||||
@@ -272,6 +286,8 @@ bool wxTable::Open(void)
|
||||
}
|
||||
strcat(sqlStmt, ")");
|
||||
|
||||
pDb->WriteSqlLog(sqlStmt);
|
||||
|
||||
// Prepare the insert statement for execution
|
||||
if (SQLPrepare(hstmtInsert, (UCHAR FAR *) sqlStmt, SQL_NTS) != SQL_SUCCESS)
|
||||
return(pDb->DispAllErrors(henv, hdbc, hstmtInsert));
|
||||
@@ -293,6 +309,7 @@ bool wxTable::Query(bool forUpdate, bool distinct)
|
||||
/********** wxTable::QueryBySqlStmt() **********/
|
||||
bool wxTable::QueryBySqlStmt(char *pSqlStmt)
|
||||
{
|
||||
pDb->WriteSqlLog(pSqlStmt);
|
||||
|
||||
return(query(DB_SELECT_STATEMENT, FALSE, FALSE, pSqlStmt));
|
||||
|
||||
@@ -328,7 +345,10 @@ bool wxTable::query(int queryType, bool forUpdate, bool distinct, char *pSqlStmt
|
||||
|
||||
// Set the SQL SELECT string
|
||||
if (queryType != DB_SELECT_STATEMENT) // A select statement was not passed in,
|
||||
GetSelectStmt(sqlStmt, queryType, distinct); // so generate a select statement.
|
||||
{ // so generate a select statement.
|
||||
GetSelectStmt(sqlStmt, queryType, distinct);
|
||||
pDb->WriteSqlLog(sqlStmt);
|
||||
}
|
||||
|
||||
// Make sure the cursor is closed first
|
||||
if (! CloseCursor(hstmt))
|
||||
@@ -358,9 +378,21 @@ void wxTable::GetSelectStmt(char *pSqlStmt, int typeOfSelect, bool distinct)
|
||||
if (distinct)
|
||||
strcat(pSqlStmt, "DISTINCT ");
|
||||
|
||||
// Was a FROM clause specified to join tables to the base table?
|
||||
// Available for ::Query() only!!!
|
||||
bool appendFromClause = FALSE;
|
||||
if (typeOfSelect == DB_SELECT_WHERE && from && strlen(from))
|
||||
appendFromClause = TRUE;
|
||||
|
||||
// Add the column list
|
||||
for (int i = 0; i < noCols; i++)
|
||||
{
|
||||
// If joining tables, the base table column names must be qualified to avoid ambiguity
|
||||
if (appendFromClause)
|
||||
{
|
||||
strcat(pSqlStmt, queryTableName);
|
||||
strcat(pSqlStmt, ".");
|
||||
}
|
||||
strcat(pSqlStmt, colDefs[i].ColName);
|
||||
if (i + 1 < noCols)
|
||||
strcat(pSqlStmt, ",");
|
||||
@@ -369,11 +401,23 @@ void wxTable::GetSelectStmt(char *pSqlStmt, int typeOfSelect, bool distinct)
|
||||
// If the datasource supports ROWID, get this column as well. Exception: Don't retrieve
|
||||
// the ROWID if querying distinct records. The rowid will always be unique.
|
||||
if (!distinct && CanUpdByROWID())
|
||||
strcat(pSqlStmt, ",ROWID");
|
||||
{
|
||||
// If joining tables, the base table column names must be qualified to avoid ambiguity
|
||||
if (appendFromClause)
|
||||
{
|
||||
strcat(pSqlStmt, ",");
|
||||
strcat(pSqlStmt, queryTableName);
|
||||
strcat(pSqlStmt, ".ROWID");
|
||||
}
|
||||
else
|
||||
strcat(pSqlStmt, ",ROWID");
|
||||
}
|
||||
|
||||
// Append the FROM tablename portion
|
||||
strcat(pSqlStmt, " FROM ");
|
||||
strcat(pSqlStmt, queryTableName);
|
||||
if (appendFromClause)
|
||||
strcat(pSqlStmt, from);
|
||||
|
||||
// Append the WHERE clause. Either append the where clause for the class
|
||||
// or build a where clause. The typeOfSelect determines this.
|
||||
@@ -468,12 +512,9 @@ bool wxTable::bindInsertParams(void)
|
||||
UDWORD precision;
|
||||
SWORD scale;
|
||||
|
||||
//glt CcolDef *tColDef;
|
||||
|
||||
// Bind each column (that can be inserted) of the table to a parameter marker
|
||||
for (int i = 0; i < noCols; i++)
|
||||
{
|
||||
//glt tColDef = &colDefs[i];
|
||||
if (! colDefs[i].InsertAllowed)
|
||||
continue;
|
||||
switch(colDefs[i].DbDataType)
|
||||
@@ -606,6 +647,9 @@ bool wxTable::CloseCursor(HSTMT cursor)
|
||||
/********** wxTable::CreateTable() **********/
|
||||
bool wxTable::CreateTable(void)
|
||||
{
|
||||
if (!pDb)
|
||||
return FALSE;
|
||||
|
||||
int i, j;
|
||||
char sqlStmt[DB_MAX_STATEMENT_LEN];
|
||||
|
||||
@@ -632,6 +676,8 @@ bool wxTable::CreateTable(void)
|
||||
}
|
||||
}
|
||||
|
||||
pDb->WriteSqlLog(sqlStmt);
|
||||
|
||||
// Commit the transaction and close the cursor
|
||||
if (! pDb->CommitTrans())
|
||||
return(FALSE);
|
||||
@@ -694,11 +740,11 @@ bool wxTable::CreateTable(void)
|
||||
// For varchars, append the size of the string
|
||||
if (colDefs[i].DbDataType == DB_DATA_TYPE_VARCHAR)
|
||||
{
|
||||
char s[10];
|
||||
// strcat(sqlStmt, "(");
|
||||
// strcat(sqlStmt, itoa(colDefs[i].SzDataObj, s, 10));
|
||||
// strcat(sqlStmt, ")");
|
||||
wxString s;
|
||||
s.Printf("(%d)", colDefs[i].SzDataObj);
|
||||
sprintf(s, "(%d)", colDefs[i].SzDataObj);
|
||||
strcat(sqlStmt, s);
|
||||
}
|
||||
needComma = TRUE;
|
||||
@@ -732,6 +778,8 @@ bool wxTable::CreateTable(void)
|
||||
// Append the closing parentheses for the create table statement
|
||||
strcat(sqlStmt, ")");
|
||||
|
||||
pDb->WriteSqlLog(sqlStmt);
|
||||
|
||||
#ifdef _CONSOLE
|
||||
cout << endl << sqlStmt << endl;
|
||||
#endif
|
||||
@@ -787,6 +835,8 @@ bool wxTable::CreateIndex(char * idxName, bool unique, int noIdxCols, CidxDef *p
|
||||
// Append closing parentheses
|
||||
strcat(sqlStmt, ")");
|
||||
|
||||
pDb->WriteSqlLog(sqlStmt);
|
||||
|
||||
#ifdef _CONSOLE
|
||||
cout << endl << sqlStmt << endl << endl;
|
||||
#endif
|
||||
@@ -837,6 +887,7 @@ int wxTable::Insert(void)
|
||||
/********** wxTable::Update(pSqlStmt) **********/
|
||||
bool wxTable::Update(char *pSqlStmt)
|
||||
{
|
||||
pDb->WriteSqlLog(pSqlStmt);
|
||||
|
||||
return(execUpdate(pSqlStmt));
|
||||
|
||||
@@ -850,6 +901,8 @@ bool wxTable::Update(void)
|
||||
// Build the SQL UPDATE statement
|
||||
GetUpdateStmt(sqlStmt, DB_UPD_KEYFIELDS);
|
||||
|
||||
pDb->WriteSqlLog(sqlStmt);
|
||||
|
||||
#ifdef _CONSOLE
|
||||
cout << endl << sqlStmt << endl << endl;
|
||||
#endif
|
||||
@@ -867,6 +920,8 @@ bool wxTable::UpdateWhere(char *pWhereClause)
|
||||
// Build the SQL UPDATE statement
|
||||
GetUpdateStmt(sqlStmt, DB_UPD_WHERE, pWhereClause);
|
||||
|
||||
pDb->WriteSqlLog(sqlStmt);
|
||||
|
||||
#ifdef _CONSOLE
|
||||
cout << endl << sqlStmt << endl << endl;
|
||||
#endif
|
||||
@@ -884,6 +939,8 @@ bool wxTable::Delete(void)
|
||||
// Build the SQL DELETE statement
|
||||
GetDeleteStmt(sqlStmt, DB_DEL_KEYFIELDS);
|
||||
|
||||
pDb->WriteSqlLog(sqlStmt);
|
||||
|
||||
// Execute the SQL DELETE statement
|
||||
return(execDelete(sqlStmt));
|
||||
|
||||
@@ -897,6 +954,8 @@ bool wxTable::DeleteWhere(char *pWhereClause)
|
||||
// Build the SQL DELETE statement
|
||||
GetDeleteStmt(sqlStmt, DB_DEL_WHERE, pWhereClause);
|
||||
|
||||
pDb->WriteSqlLog(sqlStmt);
|
||||
|
||||
// Execute the SQL DELETE statement
|
||||
return(execDelete(sqlStmt));
|
||||
|
||||
@@ -910,6 +969,8 @@ bool wxTable::DeleteMatching(void)
|
||||
// Build the SQL DELETE statement
|
||||
GetDeleteStmt(sqlStmt, DB_DEL_MATCHING);
|
||||
|
||||
pDb->WriteSqlLog(sqlStmt);
|
||||
|
||||
// Execute the SQL DELETE statement
|
||||
return(execDelete(sqlStmt));
|
||||
|
||||
@@ -1061,10 +1122,10 @@ void wxTable::GetDeleteStmt(char *pSqlStmt, int typeOfDel, char *pWhereClause)
|
||||
* They are not included as part of the where clause.
|
||||
*/
|
||||
|
||||
void wxTable::GetWhereClause(char *pWhereClause, int typeOfWhere)
|
||||
void wxTable::GetWhereClause(char *pWhereClause, int typeOfWhere, char *qualTableName)
|
||||
{
|
||||
bool moreThanOneColumn = FALSE;
|
||||
wxString colValue;
|
||||
char colValue[255];
|
||||
|
||||
// Loop through the columns building a where clause as you go
|
||||
for (int i = 0; i < noCols; i++)
|
||||
@@ -1082,30 +1143,35 @@ void wxTable::GetWhereClause(char *pWhereClause, int typeOfWhere)
|
||||
else
|
||||
moreThanOneColumn = TRUE;
|
||||
// Concatenate where phrase for the column
|
||||
if (qualTableName && strlen(qualTableName))
|
||||
{
|
||||
strcat(pWhereClause, qualTableName);
|
||||
strcat(pWhereClause, ".");
|
||||
}
|
||||
strcat(pWhereClause, colDefs[i].ColName);
|
||||
strcat(pWhereClause, " = ");
|
||||
switch(colDefs[i].SqlCtype)
|
||||
{
|
||||
case SQL_C_CHAR:
|
||||
colValue.Printf("'%s'", (UCHAR FAR *) colDefs[i].PtrDataObj);
|
||||
sprintf(colValue, "'%s'", (UCHAR FAR *) colDefs[i].PtrDataObj);
|
||||
break;
|
||||
case SQL_C_SSHORT:
|
||||
colValue.Printf("%hi", *((SWORD *) colDefs[i].PtrDataObj));
|
||||
sprintf(colValue, "%hi", *((SWORD *) colDefs[i].PtrDataObj));
|
||||
break;
|
||||
case SQL_C_USHORT:
|
||||
colValue.Printf("%hu", *((UWORD *) colDefs[i].PtrDataObj));
|
||||
sprintf(colValue, "%hu", *((UWORD *) colDefs[i].PtrDataObj));
|
||||
break;
|
||||
case SQL_C_SLONG:
|
||||
colValue.Printf("%li", *((SDWORD *) colDefs[i].PtrDataObj));
|
||||
sprintf(colValue, "%li", *((SDWORD *) colDefs[i].PtrDataObj));
|
||||
break;
|
||||
case SQL_C_ULONG:
|
||||
colValue.Printf("%lu", *((UDWORD *) colDefs[i].PtrDataObj));
|
||||
sprintf(colValue, "%lu", *((UDWORD *) colDefs[i].PtrDataObj));
|
||||
break;
|
||||
case SQL_C_FLOAT:
|
||||
colValue.Printf("%.6f", *((SFLOAT *) colDefs[i].PtrDataObj));
|
||||
sprintf(colValue, "%.6f", *((SFLOAT *) colDefs[i].PtrDataObj));
|
||||
break;
|
||||
case SQL_C_DOUBLE:
|
||||
colValue.Printf("%.6f", *((SDOUBLE *) colDefs[i].PtrDataObj));
|
||||
sprintf(colValue, "%.6f", *((SDOUBLE *) colDefs[i].PtrDataObj));
|
||||
break;
|
||||
}
|
||||
strcat(pWhereClause, colValue);
|
||||
@@ -1161,7 +1227,8 @@ bool wxTable::CanSelectForUpdate(void)
|
||||
bool wxTable::CanUpdByROWID(void)
|
||||
{
|
||||
|
||||
//@@@@@@glt - returning FALSE for testing purposes, as the ROWID is not getting updated correctly
|
||||
//NOTE: Returning FALSE for now until this can be debugged,
|
||||
// as the ROWID is not getting updated correctly
|
||||
return FALSE;
|
||||
|
||||
if ((! strcmp(pDb->dbInf.dbmsName, "Oracle")) || (! strcmp(pDb->dbInf.dbmsName, "ORACLE")))
|
||||
@@ -1345,6 +1412,9 @@ ULONG wxTable::Count(void)
|
||||
strcpy(sqlStmt, "SELECT COUNT(*) FROM ");
|
||||
strcat(sqlStmt, queryTableName);
|
||||
|
||||
if (from && strlen(from))
|
||||
strcat(sqlStmt, from);
|
||||
|
||||
// Add the where clause if one is provided
|
||||
if (where && strlen(where))
|
||||
{
|
||||
@@ -1352,6 +1422,8 @@ ULONG wxTable::Count(void)
|
||||
strcat(sqlStmt, where);
|
||||
}
|
||||
|
||||
pDb->WriteSqlLog(sqlStmt);
|
||||
|
||||
// Execute the SQL statement
|
||||
if (SQLExecDirect(hstmtCount, (UCHAR FAR *) sqlStmt, SQL_NTS) != SQL_SUCCESS)
|
||||
{
|
||||
@@ -1410,7 +1482,8 @@ bool wxTable::Refresh(void)
|
||||
// based on the key fields.
|
||||
if (SQLGetData(hstmt, noCols+1, SQL_C_CHAR, rowid, ROWID_LEN, &cb) == SQL_SUCCESS)
|
||||
{
|
||||
strcat(whereClause, "ROWID = '");
|
||||
strcat(whereClause, queryTableName);
|
||||
strcat(whereClause, ".ROWID = '");
|
||||
strcat(whereClause, rowid);
|
||||
strcat(whereClause, "'");
|
||||
}
|
||||
@@ -1418,7 +1491,7 @@ bool wxTable::Refresh(void)
|
||||
|
||||
// If unable to use the ROWID, build a where clause from the keyfields
|
||||
if (strlen(whereClause) == 0)
|
||||
GetWhereClause(whereClause, DB_WHERE_KEYFIELDS);
|
||||
GetWhereClause(whereClause, DB_WHERE_KEYFIELDS, queryTableName);
|
||||
|
||||
// Requery the record
|
||||
where = whereClause;
|
||||
@@ -1442,4 +1515,5 @@ bool wxTable::Refresh(void)
|
||||
} // wxTable::Refresh()
|
||||
|
||||
#endif
|
||||
// wxUSE_ODBC
|
||||
// wxUSE_ODBC
|
||||
|
||||
|
@@ -1075,6 +1075,19 @@ bool wxString::Matches(const char *pszMask) const
|
||||
return *pszTxt == '\0';
|
||||
}
|
||||
|
||||
// Count the number of chars
|
||||
int wxString::Freq(char ch) const
|
||||
{
|
||||
int count = 0;
|
||||
int len = Len();
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
if (GetChar(i) == ch)
|
||||
count ++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// standard C++ library string functions
|
||||
// ---------------------------------------------------------------------------
|
||||
|
Reference in New Issue
Block a user