Skip to content

Commit

Permalink
Improve schema support for Postgre
Browse files Browse the repository at this point in the history
  • Loading branch information
narfbg committed Dec 3, 2012
1 parent 838a9d6 commit 0259d12
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 12 deletions.
20 changes: 20 additions & 0 deletions system/database/drivers/pdo/subdrivers/pdo_pgsql_driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,26 @@ public function __construct($params)

// --------------------------------------------------------------------

/**
* Database connection
*
* @param bool $persistent
* @return object
*/
public function db_connect($persistent = FALSE)
{
$this->conn_id = parent::db_connect($persistent);

if (is_object($this->conn_id) && ! empty($this->schema))
{
$this->simple_query('SET search_path TO '.$this->schema.',public');
}

return $this->conn_id;
}

// --------------------------------------------------------------------

/**
* Insert ID
*
Expand Down
35 changes: 23 additions & 12 deletions system/database/drivers/postgre/postgre_driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,32 @@ public function __construct($params)
// --------------------------------------------------------------------

/**
* Non-persistent database connection
* Database connection
*
* @param bool $persistent
* @return resource
*/
public function db_connect()
public function db_connect($persistent = FALSE)
{
return @pg_connect($this->dsn);
if ($persistent === TRUE
&& ($conn = @pg_pconnect($this->dsn))
&& pg_connection_status($conn) === PGSQL_CONNECTION_BAD
&& pg_ping($conn) === FALSE
)
{
return FALSE;
}
else
{
$conn = @pg_connect($this->dsn);
}

if ($conn && ! empty($this->schema))
{
$this->simple_query('SET search_path TO '.$this->schema.',public');
}

return $conn;
}

// --------------------------------------------------------------------
Expand All @@ -149,15 +168,7 @@ public function db_connect()
*/
public function db_pconnect()
{
$conn = @pg_pconnect($this->dsn);
if ($conn && pg_connection_status($conn) === PGSQL_CONNECTION_BAD)
{
if (pg_ping($conn) === FALSE)
{
return FALSE;
}
}
return $conn;
return $this->db_connect(TRUE);
}

// --------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions user_guide_src/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ Release Date: Not Released
- Added ``update_batch()`` support.
- Removed ``limit()`` and ``order_by()`` support for *UPDATE* and *DELETE* queries as PostgreSQL does not support those features.
- Added a work-around for dead persistent connections to be re-created after a database restart.
- Changed ``db_connect()`` to include the (new) **schema** value into Postgre's **search_path** session variable.
- Improved support of the CUBRID driver, including:
- Added DSN string support.
- Added persistent connections support.
Expand Down

0 comments on commit 0259d12

Please sign in to comment.