bool pgDatabase::CanDebugEdbspl() { // Result cache - 0 = not tested, 1 = false, 2 = true. if (canDebugEdbspl == 1) return false; else if (canDebugEdbspl == 2) return true; // "show shared_preload_libraries" does not work for other than // the super users. if (GetServer()->GetSuperUser()) { // Check the appropriate plugin is loaded if (!ExecuteScalar(wxT("SHOW shared_preload_libraries;")).Contains(wxT("plugin_spl_debugger"))) { canDebugEdbspl = 1; return false; } } if (ExecuteScalar(wxT("SELECT count(*) FROM pg_proc WHERE proname = 'pldbg_get_target_info';")) == wxT("0")) { canDebugEdbspl = 1; return false; } // If this is EDBAS81, the debuggers will be built into the PLs // so we don't need to check any further. if (server->GetConnection()->EdbMinimumVersion(8, 1)) { canDebugEdbspl = 2; return true; } // On EDBAS82 and PostgreSQL, we need to check to make sure that // the debugger library is also available. if (ExecuteScalar(wxT("SELECT count(*) FROM pg_proc WHERE proname = 'edb_oid_debug';")) == wxT("0")) { canDebugEdbspl = 1; return false; } else { canDebugEdbspl = 2; return true; } return true; }
bool pgConn::IsSuperuser() { wxString res = ExecuteScalar( wxT("SELECT rolsuper FROM pg_roles ") wxT("WHERE rolname='") + qtIdent(GetUser()) + wxT("'")); return StrToBool(res); }
bool pgConn::HasPrivilege(const wxString &objTyp, const wxString &objName, const wxString &priv) { wxString res = ExecuteScalar( wxT("SELECT has_") + objTyp.Lower() + wxT("_privilege(") + qtDbString(objName) + wxT(", ") + qtDbString(priv) + wxT(")")); return StrToBool(res); }
/*---------------------------------------------------------------------- | OZN_Database::CheckTableSchema +---------------------------------------------------------------------*/ NPT_Result OZN_Database::CheckTableSchema(const OZN_TableDescription& desc) { NPT_Result res = NPT_FAILURE; NPT_String sql; NPT_String sql_create; OZN_StringProperty schema(0, ""); const char* result; // generate the sql statement we would use to create the table NPT_CHECK(OZN_Sql::CreateTable(desc, sql_create)); // generate the sql statement to query for a table schema NPT_CHECK(OZN_Sql::GetTableSchema(desc.name, sql)); // query the db, if the table doesn't exist it will fail res = ExecuteScalar(sql, schema); result = schema.GetValue().string; if (NPT_SUCCEEDED(res) && result && result[0] != '\0') { //if existing table schema sql matches the one we would use // then it is the same table and same schema version if (NPT_StringsEqual(result, sql_create)) { return NPT_SUCCESS; } // weird, the query succeeded but returned nothing return NPT_FAILURE; } // close bracket OZN_Sql::Close(sql_create); // table doesn't exist, create it NPT_CHECK(ExecuteDML(sql_create, NULL)); if (desc.unique_index_ids_count && desc.unique_index_ids) { res = OZN_Sql::CreateUniqueIndex(desc, desc.unique_index_ids, desc.unique_index_ids_count, sql); NPT_CHECK(res); // close bracket OZN_Sql::Close(sql); // create unique index NPT_CHECK(ExecuteDML(sql, NULL)); } return NPT_SUCCESS; }
bool pgConn::BackendMinimumVersion(int major, int minor) { if (!majorVersion) { wxString version = GetVersionString(); sscanf(version.ToAscii(), "%*s %d.%d.%d", &majorVersion, &minorVersion, &patchVersion); isEdb = version.Upper().Matches(wxT("ENTERPRISEDB*")); // EnterpriseDB 8.3 beta 1 & 2 and possibly later actually have PostgreSQL 8.2 style // catalogs. This is expected to change either before GA, but in the meantime we // need to check the catalogue version in more detail, and if we don't see what looks // like a 8.3 catalog, force the version number back to 8.2. Yuck. if (isEdb && majorVersion == 8 && minorVersion == 3) { if (ExecuteScalar(wxT("SELECT count(*) FROM pg_attribute WHERE attname = 'proconfig' AND attrelid = 'pg_proc'::regclass")) == wxT("0")) minorVersion = 2; } isGreenplum = version.Upper().Matches(wxT("*GREENPLUM DATABASE*")); } return majorVersion > major || (majorVersion == major && minorVersion >= minor); }
bool pgConn::HasFeature(int featureNo, bool forceCheck) { if (!features[FEATURE_INITIALIZED] || forceCheck) { features[FEATURE_INITIALIZED] = true; wxString sql = wxT("SELECT proname, pronargs, proargtypes[0] AS arg0, proargtypes[1] AS arg1, proargtypes[2] AS arg2\n") wxT(" FROM pg_proc\n") wxT(" JOIN pg_namespace n ON n.oid=pronamespace\n") wxT(" WHERE proname IN ('pg_tablespace_size', 'pg_file_read', 'pg_logfile_rotate',") wxT( " 'pg_postmaster_starttime', 'pg_terminate_backend', 'pg_reload_conf',") wxT( " 'pgstattuple', 'pgstatindex')\n") wxT(" AND nspname IN ('pg_catalog', 'public')"); pgSet *set = ExecuteSet(sql); if (set) { while (!set->Eof()) { wxString proname = set->GetVal(wxT("proname")); long pronargs = set->GetLong(wxT("pronargs")); if (proname == wxT("pg_tablespace_size") && pronargs == 1 && set->GetLong(wxT("arg0")) == 26) features[FEATURE_SIZE] = true; else if (proname == wxT("pg_file_read") && pronargs == 3 && set->GetLong(wxT("arg0")) == 25 && set->GetLong(wxT("arg1")) == 20 && set->GetLong(wxT("arg2")) == 20) features[FEATURE_FILEREAD] = true; else if (proname == wxT("pg_logfile_rotate") && pronargs == 0) features[FEATURE_ROTATELOG] = true; else if (proname == wxT("pg_postmaster_starttime") && pronargs == 0) features[FEATURE_POSTMASTER_STARTTIME] = true; else if (proname == wxT("pg_terminate_backend") && pronargs == 1 && set->GetLong(wxT("arg0")) == 23) features[FEATURE_TERMINATE_BACKEND] = true; else if (proname == wxT("pg_reload_conf") && pronargs == 0) features[FEATURE_RELOAD_CONF] = true; else if (proname == wxT("pgstattuple") && pronargs == 1 && set->GetLong(wxT("arg0")) == 25) features[FEATURE_PGSTATTUPLE] = true; else if (proname == wxT("pgstatindex") && pronargs == 1 && set->GetLong(wxT("arg0")) == 25) features[FEATURE_PGSTATINDEX] = true; set->MoveNext(); } delete set; } // Check for EDB function parameter default support wxString defCol = wxT("'proargdefaults'"); if (EdbMinimumVersion(8, 3) && !EdbMinimumVersion(8, 4)) defCol = wxT("'proargdefvals'"); wxString hasFuncDefs = ExecuteScalar(wxT("SELECT count(*) FROM pg_attribute WHERE attrelid = 'pg_catalog.pg_proc'::regclass AND attname = ") + defCol); if (hasFuncDefs == wxT("1")) features[FEATURE_FUNCTION_DEFAULTS] = true; else features[FEATURE_FUNCTION_DEFAULTS] = false; } if (featureNo <= FEATURE_INITIALIZED || featureNo >= FEATURE_LAST) return false; return features[featureNo]; }
wxString pgConn::GetVersionString() { return ExecuteScalar(wxT("SELECT version();")); }
int FbMasterDatabase::GetVersion() { return ExecuteScalar(wxString::Format(wxT("SELECT value FROM %s WHERE id=2"), GetMaster().c_str())); }