CI_DB_postgre_driver Class Reference

Inheritance diagram for CI_DB_postgre_driver:
Collaboration diagram for CI_DB_postgre_driver:

List of all members.


Public Member Functions

 _connect_string ()
 Connection String.
 db_connect ()
 Non-persistent database connection.
 db_pconnect ()
 Persistent database connection.
 db_select ()
 Select the database.
 db_set_charset ($charset, $collation)
 Set client character set.
 _version ()
 Version number query string.
 _execute ($sql)
 Execute the query.
 _prep_query ($sql)
 Prep the query.
 trans_begin ($test_mode=FALSE)
 Begin Transaction.
 trans_commit ()
 Commit Transaction.
 trans_rollback ()
 Rollback Transaction.
 escape_str ($str)
 Escape String.
 affected_rows ()
 Affected Rows.
 insert_id ()
 Insert ID.
 count_all ($table= '')
 "Count All" query
 _list_tables ($prefix_limit=FALSE)
 Show table query.
 _list_columns ($table= '')
 Show column query.
 _field_data ($table)
 Field data query.
 _error_message ()
 The error message string.
 _error_number ()
 The error message number.
 _escape_identifiers ($item)
 Escape the SQL Identifiers.
 _from_tables ($tables)
 From Tables.
 _insert ($table, $keys, $values)
 Insert statement.
 _update ($table, $values, $where, $orderby=array(), $limit=FALSE)
 Update statement.
 _truncate ($table)
 Truncate statement.
 _delete ($table, $where=array(), $like=array(), $limit=FALSE)
 Delete statement.
 _limit ($sql, $limit, $offset)
 Limit string.
 _close ($conn_id)
 Close DB Connection.

Public Attributes

 $dbdriver = 'postgre'
 $_escape_char = '"'
 $_count_string = "SELECT COUNT(*) AS "
 The syntax to count rows is slightly different across different database engines, so this string appears in each driver and is used for the count_all() and count_all_results() functions.
 $_random_keyword = ' RANDOM()'

Detailed Description

Definition at line 31 of file postgre_driver.php.


Member Function Documentation

CI_DB_postgre_driver::_close ( conn_id  ) 

Close DB Connection.

public

Parameters:
resource 
Returns:
void

Definition at line 615 of file postgre_driver.php.

00616         {
00617                 @pg_close($conn_id);
00618         }

CI_DB_postgre_driver::_connect_string (  ) 

Connection String.

private

Returns:
string

Definition at line 51 of file postgre_driver.php.

Referenced by db_connect(), and db_pconnect().

00052         {
00053                 $components = array(
00054                                                                 'hostname'      => 'host',
00055                                                                 'port'          => 'port',
00056                                                                 'database'      => 'dbname',
00057                                                                 'username'      => 'user',
00058                                                                 'password'      => 'password'
00059                                                         );
00060                 
00061                 $connect_string = "";
00062                 foreach ($components as $key => $val)
00063                 {
00064                         if (isset($this->$key) && $this->$key != '')
00065                         {
00066                                 $connect_string .= " $val=".$this->$key;
00067                         }
00068                 }
00069                 return trim($connect_string);
00070         }

Here is the caller graph for this function:

CI_DB_postgre_driver::_delete ( table,
where = array(),
like = array(),
limit = FALSE 
)

Delete statement.

Generates a platform-specific delete string from the supplied data

public

Parameters:
string the table name
array the where clause
string the limit clause
Returns:
string

Definition at line 561 of file postgre_driver.php.

00562         {
00563                 $conditions = '';
00564 
00565                 if (count($where) > 0 OR count($like) > 0)
00566                 {
00567                         $conditions = "\nWHERE ";
00568                         $conditions .= implode("\n", $this->ar_where);
00569 
00570                         if (count($where) > 0 && count($like) > 0)
00571                         {
00572                                 $conditions .= " AND ";
00573                         }
00574                         $conditions .= implode("\n", $like);
00575                 }
00576 
00577                 $limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
00578         
00579                 return "DELETE FROM ".$table.$conditions.$limit;
00580         }

CI_DB_postgre_driver::_error_message (  ) 

