bool TdsDatabaseLayer::ViewExists(const wxString& view) { bool bReturn = false; // Keep these variables outside of scope so that we can clean them up // in case of an error PreparedStatement* pStatement = NULL; DatabaseResultSet* pResult = NULL; #ifndef DONT_USE_DATABASE_LAYER_EXCEPTIONS try { #endif wxString query = _("exec sp_tables ?, NULL, NULL, '''VIEW'''"); pStatement = PrepareStatement(query); if (pStatement) { pStatement->SetParamString(1, view); pResult = pStatement->ExecuteQuery(); if (pResult) { if (pResult->Next()) { //wxPrintf(_("View found: '%s'\n"), pResult->GetResultString(_("TABLE_NAME"))); if(view.CmpNoCase(pResult->GetResultString(_("TABLE_NAME"))) == 0) { bReturn = true; } } } } #ifndef DONT_USE_DATABASE_LAYER_EXCEPTIONS } catch (DatabaseLayerException& e) { if (pResult != NULL) { CloseResultSet(pResult); pResult = NULL; } if (pStatement != NULL) { CloseStatement(pStatement); pStatement = NULL; } throw e; } #endif if (pResult != NULL) { CloseResultSet(pResult); pResult = NULL; } if (pStatement != NULL) { CloseStatement(pStatement); pStatement = NULL; } return bReturn; }
wxArrayString FirebirdDatabaseLayer::GetColumns(const wxString& table) { // Initialize variables wxArrayString returnArray; // Keep these variables outside of scope so that we can clean them up // in case of an error PreparedStatement* pStatement = NULL; DatabaseResultSet* pResult = NULL; #ifndef DONT_USE_DATABASE_LAYER_EXCEPTIONS try { #endif wxString tableUpperCase = table.Upper(); wxString query = _("SELECT RDB$FIELD_NAME FROM RDB$RELATION_FIELDS WHERE RDB$RELATION_NAME=?;"); pStatement = PrepareStatement(query); if (pStatement) { pStatement->SetParamString(1, tableUpperCase); pResult = pStatement->ExecuteQuery(); if (pResult) { while (pResult->Next()) { returnArray.Add(pResult->GetResultString(1).Trim()); } } } #ifndef DONT_USE_DATABASE_LAYER_EXCEPTIONS } catch (DatabaseLayerException& e) { if (pResult != NULL) { CloseResultSet(pResult); pResult = NULL; } if (pStatement != NULL) { CloseStatement(pStatement); pStatement = NULL; } throw e; } #endif if (pResult != NULL) { CloseResultSet(pResult); pResult = NULL; } if (pStatement != NULL) { CloseStatement(pStatement); pStatement = NULL; } return returnArray; }
wxArrayString PostgresDatabaseLayer::GetColumns(const wxString& table) { // Initialize variables wxArrayString returnArray; // Keep these variables outside of scope so that we can clean them up // in case of an error PreparedStatement* pStatement = NULL; DatabaseResultSet* pResult = NULL; #ifndef DONT_USE_DATABASE_LAYER_EXCEPTIONS try { #endif wxString query = _("SELECT column_name FROM information_schema.columns WHERE table_name=? ORDER BY ordinal_position;"); pStatement = PrepareStatement(query); if (pStatement) { pStatement->SetParamString(1, table); pResult = pStatement->ExecuteQuery(); if (pResult) { while (pResult->Next()) { returnArray.Add(pResult->GetResultString(1)); } } } #ifndef DONT_USE_DATABASE_LAYER_EXCEPTIONS } catch (DatabaseLayerException& e) { if (pResult != NULL) { CloseResultSet(pResult); pResult = NULL; } if (pStatement != NULL) { CloseStatement(pStatement); pStatement = NULL; } throw e; } #endif if (pResult != NULL) { CloseResultSet(pResult); pResult = NULL; } if (pStatement != NULL) { CloseStatement(pStatement); pStatement = NULL; } return returnArray; }
bool FirebirdDatabaseLayer::ViewExists(const wxString& view) { // Initialize variables bool bReturn = false; // Keep these variables outside of scope so that we can clean them up // in case of an error PreparedStatement* pStatement = NULL; DatabaseResultSet* pResult = NULL; #ifndef DONT_USE_DATABASE_LAYER_EXCEPTIONS try { #endif wxString viewUpperCase = view.Upper(); wxString query = _("SELECT COUNT(*) FROM RDB$RELATIONS WHERE RDB$SYSTEM_FLAG=0 AND RDB$VIEW_BLR IS NOT NULL AND RDB$RELATION_NAME=?;"); pStatement = PrepareStatement(query); if (pStatement) { pStatement->SetParamString(1, viewUpperCase); pResult = pStatement->ExecuteQuery(); if (pResult) { if (pResult->Next()) { if(pResult->GetResultInt(1) != 0) { bReturn = true; } } } } #ifndef DONT_USE_DATABASE_LAYER_EXCEPTIONS } catch (DatabaseLayerException& e) { if (pResult != NULL) { CloseResultSet(pResult); pResult = NULL; } if (pStatement != NULL) { CloseStatement(pStatement); pStatement = NULL; } throw e; } #endif if (pResult != NULL) { CloseResultSet(pResult); pResult = NULL; } if (pStatement != NULL) { CloseStatement(pStatement); pStatement = NULL; } return bReturn; }
bool PostgresDatabaseLayer::ViewExists(const wxString& view) { // Initialize variables bool bReturn = false; // Keep these variables outside of scope so that we can clean them up // in case of an error PreparedStatement* pStatement = NULL; DatabaseResultSet* pResult = NULL; #ifndef DONT_USE_DATABASE_LAYER_EXCEPTIONS try { #endif wxString query = _("SELECT COUNT(*) FROM information_schema.tables WHERE table_type='VIEW' AND table_name=?;"); pStatement = PrepareStatement(query); if (pStatement) { pStatement->SetParamString(1, view); pResult = pStatement->ExecuteQuery(); if (pResult) { if (pResult->Next()) { if(pResult->GetResultInt(1) != 0) { bReturn = true; } } } } #ifndef DONT_USE_DATABASE_LAYER_EXCEPTIONS } catch (DatabaseLayerException& e) { if (pResult != NULL) { CloseResultSet(pResult); pResult = NULL; } if (pStatement != NULL) { CloseStatement(pStatement); pStatement = NULL; } throw e; } #endif if (pResult != NULL) { CloseResultSet(pResult); pResult = NULL; } if (pStatement != NULL) { CloseStatement(pStatement); pStatement = NULL; } return bReturn; }