6 , m_typeName(wxEmptyString)
8 , m_libraryPath(wxEmptyString)
27 wxDatabaseResultSetHashSet::iterator start =
m_ResultSets.begin();
28 wxDatabaseResultSetHashSet::iterator stop =
m_ResultSets.end();
31 wxLogDebug(_(
"ResultSet NOT closed and cleaned up by the wxDatabase dtor: Cleaning!"));
41 wxDatabaseStatementHashSet::iterator start =
m_Statements.begin();
42 wxDatabaseStatementHashSet::iterator stop =
m_Statements.end();
45 wxLogDebug(_(
"wxPreparedStatement NOT closed and cleaned up by the wxDatabase dtor"));
54 if (pResultSet != NULL)
67 wxDatabaseStatementHashSet::iterator it;
73 if (pStatement != NULL)
97 if (pStatement != NULL)
122 wxVariant variant(strField);
128 wxVariant variant((
long)nField);
134 bool valueRetrievedFlag =
false;
138 #if wxUSE_DATABASE_EXCEPTIONS 144 while (pResult->
Next())
146 if (valueRetrievedFlag)
159 if (field->IsType(_(
"string")))
163 valueRetrievedFlag =
true;
167 if (!bRequireUniqueResult)
171 #if wxUSE_DATABASE_EXCEPTIONS 173 catch (wxDatabaseException& e)
192 if (!valueRetrievedFlag)
206 wxVariant variant((
long)nField);
212 wxVariant variant(strField);
218 bool valueRetrievedFlag =
false;
219 wxString value = wxEmptyString;
222 #if wxUSE_DATABASE_EXCEPTIONS 228 while (pResult->
Next())
230 if (valueRetrievedFlag)
235 value = wxEmptyString;
243 if (field->IsType(_(
"string")))
247 valueRetrievedFlag =
true;
251 if (!bRequireUniqueResult)
255 #if wxUSE_DATABASE_EXCEPTIONS 257 catch (wxDatabaseException& e)
276 if (!valueRetrievedFlag)
278 value = wxEmptyString;
290 wxVariant variant((
long)nField);
296 wxVariant variant(strField);
302 bool valueRetrievedFlag =
false;
306 #if wxUSE_DATABASE_EXCEPTIONS 312 while (pResult->
Next())
314 if (valueRetrievedFlag)
327 if (field->IsType(_(
"string")))
331 valueRetrievedFlag =
true;
335 if (!bRequireUniqueResult)
339 #if wxUSE_DATABASE_EXCEPTIONS 341 catch (wxDatabaseException& e)
360 if (!valueRetrievedFlag)
374 wxVariant variant((
long)nField);
380 wxVariant variant(strField);
386 bool valueRetrievedFlag =
false;
390 #if wxUSE_DATABASE_EXCEPTIONS 396 while (pResult->
Next())
398 if (valueRetrievedFlag)
411 if (field->IsType(_(
"string")))
415 valueRetrievedFlag =
true;
419 if (!bRequireUniqueResult)
423 #if wxUSE_DATABASE_EXCEPTIONS 425 catch (wxDatabaseException& e)
444 if (!valueRetrievedFlag)
458 wxVariant variant((
long)nField);
464 wxVariant variant(strField);
470 bool valueRetrievedFlag =
false;
471 wxDateTime value = wxInvalidDateTime;
474 #if wxUSE_DATABASE_EXCEPTIONS 480 while (pResult->
Next())
482 if (valueRetrievedFlag)
487 value = wxInvalidDateTime;
495 if (field->IsType(_(
"string")))
499 valueRetrievedFlag =
true;
503 if (!bRequireUniqueResult)
507 #if wxUSE_DATABASE_EXCEPTIONS 509 catch (wxDatabaseException& e)
528 if (!valueRetrievedFlag)
530 value = wxInvalidDateTime;
542 wxVariant variant((
long)nField);
548 wxVariant variant(strField);
554 bool valueRetrievedFlag =
false;
558 #if wxUSE_DATABASE_EXCEPTIONS 564 while (pResult->
Next())
566 if (valueRetrievedFlag)
579 if (field->IsType(_(
"string")))
583 valueRetrievedFlag =
true;
587 if (!bRequireUniqueResult)
591 #if wxUSE_DATABASE_EXCEPTIONS 593 catch (wxDatabaseException& e)
612 if (!valueRetrievedFlag)
626 wxVariant variant((
long)nField);
632 wxVariant variant(strField);
638 bool valueRetrievedFlag =
false;
642 #if wxUSE_DATABASE_EXCEPTIONS 648 while (pResult->
Next())
650 if (valueRetrievedFlag)
663 if (field->IsType(_(
"string")))
667 valueRetrievedFlag =
true;
671 if (!bRequireUniqueResult)
675 #if wxUSE_DATABASE_EXCEPTIONS 677 catch (wxDatabaseException& e)
696 if (!valueRetrievedFlag)
710 wxVariant variant((
long)nField);
716 wxVariant variant(strField);
722 wxArrayInt returnArray;
725 #if wxUSE_DATABASE_EXCEPTIONS 731 while (pResult->
Next())
733 if (field->IsType(_(
"string")))
734 returnArray.Add(pResult->
GetResultInt(field->GetString()));
736 returnArray.Add(pResult->
GetResultInt(field->GetLong()));
738 #if wxUSE_DATABASE_EXCEPTIONS 740 catch (wxDatabaseException& e)
763 wxVariant variant((
long)nField);
769 wxVariant variant(strField);
775 wxArrayString returnArray;
778 #if wxUSE_DATABASE_EXCEPTIONS 784 while (pResult->
Next())
786 if (field->IsType(_(
"string")))
791 #if wxUSE_DATABASE_EXCEPTIONS 793 catch (wxDatabaseException& e)
816 wxVariant variant((
long)nField);
822 wxVariant variant(strField);
828 wxArrayLong returnArray;
831 #if wxUSE_DATABASE_EXCEPTIONS 837 while (pResult->
Next())
839 if (field->IsType(_(
"string")))
844 #if wxUSE_DATABASE_EXCEPTIONS 846 catch (wxDatabaseException& e)
869 wxVariant variant((
long)nField);
875 wxVariant variant(strField);
881 wxArrayDouble returnArray;
884 #if wxUSE_DATABASE_EXCEPTIONS 890 while (pResult->
Next())
892 if (field->IsType(_(
"string")))
897 #if wxUSE_DATABASE_EXCEPTIONS 899 catch (wxDatabaseException& e)
927 config.SetPath(path);
928 for (
bool continue_ = config.GetFirstGroup(name, index); continue_; continue_ = config.GetNextGroup(name, index))
933 config.SetPath(
"..");
937 #if wxUSE_DATABASE_SQLITE 939 if (name.IsSameAs(
"SQLITE"))
941 database = GetSqliteDatabase(config, err);
944 #if wxUSE_DATABASE_POSTGRESQL 946 if (name.IsSameAs(
"POSTGRESQL"))
948 database = GetPostgresDatabase(config, err);
951 #if wxUSE_DATABASE_MYSQL 953 if (name.IsSameAs(
"MYSQL"))
955 database = GetMysqlDatabase(config, err);
958 #if wxUSE_DATABASE_ODBC 960 if (name.IsSameAs(
"ODBC"))
962 database = GetOdbcDatabase(config, err);
966 #if wxUSE_DATABASE_TDS 968 if (name.IsSameAs(
"TDS"))
970 database = GetTdsDatabase(config, err);
973 if (!database)
continue;
983 #if wxUSE_DATABASE_SQLITE 984 wxDatabase* wxDatabase::GetSqliteDatabase(wxConfigBase& config, wxString* err)
986 if (!config.HasGroup(
"SQLite"))
988 if (err) err->Append(
"/SQLite not defined");
991 config.SetPath(
"SQLite");
994 if (!config.Read(
"database", &database))
996 if (err) err->Append(
"/SQLite/database not defined");
1002 wxString libraryPath;
1003 if (config.Read(
"library_path", &libraryPath))
1005 pDatabase->m_libraryPath = libraryPath;
1012 #if wxUSE_DATABASE_POSTGRESQL 1013 wxDatabase* wxDatabase::GetPostgresDatabase(wxConfigBase& config, wxString* err)
1015 if (!config.HasGroup(
"PostgreSQL"))
1017 if (err) err->Append(
"/PostgreSQL not defined");
1020 config.SetPath(
"PostgreSQL");
1024 if (err) err->Append(
"PostgreSQL database backend is not available");
1029 if (!config.Read(
"database", &database))
1031 if (err) err->Append(
"/PostgreSQL/database not defined");
1040 bool haveServerInfo = config.Read(
"server", &server, wxEmptyString);
1041 bool haveUserInfo = config.Read(
"user", &user, wxEmptyString);
1042 config.Read(
"password", &password, wxEmptyString);
1043 config.Read(
"port", &port, 5432);
1047 if (haveServerInfo && haveUserInfo)
1049 else if (haveServerInfo && !haveUserInfo)
1051 else if (haveUserInfo && !haveServerInfo)
1056 wxString libraryPath;
1057 if (config.Read(
"library_path", &libraryPath))
1059 pDatabase->m_libraryPath = libraryPath;
1066 #if wxUSE_DATABASE_MYSQL 1067 wxDatabase* wxDatabase::GetMysqlDatabase(wxConfigBase& config, wxString* err)
1069 if (!config.HasGroup(
"MySQL"))
1071 if (err) err->Append(
"/MySQL not defined");
1074 config.SetPath(
"MySQL");
1078 if (err) err->Append(
"MySQL database backend is not available");
1083 if (!config.Read(
"server", &server))
1085 if (err) err->Append(
"/MySQL/server not defined");
1089 if (!config.Read(
"database", &database))
1091 if (err) err->Append(
"/MySQL/database not defined");
1095 if (!config.Read(
"user", &user))
1097 if (err) err->Append(
"/MySQL/user not defined");
1101 if (!config.Read(
"password", &password))
1103 if (err) err->Append(
"/MySQL/password not defined");
1109 wxString libraryPath;
1110 if (config.Read(
"library_path", &libraryPath))
1112 pDatabase->m_libraryPath = libraryPath;
1119 #if wxUSE_DATABASE_ODBC 1120 wxDatabase* wxDatabase::GetOdbcDatabase(wxConfigBase& config, wxString* err)
1122 if (!config.HasGroup(
"ODBC"))
1124 if (err) err->Append(
"/ODBC not defined");
1127 config.SetPath(
"ODBC");
1131 if (err) err->Append(
"ODBC database backend is not available");
1136 if (!config.Read(
"DbType", &dbType))
1138 if (err) err->Append(
"/ODBC/DbType not defined");
1143 pDatabase->m_typeName = dbType;
1145 wxString connection;
1148 if (config.Read(
"Connection", &connection))
1150 pDatabase->
Open(connection);
1155 if (!config.Read(
"DSN", &DSN, wxEmptyString))
1157 if (err) err->Append(
"/ODBC/DSN not defined");
1160 if (config.Read(
"user", &user, wxEmptyString))
1162 config.Read(
"password", &password, wxEmptyString);
1163 pDatabase->
Open(DSN, user, password);
1167 pDatabase->
Open(DSN, wxEmptyString, wxEmptyString);
1171 wxString libraryPath;
1172 if (config.Read(
"library_path", &libraryPath))
1174 pDatabase->m_libraryPath = libraryPath;
1181 #if wxUSE_DATABASE_TDS 1182 wxDatabase* wxDatabase::GetTdsDatabase(wxConfigBase& config, wxString* err)
1184 if (!config.HasGroup(
"TDS"))
1186 if (err) err->Append(
"/TDS not defined");
1189 config.SetPath(
"TDS");
1192 if (!config.Read(
"freetds", &freetds))
1194 if (err) err->Append(
"/TDS/freetds not defined. Defaulting to environment variable FREETDS");
1197 if (!config.Read(
"server", &server))
1199 if (err) err->Append(
"/TDS/server not defined");
1203 if (!config.Read(
"database", &database))
1205 if (err) err->Append(
"/TDS/database not defined");
1209 if (!config.Read(
"user", &user))
1211 if (err) err->Append(
"/TDS/user not defined. Defaulting to n\"\"");
1214 if (!config.Read(
"password", &password))
1216 if (err) err->Append(
"/TDS/password not defined. Defaulting to n\"\"");
1220 if (!config.Read(
"version", &version))
1222 if (err) err->Append(
"/TDS/version not defined. Defaulting to 7.2");
1226 if (version ==
"4.2")
1228 else if (version ==
"4.6")
1230 else if (version ==
"5.0")
1232 else if (version ==
"7.0")
1234 else if (version ==
"7.1")
1236 else if (version ==
"7.2")
1238 else if (version ==
"7.3")
1240 else if (version ==
"7.4")
1242 else if (version ==
"8.0")
1248 wxString libraryPath;
1249 if (config.Read(
"library_path", &libraryPath))
1251 pDatabase->m_libraryPath = libraryPath;
static bool IsAvailable()
virtual wxDateTime GetSingleResultDate(const wxString &strSQL, int nField, bool bRequireUniqueResult=true)
Retrieve a single date/time value from a query If multiple records are returned from the query,...
virtual bool CloseResultSet(wxDatabaseResultSet *pResultSet)
Close a result set returned by the database or a prepared statement previously.
virtual double GetResultDouble(int nField)=0
Retrieve a double from the result set by the 1-based field index.
virtual void * GetSingleResultBlob(const wxString &strSQL, int nField, wxMemoryBuffer &Buffer, bool bRequireUniqueResult=true)
Retrieve a single Blob value from a query If multiple records are returned from the query,...
virtual wxArrayDouble GetResultsArrayDouble(const wxString &strSQL, int nField)
wxDatabaseResultSetHashSet m_ResultSets
#define wxDATABASE_NO_ROWS_FOUND
virtual wxString GetResultString(int nField)=0
Retrieve a wxString from the result set by the 1-based field index.
wxDatabaseResultSet * ExecuteQuery(const wxString &strQuery)
See RunQueryWithResults.
#define wxDATABASE_NON_UNIQUE_RESULTSET
virtual int GetSingleResultInt(const wxString &strSQL, int nField, bool bRequireUniqueResult=true)
With the GetSingleResultX API, two additional exception types are thrown: wxDATABASE_NO_ROWS_FOUND - ...
static wxDatabase * GetDatabase(wxConfigBase &config, wxString *err=NULL, const wxString &path="/")
Get an instance of the first valid database specified in config.
virtual bool GetSingleResultBool(const wxString &strSQL, int nField, bool bRequireUniqueResult=true)
Retrieve a single bool value from a query If multiple records are returned from the query,...
void ThrowDatabaseException()
virtual int RunQuery(const wxString &strQuery)
Run an insert, update, or delete query on the database.
virtual int GetResultInt(int nField)=0
Retrieve an integer from the result set by the 1-based field index.
virtual bool CloseStatement(wxPreparedStatement *pStatement)
Close a prepared statement previously prepared by the database.
virtual ~wxDatabase()
Destructor.
virtual long GetResultLong(int nField)=0
Retrieve a long from the result set by the 1-based field index.
virtual wxArrayString GetResultsArrayString(const wxString &strSQL, int nField)
void SetErrorMessage(const wxString &strErrorMessage)
virtual bool Next()=0
Move to the next record in the result set.
virtual wxDateTime GetResultDate(int nField)=0
Retrieve a wxDateTime from the result set by the 1-based field index.
virtual void * GetResultBlob(int nField, wxMemoryBuffer &Buffer)=0
Retrieve a BLOB from the result set by the 1-based field index.
static bool IsAvailable()
virtual wxArrayInt GetResultsArrayInt(const wxString &strSQL, int nField)
Retrieve all the values of one field in a result set.
virtual wxArrayLong GetResultsArrayLong(const wxString &strSQL, int nField)
static bool IsAvailable()
void SetErrorCode(int nErrorCode)
void CloseStatements()
Close all prepared statement objects that have been generated but not yet closed.
virtual bool GetResultBool(int nField)=0
Retrieve a boolean from the result set by the 1-based field index.
wxDatabaseStatementHashSet m_Statements
virtual long GetSingleResultLong(const wxString &strSQL, int nField, bool bRequireUniqueResult=true)
Retrieve a single long value from a query If multiple records are returned from the query,...
virtual double GetSingleResultDouble(const wxString &strSQL, int nField, bool bRequireUniqueResult=true)
Retrieve a single double value from a query If multiple records are returned from the query,...
virtual wxString GetSingleResultString(const wxString &strSQL, int nField, bool bRequireUniqueResult=true)
Retrieve a single string value from a query If multiple records are returned from the query,...
void CloseResultSets()
Close all result set objects that have been generated but not yet closed.
virtual bool CloseResultSet(wxDatabaseResultSet *pResultSet)
Close a result set returned by the database or a prepared statement previously.