Reformatted source to normalize - no code changes

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_2_BRANCH@7946 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
George Tasker
2000-08-05 18:16:14 +00:00
parent 77dbcbc141
commit 7109c7c2f8
2 changed files with 850 additions and 839 deletions

View File

@@ -138,6 +138,7 @@ typedef struct
} wxDbTablePrivilegeInfo; } wxDbTablePrivilegeInfo;
#endif #endif
/********** wxDbColFor Constructor **********/ /********** wxDbColFor Constructor **********/
wxDbColFor::wxDbColFor() wxDbColFor::wxDbColFor()
{ {
@@ -167,12 +168,13 @@ int wxDbColFor::Format(int Nation,int dbDataType,SWORD sqlDataType,short columnS
// -- 19991224 : mj10777@gmx.net : Create // -- 19991224 : mj10777@gmx.net : Create
// There is still a lot of work to do here, but it is a start // There is still a lot of work to do here, but it is a start
// It handles all the basic data-types that I have run into up to now // It handles all the basic data-types that I have run into up to now
// The main work will have be with Dates and float Formatting (US 1,000.00 ; EU 1.000,00) // The main work will have be with Dates and float Formatting
// There are wxWindow plans for locale support and the new wxDateTime. // (US 1,000.00 ; EU 1.000,00)
// - if they define some constants (wxEUROPEAN) that can be gloably used, // There are wxWindow plans for locale support and the new wxDateTime. If
// they define some constants (wxEUROPEAN) that can be gloably used,
// they should be used here. // they should be used here.
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
// There should also be a Function to scan in a string to fill the variable // There should also be a function to scan in a string to fill the variable
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
wxString Temp0; wxString Temp0;
i_Nation = Nation; // 0 = timestamp , 1=EU, 2=UK, 3=International, 4=US i_Nation = Nation; // 0 = timestamp , 1=EU, 2=UK, 3=International, 4=US
@@ -199,17 +201,17 @@ int wxDbColFor::Format(int Nation,int dbDataType,SWORD sqlDataType,short columnS
switch(i_dbDataType) // -A-> Still a lot of proper formatting to do switch(i_dbDataType) // -A-> Still a lot of proper formatting to do
{ {
case DB_DATA_TYPE_VARCHAR: case DB_DATA_TYPE_VARCHAR:
s_Field = "%s"; // s_Field = "%s";
break; break;
case DB_DATA_TYPE_INTEGER: case DB_DATA_TYPE_INTEGER:
s_Field = "%d"; // s_Field = "%d";
break; break;
case DB_DATA_TYPE_FLOAT: case DB_DATA_TYPE_FLOAT:
if (decimalDigits == 0) if (decimalDigits == 0)
decimalDigits = 2; decimalDigits = 2;
Temp0 = "%"; Temp0 = "%";
Temp0.Printf(wxT("%s%d.%d"),Temp0.c_str(),columnSize,decimalDigits); Temp0.Printf(wxT("%s%d.%d"),Temp0.c_str(),columnSize,decimalDigits);
s_Field.Printf(wxT("%sf"),Temp0.c_str()); // s_Field.Printf(wxT("%sf"),Temp0.c_str());
break; break;
case DB_DATA_TYPE_DATE: case DB_DATA_TYPE_DATE:
if (i_Nation == 0) // timestamp YYYY-MM-DD HH:MM:SS.SSS (tested for SYBASE) if (i_Nation == 0) // timestamp YYYY-MM-DD HH:MM:SS.SSS (tested for SYBASE)
@@ -234,7 +236,7 @@ int wxDbColFor::Format(int Nation,int dbDataType,SWORD sqlDataType,short columnS
} }
break; break;
default: default:
s_Field.Printf(wxT("-E-> unknown Format(%d)-sql(%d)"),dbDataType,sqlDataType); // s_Field.Printf(wxT("Unknown Format(%d)-SQL(%d)"),dbDataType,sqlDataType); //
break; break;
}; };
return TRUE; return TRUE;
@@ -872,7 +874,10 @@ bool wxDb::getDataTypeInfo(SWORD fSqlType, wxDbSqlTypeInfo &structSQLTypeInfo)
// BJO 20000427 : OpenLink driver // BJO 20000427 : OpenLink driver
if (!wxStrncmp(dbInf.driverName, "oplodbc", 7) || if (!wxStrncmp(dbInf.driverName, "oplodbc", 7) ||
!wxStrncmp(dbInf.driverName, "OLOD", 4)) !wxStrncmp(dbInf.driverName, "OLOD", 4))
if (!wxStrcmp(structSQLTypeInfo.TypeName, "double precision")) wxStrcpy(structSQLTypeInfo.TypeName, "real"); {
if (!wxStrcmp(structSQLTypeInfo.TypeName, "double precision"))
wxStrcpy(structSQLTypeInfo.TypeName, "real");
}
#endif #endif
if (SQLGetData(hstmt, 3, SQL_C_LONG, (UCHAR*) &structSQLTypeInfo.Precision, 0, &cbRet) != SQL_SUCCESS) if (SQLGetData(hstmt, 3, SQL_C_LONG, (UCHAR*) &structSQLTypeInfo.Precision, 0, &cbRet) != SQL_SUCCESS)
@@ -1025,7 +1030,6 @@ 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];
wxString odbcErrMsg; wxString odbcErrMsg;
odbcErrMsg.sprintf("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);
@@ -1045,7 +1049,6 @@ void wxDb::DispNextError(void)
wxLogDebug(odbcErrMsg,wxT("ODBC DEBUG MESSAGE")); wxLogDebug(odbcErrMsg,wxT("ODBC DEBUG MESSAGE"));
#endif // __WXDEBUG__ #endif // __WXDEBUG__
} // wxDb::DispNextError() } // wxDb::DispNextError()
@@ -1268,7 +1271,6 @@ int wxDb::TranslateSqlState(const wxChar *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];
wxString sqlStmt; wxString sqlStmt;
// Build the grant statement // Build the grant statement
@@ -1322,7 +1324,6 @@ 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];
wxString sqlStmt; wxString sqlStmt;
// Drop the view first // Drop the view first
@@ -1495,8 +1496,8 @@ int wxDb::GetKeyFields(char *tableName, wxDbColInf* colInf, int noCols)
for (i=0;i<noCols;i++) // Find the Column name for (i=0;i<noCols;i++) // Find the Column name
if (!wxStrcmp(colInf[i].colName,szPkCol)) // We have found the Column if (!wxStrcmp(colInf[i].colName,szPkCol)) // We have found the Column
colInf[i].PkCol = iKeySeq; // Which Primary Key is this (first, second usw.) ? colInf[i].PkCol = iKeySeq; // Which Primary Key is this (first, second usw.) ?
} // if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) } // if
} // while ((retcode == SQL_SUCCESS) || (retcode == SQL_SUCCESS_WITH_INFO)) } // while
SQLFreeStmt(hstmt, SQL_CLOSE); /* Close the cursor (the hstmt is still allocated). */ SQLFreeStmt(hstmt, SQL_CLOSE); /* Close the cursor (the hstmt is still allocated). */
/*---------------------------------------------------------------------*/ /*---------------------------------------------------------------------*/
@@ -1527,15 +1528,17 @@ int wxDb::GetKeyFields(char *tableName, wxDbColInf* colInf, int noCols)
GetData( 7, SQL_C_CHAR, szFkTable, DB_MAX_TABLE_NAME_LEN+1, &cb); GetData( 7, SQL_C_CHAR, szFkTable, DB_MAX_TABLE_NAME_LEN+1, &cb);
GetData( 8, SQL_C_CHAR, szFkCol, DB_MAX_COLUMN_NAME_LEN+1, &cb); GetData( 8, SQL_C_CHAR, szFkCol, DB_MAX_COLUMN_NAME_LEN+1, &cb);
Temp0.Printf(wxT("%s[%s] "),Temp0.c_str(),szFkTable); // [ ] in case there is a blank in the Table name Temp0.Printf(wxT("%s[%s] "),Temp0.c_str(),szFkTable); // [ ] in case there is a blank in the Table name
} // if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) } // if
} // while ((retcode == SQL_SUCCESS) || (retcode == SQL_SUCCESS_WITH_INFO)) } // while
Temp0.Trim(); // Get rid of any unneeded blanks Temp0.Trim(); // Get rid of any unneeded blanks
if (Temp0 != wxT("")) if (Temp0 != wxT(""))
{ {
for (i=0;i<noCols;i++) // Find the Column name for (i=0;i<noCols;i++)
{ // Find the Column name
if (!wxStrcmp(colInf[i].colName,szPkCol)) // We have found the Column, store the Information if (!wxStrcmp(colInf[i].colName,szPkCol)) // We have found the Column, store the Information
wxStrcpy(colInf[i].PkTableName,Temp0.c_str()); // Name of the Tables where this Primary Key is used as a Foreign Key wxStrcpy(colInf[i].PkTableName,Temp0.c_str()); // Name of the Tables where this Primary Key is used as a Foreign Key
} // if (Temp0 != "") }
} // if
SQLFreeStmt(hstmt, SQL_CLOSE); /* Close the cursor (the hstmt is still allocated). */ SQLFreeStmt(hstmt, SQL_CLOSE); /* Close the cursor (the hstmt is still allocated). */
/*---------------------------------------------------------------------*/ /*---------------------------------------------------------------------*/
@@ -1570,14 +1573,14 @@ int wxDb::GetKeyFields(char *tableName, wxDbColInf* colInf, int noCols)
{ {
colInf[i].FkCol = iKeySeq; // Which Foreign Key is this (first, second usw.) ? colInf[i].FkCol = iKeySeq; // Which Foreign Key is this (first, second usw.) ?
wxStrcpy(colInf[i].FkTableName,szPkTable); // Name of the Table where this Foriegn is the Primary Key wxStrcpy(colInf[i].FkTableName,szPkTable); // Name of the Table where this Foriegn is the Primary Key
} // if (!wxStrcmp(colInf[i].colName,szFkCol)) } // if
} // for (i=0;i<noCols;i++) } // for
} // if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) } // if
} // while ((retcode == SQL_SUCCESS) || (retcode == SQL_SUCCESS_WITH_INFO)) } // while
SQLFreeStmt(hstmt, SQL_CLOSE); /* Close the cursor (the hstmt is still allocated). */ SQLFreeStmt(hstmt, SQL_CLOSE); /* Close the cursor (the hstmt is still allocated). */
/*---------------------------------------------------------------------*/
return TRUE; return TRUE;
} // wxDb::GetKeyFields() } // wxDb::GetKeyFields()
@@ -1950,23 +1953,26 @@ wxDbColInf *wxDb::GetColumns(char *tableName, int *numCols, const char *userID)
} // wxDb::GetColumns() } // wxDb::GetColumns()
#else // New GetColumns #else // New GetColumns
/* /*
BJO 20000503 BJO 20000503
These are tentative new GetColumns members which should be more database independant and These are tentative new GetColumns members which should be more database
which always returns the columns in the order they were created. independant and which always returns the columns in the order they were
created.
- The first one (wxDbColInf *wxDb::GetColumns(char *tableName[], const char* userID)) calls
the second implementation for each separate table before merging the results. This makes the
code easier to maintain as only one member (the second) makes the real work
- wxDbColInf *wxDb::GetColumns(char *tableName, int *numCols, const char *userID) is a little bit improved
- It doesn't anymore rely on the type-name to find out which database-type each column has
- It ends by sorting the columns, so that they are returned in the same order they were created
- The first one (wxDbColInf *wxDb::GetColumns(char *tableName[], const
char* userID)) calls the second implementation for each separate table
before merging the results. This makes the code easier to maintain as
only one member (the second) makes the real work
- wxDbColInf *wxDb::GetColumns(char *tableName, int *numCols, const
char *userID) is a little bit improved
- It doesn't anymore rely on the type-name to find out which database-type
each column has
- It ends by sorting the columns, so that they are returned in the same
order they were created
*/ */
typedef struct typedef struct
@@ -1975,6 +1981,7 @@ typedef struct
wxDbColInf *colInf; wxDbColInf *colInf;
} _TableColumns; } _TableColumns;
wxDbColInf *wxDb::GetColumns(char *tableName[], const char* userID) wxDbColInf *wxDb::GetColumns(char *tableName[], const char* userID)
{ {
int i, j; int i, j;
@@ -1995,7 +2002,8 @@ wxDbColInf *wxDb::GetColumns(char *tableName[], const char* userID)
{ {
TableColumns[i].colInf = GetColumns(tableName[i], &TableColumns[i].noCols, userID); TableColumns[i].colInf = GetColumns(tableName[i], &TableColumns[i].noCols, userID);
if (TableColumns[i].colInf == NULL) return NULL; if (TableColumns[i].colInf == NULL)
return NULL;
noCols += TableColumns[i].noCols; noCols += TableColumns[i].noCols;
} }
@@ -2021,7 +2029,7 @@ wxDbColInf *wxDb::GetColumns(char *tableName[], const char* userID)
delete [] TableColumns; delete [] TableColumns;
return colInf; return colInf;
} } // wxDb::GetColumns() -- NEW
wxDbColInf *wxDb::GetColumns(char *tableName, int *numCols, const char *userID) wxDbColInf *wxDb::GetColumns(char *tableName, int *numCols, const char *userID)
@@ -2038,7 +2046,6 @@ wxDbColInf *wxDb::GetColumns(char *tableName, int *numCols, const char *userID)
// NOTE: ALL column bindings associated with this wxDb instance are unbound // NOTE: ALL column bindings associated with this wxDb instance are unbound
// by this function. This function should use its own wxDb instance // by this function. This function should use its own wxDb instance
// to avoid undesired unbinding of columns. // to avoid undesired unbinding of columns.
{ {
SWORD noCols = 0; SWORD noCols = 0;
int colNo = 0; int colNo = 0;
@@ -2185,8 +2192,6 @@ wxDbColInf *wxDb::GetColumns(char *tableName, int *numCols, const char *userID)
case SQL_DATE: case SQL_DATE:
colInf[colNo].dbDataType = DB_DATA_TYPE_DATE; colInf[colNo].dbDataType = DB_DATA_TYPE_DATE;
break; break;
#ifdef __WXDEBUG__ #ifdef __WXDEBUG__
default: default:
wxString errMsg; wxString errMsg;
@@ -2194,9 +2199,6 @@ wxDbColInf *wxDb::GetColumns(char *tableName, int *numCols, const char *userID)
wxLogDebug(errMsg,wxT("ODBC DEBUG MESSAGE")); wxLogDebug(errMsg,wxT("ODBC DEBUG MESSAGE"));
#endif #endif
} }
colNo++; colNo++;
} }
} }
@@ -2218,8 +2220,6 @@ wxDbColInf *wxDb::GetColumns(char *tableName, int *numCols, const char *userID)
// Store Primary and Foreign Keys // Store Primary and Foreign Keys
GetKeyFields(tableName,colInf,noCols); GetKeyFields(tableName,colInf,noCols);
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// Now sort the the columns in order to make them appear in the right order // Now sort the the columns in order to make them appear in the right order
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
@@ -2288,9 +2288,6 @@ wxDbColInf *wxDb::GetColumns(char *tableName, int *numCols, const char *userID)
// End sorting // End sorting
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
if (numCols) if (numCols)
*numCols = noCols; *numCols = noCols;
return colInf; return colInf;
@@ -2298,7 +2295,7 @@ wxDbColInf *wxDb::GetColumns(char *tableName, int *numCols, const char *userID)
} // wxDb::GetColumns() } // wxDb::GetColumns()
#endif #endif // #else OLD_GETCOLUMNS
/********** wxDb::GetColumnCount() **********/ /********** wxDb::GetColumnCount() **********/
@@ -2430,7 +2427,6 @@ 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];
wxString tblNameSave; wxString tblNameSave;
wxString UserID; wxString UserID;
@@ -2467,7 +2463,6 @@ wxDbInf *wxDb::GetCatalog(char *userID)
// - Create the Cols array = NULL // - Create the Cols array = NULL
//------------------------------------------------------------- //-------------------------------------------------------------
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
@@ -2477,7 +2472,6 @@ wxDbInf *wxDb::GetCatalog(char *userID)
Dbms() != dbmsMY_SQL && Dbms() != dbmsMY_SQL &&
Dbms() != dbmsACCESS) Dbms() != dbmsACCESS)
{ {
retcode = SQLTables(hstmt, retcode = SQLTables(hstmt,
NULL, 0, // All qualifiers NULL, 0, // All qualifiers
(UCHAR *) UserID.c_str(), SQL_NTS, // User specified (UCHAR *) UserID.c_str(), SQL_NTS, // User specified
@@ -2486,7 +2480,6 @@ wxDbInf *wxDb::GetCatalog(char *userID)
} }
else else
{ {
retcode = SQLTables(hstmt, retcode = SQLTables(hstmt,
NULL, 0, // All qualifiers NULL, 0, // All qualifiers
NULL, 0, // User specified NULL, 0, // User specified
@@ -2504,7 +2497,6 @@ wxDbInf *wxDb::GetCatalog(char *userID)
while ((retcode = SQLFetch(hstmt)) == SQL_SUCCESS) // Table Information while ((retcode = SQLFetch(hstmt)) == SQL_SUCCESS) // Table Information
{ {
if (pass == 1) // First pass, just count the Tables if (pass == 1) // First pass, just count the Tables
{ {
if (pDbInf->numTables == 0) if (pDbInf->numTables == 0)
@@ -2535,9 +2527,9 @@ wxDbInf *wxDb::GetCatalog(char *userID)
GetData( 5, SQL_C_CHAR, (UCHAR*) (pDbInf->pTableInf+noTab)->tableRemarks, 254+1, &cb); GetData( 5, SQL_C_CHAR, (UCHAR*) (pDbInf->pTableInf+noTab)->tableRemarks, 254+1, &cb);
noTab++; noTab++;
} // if (pass == 2) We now know the amount of Tables } // if
} // while ((retcode = SQLFetch(hstmt)) == SQL_SUCCESS) } // while
} // for (pass = 1; pass <= 2; pass++) } // for
SQLFreeStmt(hstmt, SQL_CLOSE); SQLFreeStmt(hstmt, SQL_CLOSE);
// Query how many columns are in each table // Query how many columns are in each table
@@ -2545,7 +2537,9 @@ wxDbInf *wxDb::GetCatalog(char *userID)
{ {
(pDbInf->pTableInf+noTab)->numCols = GetColumnCount((pDbInf->pTableInf+noTab)->tableName,UserID); (pDbInf->pTableInf+noTab)->numCols = GetColumnCount((pDbInf->pTableInf+noTab)->tableName,UserID);
} }
return pDbInf; return pDbInf;
} // wxDb::GetCatalog() } // wxDb::GetCatalog()
@@ -2704,7 +2698,6 @@ bool wxDb::TableExists(const char *tableName, const char *userID, const char *ta
if (Dbms() == dbmsDBASE) if (Dbms() == dbmsDBASE)
{ {
wxString dbName; wxString dbName;
if (tablePath && wxStrlen(tablePath)) if (tablePath && wxStrlen(tablePath))
dbName.sprintf("%s\\%s.dbf",tablePath,tableName); dbName.sprintf("%s\\%s.dbf",tablePath,tableName);
@@ -2771,10 +2764,12 @@ bool wxDb::TableExists(const char *tableName, const char *userID, const char *ta
} }
SQLFreeStmt(hstmt, SQL_CLOSE); SQLFreeStmt(hstmt, SQL_CLOSE);
return(TRUE); return(TRUE);
} // wxDb::TableExists() } // wxDb::TableExists()
#if EXPERIMENTAL_WXDB_FUNCTIONS // will be added in 2.4 #if EXPERIMENTAL_WXDB_FUNCTIONS // will be added in 2.4
/********** wxDB::TablePrivileges() **********/ /********** wxDB::TablePrivileges() **********/
bool wxDB::TablePrivileges(const char *tableName, const char* priv, bool wxDB::TablePrivileges(const char *tableName, const char* priv,
@@ -2862,9 +2857,11 @@ bool wxDB::TablePrivileges(const char *tableName, const char* priv,
} }
return FALSE; return FALSE;
} // wxDB::TablePrivileges } // wxDB::TablePrivileges
#endif #endif
/********** wxDb::SetSqlLogging() **********/ /********** wxDb::SetSqlLogging() **********/
bool wxDb::SetSqlLogging(wxDbSqlLogState state, const char *filename, bool append) bool wxDb::SetSqlLogging(wxDbSqlLogState state, const char *filename, bool append)
{ {
@@ -2948,6 +2945,7 @@ wxDBMS wxDb::Dbms(void)
* *
* SYBASE (Enterprise) * SYBASE (Enterprise)
* - If a column is part of the Primary Key, the column cannot be NULL * - If a column is part of the Primary Key, the column cannot be NULL
* - Maximum row size is somewhere in the neighborhood of 1920 bytes
* *
* MY_SQL * MY_SQL
* - If a column is part of the Primary Key, the column cannot be NULL * - If a column is part of the Primary Key, the column cannot be NULL
@@ -2955,10 +2953,11 @@ wxDBMS wxDb::Dbms(void)
* - Columns that are part of primary or secondary keys must be defined as being NOT NULL * - Columns that are part of primary or secondary keys must be defined as being NOT NULL
* when they are created. Some code is added in ::CreateIndex to try to adjust the * when they are created. Some code is added in ::CreateIndex to try to adjust the
* column definition if it is not defined correctly, but it is experimental * column definition if it is not defined correctly, but it is experimental
* - Does not support sub-queries in SQL statements
* *
* POSTGRES * POSTGRES
* - Does not support the keywords 'ASC' or 'DESC' as of release v6.5.0 * - Does not support the keywords 'ASC' or 'DESC' as of release v6.5.0
* * - Does not support sub-queries in SQL statements
* *
*/ */
{ {
@@ -2979,10 +2978,11 @@ wxDBMS wxDb::Dbms(void)
// Is it also returned by Sybase Adapatitve server? // Is it also returned by Sybase Adapatitve server?
// OpenLink driver name is OLOD3032.DLL for msw and oplodbc.so for unix // OpenLink driver name is OLOD3032.DLL for msw and oplodbc.so for unix
if (!wxStricmp(dbInf.dbmsName,"SQL Server")) if (!wxStricmp(dbInf.dbmsName,"SQL Server"))
{
if (!wxStrncmp(dbInf.driverName, "oplodbc", 7) || if (!wxStrncmp(dbInf.driverName, "oplodbc", 7) ||
!wxStrncmp(dbInf.driverName, "OLOD", 4)) !wxStrncmp(dbInf.driverName, "OLOD", 4))
return dbmsMS_SQL_SERVER; else return dbmsSYBASE_ASE; return dbmsMS_SQL_SERVER; else return dbmsSYBASE_ASE;
}
if (!wxStricmp(dbInf.dbmsName,"Microsoft SQL Server")) if (!wxStricmp(dbInf.dbmsName,"Microsoft SQL Server"))
return(dbmsMS_SQL_SERVER); return(dbmsMS_SQL_SERVER);
@@ -2995,7 +2995,6 @@ wxDBMS wxDb::Dbms(void)
if (!wxStricmp(baseName,"Informix")) if (!wxStricmp(baseName,"Informix"))
return(dbmsINFORMIX); return(dbmsINFORMIX);
baseName[6] = 0; baseName[6] = 0;
if (!wxStricmp(baseName,"Oracle")) if (!wxStricmp(baseName,"Oracle"))
return(dbmsORACLE); return(dbmsORACLE);
@@ -3011,6 +3010,7 @@ wxDBMS wxDb::Dbms(void)
return(dbmsDBASE); return(dbmsDBASE);
return(dbmsUNIDENTIFIED); return(dbmsUNIDENTIFIED);
} // wxDb::Dbms() } // wxDb::Dbms()
@@ -3151,7 +3151,6 @@ bool wxDbSqlLog(wxDbSqlLogState state, const wxChar *filename)
} }
SQLLOGstate = state; SQLLOGstate = state;
// wxStrcpy(SQLLOGfn,filename);
SQLLOGfn = filename; SQLLOGfn = filename;
return(TRUE); return(TRUE);

View File

@@ -191,7 +191,6 @@ wxDbTable::wxDbTable(wxDb *pwxDb, const char *tblName, const int nCols,
pDb->GetNextError(henv, hdbc, hstmtInternal); pDb->GetNextError(henv, hdbc, hstmtInternal);
if (! wxStrcmp(pDb->sqlState, "01S02")) // Option Value Changed if (! wxStrcmp(pDb->sqlState, "01S02")) // Option Value Changed
{ {
// Datasource does not support static cursors. Driver // Datasource does not support static cursors. Driver
// will substitute a cursor type. Call SQLGetStmtOption() // will substitute a cursor type. Call SQLGetStmtOption()
// to determine which cursor type was selected. // to determine which cursor type was selected.
@@ -202,17 +201,20 @@ wxDbTable::wxDbTable(wxDb *pwxDb, const char *tblName, const int nCols,
switch(cursorType) switch(cursorType)
{ {
case SQL_CURSOR_FORWARD_ONLY: case SQL_CURSOR_FORWARD_ONLY:
cout << "Forward Only"; break; cout << "Forward Only";
break;
case SQL_CURSOR_STATIC: case SQL_CURSOR_STATIC:
cout << "Static"; break; cout << "Static";
break;
case SQL_CURSOR_KEYSET_DRIVEN: case SQL_CURSOR_KEYSET_DRIVEN:
cout << "Keyset Driven"; break; cout << "Keyset Driven";
break;
case SQL_CURSOR_DYNAMIC: case SQL_CURSOR_DYNAMIC:
cout << "Dynamic"; break; cout << "Dynamic";
break;
} }
cout << endl << endl; cout << endl << endl;
#endif #endif
// BJO20000425 // BJO20000425
if (pDb->FwdOnlyCursors() && cursorType != SQL_CURSOR_FORWARD_ONLY) if (pDb->FwdOnlyCursors() && cursorType != SQL_CURSOR_FORWARD_ONLY)
{ {
@@ -317,7 +319,6 @@ wxDbTable::~wxDbTable()
if (hstmtUpdate) if (hstmtUpdate)
if (SQLFreeStmt(hstmtUpdate, SQL_DROP) != SQL_SUCCESS) if (SQLFreeStmt(hstmtUpdate, SQL_DROP) != SQL_SUCCESS)
pDb->DispAllErrors(henv, hdbc); pDb->DispAllErrors(henv, hdbc);
} }
if (hstmtInternal) if (hstmtInternal)
@@ -331,7 +332,6 @@ wxDbTable::~wxDbTable()
if (hstmtCount) if (hstmtCount)
DeleteCursor(hstmtCount); DeleteCursor(hstmtCount);
} // wxDbTable::~wxDbTable() } // wxDbTable::~wxDbTable()
@@ -359,7 +359,6 @@ bool wxDbTable::bindInsertParams(void)
continue; continue;
switch(colDefs[i].DbDataType) switch(colDefs[i].DbDataType)
{ {
case DB_DATA_TYPE_VARCHAR: case DB_DATA_TYPE_VARCHAR:
fSqlType = pDb->GetTypeInfVarchar().FsqlType; fSqlType = pDb->GetTypeInfVarchar().FsqlType;
precision = colDefs[i].SzDataObj; precision = colDefs[i].SzDataObj;
@@ -400,8 +399,10 @@ bool wxDbTable::bindInsertParams(void)
if (SQLBindParameter(hstmtInsert, colNo++, SQL_PARAM_INPUT, colDefs[i].SqlCtype, if (SQLBindParameter(hstmtInsert, colNo++, SQL_PARAM_INPUT, colDefs[i].SqlCtype,
fSqlType, precision, scale, (UCHAR*) colDefs[i].PtrDataObj, fSqlType, precision, scale, (UCHAR*) colDefs[i].PtrDataObj,
precision+1,&colDefs[i].CbValue) != SQL_SUCCESS) precision+1,&colDefs[i].CbValue) != SQL_SUCCESS)
{
return(pDb->DispAllErrors(henv, hdbc, hstmtInsert)); return(pDb->DispAllErrors(henv, hdbc, hstmtInsert));
} }
}
// Completed successfully // Completed successfully
return(TRUE); return(TRUE);
@@ -462,8 +463,10 @@ bool wxDbTable::bindUpdateParams(void)
if (SQLBindParameter(hstmtUpdate, colNo++, SQL_PARAM_INPUT, colDefs[i].SqlCtype, if (SQLBindParameter(hstmtUpdate, colNo++, SQL_PARAM_INPUT, colDefs[i].SqlCtype,
fSqlType, precision, scale, (UCHAR*) colDefs[i].PtrDataObj, fSqlType, precision, scale, (UCHAR*) colDefs[i].PtrDataObj,
precision+1, &colDefs[i].CbValue) != SQL_SUCCESS) precision+1, &colDefs[i].CbValue) != SQL_SUCCESS)
{
return(pDb->DispAllErrors(henv, hdbc, hstmtUpdate)); return(pDb->DispAllErrors(henv, hdbc, hstmtUpdate));
} }
}
// Completed successfully // Completed successfully
return(TRUE); return(TRUE);
@@ -482,8 +485,10 @@ bool wxDbTable::bindCols(HSTMT cursor)
{ {
if (SQLBindCol(cursor, i+1, colDefs[i].SqlCtype, (UCHAR*) colDefs[i].PtrDataObj, if (SQLBindCol(cursor, i+1, colDefs[i].SqlCtype, (UCHAR*) colDefs[i].PtrDataObj,
colDefs[i].SzDataObj, &cb) != SQL_SUCCESS) colDefs[i].SzDataObj, &cb) != SQL_SUCCESS)
{
return (pDb->DispAllErrors(henv, hdbc, cursor)); return (pDb->DispAllErrors(henv, hdbc, cursor));
} }
}
// Completed successfully // Completed successfully
return(TRUE); return(TRUE);
@@ -504,11 +509,13 @@ bool wxDbTable::getRec(UWORD fetchType)
retcode = SQLExtendedFetch(hstmt, fetchType, 0, &cRowsFetched, &rowStatus); retcode = SQLExtendedFetch(hstmt, fetchType, 0, &cRowsFetched, &rowStatus);
if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO) if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO)
{
if (retcode == SQL_NO_DATA_FOUND) if (retcode == SQL_NO_DATA_FOUND)
return(FALSE); return(FALSE);
else else
return(pDb->DispAllErrors(henv, hdbc, hstmt)); return(pDb->DispAllErrors(henv, hdbc, hstmt));
} }
}
else else
{ {
// Fetch the next record from the record set // Fetch the next record from the record set
@@ -571,7 +578,9 @@ bool wxDbTable::query(int queryType, bool forUpdate, bool distinct, const char *
{ // so generate a select statement. { // so generate a select statement.
BuildSelectStmt(sqlStmt, queryType, distinct); BuildSelectStmt(sqlStmt, queryType, distinct);
pDb->WriteSqlLog(sqlStmt); pDb->WriteSqlLog(sqlStmt);
} else wxStrcpy(sqlStmt, pSqlStmt); }
else
wxStrcpy(sqlStmt, pSqlStmt);
SQLFreeStmt(hstmt, SQL_CLOSE); SQLFreeStmt(hstmt, SQL_CLOSE);
if (SQLExecDirect(hstmt, (UCHAR FAR *) sqlStmt, SQL_NTS) == SQL_SUCCESS) if (SQLExecDirect(hstmt, (UCHAR FAR *) sqlStmt, SQL_NTS) == SQL_SUCCESS)
@@ -741,6 +750,7 @@ bool wxDbTable::GetPrev(void)
} }
else else
return(getRec(SQL_FETCH_PRIOR)); return(getRec(SQL_FETCH_PRIOR));
} // wxDbTable::GetPrev() } // wxDbTable::GetPrev()
@@ -754,6 +764,7 @@ bool wxDbTable::operator--(int)
} }
else else
return(getRec(SQL_FETCH_PRIOR)); return(getRec(SQL_FETCH_PRIOR));
} // wxDbTable::operator-- } // wxDbTable::operator--
@@ -767,6 +778,7 @@ bool wxDbTable::GetFirst(void)
} }
else else
return(getRec(SQL_FETCH_FIRST)); return(getRec(SQL_FETCH_FIRST));
} // wxDbTable::GetFirst() } // wxDbTable::GetFirst()
@@ -780,6 +792,7 @@ bool wxDbTable::GetLast(void)
} }
else else
return(getRec(SQL_FETCH_LAST)); return(getRec(SQL_FETCH_LAST));
} // wxDbTable::GetLast() } // wxDbTable::GetLast()
@@ -942,7 +955,6 @@ bool wxDbTable::CreateTable(bool attemptDrop)
return FALSE; return FALSE;
int i, j; int i, j;
// char sqlStmt[DB_MAX_STATEMENT_LEN];
wxString sqlStmt; wxString sqlStmt;
#ifdef DBDEBUG_CONSOLE #ifdef DBDEBUG_CONSOLE
@@ -999,13 +1011,17 @@ bool wxDbTable::CreateTable(bool attemptDrop)
switch(colDefs[i].DbDataType) switch(colDefs[i].DbDataType)
{ {
case DB_DATA_TYPE_VARCHAR: case DB_DATA_TYPE_VARCHAR:
sqlStmt += pDb->GetTypeInfVarchar().TypeName; break; sqlStmt += pDb->GetTypeInfVarchar().TypeName;
break;
case DB_DATA_TYPE_INTEGER: case DB_DATA_TYPE_INTEGER:
sqlStmt += pDb->GetTypeInfInteger().TypeName; break; sqlStmt += pDb->GetTypeInfInteger().TypeName;
break;
case DB_DATA_TYPE_FLOAT: case DB_DATA_TYPE_FLOAT:
sqlStmt += pDb->GetTypeInfFloat().TypeName; break; sqlStmt += pDb->GetTypeInfFloat().TypeName;
break;
case DB_DATA_TYPE_DATE: case DB_DATA_TYPE_DATE:
sqlStmt += pDb->GetTypeInfDate().TypeName; break; sqlStmt += pDb->GetTypeInfDate().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)
@@ -1084,7 +1100,7 @@ bool wxDbTable::CreateTable(bool attemptDrop)
// Commit the transaction and close the cursor // Commit the transaction and close the cursor
if (!pDb->CommitTrans()) if (!pDb->CommitTrans())
return(FALSE); rEturn(FALSE);
if (!CloseCursor(hstmt)) if (!CloseCursor(hstmt))
return(FALSE); return(FALSE);
@@ -1187,13 +1203,17 @@ bool wxDbTable::CreateIndex(const char * idxName, bool unique, int noIdxCols, wx
switch(colDefs[j].DbDataType) switch(colDefs[j].DbDataType)
{ {
case DB_DATA_TYPE_VARCHAR: case DB_DATA_TYPE_VARCHAR:
typeNameAndSize = pDb->GetTypeInfVarchar().TypeName; break; typeNameAndSize = pDb->GetTypeInfVarchar().TypeName;
break;
case DB_DATA_TYPE_INTEGER: case DB_DATA_TYPE_INTEGER:
typeNameAndSize = pDb->GetTypeInfInteger().TypeName; break; typeNameAndSize = pDb->GetTypeInfInteger().TypeName;
break;
case DB_DATA_TYPE_FLOAT: case DB_DATA_TYPE_FLOAT:
typeNameAndSize = pDb->GetTypeInfFloat().TypeName; break; typeNameAndSize = pDb->GetTypeInfFloat().TypeName;
break;
case DB_DATA_TYPE_DATE: case DB_DATA_TYPE_DATE:
typeNameAndSize = pDb->GetTypeInfDate().TypeName; break; typeNameAndSize = pDb->GetTypeInfDate().TypeName;
break;
} }
// For varchars, append the size of the string // For varchars, append the size of the string
@@ -1807,7 +1827,6 @@ void wxDbTable::ClearMemberVars(void)
pDt->second = 0; pDt->second = 0;
pDt->fraction = 0; pDt->fraction = 0;
break; break;
} }
} }
@@ -1889,14 +1908,11 @@ wxDbColDataPtr* wxDbTable::SetColDefs (wxDbColInf *pColInfs, ULONG numCols)
switch (pColInfs[index].dbDataType) switch (pColInfs[index].dbDataType)
{ {
case DB_DATA_TYPE_VARCHAR: case DB_DATA_TYPE_VARCHAR:
{
pColDataPtrs[index].PtrDataObj = new char[pColInfs[index].bufferLength+1]; pColDataPtrs[index].PtrDataObj = new char[pColInfs[index].bufferLength+1];
pColDataPtrs[index].SzDataObj = pColInfs[index].columnSize; pColDataPtrs[index].SzDataObj = pColInfs[index].columnSize;
pColDataPtrs[index].SqlCtype = SQL_C_CHAR; pColDataPtrs[index].SqlCtype = SQL_C_CHAR;
break; break;
}
case DB_DATA_TYPE_INTEGER: case DB_DATA_TYPE_INTEGER:
{
// Can be long or short // Can be long or short
if (pColInfs[index].bufferLength == sizeof(long)) if (pColInfs[index].bufferLength == sizeof(long))
{ {
@@ -1911,9 +1927,7 @@ wxDbColDataPtr* wxDbTable::SetColDefs (wxDbColInf *pColInfs, ULONG numCols)
pColDataPtrs[index].SqlCtype = SQL_C_SSHORT; pColDataPtrs[index].SqlCtype = SQL_C_SSHORT;
} }
break; break;
}
case DB_DATA_TYPE_FLOAT: case DB_DATA_TYPE_FLOAT:
{
// Can be float or double // Can be float or double
if (pColInfs[index].bufferLength == sizeof(float)) if (pColInfs[index].bufferLength == sizeof(float))
{ {
@@ -1928,20 +1942,18 @@ wxDbColDataPtr* wxDbTable::SetColDefs (wxDbColInf *pColInfs, ULONG numCols)
pColDataPtrs[index].SqlCtype = SQL_C_DOUBLE; pColDataPtrs[index].SqlCtype = SQL_C_DOUBLE;
} }
break; break;
}
case DB_DATA_TYPE_DATE: case DB_DATA_TYPE_DATE:
{
pColDataPtrs[index].PtrDataObj = new TIMESTAMP_STRUCT; pColDataPtrs[index].PtrDataObj = new TIMESTAMP_STRUCT;
pColDataPtrs[index].SzDataObj = sizeof(TIMESTAMP_STRUCT); pColDataPtrs[index].SzDataObj = sizeof(TIMESTAMP_STRUCT);
pColDataPtrs[index].SqlCtype = SQL_C_TIMESTAMP; pColDataPtrs[index].SqlCtype = SQL_C_TIMESTAMP;
break; break;
} }
}
SetColDefs (index,pColInfs[index].colName,pColInfs[index].dbDataType, pColDataPtrs[index].PtrDataObj, pColDataPtrs[index].SqlCtype, pColDataPtrs[index].SzDataObj); SetColDefs (index,pColInfs[index].colName,pColInfs[index].dbDataType, pColDataPtrs[index].PtrDataObj, pColDataPtrs[index].SqlCtype, pColDataPtrs[index].SzDataObj);
} }
} }
return (pColDataPtrs); return (pColDataPtrs);
} // wxDbTable::SetColDef() } // wxDbTable::SetColDef()