The error message string.

private

Returns:
string

Definition at line 406 of file postgre_driver.php.

00407         {
00408                 return pg_last_error($this->conn_id);
00409         }

CI_DB_postgre_driver::_error_number (  ) 

The error message number.

private

Returns:
integer

Definition at line 419 of file postgre_driver.php.

00420         {
00421                 return '';
00422         }

CI_DB_postgre_driver::_escape_identifiers ( item  ) 

Escape the SQL Identifiers.

This function escapes column and table names

private

Parameters:
string 
Returns:
string

Definition at line 435 of file postgre_driver.php.

00436         {
00437                 if ($this->_escape_char == '')
00438                 {
00439                         return $item;
00440                 }
00441         
00442                 if (strpos($item, '.') !== FALSE)
00443                 {
00444                         $str = $this->_escape_char.str_replace('.', $this->_escape_char.'.'.$this->_escape_char, $item).$this->_escape_char;                    
00445                 }
00446                 else
00447                 {
00448                         $str = $this->_escape_char.$item.$this->_escape_char;
00449                 }
00450                 
00451                 // remove duplicates if the user already included the escape
00452                 return preg_replace('/['.$this->_escape_char.']+/', $this->_escape_char, $str);
00453         }

CI_DB_postgre_driver::_execute ( sql  ) 

Execute the query.

private called by the base class

Parameters:
string an SQL query
Returns:
resource

Definition at line 150 of file postgre_driver.php.

References _prep_query().

00151         {
00152                 $sql = $this->_prep_query($sql);
00153                 return @pg_query($this->conn_id, $sql);
00154         }

Here is the call graph for this function:

CI_DB_postgre_driver::_field_data ( table  ) 

Field data query.

Generates a platform-specific query so that the column data can be retrieved

public

Parameters:
string the table name
Returns:
object

Definition at line 393 of file postgre_driver.php.

00394         {
00395                 return "SELECT * FROM ".$table." LIMIT 1";
00396         }

CI_DB_postgre_driver::_from_tables ( tables  ) 

From Tables.

This function implicitly groups FROM tables so there is no confusion about operator precedence in harmony with SQL standards

public

Parameters:
type 
Returns:
type

Definition at line 467 of file postgre_driver.php.

00468         {
00469                 if ( ! is_array($tables))
00470                 {
00471                         $tables = array($tables);
00472                 }
00473                 
00474                 return implode(', ', $tables);
00475         }

CI_DB_postgre_driver::_insert ( table,
keys,
values 
)

Insert statement.

Generates a platform-specific insert string from the supplied data

public

Parameters:
string the table name
array the insert keys
array the insert values
Returns:
string

Definition at line 490 of file postgre_driver.php.

00491         {       
00492                 return "INSERT INTO ".$table." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")";
00493         }

CI_DB_postgre_driver::_limit ( sql,
limit,
offset 
)

Limit string.

Generates a platform-specific LIMIT clause

public

Parameters:
string the sql query string
integer the number of rows to limit the query to
integer the offset value
Returns:
string

Definition at line 594 of file postgre_driver.php.

00595         {       
00596                 $sql .= "LIMIT ".$limit;
00597         
00598                 if ($offset > 0)
00599                 {
00600                         $sql .= " OFFSET ".$offset;
00601                 }
00602                 
00603                 return $sql;
00604         }

CI_DB_postgre_driver::_list_columns ( table = ''  ) 

Show column query.

Generates a platform-specific query string so that the column names can be fetched

public

Parameters:
string the table name
Returns:
string

Definition at line 377 of file postgre_driver.php.

00378         {
00379                 return "SELECT column_name FROM information_schema.columns WHERE table_name ='".$table."'";
00380         }

CI_DB_postgre_driver::_list_tables ( prefix_limit = FALSE  ) 

Show table query.

Generates a platform-specific query string so that the table names can be fetched

private

Parameters:
boolean 
Returns:
string

Definition at line 354 of file postgre_driver.php.

00355         {       
00356                 $sql = "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public'";        
00357                 
00358                 if ($prefix_limit !== FALSE AND $this->dbprefix != '')
00359                 {
00360                         $sql .= " AND table_name LIKE '".$this->dbprefix."%'";
00361                 }
00362                 
00363                 return $sql;
00364         }

