CI_DB_sqlite_driver Class Reference

Inheritance diagram for CI_DB_sqlite_driver:
Collaboration diagram for CI_DB_sqlite_driver:

List of all members.


Public Member Functions

 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)
 List 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.
 _rename_table ($table_name, $new_table_name)
 Rename a table.

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 = ' Random()'

Detailed Description

Definition at line 33 of file sqlite_driver.php.


Member Function Documentation

CI_DB_sqlite_driver::_close ( conn_id  ) 

Close DB Connection.

public

Parameters:
resource 
Returns:
void

Definition at line 633 of file sqlite_driver.php.

00634         {
00635                 @sqlite_close($conn_id);
00636         }

CI_DB_sqlite_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 576 of file sqlite_driver.php.

Referenced by _truncate().

00577         {
00578                 $conditions = '';
00579 
00580                 if (count($where) > 0 OR count($like) > 0)
00581                 {
00582                         $conditions = "\nWHERE ";
00583                         $conditions .= implode("\n", $this->ar_where);
00584 
00585                         if (count($where) > 0 && count($like) > 0)
00586                         {
00587                                 $conditions .= " AND ";
00588                         }
00589                         $conditions .= implode("\n", $like);
00590                 }
00591 
00592                 $limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
00593         
00594                 return "DELETE FROM ".$table.$conditions.$limit;
00595         }

Here is the caller graph for this function:

CI_DB_sqlite_driver::_error_message (  ) 

The error message string.

private

Returns:
string

Definition at line 373 of file sqlite_driver.php.

00374         {
00375                 return sqlite_error_string(sqlite_last_error($this->conn_id));
00376         }

CI_DB_sqlite_driver::_error_number (  ) 

The error message number.

private

Returns:
integer

Definition at line 386 of file sqlite_driver.php.

00387         {
00388                 return sqlite_last_error($this->conn_id);
00389         }

CI_DB_sqlite_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 403 of file sqlite_driver.php.

00404         {
00405 
00406                 // other database drivers use this to add backticks, hence this
00407                 // function is simply going to return the tablename for sqlite          
00408                 return $table;
00409         }

CI_DB_sqlite_driver::_execute ( sql  ) 

Execute the query.

private called by the base class

Parameters:
string an SQL query
Returns:
resource

Definition at line 142 of file sqlite_driver.php.

References _prep_query().

00143         {
00144                 $sql = $this->_prep_query($sql);
00145                 return @sqlite_query($this->conn_id, $sql);
00146         }

Here is the call graph for this function:

CI_DB_sqlite_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 360 of file sqlite_driver.php.

00361         {
00362                 return "SELECT * FROM ".$this->_escape_table($table)." LIMIT 1";
00363         }

CI_DB_sqlite_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 483 of file sqlite_driver.php.

00484         {
00485                 if ( ! is_array($tables))
00486                 {
00487                         $tables = array($tables);
00488                 }
00489                 
00490                 return '('.implode(', ', $tables).')';
00491         }

CI_DB_sqlite_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 506 of file sqlite_driver.php.

00507         {       
00508                 return "INSERT INTO ".$this->_escape_table($table)." (".implode(', ', $keys).") VALUES (".implode(', ', $values).")";
00509         }

CI_DB_sqlite_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 610 of file sqlite_driver.php.

00611         {       
00612                 if ($offset == 0)
00613                 {
00614                         $offset = '';
00615                 }
00616                 else
00617                 {
00618                         $offset .= ", ";
00619                 }
00620                 
00621                 return $sql."LIMIT ".$offset.$limit;
00622         }

CI_DB_sqlite_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 343 of file sqlite_driver.php.

00344         {
00345                 // Not supported
00346                 return FALSE;
00347         }

CI_DB_sqlite_driver::_list_tables ( prefix_limit = FALSE  ) 

List table query.

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

private

Parameters:
boolean 
Returns:
string

Definition at line 321 of file sqlite_driver.php.

00322         {
00323                 $sql = "SELECT name from sqlite_master WHERE type='table'";
00324 
00325                 if ($prefix_limit !== FALSE AND $this->dbprefix != '')
00326                 {
00327                         $sql .= " AND 'name' LIKE '".$this->dbprefix."%'";
00328                 }
00329                 return $sql;
00330         }

CI_DB_sqlite_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 159 of file sqlite_driver.php.

Referenced by _execute().

00160         {
00161                 return $sql;
00162         }

Here is the caller graph for this function:

CI_DB_sqlite_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 423 of file sqlite_driver.php.

