Replaced tabs and cleaned up indentations.
Replaced all the char arrays I could with wxStrings. Should noticably reduce memory used by classes. Fixed "for (int i=0...)" occurances git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@5755 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -100,7 +100,8 @@ DbList WXDLLEXPORT *PtrBegDbList = 0;
|
|||||||
// SQL Log defaults to be used by GetDbConnection
|
// SQL Log defaults to be used by GetDbConnection
|
||||||
enum sqlLog SQLLOGstate = sqlLogOFF;
|
enum sqlLog SQLLOGstate = sqlLogOFF;
|
||||||
|
|
||||||
char SQLLOGfn[DB_PATH_MAX+1] = "sqllog.txt";
|
//char SQLLOGfn[DB_PATH_MAX+1] = SQL_LOG_FILENAME;
|
||||||
|
char *SQLLOGfn = SQL_LOG_FILENAME;
|
||||||
|
|
||||||
// The wxDB::errorList is copied to this variable when the wxDB object
|
// The wxDB::errorList is copied to this variable when the wxDB object
|
||||||
// is closed. This way, the error list is still available after the
|
// is closed. This way, the error list is still available after the
|
||||||
@@ -117,7 +118,8 @@ wxColFor::wxColFor()
|
|||||||
{
|
{
|
||||||
i_Nation = 0; // 0=EU, 1=UK, 2=International, 3=US
|
i_Nation = 0; // 0=EU, 1=UK, 2=International, 3=US
|
||||||
s_Field = "";
|
s_Field = "";
|
||||||
for (int i=0;i<7;i++)
|
int i;
|
||||||
|
for (i=0;i<7;i++)
|
||||||
{
|
{
|
||||||
s_Format[i] = "";
|
s_Format[i] = "";
|
||||||
s_Menge[i] = "";
|
s_Menge[i] = "";
|
||||||
@@ -504,6 +506,7 @@ bool wxDB::getDbInfo(void)
|
|||||||
// After upgrading to MSVC6, the original 20 char buffer below was insufficient,
|
// After upgrading to MSVC6, the original 20 char buffer below was insufficient,
|
||||||
// causing database connectivity to fail in some cases.
|
// causing database connectivity to fail in some cases.
|
||||||
retcode = SQLGetInfo(hdbc, SQL_DBMS_VER, (UCHAR*) dbInf.dbmsVer, 64, &cb);
|
retcode = SQLGetInfo(hdbc, SQL_DBMS_VER, (UCHAR*) dbInf.dbmsVer, 64, &cb);
|
||||||
|
|
||||||
if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO )
|
if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO )
|
||||||
return(DispAllErrors(henv, hdbc));
|
return(DispAllErrors(henv, hdbc));
|
||||||
|
|
||||||
@@ -883,15 +886,14 @@ void wxDB::Close(void)
|
|||||||
CstructTablesInUse *tiu;
|
CstructTablesInUse *tiu;
|
||||||
wxNode *pNode;
|
wxNode *pNode;
|
||||||
pNode = TablesInUse.First();
|
pNode = TablesInUse.First();
|
||||||
char s[80];
|
wxString s,s2;
|
||||||
char s2[80];
|
|
||||||
while (pNode)
|
while (pNode)
|
||||||
{
|
{
|
||||||
tiu = (CstructTablesInUse *)pNode->Data();
|
tiu = (CstructTablesInUse *)pNode->Data();
|
||||||
if (tiu->pDb == this)
|
if (tiu->pDb == this)
|
||||||
{
|
{
|
||||||
sprintf(s, "(%-20s) tableID:[%6lu] pDb:[%p]", tiu->tableName,tiu->tableID,tiu->pDb);
|
s.sprintf("(%-20s) tableID:[%6lu] pDb:[%p]", tiu->tableName,tiu->tableID,tiu->pDb);
|
||||||
sprintf(s2,"Orphaned found using pDb:[%p]",this);
|
s2.sprintf("Orphaned found using pDb:[%p]",this);
|
||||||
wxMessageBox (s,s2);
|
wxMessageBox (s,s2);
|
||||||
}
|
}
|
||||||
pNode = pNode->Next();
|
pNode = pNode->Next();
|
||||||
@@ -938,24 +940,25 @@ bool wxDB::RollbackTrans(void)
|
|||||||
/********** wxDB::DispAllErrors() **********/
|
/********** wxDB::DispAllErrors() **********/
|
||||||
bool wxDB::DispAllErrors(HENV aHenv, HDBC aHdbc, HSTMT aHstmt)
|
bool wxDB::DispAllErrors(HENV aHenv, HDBC aHdbc, HSTMT aHstmt)
|
||||||
{
|
{
|
||||||
char odbcErrMsg[DB_MAX_ERROR_MSG_LEN];
|
// char odbcErrMsg[DB_MAX_ERROR_MSG_LEN];
|
||||||
|
wxString odbcErrMsg;
|
||||||
|
|
||||||
while (SQLError(aHenv, aHdbc, aHstmt, (UCHAR FAR *) sqlState, &nativeError, (UCHAR FAR *) errorMsg, SQL_MAX_MESSAGE_LENGTH - 1, &cbErrorMsg) == SQL_SUCCESS)
|
while (SQLError(aHenv, aHdbc, aHstmt, (UCHAR FAR *) sqlState, &nativeError, (UCHAR FAR *) errorMsg, SQL_MAX_MESSAGE_LENGTH - 1, &cbErrorMsg) == SQL_SUCCESS)
|
||||||
{
|
{
|
||||||
sprintf(odbcErrMsg, "SQL State = %s\nNative Error Code = %li\nError Message = %s\n", sqlState, nativeError, errorMsg);
|
odbcErrMsg.sprintf("SQL State = %s\nNative Error Code = %li\nError Message = %s\n", sqlState, nativeError, errorMsg);
|
||||||
logError(odbcErrMsg, sqlState);
|
logError(odbcErrMsg.GetData(), sqlState);
|
||||||
if (!silent)
|
if (!silent)
|
||||||
{
|
{
|
||||||
#ifdef DBDEBUG_CONSOLE
|
#ifdef DBDEBUG_CONSOLE
|
||||||
// When run in console mode, use standard out to display errors.
|
// When run in console mode, use standard out to display errors.
|
||||||
cout << odbcErrMsg << endl;
|
cout << odbcErrMsg.GetData() << endl;
|
||||||
cout << "Press any key to continue..." << endl;
|
cout << "Press any key to continue..." << endl;
|
||||||
getchar();
|
getchar();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __WXDEBUG__
|
#ifdef __WXDEBUG__
|
||||||
wxMessageBox(odbcErrMsg);
|
wxMessageBox(odbcErrMsg.GetData(),"DEBUG MESSAGE from DispAllErrors()");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -978,17 +981,18 @@ bool wxDB::GetNextError(HENV aHenv, HDBC aHdbc, HSTMT aHstmt)
|
|||||||
/********** wxDB::DispNextError() **********/
|
/********** wxDB::DispNextError() **********/
|
||||||
void wxDB::DispNextError(void)
|
void wxDB::DispNextError(void)
|
||||||
{
|
{
|
||||||
char odbcErrMsg[DB_MAX_ERROR_MSG_LEN];
|
// char odbcErrMsg[DB_MAX_ERROR_MSG_LEN];
|
||||||
|
wxString odbcErrMsg;
|
||||||
|
|
||||||
sprintf(odbcErrMsg, "SQL State = %s\nNative Error Code = %li\nError Message = %s\n", sqlState, nativeError, errorMsg);
|
odbcErrMsg.sprintf("SQL State = %s\nNative Error Code = %li\nError Message = %s\n", sqlState, nativeError, errorMsg);
|
||||||
logError(odbcErrMsg, sqlState);
|
logError(odbcErrMsg.GetData(), sqlState);
|
||||||
|
|
||||||
if (silent)
|
if (silent)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
#ifdef DBDEBUG_CONSOLE
|
#ifdef DBDEBUG_CONSOLE
|
||||||
// When run in console mode, use standard out to display errors.
|
// When run in console mode, use standard out to display errors.
|
||||||
cout << odbcErrMsg << endl;
|
cout << odbcErrMsg.GetData() << endl;
|
||||||
cout << "Press any key to continue..." << endl;
|
cout << "Press any key to continue..." << endl;
|
||||||
getchar();
|
getchar();
|
||||||
#endif
|
#endif
|
||||||
@@ -1215,52 +1219,53 @@ int wxDB::TranslateSqlState(const char *SQLState)
|
|||||||
/********** wxDB::Grant() **********/
|
/********** wxDB::Grant() **********/
|
||||||
bool wxDB::Grant(int privileges, const char *tableName, const char *userList)
|
bool wxDB::Grant(int privileges, const char *tableName, const char *userList)
|
||||||
{
|
{
|
||||||
char sqlStmt[DB_MAX_STATEMENT_LEN];
|
// char sqlStmt[DB_MAX_STATEMENT_LEN];
|
||||||
|
wxString sqlStmt;
|
||||||
|
|
||||||
// Build the grant statement
|
// Build the grant statement
|
||||||
wxStrcpy(sqlStmt, "GRANT ");
|
sqlStmt = "GRANT ";
|
||||||
if (privileges == DB_GRANT_ALL)
|
if (privileges == DB_GRANT_ALL)
|
||||||
wxStrcat(sqlStmt, "ALL");
|
sqlStmt += "ALL";
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int c = 0;
|
int c = 0;
|
||||||
if (privileges & DB_GRANT_SELECT)
|
if (privileges & DB_GRANT_SELECT)
|
||||||
{
|
{
|
||||||
wxStrcat(sqlStmt, "SELECT");
|
sqlStmt += "SELECT";
|
||||||
c++;
|
c++;
|
||||||
}
|
}
|
||||||
if (privileges & DB_GRANT_INSERT)
|
if (privileges & DB_GRANT_INSERT)
|
||||||
{
|
{
|
||||||
if (c++)
|
if (c++)
|
||||||
wxStrcat(sqlStmt, ", ");
|
sqlStmt += ", ";
|
||||||
wxStrcat(sqlStmt, "INSERT");
|
sqlStmt += "INSERT";
|
||||||
}
|
}
|
||||||
if (privileges & DB_GRANT_UPDATE)
|
if (privileges & DB_GRANT_UPDATE)
|
||||||
{
|
{
|
||||||
if (c++)
|
if (c++)
|
||||||
wxStrcat(sqlStmt, ", ");
|
sqlStmt += ", ";
|
||||||
wxStrcat(sqlStmt, "UPDATE");
|
sqlStmt += "UPDATE";
|
||||||
}
|
}
|
||||||
if (privileges & DB_GRANT_DELETE)
|
if (privileges & DB_GRANT_DELETE)
|
||||||
{
|
{
|
||||||
if (c++)
|
if (c++)
|
||||||
wxStrcat(sqlStmt, ", ");
|
sqlStmt += ", ";
|
||||||
wxStrcat(sqlStmt, "DELETE");
|
sqlStmt += "DELETE";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
wxStrcat(sqlStmt, " ON ");
|
sqlStmt += " ON ";
|
||||||
wxStrcat(sqlStmt, tableName);
|
sqlStmt += tableName;
|
||||||
wxStrcat(sqlStmt, " TO ");
|
sqlStmt += " TO ";
|
||||||
wxStrcat(sqlStmt, userList);
|
sqlStmt += userList;
|
||||||
|
|
||||||
#ifdef DBDEBUG_CONSOLE
|
#ifdef DBDEBUG_CONSOLE
|
||||||
cout << endl << sqlStmt << endl;
|
cout << endl << sqlStmt.GetData() << endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
WriteSqlLog(sqlStmt);
|
WriteSqlLog(sqlStmt.GetData());
|
||||||
|
|
||||||
return(ExecSql(sqlStmt));
|
return(ExecSql(sqlStmt.GetData()));
|
||||||
|
|
||||||
} // wxDB::Grant()
|
} // wxDB::Grant()
|
||||||
|
|
||||||
@@ -1268,33 +1273,34 @@ bool wxDB::Grant(int privileges, const char *tableName, const char *userList)
|
|||||||
/********** wxDB::CreateView() **********/
|
/********** wxDB::CreateView() **********/
|
||||||
bool wxDB::CreateView(const char *viewName, const char *colList, const char *pSqlStmt, bool attemptDrop)
|
bool wxDB::CreateView(const char *viewName, const char *colList, const char *pSqlStmt, bool attemptDrop)
|
||||||
{
|
{
|
||||||
char sqlStmt[DB_MAX_STATEMENT_LEN];
|
// char sqlStmt[DB_MAX_STATEMENT_LEN];
|
||||||
|
wxString sqlStmt;
|
||||||
|
|
||||||
// Drop the view first
|
// Drop the view first
|
||||||
if (attemptDrop && !DropView(viewName))
|
if (attemptDrop && !DropView(viewName))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
// Build the create view statement
|
// Build the create view statement
|
||||||
wxStrcpy(sqlStmt, "CREATE VIEW ");
|
sqlStmt = "CREATE VIEW ";
|
||||||
wxStrcat(sqlStmt, viewName);
|
sqlStmt += viewName;
|
||||||
|
|
||||||
if (wxStrlen(colList))
|
if (wxStrlen(colList))
|
||||||
{
|
{
|
||||||
wxStrcat(sqlStmt, " (");
|
sqlStmt += " (";
|
||||||
wxStrcat(sqlStmt, colList);
|
sqlStmt += colList;
|
||||||
wxStrcat(sqlStmt, ")");
|
sqlStmt += ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
wxStrcat(sqlStmt, " AS ");
|
sqlStmt += " AS ";
|
||||||
wxStrcat(sqlStmt, pSqlStmt);
|
sqlStmt += pSqlStmt;
|
||||||
|
|
||||||
WriteSqlLog(sqlStmt);
|
WriteSqlLog(sqlStmt.GetData());
|
||||||
|
|
||||||
#ifdef DBDEBUG_CONSOLE
|
#ifdef DBDEBUG_CONSOLE
|
||||||
cout << sqlStmt << endl;
|
cout << sqlStmt.GetData() << endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return(ExecSql(sqlStmt));
|
return(ExecSql(sqlStmt.GetData()));
|
||||||
|
|
||||||
} // wxDB::CreateView()
|
} // wxDB::CreateView()
|
||||||
|
|
||||||
@@ -1308,17 +1314,18 @@ bool wxDB::DropView(const char *viewName)
|
|||||||
* below for any other databases when those databases are defined
|
* below for any other databases when those databases are defined
|
||||||
* to handle this situation consistently
|
* to handle this situation consistently
|
||||||
*/
|
*/
|
||||||
char sqlStmt[DB_MAX_STATEMENT_LEN];
|
// char sqlStmt[DB_MAX_STATEMENT_LEN];
|
||||||
|
wxString sqlStmt;
|
||||||
|
|
||||||
sprintf(sqlStmt, "DROP VIEW %s", viewName);
|
sqlStmt.sprintf("DROP VIEW %s", viewName);
|
||||||
|
|
||||||
WriteSqlLog(sqlStmt);
|
WriteSqlLog(sqlStmt.GetData());
|
||||||
|
|
||||||
#ifdef DBDEBUG_CONSOLE
|
#ifdef DBDEBUG_CONSOLE
|
||||||
cout << endl << sqlStmt << endl;
|
cout << endl << sqlStmt.GetData() << endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (SQLExecDirect(hstmt, (UCHAR FAR *) sqlStmt, SQL_NTS) != SQL_SUCCESS)
|
if (SQLExecDirect(hstmt, (UCHAR FAR *) sqlStmt.GetData(), SQL_NTS) != SQL_SUCCESS)
|
||||||
{
|
{
|
||||||
// Check for "Base table not found" error and ignore
|
// Check for "Base table not found" error and ignore
|
||||||
GetNextError(henv, hdbc, hstmt);
|
GetNextError(henv, hdbc, hstmt);
|
||||||
@@ -1998,7 +2005,8 @@ wxDbInf *wxDB::GetCatalog(char *userID)
|
|||||||
int pass;
|
int pass;
|
||||||
RETCODE retcode;
|
RETCODE retcode;
|
||||||
SDWORD cb;
|
SDWORD cb;
|
||||||
char tblNameSave[DB_MAX_TABLE_NAME_LEN+1];
|
// char tblNameSave[DB_MAX_TABLE_NAME_LEN+1];
|
||||||
|
wxString tblNameSave;
|
||||||
|
|
||||||
wxString UserID;
|
wxString UserID;
|
||||||
|
|
||||||
@@ -2036,7 +2044,7 @@ wxDbInf *wxDB::GetCatalog(char *userID)
|
|||||||
for (pass = 1; pass <= 2; pass++)
|
for (pass = 1; pass <= 2; pass++)
|
||||||
{
|
{
|
||||||
SQLFreeStmt(hstmt, SQL_CLOSE); // Close if Open
|
SQLFreeStmt(hstmt, SQL_CLOSE); // Close if Open
|
||||||
strcpy(tblNameSave,"");
|
tblNameSave = "";
|
||||||
|
|
||||||
if (wxStrcmp(UserID.GetData(),"") &&
|
if (wxStrcmp(UserID.GetData(),"") &&
|
||||||
Dbms() != dbmsMY_SQL &&
|
Dbms() != dbmsMY_SQL &&
|
||||||
@@ -2130,7 +2138,7 @@ bool wxDB::Catalog(const char *userID, const char *fileName)
|
|||||||
RETCODE retcode;
|
RETCODE retcode;
|
||||||
SDWORD cb;
|
SDWORD cb;
|
||||||
char tblName[DB_MAX_TABLE_NAME_LEN+1];
|
char tblName[DB_MAX_TABLE_NAME_LEN+1];
|
||||||
char tblNameSave[DB_MAX_TABLE_NAME_LEN+1];
|
wxString tblNameSave;
|
||||||
char colName[DB_MAX_COLUMN_NAME_LEN+1];
|
char colName[DB_MAX_COLUMN_NAME_LEN+1];
|
||||||
SWORD sqlDataType;
|
SWORD sqlDataType;
|
||||||
char typeName[30+1];
|
char typeName[30+1];
|
||||||
@@ -2189,12 +2197,12 @@ bool wxDB::Catalog(const char *userID, const char *fileName)
|
|||||||
}
|
}
|
||||||
|
|
||||||
wxString outStr;
|
wxString outStr;
|
||||||
wxStrcpy(tblNameSave,"");
|
tblNameSave = "";
|
||||||
int cnt = 0;
|
int cnt = 0;
|
||||||
|
|
||||||
while ((retcode = SQLFetch(hstmt)) == SQL_SUCCESS)
|
while ((retcode = SQLFetch(hstmt)) == SQL_SUCCESS)
|
||||||
{
|
{
|
||||||
if (wxStrcmp(tblName,tblNameSave))
|
if (wxStrcmp(tblName,tblNameSave.GetData()))
|
||||||
{
|
{
|
||||||
if (cnt)
|
if (cnt)
|
||||||
fputs("\n", fp);
|
fputs("\n", fp);
|
||||||
@@ -2211,7 +2219,7 @@ bool wxDB::Catalog(const char *userID, const char *fileName)
|
|||||||
fputs("===================== ", fp);
|
fputs("===================== ", fp);
|
||||||
fputs("========= ", fp);
|
fputs("========= ", fp);
|
||||||
fputs("=========\n", fp);
|
fputs("=========\n", fp);
|
||||||
wxStrcpy(tblNameSave,tblName);
|
tblNameSave = tblName;
|
||||||
}
|
}
|
||||||
|
|
||||||
GetData(3,SQL_C_CHAR, (UCHAR *)tblName, DB_MAX_TABLE_NAME_LEN+1, &cb);
|
GetData(3,SQL_C_CHAR, (UCHAR *)tblName, DB_MAX_TABLE_NAME_LEN+1, &cb);
|
||||||
@@ -2616,12 +2624,7 @@ bool GetDataSource(HENV henv, char *Dsn, SWORD DsnMax, char *DsDesc, SWORD DsDes
|
|||||||
|
|
||||||
if (SQLDataSources(henv, direction, (UCHAR FAR *) Dsn, DsnMax, &cb1,
|
if (SQLDataSources(henv, direction, (UCHAR FAR *) Dsn, DsnMax, &cb1,
|
||||||
(UCHAR FAR *) DsDesc, DsDescMax, &cb2) == SQL_SUCCESS)
|
(UCHAR FAR *) DsDesc, DsDescMax, &cb2) == SQL_SUCCESS)
|
||||||
{
|
|
||||||
#ifndef _IODBC_
|
|
||||||
DsDesc[cb2+1] = 0; // Set the terminating character for the string
|
|
||||||
#endif
|
|
||||||
return(TRUE);
|
return(TRUE);
|
||||||
}
|
|
||||||
else
|
else
|
||||||
return(FALSE);
|
return(FALSE);
|
||||||
|
|
||||||
|
@@ -141,9 +141,9 @@ wxTable::wxTable(wxDB *pwxDB, const char *tblName, const int nCols,
|
|||||||
|
|
||||||
pDb->nTables++;
|
pDb->nTables++;
|
||||||
|
|
||||||
char s[200];
|
wxString s;
|
||||||
tableID = ++lastTableID;
|
tableID = ++lastTableID;
|
||||||
sprintf(s, "wxTable constructor (%-20s) tableID:[%6lu] pDb:[%p]", tblName,tableID,pDb);
|
s.sprintf("wxTable constructor (%-20s) tableID:[%6lu] pDb:[%p]", tblName,tableID,pDb);
|
||||||
|
|
||||||
#ifdef __WXDEBUG__
|
#ifdef __WXDEBUG__
|
||||||
CstructTablesInUse *tableInUse;
|
CstructTablesInUse *tableInUse;
|
||||||
@@ -154,7 +154,7 @@ wxTable::wxTable(wxDB *pwxDB, const char *tblName, const int nCols,
|
|||||||
TablesInUse.Append(tableInUse);
|
TablesInUse.Append(tableInUse);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
pDb->WriteSqlLog(s);
|
pDb->WriteSqlLog(s.GetData());
|
||||||
|
|
||||||
// Grab the HENV and HDBC from the wxDB object
|
// Grab the HENV and HDBC from the wxDB object
|
||||||
henv = pDb->henv;
|
henv = pDb->henv;
|
||||||
@@ -245,17 +245,18 @@ wxTable::wxTable(wxDB *pwxDB, const char *tblName, const int nCols,
|
|||||||
/********** wxTable::~wxTable() **********/
|
/********** wxTable::~wxTable() **********/
|
||||||
wxTable::~wxTable()
|
wxTable::~wxTable()
|
||||||
{
|
{
|
||||||
char s[80];
|
wxString s;
|
||||||
if (pDb)
|
if (pDb)
|
||||||
{
|
{
|
||||||
sprintf(s, "wxTable destructor (%-20s) tableID:[%6lu] pDb:[%p]", tableName,tableID,pDb);
|
s.sprintf("wxTable destructor (%-20s) tableID:[%6lu] pDb:[%p]", tableName,tableID,pDb);
|
||||||
pDb->WriteSqlLog(s);
|
pDb->WriteSqlLog(s.GetData());
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __WXDEBUG__
|
#ifdef __WXDEBUG__
|
||||||
if (tableID)
|
if (tableID)
|
||||||
{
|
{
|
||||||
bool found = FALSE;
|
bool found = FALSE;
|
||||||
|
|
||||||
wxNode *pNode;
|
wxNode *pNode;
|
||||||
pNode = TablesInUse.First();
|
pNode = TablesInUse.First();
|
||||||
while (pNode && !found)
|
while (pNode && !found)
|
||||||
@@ -264,16 +265,16 @@ wxTable::~wxTable()
|
|||||||
{
|
{
|
||||||
found = TRUE;
|
found = TRUE;
|
||||||
if (!TablesInUse.DeleteNode(pNode))
|
if (!TablesInUse.DeleteNode(pNode))
|
||||||
wxMessageBox (s,"Unable to delete node!");
|
wxMessageBox (s.GetData(),"Unable to delete node!");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
pNode = pNode->Next();
|
pNode = pNode->Next();
|
||||||
}
|
}
|
||||||
if (!found)
|
if (!found)
|
||||||
{
|
{
|
||||||
char msg[250];
|
wxString msg;
|
||||||
sprintf(msg,"Unable to find the tableID in the linked\nlist of tables in use.\n\n%s",s);
|
msg.sprintf("Unable to find the tableID in the linked\nlist of tables in use.\n\n%s",s.GetData());
|
||||||
wxMessageBox (msg,"NOTICE...");
|
wxMessageBox (msg.GetData(),"NOTICE...");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -574,21 +575,22 @@ bool wxTable::Open(void)
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
char sqlStmt[DB_MAX_STATEMENT_LEN];
|
// char sqlStmt[DB_MAX_STATEMENT_LEN];
|
||||||
|
wxString sqlStmt;
|
||||||
|
|
||||||
// Verify that the table exists in the database
|
// Verify that the table exists in the database
|
||||||
if (!pDb->TableExists(tableName,pDb->GetUsername(),tablePath))
|
if (!pDb->TableExists(tableName,pDb->GetUsername(),tablePath))
|
||||||
{
|
{
|
||||||
char s[250];
|
wxString s;
|
||||||
if (wxStrcmp(tablePath,""))
|
if (wxStrcmp(tablePath,""))
|
||||||
sprintf(s, "Error opening '%s/%s'.\n",tablePath,tableName);
|
s.sprintf("Error opening '%s/%s'.\n",tablePath,tableName);
|
||||||
else
|
else
|
||||||
sprintf(s, "Error opening '%s'.\n", tableName);
|
s.sprintf("Error opening '%s'.\n", tableName);
|
||||||
if (!pDb->TableExists(tableName,NULL,tablePath))
|
if (!pDb->TableExists(tableName,NULL,tablePath))
|
||||||
wxStrcat(s,"Table/view does not exist in the database.\n");
|
s += "Table/view does not exist in the database.\n";
|
||||||
else
|
else
|
||||||
wxStrcat(s,"Current logged in user does not have sufficient privileges to access this table.\n");
|
s += "Current logged in user does not have sufficient privileges to access this table.\n";
|
||||||
pDb->LogError(s);
|
pDb->LogError(s.GetData());
|
||||||
return(FALSE);
|
return(FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -613,33 +615,33 @@ bool wxTable::Open(void)
|
|||||||
if (!queryOnly && noCols > 0)
|
if (!queryOnly && noCols > 0)
|
||||||
{
|
{
|
||||||
bool needComma = FALSE;
|
bool needComma = FALSE;
|
||||||
sprintf(sqlStmt, "INSERT INTO %s (", tableName);
|
sqlStmt.sprintf("INSERT INTO %s (", tableName);
|
||||||
for (i = 0; i < noCols; i++)
|
for (i = 0; i < noCols; i++)
|
||||||
{
|
{
|
||||||
if (! colDefs[i].InsertAllowed)
|
if (! colDefs[i].InsertAllowed)
|
||||||
continue;
|
continue;
|
||||||
if (needComma)
|
if (needComma)
|
||||||
wxStrcat(sqlStmt, ",");
|
sqlStmt += ",";
|
||||||
wxStrcat(sqlStmt, colDefs[i].ColName);
|
sqlStmt += colDefs[i].ColName;
|
||||||
needComma = TRUE;
|
needComma = TRUE;
|
||||||
}
|
}
|
||||||
needComma = FALSE;
|
needComma = FALSE;
|
||||||
wxStrcat(sqlStmt, ") VALUES (");
|
sqlStmt += ") VALUES (";
|
||||||
for (i = 0; i < noCols; i++)
|
for (i = 0; i < noCols; i++)
|
||||||
{
|
{
|
||||||
if (! colDefs[i].InsertAllowed)
|
if (! colDefs[i].InsertAllowed)
|
||||||
continue;
|
continue;
|
||||||
if (needComma)
|
if (needComma)
|
||||||
wxStrcat(sqlStmt, ",");
|
sqlStmt += ",";
|
||||||
wxStrcat(sqlStmt, "?");
|
sqlStmt += "?";
|
||||||
needComma = TRUE;
|
needComma = TRUE;
|
||||||
}
|
}
|
||||||
wxStrcat(sqlStmt, ")");
|
sqlStmt += ")";
|
||||||
|
|
||||||
// pDb->WriteSqlLog(sqlStmt);
|
// pDb->WriteSqlLog(sqlStmt);
|
||||||
|
|
||||||
// Prepare the insert statement for execution
|
// Prepare the insert statement for execution
|
||||||
if (SQLPrepare(hstmtInsert, (UCHAR FAR *) sqlStmt, SQL_NTS) != SQL_SUCCESS)
|
if (SQLPrepare(hstmtInsert, (UCHAR FAR *) sqlStmt.GetData(), SQL_NTS) != SQL_SUCCESS)
|
||||||
return(pDb->DispAllErrors(henv, hdbc, hstmtInsert));
|
return(pDb->DispAllErrors(henv, hdbc, hstmtInsert));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -884,7 +886,8 @@ bool wxTable::CreateTable(bool attemptDrop)
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
int i, j;
|
int i, j;
|
||||||
char sqlStmt[DB_MAX_STATEMENT_LEN];
|
// char sqlStmt[DB_MAX_STATEMENT_LEN];
|
||||||
|
wxString sqlStmt;
|
||||||
|
|
||||||
#ifdef DBDEBUG_CONSOLE
|
#ifdef DBDEBUG_CONSOLE
|
||||||
cout << "Creating Table " << tableName << "..." << endl;
|
cout << "Creating Table " << tableName << "..." << endl;
|
||||||
@@ -923,7 +926,8 @@ bool wxTable::CreateTable(bool attemptDrop)
|
|||||||
|
|
||||||
// Build a CREATE TABLE string from the colDefs structure.
|
// Build a CREATE TABLE string from the colDefs structure.
|
||||||
bool needComma = FALSE;
|
bool needComma = FALSE;
|
||||||
sprintf(sqlStmt, "CREATE TABLE %s (", tableName);
|
sqlStmt.sprintf("CREATE TABLE %s (", tableName);
|
||||||
|
|
||||||
for (i = 0; i < noCols; i++)
|
for (i = 0; i < noCols; i++)
|
||||||
{
|
{
|
||||||
// Exclude derived columns since they are NOT part of the base table
|
// Exclude derived columns since they are NOT part of the base table
|
||||||
@@ -931,38 +935,38 @@ bool wxTable::CreateTable(bool attemptDrop)
|
|||||||
continue;
|
continue;
|
||||||
// Comma Delimiter
|
// Comma Delimiter
|
||||||
if (needComma)
|
if (needComma)
|
||||||
wxStrcat(sqlStmt, ",");
|
sqlStmt += ",";
|
||||||
// Column Name
|
// Column Name
|
||||||
wxStrcat(sqlStmt, colDefs[i].ColName);
|
sqlStmt += colDefs[i].ColName;
|
||||||
wxStrcat(sqlStmt, " ");
|
sqlStmt += " ";
|
||||||
// Column Type
|
// Column Type
|
||||||
switch(colDefs[i].DbDataType)
|
switch(colDefs[i].DbDataType)
|
||||||
{
|
{
|
||||||
case DB_DATA_TYPE_VARCHAR:
|
case DB_DATA_TYPE_VARCHAR:
|
||||||
wxStrcat(sqlStmt, pDb->typeInfVarchar.TypeName); break;
|
sqlStmt += pDb->typeInfVarchar.TypeName; break;
|
||||||
case DB_DATA_TYPE_INTEGER:
|
case DB_DATA_TYPE_INTEGER:
|
||||||
wxStrcat(sqlStmt, pDb->typeInfInteger.TypeName); break;
|
sqlStmt += pDb->typeInfInteger.TypeName; break;
|
||||||
case DB_DATA_TYPE_FLOAT:
|
case DB_DATA_TYPE_FLOAT:
|
||||||
wxStrcat(sqlStmt, pDb->typeInfFloat.TypeName); break;
|
sqlStmt += pDb->typeInfFloat.TypeName; break;
|
||||||
case DB_DATA_TYPE_DATE:
|
case DB_DATA_TYPE_DATE:
|
||||||
wxStrcat(sqlStmt, pDb->typeInfDate.TypeName); break;
|
sqlStmt += pDb->typeInfDate.TypeName; break;
|
||||||
}
|
}
|
||||||
// For varchars, append the size of the string
|
// For varchars, append the size of the string
|
||||||
if (colDefs[i].DbDataType == DB_DATA_TYPE_VARCHAR)
|
if (colDefs[i].DbDataType == DB_DATA_TYPE_VARCHAR)
|
||||||
{
|
{
|
||||||
char s[10];
|
wxString s;
|
||||||
// wxStrcat(sqlStmt, "(");
|
// wxStrcat(sqlStmt, "(");
|
||||||
// wxStrcat(sqlStmt, itoa(colDefs[i].SzDataObj, s, 10));
|
// wxStrcat(sqlStmt, itoa(colDefs[i].SzDataObj, s, 10));
|
||||||
// wxStrcat(sqlStmt, ")");
|
// wxStrcat(sqlStmt, ")");
|
||||||
sprintf(s, "(%d)", colDefs[i].SzDataObj);
|
s.sprintf("(%d)", colDefs[i].SzDataObj);
|
||||||
wxStrcat(sqlStmt, s);
|
sqlStmt += s.GetData();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pDb->Dbms() == dbmsSYBASE_ASE || pDb->Dbms() == dbmsMY_SQL)
|
if (pDb->Dbms() == dbmsSYBASE_ASE || pDb->Dbms() == dbmsMY_SQL)
|
||||||
{
|
{
|
||||||
if (colDefs[i].KeyField)
|
if (colDefs[i].KeyField)
|
||||||
{
|
{
|
||||||
wxStrcat(sqlStmt, " NOT NULL");
|
sqlStmt += " NOT NULL";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -981,14 +985,14 @@ bool wxTable::CreateTable(bool attemptDrop)
|
|||||||
{
|
{
|
||||||
if (pDb->Dbms() != dbmsMY_SQL)
|
if (pDb->Dbms() != dbmsMY_SQL)
|
||||||
{
|
{
|
||||||
wxStrcat(sqlStmt, ",CONSTRAINT ");
|
sqlStmt += ",CONSTRAINT ";
|
||||||
wxStrcat(sqlStmt, tableName);
|
sqlStmt += tableName;
|
||||||
wxStrcat(sqlStmt, "_PIDX PRIMARY KEY (");
|
sqlStmt += "_PIDX PRIMARY KEY (";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* MySQL goes out on this one. We also declare the relevant key NON NULL above */
|
/* MySQL goes out on this one. We also declare the relevant key NON NULL above */
|
||||||
wxStrcat(sqlStmt, ", PRIMARY KEY (");
|
sqlStmt += ", PRIMARY KEY (";
|
||||||
}
|
}
|
||||||
|
|
||||||
// List column name(s) of column(s) comprising the primary key
|
// List column name(s) of column(s) comprising the primary key
|
||||||
@@ -997,23 +1001,23 @@ bool wxTable::CreateTable(bool attemptDrop)
|
|||||||
if (colDefs[i].KeyField)
|
if (colDefs[i].KeyField)
|
||||||
{
|
{
|
||||||
if (j++) // Multi part key, comma separate names
|
if (j++) // Multi part key, comma separate names
|
||||||
wxStrcat(sqlStmt, ",");
|
sqlStmt += ",";
|
||||||
wxStrcat(sqlStmt, colDefs[i].ColName);
|
sqlStmt += colDefs[i].ColName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
wxStrcat(sqlStmt, ")");
|
sqlStmt += ")";
|
||||||
}
|
}
|
||||||
// Append the closing parentheses for the create table statement
|
// Append the closing parentheses for the create table statement
|
||||||
wxStrcat(sqlStmt, ")");
|
sqlStmt += ")";
|
||||||
|
|
||||||
pDb->WriteSqlLog(sqlStmt);
|
pDb->WriteSqlLog(sqlStmt.GetData());
|
||||||
|
|
||||||
#ifdef DBDEBUG_CONSOLE
|
#ifdef DBDEBUG_CONSOLE
|
||||||
cout << endl << sqlStmt << endl;
|
cout << endl << sqlStmt.GetData() << endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Execute the CREATE TABLE statement
|
// Execute the CREATE TABLE statement
|
||||||
RETCODE retcode = SQLExecDirect(hstmt, (UCHAR FAR *) sqlStmt, SQL_NTS);
|
RETCODE retcode = SQLExecDirect(hstmt, (UCHAR FAR *) sqlStmt.GetData(), SQL_NTS);
|
||||||
if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO)
|
if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO)
|
||||||
{
|
{
|
||||||
pDb->DispAllErrors(henv, hdbc, hstmt);
|
pDb->DispAllErrors(henv, hdbc, hstmt);
|
||||||
@@ -1042,17 +1046,18 @@ bool wxTable::DropTable()
|
|||||||
// below for any other databases when those databases are defined
|
// below for any other databases when those databases are defined
|
||||||
// to handle this situation consistently
|
// to handle this situation consistently
|
||||||
|
|
||||||
char sqlStmt[DB_MAX_STATEMENT_LEN];
|
// char sqlStmt[DB_MAX_STATEMENT_LEN];
|
||||||
|
wxString sqlStmt;
|
||||||
|
|
||||||
sprintf(sqlStmt, "DROP TABLE %s", tableName);
|
sqlStmt.sprintf("DROP TABLE %s", tableName);
|
||||||
|
|
||||||
pDb->WriteSqlLog(sqlStmt);
|
pDb->WriteSqlLog(sqlStmt.GetData());
|
||||||
|
|
||||||
#ifdef DBDEBUG_CONSOLE
|
#ifdef DBDEBUG_CONSOLE
|
||||||
cout << endl << sqlStmt << endl;
|
cout << endl << sqlStmt.GetData() << endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (SQLExecDirect(hstmt, (UCHAR FAR *) sqlStmt, SQL_NTS) != SQL_SUCCESS)
|
if (SQLExecDirect(hstmt, (UCHAR FAR *) sqlStmt.GetData(), SQL_NTS) != SQL_SUCCESS)
|
||||||
{
|
{
|
||||||
// Check for "Base table not found" error and ignore
|
// Check for "Base table not found" error and ignore
|
||||||
pDb->GetNextError(henv, hdbc, hstmt);
|
pDb->GetNextError(henv, hdbc, hstmt);
|
||||||
@@ -1085,52 +1090,53 @@ bool wxTable::DropTable()
|
|||||||
/********** wxTable::CreateIndex() **********/
|
/********** wxTable::CreateIndex() **********/
|
||||||
bool wxTable::CreateIndex(const char * idxName, bool unique, int noIdxCols, CidxDef *pIdxDefs, bool attemptDrop)
|
bool wxTable::CreateIndex(const char * idxName, bool unique, int noIdxCols, CidxDef *pIdxDefs, bool attemptDrop)
|
||||||
{
|
{
|
||||||
char sqlStmt[DB_MAX_STATEMENT_LEN];
|
// char sqlStmt[DB_MAX_STATEMENT_LEN];
|
||||||
|
wxString sqlStmt;
|
||||||
|
|
||||||
// Drop the index first
|
// Drop the index first
|
||||||
if (attemptDrop && !DropIndex(idxName))
|
if (attemptDrop && !DropIndex(idxName))
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
|
|
||||||
// Build a CREATE INDEX statement
|
// Build a CREATE INDEX statement
|
||||||
wxStrcpy(sqlStmt, "CREATE ");
|
sqlStmt = "CREATE ";
|
||||||
if (unique)
|
if (unique)
|
||||||
wxStrcat(sqlStmt, "UNIQUE ");
|
sqlStmt += "UNIQUE ";
|
||||||
|
|
||||||
wxStrcat(sqlStmt, "INDEX ");
|
sqlStmt += "INDEX ";
|
||||||
wxStrcat(sqlStmt, idxName);
|
sqlStmt += idxName;
|
||||||
wxStrcat(sqlStmt, " ON ");
|
sqlStmt += " ON ";
|
||||||
wxStrcat(sqlStmt, tableName);
|
sqlStmt += tableName;
|
||||||
wxStrcat(sqlStmt, " (");
|
sqlStmt += " (";
|
||||||
|
|
||||||
// Append list of columns making up index
|
// Append list of columns making up index
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < noIdxCols; i++)
|
for (i = 0; i < noIdxCols; i++)
|
||||||
{
|
{
|
||||||
wxStrcat(sqlStmt, pIdxDefs[i].ColName);
|
sqlStmt += pIdxDefs[i].ColName;
|
||||||
/* Postgres doesn't cope with ASC */
|
/* Postgres doesn't cope with ASC */
|
||||||
if (pDb->Dbms() != dbmsPOSTGRES)
|
if (pDb->Dbms() != dbmsPOSTGRES)
|
||||||
{
|
{
|
||||||
if (pIdxDefs[i].Ascending)
|
if (pIdxDefs[i].Ascending)
|
||||||
wxStrcat(sqlStmt, " ASC");
|
sqlStmt += " ASC";
|
||||||
else
|
else
|
||||||
wxStrcat(sqlStmt, " DESC");
|
sqlStmt += " DESC";
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((i + 1) < noIdxCols)
|
if ((i + 1) < noIdxCols)
|
||||||
wxStrcat(sqlStmt, ",");
|
sqlStmt += ",";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Append closing parentheses
|
// Append closing parentheses
|
||||||
wxStrcat(sqlStmt, ")");
|
sqlStmt += ")";
|
||||||
|
|
||||||
pDb->WriteSqlLog(sqlStmt);
|
pDb->WriteSqlLog(sqlStmt.GetData());
|
||||||
|
|
||||||
#ifdef DBDEBUG_CONSOLE
|
#ifdef DBDEBUG_CONSOLE
|
||||||
cout << endl << sqlStmt << endl << endl;
|
cout << endl << sqlStmt.GetData() << endl << endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Execute the CREATE INDEX statement
|
// Execute the CREATE INDEX statement
|
||||||
if (SQLExecDirect(hstmt, (UCHAR FAR *) sqlStmt, SQL_NTS) != SQL_SUCCESS)
|
if (SQLExecDirect(hstmt, (UCHAR FAR *) sqlStmt.GetData(), SQL_NTS) != SQL_SUCCESS)
|
||||||
{
|
{
|
||||||
pDb->DispAllErrors(henv, hdbc, hstmt);
|
pDb->DispAllErrors(henv, hdbc, hstmt);
|
||||||
pDb->RollbackTrans();
|
pDb->RollbackTrans();
|
||||||
@@ -1158,22 +1164,23 @@ bool wxTable::DropIndex(const char * idxName)
|
|||||||
// below for any other databases when those databases are defined
|
// below for any other databases when those databases are defined
|
||||||
// to handle this situation consistently
|
// to handle this situation consistently
|
||||||
|
|
||||||
char sqlStmt[DB_MAX_STATEMENT_LEN];
|
// char sqlStmt[DB_MAX_STATEMENT_LEN];
|
||||||
|
wxString sqlStmt;
|
||||||
|
|
||||||
if (pDb->Dbms() == dbmsACCESS)
|
if (pDb->Dbms() == dbmsACCESS)
|
||||||
sprintf(sqlStmt, "DROP INDEX %s ON %s",idxName,tableName);
|
sqlStmt.sprintf("DROP INDEX %s ON %s",idxName,tableName);
|
||||||
else if (pDb->Dbms() == dbmsSYBASE_ASE)
|
else if (pDb->Dbms() == dbmsSYBASE_ASE)
|
||||||
sprintf(sqlStmt, "DROP INDEX %s.%s",tableName,idxName);
|
sqlStmt.sprintf("DROP INDEX %s.%s",tableName,idxName);
|
||||||
else
|
else
|
||||||
sprintf(sqlStmt, "DROP INDEX %s",idxName);
|
sqlStmt.sprintf("DROP INDEX %s",idxName);
|
||||||
|
|
||||||
pDb->WriteSqlLog(sqlStmt);
|
pDb->WriteSqlLog(sqlStmt.GetData());
|
||||||
|
|
||||||
#ifdef DBDEBUG_CONSOLE
|
#ifdef DBDEBUG_CONSOLE
|
||||||
cout << endl << sqlStmt << endl;
|
cout << endl << sqlStmt.GetData() << endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (SQLExecDirect(hstmt, (UCHAR FAR *) sqlStmt, SQL_NTS) != SQL_SUCCESS)
|
if (SQLExecDirect(hstmt, (UCHAR FAR *) sqlStmt.GetData(), SQL_NTS) != SQL_SUCCESS)
|
||||||
{
|
{
|
||||||
// Check for "Index not found" error and ignore
|
// Check for "Index not found" error and ignore
|
||||||
pDb->GetNextError(henv, hdbc, hstmt);
|
pDb->GetNextError(henv, hdbc, hstmt);
|
||||||
@@ -1251,7 +1258,7 @@ bool wxTable::Update(void)
|
|||||||
pDb->WriteSqlLog(sqlStmt);
|
pDb->WriteSqlLog(sqlStmt);
|
||||||
|
|
||||||
#ifdef DBDEBUG_CONSOLE
|
#ifdef DBDEBUG_CONSOLE
|
||||||
cout << endl << sqlStmt << endl << endl;
|
cout << endl << sqlStmt.GetData() << endl << endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Execute the SQL UPDATE statement
|
// Execute the SQL UPDATE statement
|
||||||
@@ -1289,7 +1296,7 @@ bool wxTable::UpdateWhere(const char *pWhereClause)
|
|||||||
pDb->WriteSqlLog(sqlStmt);
|
pDb->WriteSqlLog(sqlStmt);
|
||||||
|
|
||||||
#ifdef DBDEBUG_CONSOLE
|
#ifdef DBDEBUG_CONSOLE
|
||||||
cout << endl << sqlStmt << endl << endl;
|
cout << endl << sqlStmt.GetData() << endl << endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Execute the SQL UPDATE statement
|
// Execute the SQL UPDATE statement
|
||||||
@@ -1837,26 +1844,27 @@ void wxTable::SetCursor(HSTMT *hstmtActivate)
|
|||||||
ULONG wxTable::Count(const char *args)
|
ULONG wxTable::Count(const char *args)
|
||||||
{
|
{
|
||||||
ULONG l;
|
ULONG l;
|
||||||
char sqlStmt[DB_MAX_STATEMENT_LEN];
|
// char sqlStmt[DB_MAX_STATEMENT_LEN];
|
||||||
|
wxString sqlStmt;
|
||||||
SDWORD cb;
|
SDWORD cb;
|
||||||
|
|
||||||
// Build a "SELECT COUNT(*) FROM queryTableName [WHERE whereClause]" SQL Statement
|
// Build a "SELECT COUNT(*) FROM queryTableName [WHERE whereClause]" SQL Statement
|
||||||
wxStrcpy(sqlStmt, "SELECT COUNT(");
|
sqlStmt = "SELECT COUNT(";
|
||||||
wxStrcat(sqlStmt, args);
|
sqlStmt += args;
|
||||||
wxStrcat(sqlStmt, ") FROM ");
|
sqlStmt += ") FROM ";
|
||||||
wxStrcat(sqlStmt, queryTableName);
|
sqlStmt += queryTableName;
|
||||||
|
|
||||||
if (from && wxStrlen(from))
|
if (from && wxStrlen(from))
|
||||||
wxStrcat(sqlStmt, from);
|
sqlStmt += from;
|
||||||
|
|
||||||
// Add the where clause if one is provided
|
// Add the where clause if one is provided
|
||||||
if (where && wxStrlen(where))
|
if (where && wxStrlen(where))
|
||||||
{
|
{
|
||||||
wxStrcat(sqlStmt, " WHERE ");
|
sqlStmt += " WHERE ";
|
||||||
wxStrcat(sqlStmt, where);
|
sqlStmt += where;
|
||||||
}
|
}
|
||||||
|
|
||||||
pDb->WriteSqlLog(sqlStmt);
|
pDb->WriteSqlLog(sqlStmt.GetData());
|
||||||
|
|
||||||
// Initialize the Count cursor if it's not already initialized
|
// Initialize the Count cursor if it's not already initialized
|
||||||
if (!hstmtCount)
|
if (!hstmtCount)
|
||||||
@@ -1868,7 +1876,7 @@ ULONG wxTable::Count(const char *args)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Execute the SQL statement
|
// Execute the SQL statement
|
||||||
if (SQLExecDirect(*hstmtCount, (UCHAR FAR *) sqlStmt, SQL_NTS) != SQL_SUCCESS)
|
if (SQLExecDirect(*hstmtCount, (UCHAR FAR *) sqlStmt.GetData(), SQL_NTS) != SQL_SUCCESS)
|
||||||
{
|
{
|
||||||
pDb->DispAllErrors(henv, hdbc, *hstmtCount);
|
pDb->DispAllErrors(henv, hdbc, *hstmtCount);
|
||||||
return(0);
|
return(0);
|
||||||
|
Reference in New Issue
Block a user