CI_DB_postgre_driver::_prep_query ( sql  ) 

Prep the query.

If needed, each database adapter can prep the query string

private called by execute()

Parameters:
string an SQL query
Returns:
string

Definition at line 167 of file postgre_driver.php.

Referenced by _execute().

00168         {
00169                 return $sql;
00170         }

Here is the caller graph for this function:

CI_DB_postgre_driver::_truncate ( table  ) 

Truncate statement.

Generates a platform-specific truncate string from the supplied data If the database does not support the truncate() command This function maps to "DELETE FROM table"

public

Parameters:
string the table name
Returns:
string

Definition at line 543 of file postgre_driver.php.

00544         {
00545                 return "TRUNCATE ".$table;
00546         }

CI_DB_postgre_driver::_update ( table,
values,
where,
orderby = array(),
limit = FALSE 
)

Update statement.

Generates a platform-specific update string from the supplied data

public

Parameters:
string the table name
array the update data
array the where clause
array the orderby clause
array the limit clause
Returns:
string

Definition at line 510 of file postgre_driver.php.

00511         {
00512                 foreach($values as $key => $val)
00513                 {
00514                         $valstr[] = $key." = ".$val;
00515                 }
00516                 
00517                 $limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
00518                 
00519                 $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):'';
00520         
00521                 $sql = "UPDATE ".$table." SET ".implode(', ', $valstr);
00522 
00523                 $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : '';
00524 
00525                 $sql .= $orderby.$limit;
00526                 
00527                 return $sql;
00528         }

CI_DB_postgre_driver::_version (  ) 

Version number query string.

public

Returns:
string

Definition at line 136 of file postgre_driver.php.

Referenced by insert_id().

00137         {
00138                 return "SELECT version() AS ver";
00139         }

Here is the caller graph for this function:

CI_DB_postgre_driver::affected_rows (  ) 

Affected Rows.

public

Returns:
integer

Definition at line 271 of file postgre_driver.php.

00272         {
00273                 return @pg_affected_rows($this->result_id);
00274         }

CI_DB_postgre_driver::count_all ( table = ''  ) 

"Count All" query

Generates a platform-specific query string that counts all records in the specified database

public

Parameters:
string 
Returns:
string

Definition at line 329 of file postgre_driver.php.

00330         {
00331                 if ($table == '')
00332                         return '0';
00333 
00334                 $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows'). " FROM " . $this->_protect_identifiers($table, TRUE, NULL, FALSE));
00335                                 
00336                 if ($query->num_rows() == 0)
00337                         return '0';
00338 
00339                 $row = $query->row();
00340                 return $row->numrows;
00341         }

CI_DB_postgre_driver::db_connect (  ) 

Non-persistent database connection.

private called by the base class

Returns:
resource

Definition at line 80 of file postgre_driver.php.

References _connect_string().

00081         {               
00082                 return @pg_connect($this->_connect_string());
00083         }

Here is the call graph for this function:

CI_DB_postgre_driver::db_pconnect (  ) 

Persistent database connection.

private called by the base class

Returns:
resource

Definition at line 93 of file postgre_driver.php.

References _connect_string().

00094         {
00095                 return @pg_pconnect($this->_connect_string());
00096         }

Here is the call graph for this function:

CI_DB_postgre_driver::db_select (  ) 

Select the database.

private called by the base class

Returns:
resource

Definition at line 106 of file postgre_driver.php.

00107         {
00108                 // Not needed for Postgre so we'll return TRUE
00109                 return TRUE;
00110         }

CI_DB_postgre_driver::db_set_charset ( charset,
collation 
)

Set client character set.

public

Parameters:
string 
string 
Returns:
resource

Definition at line 122 of file postgre_driver.php.

00123         {
00124                 // @todo - add support if needed
00125                 return TRUE;
00126         }

CI_DB_postgre_driver::escape_str ( str  ) 

Escape String.

public

Parameters:
string 
Returns:
string

Definition at line 258 of file postgre_driver.php.

