CI_DB_odbc_driver Class Reference

Inheritance diagram for CI_DB_odbc_driver:
Collaboration diagram for CI_DB_odbc_driver:

List of all members.


Public Member Functions

 CI_DB_odbc_driver ()
 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_table ($table)
 Escape Table Name.
 _protect_identifiers ($item, $first_word_only=FALSE)
 Protect 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

 $_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

Detailed Description

Definition at line 31 of file odbc_driver.php.


Member Function Documentation

CI_DB_odbc_driver::_close ( conn_id  ) 

Close DB Connection.

public

Parameters:
resource 
Returns:
void

Definition at line 607 of file odbc_driver.php.

00608         {
00609                 @odbc_close($conn_id);
00610         }

CI_DB_odbc_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 558 of file odbc_driver.php.

Referenced by _truncate().

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

Here is the caller graph for this function:

CI_DB_odbc_driver::_error_message (  ) 

The error message string.

private

Returns:
string

Definition at line 357 of file odbc_driver.php.

00358         {
00359                 return odbc_errormsg($this->conn_id);
00360         }

CI_DB_odbc_driver::_error_number (  ) 

The error message number.

private

Returns:
integer

Definition at line 370 of file odbc_driver.php.

00371         {
00372                 return odbc_error($this->conn_id);
00373         }

CI_DB_odbc_driver::_escape_table ( table  ) 

Escape Table Name.

This function adds backticks if the table name has a period in it. Some DBs will get cranky unless periods are escaped

private

Parameters:
string the table name
Returns:
string

Definition at line 387 of file odbc_driver.php.

00388         {
00389                 // used to add backticks in other db drivers            
00390                 return $table;
00391         }

CI_DB_odbc_driver::_execute ( sql  ) 

Execute the query.

private called by the base class

Parameters:
string an SQL query
Returns:
resource

Definition at line 123 of file odbc_driver.php.

References _prep_query().

00124         {
00125                 $sql = $this->_prep_query($sql);
00126                 return @odbc_exec($this->conn_id, $sql);
00127         }

Here is the call graph for this function:

CI_DB_odbc_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 344 of file odbc_driver.php.

00345         {
00346                 return "SELECT TOP 1 FROM ".$this->_escape_table($table);
00347         }

CI_DB_odbc_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 465 of file odbc_driver.php.

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

CI_DB_odbc_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 488 of file odbc_driver.php.

00489         {       
00490                 return "INSERT INTO ".$this->_escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")";
00491         }

CI_DB_odbc_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 592 of file odbc_driver.php.

00593         {
00594                 // Does ODBC doesn't use the LIMIT clause?
00595                 return $sql;
00596         }

CI_DB_odbc_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 328 of file odbc_driver.php.

00329         {
00330                 return "SHOW COLUMNS FROM ".$this->_escape_table($table);
00331         }

CI_DB_odbc_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 304 of file odbc_driver.php.

00305         {
00306                 $sql = "SHOW TABLES FROM `".$this->database."`";
00307 
00308                 if ($prefix_limit !== FALSE AND $this->dbprefix != '')
00309                 {
00310                         //$sql .= " LIKE '".$this->dbprefix."%'";
00311                         return FALSE; // not currently supported
00312                 }
00313                 
00314                 return $sql;
00315         }

CI_DB_odbc_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 140 of file odbc_driver.php.

Referenced by _execute().

00141         {
00142                 return $sql;
00143         }

Here is the caller graph for this function:

CI_DB_odbc_driver::_protect_identifiers ( item,
first_word_only = FALSE 
)

Protect Identifiers.

This function adds backticks if appropriate based on db type

private

Parameters:
mixed the item to escape
boolean only affect the first word
Returns:
mixed the item with backticks

Definition at line 405 of file odbc_driver.php.

Referenced by count_all().

00406         {
00407                 if (is_array($item))
00408                 {
00409                         $escaped_array = array();
00410 
00411                         foreach($item as $k=>$v)
00412                         {
00413                                 $escaped_array[$this->_protect_identifiers($k)] = $this->_protect_identifiers($v, $first_word_only);
00414                         }
00415 
00416                         return $escaped_array;
00417                 }       
00418 
00419                 // This function may get "item1 item2" as a string, and so
00420                 // we may need "`item1` `item2`" and not "`item1 item2`"
00421                 if (ctype_alnum($item) === FALSE)
00422                 {
00423                         if (strpos($item, '.') !== FALSE)
00424                         {
00425                                 $aliased_tables = implode(".",$this->ar_aliased_tables).'.';
00426                                 $table_name =  substr($item, 0, strpos($item, '.')+1);
00427                                 $item = (strpos($aliased_tables, $table_name) !== FALSE) ? $item = $item : $this->dbprefix.$item;
00428                         }
00429 
00430                         // This function may get "field >= 1", and need it to return "`field` >= 1"
00431                         $lbound = ($first_word_only === TRUE) ? '' : '|\s|\(';
00432 
00433                         $item = preg_replace('/(^'.$lbound.')([\w\d\-\_]+?)(\s|\)|$)/iS', '$1`$2`$3', $item);
00434                 }
00435                 else
00436                 {
00437                         return "{$item}";
00438                 }
00439 
00440                 $exceptions = array('AS', '/', '-', '%', '+', '*', 'OR', 'IS');
00441                 
00442                 foreach ($exceptions as $exception)
00443                 {
00444                 
00445                         if (stristr($item, " {$exception} ") !== FALSE)
00446                         {
00447                                 $item = preg_replace('/ ('.preg_quote($exception).') /i', ' $1 ', $item);
00448                         }
00449                 }
00450                 return $item;
00451         }