Referenced by count_all().

00424         {
00425                 if (is_array($item))
00426                 {
00427                         $escaped_array = array();
00428 
00429                         foreach($item as $k=>$v)
00430                         {
00431                                 $escaped_array[$this->_protect_identifiers($k)] = $this->_protect_identifiers($v, $first_word_only);
00432                         }
00433 
00434                         return $escaped_array;
00435                 }       
00436 
00437                 // This function may get "item1 item2" as a string, and so
00438                 // we may need "item1 item2" and not "item1 item2"
00439                 if (ctype_alnum($item) === FALSE)
00440                 {
00441                         if (strpos($item, '.') !== FALSE)
00442                         {
00443                                 $aliased_tables = implode(".",$this->ar_aliased_tables).'.';
00444                                 $table_name =  substr($item, 0, strpos($item, '.')+1);
00445                                 $item = (strpos($aliased_tables, $table_name) !== FALSE) ? $item = $item : $this->dbprefix.$item;
00446                         }
00447 
00448                         // This function may get "field >= 1", and need it to return "field >= 1"
00449                         $lbound = ($first_word_only === TRUE) ? '' : '|\s|\(';
00450 
00451                         $item = preg_replace('/(^'.$lbound.')([\w\d\-\_]+?)(\s|\)|$)/iS', '$1$2$3', $item);
00452                 }
00453                 else
00454                 {
00455                         return "{$item}";
00456                 }
00457 
00458                 $exceptions = array('AS', '/', '-', '%', '+', '*', 'OR', 'IS');
00459                 
00460                 foreach ($exceptions as $exception)
00461                 {
00462                 
00463                         if (stristr($item, " {$exception} ") !== FALSE)
00464                         {
00465                                 $item = preg_replace('/ ('.preg_quote($exception).') /i', ' $1 ', $item);
00466                         }
00467                 }
00468                 return $item;
00469         }

Here is the caller graph for this function:

CI_DB_sqlite_driver::_rename_table ( table_name,
new_table_name 
)

Rename a table.

Generates a platform-specific query so that a table can be renamed

private

Parameters:
string the old table name
string the new table name
Returns:
string

Definition at line 650 of file sqlite_driver.php.

00651         {
00652                 $sql = 'ALTER TABLE '.$this->db->_protect_identifiers($table_name)." RENAME TO ".$this->db->_protect_identifiers($new_table_name);
00653                 return $sql;
00654         }

CI_DB_sqlite_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 558 of file sqlite_driver.php.

References _delete().

00559         {
00560                 return $this->_delete($table);
00561         }

Here is the call graph for this function:

CI_DB_sqlite_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 526 of file sqlite_driver.php.

00527         {
00528                 foreach($values as $key => $val)
00529                 {
00530                         $valstr[] = $key." = ".$val;
00531                 }
00532                 
00533                 $limit = ( ! $limit) ? '' : ' LIMIT '.$limit;
00534                 
00535                 $orderby = (count($orderby) >= 1)?' ORDER BY '.implode(", ", $orderby):'';
00536         
00537                 $sql = "UPDATE ".$this->_escape_table($table)." SET ".implode(', ', $valstr);
00538                 $sql .= ($where != '' AND count($where) >=1) ? " WHERE ".implode(" ", $where) : '';
00539                 $sql .= $orderby.$limit;
00540                 
00541                 return $sql;
00542         }

CI_DB_sqlite_driver::_version (  ) 

Version number query string.

public

Returns:
string

Definition at line 128 of file sqlite_driver.php.

00129         {
00130                 return sqlite_libversion();
00131         }

CI_DB_sqlite_driver::affected_rows (  ) 

Affected Rows.

public

Returns:
integer

Definition at line 266 of file sqlite_driver.php.

00267         {
00268                 return sqlite_changes($this->conn_id);
00269         }

CI_DB_sqlite_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 296 of file sqlite_driver.php.

References _protect_identifiers().

00297         {
00298                 if ($table == '')
00299                         return '0';
00300         
00301                 $query = $this->query($this->_count_string . $this->_protect_identifiers('numrows'). " FROM " . $this->_protect_identifiers($this->dbprefix.$table));
00302                 
00303                 if ($query->num_rows() == 0)
00304                         return '0';
00305 
00306                 $row = $query->row();
00307                 return $row->numrows;
00308         }

Here is the call graph for this function:

CI_DB_sqlite_driver::db_connect (  ) 

Non-persistent database connection.

private called by the base class

