Firebird DB support added. Basic testing is done, and appears to work fully. Need real users to test the additions please

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@31157 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
George Tasker 2004-12-28 00:33:09 +00:00
parent 856e0fa454
commit 215a0070c1
3 changed files with 45 additions and 8 deletions

View File

@ -460,7 +460,8 @@ enum wxDBMS
dbmsDB2, dbmsDB2,
dbmsINTERBASE, dbmsINTERBASE,
dbmsPERVASIVE_SQL, dbmsPERVASIVE_SQL,
dbmsXBASE_SEQUITER dbmsXBASE_SEQUITER,
dbmsFIREBIRD
}; };

View File

@ -2493,6 +2493,7 @@ wxDbColInf *wxDb::GetColumns(wxChar *tableName[], const wxChar *userID)
// Oracle and Interbase table names are uppercase only, so force // Oracle and Interbase table names are uppercase only, so force
// the name to uppercase just in case programmer forgot to do this // the name to uppercase just in case programmer forgot to do this
if ((Dbms() == dbmsORACLE) || if ((Dbms() == dbmsORACLE) ||
(Dbms() == dbmsFIREBIRD) ||
(Dbms() == dbmsINTERBASE)) (Dbms() == dbmsINTERBASE))
TableName = TableName.Upper(); TableName = TableName.Upper();
@ -2648,6 +2649,7 @@ wxDbColInf *wxDb::GetColumns(const wxString &tableName, UWORD *numCols, const wx
// Oracle and Interbase table names are uppercase only, so force // Oracle and Interbase table names are uppercase only, so force
// the name to uppercase just in case programmer forgot to do this // the name to uppercase just in case programmer forgot to do this
if ((Dbms() == dbmsORACLE) || if ((Dbms() == dbmsORACLE) ||
(Dbms() == dbmsFIREBIRD) ||
(Dbms() == dbmsINTERBASE)) (Dbms() == dbmsINTERBASE))
TableName = TableName.Upper(); TableName = TableName.Upper();
@ -2903,6 +2905,7 @@ wxDbColInf *wxDb::GetColumns(const wxString &tableName, int *numCols, const wxCh
// Oracle and Interbase table names are uppercase only, so force // Oracle and Interbase table names are uppercase only, so force
// the name to uppercase just in case programmer forgot to do this // the name to uppercase just in case programmer forgot to do this
if ((Dbms() == dbmsORACLE) || if ((Dbms() == dbmsORACLE) ||
(Dbms() == dbmsFIREBIRD) ||
(Dbms() == dbmsINTERBASE)) (Dbms() == dbmsINTERBASE))
TableName = TableName.Upper(); TableName = TableName.Upper();
@ -3142,6 +3145,7 @@ int wxDb::GetColumnCount(const wxString &tableName, const wxChar *userID)
// Oracle and Interbase table names are uppercase only, so force // Oracle and Interbase table names are uppercase only, so force
// the name to uppercase just in case programmer forgot to do this // the name to uppercase just in case programmer forgot to do this
if ((Dbms() == dbmsORACLE) || if ((Dbms() == dbmsORACLE) ||
(Dbms() == dbmsFIREBIRD) ||
(Dbms() == dbmsINTERBASE)) (Dbms() == dbmsINTERBASE))
TableName = TableName.Upper(); TableName = TableName.Upper();
@ -3350,6 +3354,7 @@ bool wxDb::Catalog(const wxChar *userID, const wxString &fileName)
if (!UserID.empty() && if (!UserID.empty() &&
Dbms() != dbmsMY_SQL && Dbms() != dbmsMY_SQL &&
Dbms() != dbmsACCESS && Dbms() != dbmsACCESS &&
Dbms() != dbmsFIREBIRD &&
Dbms() != dbmsINTERBASE && Dbms() != dbmsINTERBASE &&
Dbms() != dbmsMS_SQL_SERVER) Dbms() != dbmsMS_SQL_SERVER)
{ {
@ -3470,6 +3475,7 @@ bool wxDb::TableExists(const wxString &tableName, const wxChar *userID, const wx
// Oracle and Interbase table names are uppercase only, so force // Oracle and Interbase table names are uppercase only, so force
// the name to uppercase just in case programmer forgot to do this // the name to uppercase just in case programmer forgot to do this
if ((Dbms() == dbmsORACLE) || if ((Dbms() == dbmsORACLE) ||
(Dbms() == dbmsFIREBIRD) ||
(Dbms() == dbmsINTERBASE)) (Dbms() == dbmsINTERBASE))
TableName = TableName.Upper(); TableName = TableName.Upper();
@ -3483,6 +3489,7 @@ bool wxDb::TableExists(const wxString &tableName, const wxChar *userID, const wx
Dbms() != dbmsACCESS && Dbms() != dbmsACCESS &&
Dbms() != dbmsMS_SQL_SERVER && Dbms() != dbmsMS_SQL_SERVER &&
Dbms() != dbmsDB2 && Dbms() != dbmsDB2 &&
Dbms() != dbmsFIREBIRD &&
Dbms() != dbmsINTERBASE && Dbms() != dbmsINTERBASE &&
Dbms() != dbmsPERVASIVE_SQL) Dbms() != dbmsPERVASIVE_SQL)
{ {
@ -3541,6 +3548,7 @@ bool wxDb::TablePrivileges(const wxString &tableName, const wxString &priv, cons
// Oracle and Interbase table names are uppercase only, so force // Oracle and Interbase table names are uppercase only, so force
// the name to uppercase just in case programmer forgot to do this // the name to uppercase just in case programmer forgot to do this
if ((Dbms() == dbmsORACLE) || if ((Dbms() == dbmsORACLE) ||
(Dbms() == dbmsFIREBIRD) ||
(Dbms() == dbmsINTERBASE)) (Dbms() == dbmsINTERBASE))
TableName = TableName.Upper(); TableName = TableName.Upper();
@ -3785,8 +3793,18 @@ wxDBMS wxDb::Dbms(void)
if (dbmsType != dbmsUNIDENTIFIED) if (dbmsType != dbmsUNIDENTIFIED)
return(dbmsType); return(dbmsType);
#ifdef DBDEBUG_CONSOLE
// When run in console mode, use standard out to display errors.
cout << "Database connecting to: " << dbInf.dbmsName << endl;
cout << wxT("Press any key to continue...") << endl;
getchar();
#endif // DBDEBUG_CONSOLE
wxLogDebug(wxT("Database connecting to: "));
wxLogDebug(dbInf.dbmsName);
wxChar baseName[25+1]; wxChar baseName[25+1];
wxStrncpy(baseName,dbInf.dbmsName,25); wxStrncpy(baseName, dbInf.dbmsName, 25);
baseName[25] = 0; baseName[25] = 0;
// RGG 20001025 : add support for Interbase // RGG 20001025 : add support for Interbase
@ -3829,6 +3847,9 @@ wxDBMS wxDb::Dbms(void)
if (!wxStricmp(baseName,wxT("Informix"))) if (!wxStricmp(baseName,wxT("Informix")))
return((wxDBMS)(dbmsType = dbmsINFORMIX)); return((wxDBMS)(dbmsType = dbmsINFORMIX));
if (!wxStricmp(baseName,wxT("Firebird")))
return((wxDBMS)(dbmsType = dbmsFIREBIRD));
baseName[6] = 0; baseName[6] = 0;
if (!wxStricmp(baseName,wxT("Oracle"))) if (!wxStricmp(baseName,wxT("Oracle")))
return((wxDBMS)(dbmsType = dbmsORACLE)); return((wxDBMS)(dbmsType = dbmsORACLE));

View File

@ -170,6 +170,11 @@ bool wxDbTable::initialize(wxDb *pwxDb, const wxString &tblName, const UWORD num
return false; return false;
tableName = tblName; // Table Name tableName = tblName; // Table Name
if ((pDb->Dbms() == dbmsORACLE) ||
(pDb->Dbms() == dbmsFIREBIRD) ||
(pDb->Dbms() == dbmsINTERBASE))
tableName = tableName.Upper();
if (tblPath.Length()) if (tblPath.Length())
tablePath = tblPath; // Table Path - used for dBase files tablePath = tblPath; // Table Path - used for dBase files
else else
@ -180,6 +185,11 @@ bool wxDbTable::initialize(wxDb *pwxDb, const wxString &tblName, const UWORD num
else else
queryTableName = tblName; queryTableName = tblName;
if ((pDb->Dbms() == dbmsORACLE) ||
(pDb->Dbms() == dbmsFIREBIRD) ||
(pDb->Dbms() == dbmsINTERBASE))
queryTableName = queryTableName.Upper();
pDb->incrementTableCount(); pDb->incrementTableCount();
wxString s; wxString s;
@ -778,7 +788,7 @@ bool wxDbTable::Open(bool checkPrivileges, bool checkTableExists)
// Unfortunately this optimization doesn't seem to be // Unfortunately this optimization doesn't seem to be
// reliable! // reliable!
if (// *(pDb->dbInf.accessibleTables) == 'N' && if (// *(pDb->dbInf.accessibleTables) == 'N' &&
!pDb->TablePrivileges(tableName,wxT("SELECT"), pDb->GetUsername(), pDb->GetUsername(), tablePath)) !pDb->TablePrivileges(tableName, wxT("SELECT"), pDb->GetUsername(), pDb->GetUsername(), tablePath))
s = wxT("Connecting user does not have sufficient privileges to access this table.\n"); s = wxT("Connecting user does not have sufficient privileges to access this table.\n");
} }
@ -1469,6 +1479,7 @@ bool wxDbTable::CreateTable(bool attemptDrop)
pDb->Dbms() == dbmsMY_SQL || pDb->Dbms() == dbmsMY_SQL ||
pDb->Dbms() == dbmsSYBASE_ASE || pDb->Dbms() == dbmsSYBASE_ASE ||
pDb->Dbms() == dbmsINTERBASE || pDb->Dbms() == dbmsINTERBASE ||
pDb->Dbms() == dbmsFIREBIRD ||
pDb->Dbms() == dbmsMS_SQL_SERVER) pDb->Dbms() == dbmsMS_SQL_SERVER)
{ {
if (colDefs[i].KeyField) if (colDefs[i].KeyField)
@ -1498,6 +1509,7 @@ bool wxDbTable::CreateTable(bool attemptDrop)
case dbmsSYBASE_ASA: case dbmsSYBASE_ASA:
case dbmsSYBASE_ASE: case dbmsSYBASE_ASE:
case dbmsMY_SQL: case dbmsMY_SQL:
case dbmsFIREBIRD:
{ {
// 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
sqlStmt += wxT(",PRIMARY KEY ("); sqlStmt += wxT(",PRIMARY KEY (");
@ -1746,6 +1758,7 @@ bool wxDbTable::CreateIndex(const wxString &idxName, bool unique, UWORD noIdxCol
// Postgres and SQL Server 7 do not support the ASC/DESC keywords for index columns // Postgres and SQL Server 7 do not support the ASC/DESC keywords for index columns
if (!((pDb->Dbms() == dbmsMS_SQL_SERVER) && (wxStrncmp(pDb->dbInf.dbmsVer,_T("07"),2)==0)) && if (!((pDb->Dbms() == dbmsMS_SQL_SERVER) && (wxStrncmp(pDb->dbInf.dbmsVer,_T("07"),2)==0)) &&
!(pDb->Dbms() == dbmsFIREBIRD) &&
!(pDb->Dbms() == dbmsPOSTGRES)) !(pDb->Dbms() == dbmsPOSTGRES))
{ {
if (pIdxDefs[i].Ascending) if (pIdxDefs[i].Ascending)
@ -1770,7 +1783,8 @@ bool wxDbTable::CreateIndex(const wxString &idxName, bool unique, UWORD noIdxCol
#endif #endif
// Execute the CREATE INDEX statement // Execute the CREATE INDEX statement
if (SQLExecDirect(hstmt, (SQLTCHAR FAR *) sqlStmt.c_str(), SQL_NTS) != SQL_SUCCESS) RETCODE retcode = SQLExecDirect(hstmt, (SQLTCHAR FAR *) sqlStmt.c_str(), SQL_NTS);
if (retcode != SQL_SUCCESS)
{ {
pDb->DispAllErrors(henv, hdbc, hstmt); pDb->DispAllErrors(henv, hdbc, hstmt);
pDb->RollbackTrans(); pDb->RollbackTrans();
@ -1820,8 +1834,8 @@ bool wxDbTable::DropIndex(const wxString &idxName)
#ifdef DBDEBUG_CONSOLE #ifdef DBDEBUG_CONSOLE
cout << endl << sqlStmt.c_str() << endl; cout << endl << sqlStmt.c_str() << endl;
#endif #endif
RETCODE retcode = SQLExecDirect(hstmt, (SQLTCHAR FAR *) sqlStmt.c_str(), SQL_NTS);
if (SQLExecDirect(hstmt, (SQLTCHAR FAR *) sqlStmt.c_str(), SQL_NTS) != SQL_SUCCESS) if (retcode != 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);
@ -1831,7 +1845,8 @@ bool wxDbTable::DropIndex(const wxString &idxName)
if (!((pDb->Dbms() == dbmsSYBASE_ASA && !wxStrcmp(pDb->sqlState,wxT("42000"))) || // v5.x (and lower?) if (!((pDb->Dbms() == dbmsSYBASE_ASA && !wxStrcmp(pDb->sqlState,wxT("42000"))) || // v5.x (and lower?)
(pDb->Dbms() == dbmsSYBASE_ASE && !wxStrcmp(pDb->sqlState,wxT("37000"))) || (pDb->Dbms() == dbmsSYBASE_ASE && !wxStrcmp(pDb->sqlState,wxT("37000"))) ||
(pDb->Dbms() == dbmsMS_SQL_SERVER && !wxStrcmp(pDb->sqlState,wxT("S1000"))) || (pDb->Dbms() == dbmsMS_SQL_SERVER && !wxStrcmp(pDb->sqlState,wxT("S1000"))) ||
(pDb->Dbms() == dbmsINTERBASE && !wxStrcmp(pDb->sqlState,wxT("S1000"))) || (pDb->Dbms() == dbmsINTERBASE && !wxStrcmp(pDb->sqlState,wxT("S1000"))) ||
(pDb->Dbms() == dbmsFIREBIRD && !wxStrcmp(pDb->sqlState,wxT("HY000"))) ||
(pDb->Dbms() == dbmsSYBASE_ASE && !wxStrcmp(pDb->sqlState,wxT("S0002"))) || // Base table not found (pDb->Dbms() == dbmsSYBASE_ASE && !wxStrcmp(pDb->sqlState,wxT("S0002"))) || // Base table not found
(pDb->Dbms() == dbmsMY_SQL && !wxStrcmp(pDb->sqlState,wxT("42S12"))) || // tested by Christopher Ludwik Marino-Cebulski using v3.23.21beta (pDb->Dbms() == dbmsMY_SQL && !wxStrcmp(pDb->sqlState,wxT("42S12"))) || // tested by Christopher Ludwik Marino-Cebulski using v3.23.21beta
(pDb->Dbms() == dbmsPOSTGRES && !wxStrcmp(pDb->sqlState,wxT("08S01"))) (pDb->Dbms() == dbmsPOSTGRES && !wxStrcmp(pDb->sqlState,wxT("08S01")))
@ -1903,7 +1918,7 @@ int wxDbTable::Insert(void)
// Insert the record by executing the already prepared insert statement // Insert the record by executing the already prepared insert statement
RETCODE retcode; RETCODE retcode;
retcode=SQLExecute(hstmtInsert); retcode = SQLExecute(hstmtInsert);
if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO && if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO &&
retcode != SQL_NEED_DATA) retcode != SQL_NEED_DATA)
{ {