wxString pgConn::SystemNamespaceRestriction(const wxString &nsp) { if (reservedNamespaces.IsEmpty()) { reservedNamespaces = wxT("'information_schema'"); if (GetIsEdb()) reservedNamespaces += wxT(", 'sys'"); pgSet *set = ExecuteSet( wxT("SELECT nspname FROM pg_namespace nsp\n") wxT(" JOIN pg_proc pr ON pronamespace=nsp.oid\n") wxT(" WHERE proname IN ('slonyversion')")); if (set) { while (!set->Eof()) { reservedNamespaces += wxT(", ") + qtDbString(set->GetVal(wxT("nspname"))); set->MoveNext(); } delete set; } } if (BackendMinimumVersion(8, 1)) return wxT("(") + nsp + wxT(" NOT LIKE E'pg\\_%' AND ") + nsp + wxT(" NOT in (") + reservedNamespaces + wxT("))"); else return wxT("(") + nsp + wxT(" NOT LIKE 'pg\\_%' AND ") + nsp + wxT(" NOT in (") + reservedNamespaces + wxT("))"); }
// Greenplum sometimes adds features in patch releases, because Greenplum // releases are not coordinated with PostgreSQL minor releases. bool pgConn::BackendMinimumVersion(int major, int minor, int patch) { if (!majorVersion) BackendMinimumVersion(0, 0); return majorVersion > major || (majorVersion == major && minorVersion > minor) || (majorVersion == major && minorVersion == minor && patchVersion >= patch); }
wxString pgConn::qtDbString(const wxString &value) { wxString result = value; result.Replace(wxT("\\"), wxT("\\\\")); result.Replace(wxT("'"), wxT("''")); result.Append(wxT("'")); if (BackendMinimumVersion(8, 1)) { if (result.Contains(wxT("\\"))) result.Prepend(wxT("E'")); else result.Prepend(wxT("'")); } else result.Prepend(wxT("'")); return result; }
bool pgConn::EdbMinimumVersion(int major, int minor) { return BackendMinimumVersion(major, minor) && GetIsEdb(); }
bool pgConn::GetIsGreenplum() { // to retrieve Greenplum flag BackendMinimumVersion(0, 0); return isGreenplum; }
bool pgConn::GetIsEdb() { // to retrieve edb flag BackendMinimumVersion(0, 0); return isEdb; }
bool pgConn::Initialize() { // Set client encoding to Unicode/Ascii, Datestyle to ISO, and ask for notices. if (PQstatus(conn) == CONNECTION_OK) { connStatus = PGCONN_OK; PQsetNoticeProcessor(conn, pgNoticeProcessor, this); wxString sql = wxT("SET DateStyle=ISO;\nSET client_min_messages=notice;\n"); if (BackendMinimumVersion(9, 0)) sql += wxT("SET bytea_output=escape;\n"); sql += wxT("SELECT oid, pg_encoding_to_char(encoding) AS encoding, datlastsysoid\n") wxT(" FROM pg_database WHERE "); if (save_oid) sql += wxT("oid = ") + NumToStr(save_oid); else { // Note, can't use qtDbString here as we don't know the server version yet. wxString db = save_database; db.Replace(wxT("\\"), wxT("\\\\")); db.Replace(wxT("'"), wxT("''")); sql += wxT("datname=") + qtString(db); } pgSet *set = ExecuteSet(sql); if (set) { if (set->ColNumber(wxT("\"datlastsysoid\"")) >= 0) needColQuoting = true; lastSystemOID = set->GetOid(wxT("datlastsysoid")); dbOid = set->GetOid(wxT("oid")); wxString encoding = set->GetVal(wxT("encoding")); if (encoding != wxT("SQL_ASCII") && encoding != wxT("MULE_INTERNAL")) { encoding = wxT("UNICODE"); conv = &wxConvUTF8; } else conv = &wxConvLibc; wxLogInfo(wxT("Setting client_encoding to '%s'"), encoding.c_str()); if (PQsetClientEncoding(conn, encoding.ToAscii())) { wxLogError(wxT("%s"), GetLastError().c_str()); } delete set; // Switch to the requested default role if supported by backend if (dbRole != wxEmptyString && BackendMinimumVersion(8, 1)) { sql = wxT("SET ROLE TO "); sql += qtIdent(dbRole); pgSet *set = ExecuteSet(sql); if (set) delete set; else return false; } return true; } } return false; }
bool dbgPgConn::GetIsGreenplum() { // to retrieve edb flag BackendMinimumVersion(0, 0); return m_isGreenplum; }
bool pgConn::GetIsHawq() { // to retrieve Greenplum HAWQ flag BackendMinimumVersion(0, 0); return isHawq; }