00259         {       
00260                 return pg_escape_string($str);
00261         }

CI_DB_postgre_driver::insert_id (  ) 

Insert ID.

public

Returns:
integer

Definition at line 284 of file postgre_driver.php.

References _version().

00285         {
00286                 $v = $this->_version();
00287                 $v = $v['server'];
00288                 
00289                 $table  = func_num_args() > 0 ? func_get_arg(0) : null;
00290                 $column = func_num_args() > 1 ? func_get_arg(1) : null;
00291                 
00292                 if ($table == null && $v >= '8.1')
00293                 {
00294                         $sql='SELECT LASTVAL() as ins_id';
00295                 }
00296                 elseif ($table != null && $column != null && $v >= '8.0')
00297                 {
00298                         $sql = sprintf("SELECT pg_get_serial_sequence('%s','%s') as seq", $table, $column);
00299                         $query = $this->query($sql);
00300                         $row = $query->row();
00301                         $sql = sprintf("SELECT CURRVAL('%s') as ins_id", $row->seq);
00302                 }
00303                 elseif ($table != null)
00304                 {
00305                         // seq_name passed in table parameter
00306                         $sql = sprintf("SELECT CURRVAL('%s') as ins_id", $table);
00307                 }
00308                 else
00309                 {
00310                         return pg_last_oid($this->result_id);
00311                 }
00312                 $query = $this->query($sql);
00313                 $row = $query->row();
00314                 return $row->ins_id;
00315         }

Here is the call graph for this function:

CI_DB_postgre_driver::trans_begin ( test_mode = FALSE  ) 

Begin Transaction.

public

Returns:
bool

Definition at line 180 of file postgre_driver.php.

00181         {
00182                 if ( ! $this->trans_enabled)
00183                 {
00184                         return TRUE;
00185                 }
00186                 
00187                 // When transactions are nested we only begin/commit/rollback the outermost ones
00188                 if ($this->_trans_depth > 0)
00189                 {
00190                         return TRUE;
00191                 }
00192 
00193                 // Reset the transaction failure flag.
00194                 // If the $test_mode flag is set to TRUE transactions will be rolled back
00195                 // even if the queries produce a successful result.
00196                 $this->_trans_failure = ($test_mode === TRUE) ? TRUE : FALSE;
00197 
00198                 return @pg_exec($this->conn_id, "begin");
00199         }

CI_DB_postgre_driver::trans_commit (  ) 

Commit Transaction.

public

Returns:
bool

Definition at line 209 of file postgre_driver.php.

00210         {
00211                 if ( ! $this->trans_enabled)
00212                 {
00213                         return TRUE;
00214                 }
00215 
00216                 // When transactions are nested we only begin/commit/rollback the outermost ones
00217                 if ($this->_trans_depth > 0)
00218                 {
00219                         return TRUE;
00220                 }
00221 
00222                 return @pg_exec($this->conn_id, "commit");
00223         }

CI_DB_postgre_driver::trans_rollback (  ) 

Rollback Transaction.

public

Returns:
bool

Definition at line 233 of file postgre_driver.php.

00234         {
00235                 if ( ! $this->trans_enabled)
00236                 {
00237                         return TRUE;
00238                 }
00239 
00240                 // When transactions are nested we only begin/commit/rollback the outermost ones
00241                 if ($this->_trans_depth > 0)
00242                 {
00243                         return TRUE;
00244                 }
00245 
00246                 return @pg_exec($this->conn_id, "rollback");
00247         }


Member Data Documentation

CI_DB_postgre_driver::$_count_string = "SELECT COUNT(*) AS "

The syntax to count rows is slightly different across different database engines, so this string appears in each driver and is used for the count_all() and count_all_results() functions.

Definition at line 42 of file postgre_driver.php.

CI_DB_postgre_driver::$_escape_char = '"'

Definition at line 35 of file postgre_driver.php.

CI_DB_postgre_driver::$_random_keyword = ' RANDOM()'

Definition at line 43 of file postgre_driver.php.

CI_DB_postgre_driver::$dbdriver = 'postgre'

Definition at line 33 of file postgre_driver.php.


The documentation for this class was generated from the following file: