3 #if wxUSE_DATABASE_POSTGRESQL 9 #ifndef DONT_USE_DYNAMIC_DATABASE_LINKING 14 SetErrorMessage(wxT(
"Error loading PostgreSQL library"));
15 ThrowDatabaseException();
19 m_strServer = _(
"localhost");
21 m_strPassword = wxT(
"");
22 m_strDatabase = wxT(
"");
29 #ifndef DONT_USE_DYNAMIC_DATABASE_LINKING 34 SetErrorMessage(wxT(
"Error loading PostgreSQL library"));
35 ThrowDatabaseException();
39 m_strServer = _(
"localhost");
41 m_strPassword = wxT(
"");
50 #ifndef DONT_USE_DYNAMIC_DATABASE_LINKING 55 SetErrorMessage(wxT(
"Error loading PostgreSQL library"));
56 ThrowDatabaseException();
60 m_strServer = strServer;
62 m_strPassword = wxT(
"");
71 #ifndef DONT_USE_DYNAMIC_DATABASE_LINKING 76 SetErrorMessage(wxT(
"Error loading PostgreSQL library"));
77 ThrowDatabaseException();
81 m_strServer = _(
"localhost");
83 m_strPassword = strPassword;
92 #ifndef DONT_USE_DYNAMIC_DATABASE_LINKING 97 SetErrorMessage(wxT(
"Error loading PostgreSQL library"));
98 ThrowDatabaseException();
102 m_strServer = strServer;
104 m_strPassword = strPassword;
113 #ifndef DONT_USE_DYNAMIC_DATABASE_LINKING 118 SetErrorMessage(wxT(
"Error loading PostgreSQL library"));
119 ThrowDatabaseException();
123 m_strServer = strServer;
125 m_strPassword = strPassword;
126 m_strPort = wxString::Format(_(
"%d"), nPort);
143 wxCharBuffer serverCharBuffer;
144 const char* pHost = NULL;
146 const char* pDatabase = pDatabaseBuffer;
147 wxCharBuffer userCharBuffer;
148 const char* pUser = NULL;
149 wxCharBuffer passwordCharBuffer;
150 const char* pPassword = NULL;
151 const char* pTty = NULL;
152 const char* pOptions = NULL;
153 wxCharBuffer portCharBuffer;
154 const char* pPort = NULL;
159 pHost = serverCharBuffer;
165 pUser = userCharBuffer;
171 pPassword = passwordCharBuffer;
177 pPort = portCharBuffer;
222 bool wxPostgresDatabase::Open(
const wxString& strServer,
const wxString& strDatabase,
const wxString& strUser,
const wxString& strPassword)
232 bool wxPostgresDatabase::Open(
const wxString& strServer,
int nPort,
const wxString& strDatabase,
const wxString& strUser,
const wxString& strPassword)
259 m_strPort = wxString::Format(_(
"%d"), nPort);
308 rowsAffected.ToLong(&rows);
350 bool bReturn =
false;
356 #if wxUSE_DATABASE_EXCEPTIONS 360 wxString query = _(
"SELECT COUNT(*) FROM information_schema.tables WHERE table_type='BASE TABLE' AND table_name=?;");
377 #if wxUSE_DATABASE_EXCEPTIONS 379 catch (wxDatabaseException& e)
387 if (pStatement != NULL)
403 if (pStatement != NULL)
415 bool bReturn =
false;
421 #if wxUSE_DATABASE_EXCEPTIONS 425 wxString query = _(
"SELECT COUNT(*) FROM information_schema.tables WHERE table_type='VIEW' AND table_name=?;");
442 #if wxUSE_DATABASE_EXCEPTIONS 444 catch (wxDatabaseException& e)
452 if (pStatement != NULL)
468 if (pStatement != NULL)
479 wxArrayString returnArray;
482 #if wxUSE_DATABASE_EXCEPTIONS 486 wxString query = _(
"SELECT table_name FROM information_schema.tables WHERE table_type='BASE TABLE' AND table_schema='public';");
489 while (pResult->
Next())
493 #if wxUSE_DATABASE_EXCEPTIONS 495 catch (wxDatabaseException& e)
518 wxArrayString returnArray;
521 #if wxUSE_DATABASE_EXCEPTIONS 525 wxString query = _(
"SELECT table_name FROM information_schema.tables WHERE table_type='VIEW' AND table_schema='public';");
528 while (pResult->
Next())
532 #if wxUSE_DATABASE_EXCEPTIONS 534 catch (wxDatabaseException& e)
558 wxArrayString returnArray;
565 #if wxUSE_DATABASE_EXCEPTIONS 569 wxString query = _(
"SELECT column_name FROM information_schema.columns WHERE table_name=? ORDER BY ordinal_position;");
577 while (pResult->
Next())
583 #if wxUSE_DATABASE_EXCEPTIONS 585 catch (wxDatabaseException& e)
593 if (pStatement != NULL)
609 if (pStatement != NULL)
622 wxArrayString returnArray;
629 #if wxUSE_DATABASE_EXCEPTIONS 633 wxString query = _(
"SELECT pg_attribute.attname,format_type(pg_attribute.atttypid, pg_attribute.atttypmod) FROM pg_index, pg_class, pg_attribute WHERE pg_class.oid = ? ::regclass AND indrelid = pg_class.oid AND pg_attribute.attrelid = pg_class.oid AND pg_attribute.attnum = any(pg_index.indkey) AND indisprimary;");
641 while (pResult->
Next())
647 #if wxUSE_DATABASE_EXCEPTIONS 649 catch (wxDatabaseException& e)
657 if (pStatement != NULL)
673 if (pStatement != NULL)
693 bool bAvailable =
false;
695 bAvailable = pInterface && pInterface->
Init();
696 wxDELETE(pInterface);
700 #endif//wxUSE_DATABASE_POSTGRESQL
virtual wxPreparedStatement * PrepareStatement(const wxString &strQuery)
Prepare a SQL statement which can be reused with different parameters.
virtual bool IsOpen()
Is the connection to the database open?
virtual wxArrayString GetColumns(const wxString &table)
Retrieve all column names for a table.
static wxPostgresPreparedStatement * CreateStatement(wxDynamicPostgresInterface *pInterface, PGconn *pDatabase, const wxString &strSQL)
PQclientEncodingType GetPQclientEncoding()
virtual wxArrayString GetPKColumns(const wxString &table)
get Primary keys column names
PQsetClientEncodingType GetPQsetClientEncoding()
virtual void RollBack()
Rollback the current transaction.
virtual wxString GetResultString(int nField)=0
Retrieve a wxString from the result set by the 1-based field index.
virtual void Commit()
Commit the current transaction.
wxDatabaseResultSet * ExecuteQuery(const wxString &strQuery)
See RunQueryWithResults.
static int TranslateErrorCode(int nCode)
virtual int RunQuery(const wxString &strQuery, bool bParseQuery)
Run an insert, update, or delete query on the database.
PQsetdbLoginType GetPQsetdbLogin()
PQencodingToCharType GetPQencodingToChar()
PQfinishType GetPQfinish()
void ThrowDatabaseException()
PQstatusType GetPQstatus()
virtual int GetResultInt(int nField)=0
Retrieve an integer from the result set by the 1-based field index.
virtual wxDatabaseResultSet * RunQueryWithResults(const wxString &strQuery)
Run a select query on the database.
virtual bool CloseStatement(wxPreparedStatement *pStatement)
Close a prepared statement previously prepared by the database.
virtual bool ViewExists(const wxString &view)
Check for the existence of a view by name.
virtual bool Close()
close database
virtual wxArrayString GetTables()
Retrieve all table names.
void SetErrorMessage(const wxString &strErrorMessage)
wxDatabaseResultSet * ExecuteQuery()
See RunQueryWithResults.
virtual ~wxPostgresDatabase()
virtual bool Next()=0
Move to the next record in the result set.
void LogStatementForCleanup(wxPreparedStatement *pStatement)
Add prepared statement object pointer to the list for "garbage collection".
void SetEncoding(wxFontEncoding encoding)
void LogResultSetForCleanup(wxDatabaseResultSet *pResultSet)
Add result set object pointer to the list for "garbage collection".
#define wxDATABASE_QUERY_RESULT_ERROR
wxDynamicPostgresInterface * m_pInterface
static bool IsAvailable()
virtual void BeginTransaction()
Begin a transaction.
void SetErrorCode(int nErrorCode)
#define wxDATABASE_ERROR_LOADING_LIBRARY
void CloseStatements()
Close all prepared statement objects that have been generated but not yet closed.
virtual wxString ConvertFromUnicodeStream(const char *inputBuffer)
PQresultStatusType GetPQresultStatus()
const wxCSConv * GetEncoding()
virtual const wxCharBuffer ConvertToUnicodeStream(const wxString &inputString)
PQerrorMessageType GetPQerrorMessage()
virtual bool TableExists(const wxString &table)
Check for the existence of a table by name.
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.
virtual wxArrayString GetViews()
Retrieve all view names.
PQcmdTuplesType GetPQcmdTuples()
virtual void SetParamString(int nPosition, const wxString &strValue)=0
Set the parameter at the 1-based position to a wxString value.