Add support for non-public schemas with pgsql (#2341)

This commit is contained in:
Nicholas Hastings
2026-07-27 20:35:59 -04:00
parent bc69fc9f8e
commit cfa6193bb8
7 changed files with 24 additions and 3 deletions
+2
View File
@@ -137,11 +137,13 @@ PgDatabase::PgDatabase(PGconn *pgsql, const DatabaseInfo *info, bool persistent)
m_Database.assign(info->database);
m_User.assign(info->user);
m_Pass.assign(info->pass);
m_Schema.assign(info->dbiVersion >= 10 && info->schemaName ? info->schemaName : "");
m_Info.database = m_Database.c_str();
m_Info.host = m_Host.c_str();
m_Info.user = m_User.c_str();
m_Info.pass = m_Pass.c_str();
m_Info.schemaName = m_Schema.c_str();
m_Info.driver = NULL;
m_Info.maxTimeout = info->maxTimeout;
m_Info.port = info->port;
+1
View File
@@ -85,6 +85,7 @@ private:
String m_Database;
String m_User;
String m_Pass;
String m_Schema;
bool m_bPersistent;
};
+13 -2
View File
@@ -93,12 +93,14 @@ const char *PgDriver::GetProductName()
PGconn *Connect(const DatabaseInfo *info, char *error, size_t maxlength)
{
const char *keywords[7];
const char *values[7];
const char *keywords[8];
const char *values[8];
unsigned int count = 0;
char port[16];
char timeout[16];
char options[1024];
const char *searchPath = info->dbiVersion >= 10 ? info->schemaName : NULL;
keywords[count] = "host";
values[count++] = info->host;
@@ -131,6 +133,14 @@ PGconn *Connect(const DatabaseInfo *info, char *error, size_t maxlength)
values[count++] = timeout;
}
if (searchPath && searchPath[0] != '\0')
{
// libpq splits options on spaces; schema names containing spaces need escaping.
snprintf(options, sizeof(options), "-c search_path=%s", searchPath);
keywords[count] = "options";
values[count++] = options;
}
keywords[count] = NULL;
values[count] = NULL;
@@ -192,6 +202,7 @@ IDatabase *PgDriver::Connect(const DatabaseInfo *info, bool persistent, char *er
&& CompareField(info->user, other.user)
&& CompareField(info->pass, other.pass)
&& CompareField(info->database, other.database)
&& CompareField(info->dbiVersion >= 10 ? info->schemaName : NULL, other.schemaName)
&& (info->port == other.port))
{
db->IncReferenceCount();