Returns:
resource

Definition at line 49 of file sqlite_driver.php.

References log_message().

00050         {
00051                 if ( ! $conn_id = @sqlite_open($this->database, FILE_WRITE_MODE, $error))
00052                 {
00053                         log_message('error', $error);
00054                         
00055                         if ($this->db_debug)
00056                         {
00057                                 $this->display_error($error, '', TRUE);
00058                         }
00059                         
00060                         return FALSE;
00061                 }
00062                 
00063                 return $conn_id;
00064         }

Here is the call graph for this function:

CI_DB_sqlite_driver::db_pconnect (  ) 

Persistent database connection.

private called by the base class

Returns:
resource

Definition at line 74 of file sqlite_driver.php.

References log_message().

00075         {
00076                 if ( ! $conn_id = @sqlite_popen($this->database, FILE_WRITE_MODE, $error))
00077                 {
00078                         log_message('error', $error);
00079                         
00080                         if ($this->db_debug)
00081                         {
00082                                 $this->display_error($error, '', TRUE);
00083                         }
00084                         
00085                         return FALSE;
00086                 }
00087                 
00088                 return $conn_id;
00089         }

Here is the call graph for this function:

CI_DB_sqlite_driver::db_select (  ) 

Select the database.

private called by the base class

Returns:
resource

Definition at line 99 of file sqlite_driver.php.

00100         {
00101                 return TRUE;
00102         }

CI_DB_sqlite_driver::db_set_charset ( charset,
collation 
)

Set client character set.

public

Parameters:
string 
string 
Returns:
resource

Definition at line 114 of file sqlite_driver.php.

00115         {
00116                 // TODO - add support if needed
00117                 return TRUE;
00118         }

CI_DB_sqlite_driver::escape_str ( str  ) 

Escape String.

public

Parameters:
string 
Returns:
string

Definition at line 253 of file sqlite_driver.php.

00254         {
00255                 return sqlite_escape_string($str);
00256         }

CI_DB_sqlite_driver::insert_id (  ) 

Insert ID.

public

Returns:
integer

Definition at line 279 of file sqlite_driver.php.

00280         {
00281                 return @sqlite_last_insert_rowid($this->conn_id);
00282         }

CI_DB_sqlite_driver::trans_begin ( test_mode = FALSE  ) 

Begin Transaction.

public

Returns:
bool

Definition at line 172 of file sqlite_driver.php.

00173         {
00174                 if ( ! $this->trans_enabled)
00175                 {
00176                         return TRUE;
00177                 }
00178                 
00179                 // When transactions are nested we only begin/commit/rollback the outermost ones
00180                 if ($this->_trans_depth > 0)
00181                 {
00182                         return TRUE;
00183                 }
00184 
00185                 // Reset the transaction failure flag.
00186                 // If the $test_mode flag is set to TRUE transactions will be rolled back
00187                 // even if the queries produce a successful result.
00188                 $this->_trans_failure = ($test_mode === TRUE) ? TRUE : FALSE;
00189 
00190                 $this->simple_query('BEGIN TRANSACTION');
00191                 return TRUE;
00192         }

CI_DB_sqlite_driver::trans_commit (  ) 

Commit Transaction.

public

Returns:
bool

Definition at line 202 of file sqlite_driver.php.

00203         {
00204                 if ( ! $this->trans_enabled)
00205                 {
00206                         return TRUE;
00207                 }
00208 
00209                 // When transactions are nested we only begin/commit/rollback the outermost ones
00210                 if ($this->_trans_depth > 0)
00211                 {
00212                         return TRUE;
00213                 }
00214 
00215                 $this->simple_query('COMMIT');
00216                 return TRUE;
00217         }

CI_DB_sqlite_driver::trans_rollback (  ) 

Rollback Transaction.

public

Returns:
bool

Definition at line 227 of file sqlite_driver.php.

00228         {
00229                 if ( ! $this->trans_enabled)
00230                 {
00231                         return TRUE;
00232                 }
00233 
00234                 // When transactions are nested we only begin/commit/rollback the outermost ones
00235                 if ($this->_trans_depth > 0)
00236                 {
00237                         return TRUE;
00238                 }
00239 
00240                 $this->simple_query('ROLLBACK');
00241                 return TRUE;
00242         }


Member Data Documentation

CI_DB_sqlite_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 40 of file sqlite_driver.php.

CI_DB_sqlite_driver::$_random_keyword = ' Random()'

Definition at line 41 of file sqlite_driver.php.


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