Here is the caller graph for this function:

CI_DB_odbc_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 540 of file odbc_driver.php.

References _delete().

00541         {
00542                 return $this->_delete($table);
00543         }

Here is the call graph for this function:

CI_DB_odbc_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 508 of file odbc_driver.php.

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

CI_DB_odbc_driver::_version (  ) 

Version number query string.

public

Returns:
string

Definition at line 109 of file odbc_driver.php.

00110         {
00111                 return "SELECT version() AS ver";
00112         }

CI_DB_odbc_driver::affected_rows (  ) 

Affected Rows.

public

Returns:
integer

Definition at line 249 of file odbc_driver.php.

00250         {
00251                 return @odbc_num_rows($this->conn_id);
00252         }

CI_DB_odbc_driver::CI_DB_odbc_driver (  ) 

Definition at line 42 of file odbc_driver.php.

00043         {
00044                 $this->_random_keyword = ' RND('.time().')'; // database specific random keyword
00045         }

CI_DB_odbc_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 279 of file odbc_driver.php.

References _protect_identifiers().

00280         {
00281                 if ($table == '')
00282                         return '0';
00283         
00284                 $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows'). " FROM " . $this->_protect_identifiers($this->dbprefix.$table));
00285         
00286                 if ($query->num_rows() == 0)
00287                         return '0';
00288 
00289                 $row = $query->row();
00290                 return $row->numrows;
00291         }

Here is the call graph for this function:

CI_DB_odbc_driver::db_connect (  ) 

Non-persistent database connection.

private called by the base class

Returns:
resource

Definition at line 53 of file odbc_driver.php.

00054         {
00055                 return @odbc_connect($this->hostname, $this->username, $this->password);
00056         }

CI_DB_odbc_driver::db_pconnect (  ) 

Persistent database connection.

private called by the base class

Returns:
resource

Definition at line 66 of file odbc_driver.php.

00067         {
00068                 return @odbc_pconnect($this->hostname, $this->username, $this->password);
00069         }

CI_DB_odbc_driver::db_select (  ) 

Select the database.

private called by the base class

Returns:
resource

Definition at line 79 of file odbc_driver.php.

00080         {
00081                 // Not needed for ODBC
00082                 return TRUE;
00083         }

CI_DB_odbc_driver::db_set_charset ( charset,
collation 
)

Set client character set.

public

Parameters:
string 
string 
Returns:
resource

Definition at line 95 of file odbc_driver.php.

00096         {
00097                 // TODO - add support if needed
00098                 return TRUE;
00099         }

CI_DB_odbc_driver::escape_str ( str  ) 

Escape String.

public

Parameters:
string 
Returns:
string

Definition at line 235 of file odbc_driver.php.

00236         {
00237                 // ODBC doesn't require escaping
00238                 return $str;
00239         }

CI_DB_odbc_driver::insert_id (  ) 

Insert ID.

public

Returns:
integer

Definition at line 262 of file odbc_driver.php.

00263         {
00264                 return @odbc_insert_id($this->conn_id);
00265         }

CI_DB_odbc_driver::trans_begin ( test_mode = FALSE  ) 

Begin Transaction.

public

Returns:
bool

Definition at line 153 of file odbc_driver.php.

00154         {
00155                 if ( ! $this->trans_enabled)
00156                 {
00157                         return TRUE;
00158                 }
00159                 
00160                 // When transactions are nested we only begin/commit/rollback the outermost ones
00161                 if ($this->_trans_depth > 0)
00162                 {
00163                         return TRUE;
00164                 }
00165 
00166                 // Reset the transaction failure flag.
00167                 // If the $test_mode flag is set to TRUE transactions will be rolled back
00168                 // even if the queries produce a successful result.
00169                 $this->_trans_failure = ($test_mode === TRUE) ? TRUE : FALSE;
00170 
00171                 return odbc_autocommit($this->conn_id, FALSE);
00172         }

CI_DB_odbc_driver::trans_commit (  ) 

Commit Transaction.

public

Returns:
bool

Definition at line 182 of file odbc_driver.php.

00183         {
00184                 if ( ! $this->trans_enabled)
00185                 {
00186                         return TRUE;
00187                 }
00188 
00189                 // When transactions are nested we only begin/commit/rollback the outermost ones
00190                 if ($this->_trans_depth > 0)
00191                 {
00192                         return TRUE;
00193                 }
00194 
00195                 $ret = odbc_commit($this->conn_id);
00196                 odbc_autocommit($this->conn_id, TRUE);
00197                 return $ret;
00198         }

CI_DB_odbc_driver::trans_rollback (  ) 

Rollback Transaction.

public

Returns:
bool

Definition at line 208 of file odbc_driver.php.

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


Member Data Documentation

CI_DB_odbc_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 38 of file odbc_driver.php.

CI_DB_odbc_driver::$_random_keyword

Definition at line 39 of file odbc_driver.php.


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