Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
Zend_Db_Adapter_Pdo_Sqlite Class Reference
Inheritance diagram for Zend_Db_Adapter_Pdo_Sqlite:
Zend_Db_Adapter_Pdo_Abstract Zend_Db_Adapter_Abstract

Public Member Functions

 __construct (array $config=array())
 
 listTables ()
 
 describeTable ($tableName, $schemaName=null)
 
 limit ($sql, $count, $offset=0)
 
- Public Member Functions inherited from Zend_Db_Adapter_Pdo_Abstract
 isConnected ()
 
 closeConnection ()
 
 prepare ($sql)
 
 lastInsertId ($tableName=null, $primaryKey=null)
 
 query ($sql, $bind=array())
 
 exec ($sql)
 
 setFetchMode ($mode)
 
 supportsParameters ($type)
 
 getServerVersion ()
 
- Public Member Functions inherited from Zend_Db_Adapter_Abstract
 __construct ($config)
 
 getConnection ()
 
 getConfig ()
 
 setProfiler ($profiler)
 
 getProfiler ()
 
 getStatementClass ()
 
 setStatementClass ($class)
 
 query ($sql, $bind=array())
 
 beginTransaction ()
 
 commit ()
 
 rollBack ()
 
 insert ($table, array $bind)
 
 update ($table, array $bind, $where='')
 
 delete ($table, $where='')
 
 select ()
 
 getFetchMode ()
 
 fetchAll ($sql, $bind=array(), $fetchMode=null)
 
 fetchRow ($sql, $bind=array(), $fetchMode=null)
 
 fetchAssoc ($sql, $bind=array())
 
 fetchCol ($sql, $bind=array())
 
 fetchPairs ($sql, $bind=array())
 
 fetchOne ($sql, $bind=array())
 
 quote ($value, $type=null)
 
 quoteInto ($text, $value, $type=null, $count=null)
 
 quoteIdentifier ($ident, $auto=false)
 
 quoteColumnAs ($ident, $alias, $auto=false)
 
 quoteTableAs ($ident, $alias=null, $auto=false)
 
 getQuoteIdentifierSymbol ()
 
 lastSequenceId ($sequenceName)
 
 nextSequenceId ($sequenceName)
 
 foldCase ($key)
 
 __sleep ()
 
 __wakeup ()
 
 listTables ()
 
 describeTable ($tableName, $schemaName=null)
 
 isConnected ()
 
 closeConnection ()
 
 prepare ($sql)
 
 lastInsertId ($tableName=null, $primaryKey=null)
 
 setFetchMode ($mode)
 
 limit ($sql, $count, $offset=0)
 
 supportsParameters ($type)
 
 getServerVersion ()
 

Protected Member Functions

 _checkRequiredOptions (array $config)
 
 _dsn ()
 
 _connect ()
 
 _quote ($value)
 
- Protected Member Functions inherited from Zend_Db_Adapter_Pdo_Abstract
 _dsn ()
 
 _connect ()
 
 _quote ($value)
 
 _beginTransaction ()
 
 _commit ()
 
 _rollBack ()
 
- Protected Member Functions inherited from Zend_Db_Adapter_Abstract
 _checkRequiredOptions (array $config)
 
 _whereExpr ($where)
 
 _quote ($value)
 
 _quoteIdentifierAs ($ident, $alias=null, $auto=false, $as=' AS ')
 
 _quoteIdentifier ($value, $auto=false)
 
 _connect ()
 
 _beginTransaction ()
 
 _commit ()
 
 _rollBack ()
 

Protected Attributes

 $_pdoType = 'sqlite'
 
 $_numericDataTypes
 
- Protected Attributes inherited from Zend_Db_Adapter_Pdo_Abstract
 $_defaultStmtClass = 'Zend_Db_Statement_Pdo'
 
- Protected Attributes inherited from Zend_Db_Adapter_Abstract
 $_config = array()
 
 $_fetchMode = Zend_Db::FETCH_ASSOC
 
 $_profiler
 
 $_defaultStmtClass = 'Zend_Db_Statement'
 
 $_defaultProfilerClass = 'Zend_Db_Profiler'
 
 $_connection = null
 
 $_caseFolding = Zend_Db::CASE_NATURAL
 
 $_autoQuoteIdentifiers = true
 
 $_numericDataTypes
 
 $_allowSerialization = true
 
 $_autoReconnectOnUnserialize = false
 

Detailed Description

Definition at line 39 of file Sqlite.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( array  $config = array())

Constructor.

$config is an array of key/value pairs containing configuration options. Note that the SQLite options are different than most of the other PDO adapters in that no username or password are needed. Also, an extra config key "sqlite2" specifies compatibility mode.

dbname => (string) The name of the database to user (required, use :memory: for memory-based database)

sqlite2 => (boolean) PDO_SQLITE defaults to SQLite 3. For compatibility with an older SQLite 2 database, set this to TRUE.

Parameters
array$configAn array of configuration keys.

Definition at line 84 of file Sqlite.php.

85  {
86  if (isset($config['sqlite2']) && $config['sqlite2']) {
87  $this->_pdoType = 'sqlite2';
88  }
89 
90  // SQLite uses no username/password. Stub to satisfy parent::_connect()
91  $this->_config['username'] = null;
92  $this->_config['password'] = null;
93 
94  return parent::__construct($config);
95  }
$config
Definition: fraud_order.php:17

Member Function Documentation

◆ _checkRequiredOptions()

_checkRequiredOptions ( array  $config)
protected

Check for config options that are mandatory. Throw exceptions if any are missing.

Parameters
array$config
Exceptions
Zend_Db_Adapter_Exception
See also
Zend_Db_Adapter_Exception

Definition at line 104 of file Sqlite.php.

105  {
106  // we need at least a dbname
107  if (! array_key_exists('dbname', $config)) {
109  #require_once 'Zend/Db/Adapter/Exception.php';
110  throw new Zend_Db_Adapter_Exception("Configuration array must have a key for 'dbname' that names the database instance");
111  }
112  }
$config
Definition: fraud_order.php:17

◆ _connect()

_connect ( )
protected

Special configuration for SQLite behavior: make sure that result sets contain keys like 'column' instead of 'table.column'.

Exceptions
Zend_Db_Adapter_Exception

if we already have a PDO object, no need to re-connect.

See also
Zend_Db_Adapter_Exception
Zend_Db_Adapter_Exception

Definition at line 128 of file Sqlite.php.

129  {
133  if ($this->_connection) {
134  return;
135  }
136 
137  parent::_connect();
138 
139  $retval = $this->_connection->exec('PRAGMA full_column_names=0');
140  if ($retval === false) {
141  $error = $this->_connection->errorInfo();
143  #require_once 'Zend/Db/Adapter/Exception.php';
144  throw new Zend_Db_Adapter_Exception($error[2]);
145  }
146 
147  $retval = $this->_connection->exec('PRAGMA short_column_names=1');
148  if ($retval === false) {
149  $error = $this->_connection->errorInfo();
151  #require_once 'Zend/Db/Adapter/Exception.php';
152  throw new Zend_Db_Adapter_Exception($error[2]);
153  }
154  }

◆ _dsn()

_dsn ( )
protected

DSN builder

Definition at line 117 of file Sqlite.php.

118  {
119  return $this->_pdoType .':'. $this->_config['dbname'];
120  }

◆ _quote()

_quote (   $value)
protected

Quote a raw string.

Parameters
string$valueRaw string
Returns
string Quoted string

Definition at line 303 of file Sqlite.php.

304  {
305  if (!is_int($value) && !is_float($value)) {
306  // Fix for null-byte injection
307  $value = addcslashes($value, "\000\032");
308  }
309  return parent::_quote($value);
310  }
$value
Definition: gender.phtml:16

◆ describeTable()

describeTable (   $tableName,
  $schemaName = null 
)

Returns the column descriptions for a table.

The return value is an associative array keyed by the column name, as returned by the RDBMS.

The value of each array element is an associative array with the following keys:

SCHEMA_NAME => string; name of database or schema TABLE_NAME => string; COLUMN_NAME => string; column name COLUMN_POSITION => number; ordinal position of column in table DATA_TYPE => string; SQL datatype name of column DEFAULT => string; default expression of column, null if none NULLABLE => boolean; true if column can have nulls LENGTH => number; length of CHAR/VARCHAR SCALE => number; scale of NUMERIC/DECIMAL PRECISION => number; precision of NUMERIC/DECIMAL UNSIGNED => boolean; unsigned property of an integer type PRIMARY => boolean; true if column is part of the primary key PRIMARY_POSITION => integer; position of column in primary key IDENTITY => integer; true if column is auto-generated with unique values

Parameters
string$tableName
string$schemaNameOPTIONAL
Returns
array

Use FETCH_NUM so we are not dependent on the CASE attribute of the PDO connection

SQLite INTEGER primary key is always auto-increment.

Definition at line 198 of file Sqlite.php.

199  {
200  $sql = 'PRAGMA ';
201 
202  if ($schemaName) {
203  $sql .= $this->quoteIdentifier($schemaName) . '.';
204  }
205 
206  $sql .= 'table_info('.$this->quoteIdentifier($tableName).')';
207 
208  $stmt = $this->query($sql);
209 
213  $result = $stmt->fetchAll(Zend_Db::FETCH_NUM);
214 
215  $cid = 0;
216  $name = 1;
217  $type = 2;
218  $notnull = 3;
219  $dflt_value = 4;
220  $pk = 5;
221 
222  $desc = array();
223 
224  $p = 1;
225  foreach ($result as $key => $row) {
226  list($length, $scale, $precision, $primary, $primaryPosition, $identity) =
227  array(null, null, null, false, null, false);
228  if (preg_match('/^((?:var)?char)\((\d+)\)/i', $row[$type], $matches)) {
229  $row[$type] = $matches[1];
230  $length = $matches[2];
231  } else if (preg_match('/^decimal\((\d+),(\d+)\)/i', $row[$type], $matches)) {
232  $row[$type] = 'DECIMAL';
233  $precision = $matches[1];
234  $scale = $matches[2];
235  }
236  if ((bool) $row[$pk]) {
237  $primary = true;
238  $primaryPosition = $p;
242  $identity = (bool) ($row[$type] == 'INTEGER');
243  ++$p;
244  }
245  $desc[$this->foldCase($row[$name])] = array(
246  'SCHEMA_NAME' => $this->foldCase($schemaName),
247  'TABLE_NAME' => $this->foldCase($tableName),
248  'COLUMN_NAME' => $this->foldCase($row[$name]),
249  'COLUMN_POSITION' => $row[$cid]+1,
250  'DATA_TYPE' => $row[$type],
251  'DEFAULT' => $row[$dflt_value],
252  'NULLABLE' => ! (bool) $row[$notnull],
253  'LENGTH' => $length,
254  'SCALE' => $scale,
255  'PRECISION' => $precision,
256  'UNSIGNED' => null, // Sqlite3 does not support unsigned data
257  'PRIMARY' => $primary,
258  'PRIMARY_POSITION' => $primaryPosition,
259  'IDENTITY' => $identity
260  );
261  }
262  return $desc;
263  }
$tableName
Definition: trigger.php:13
$type
Definition: item.phtml:13
const FETCH_NUM
Definition: Db.php:153
quoteIdentifier($ident, $auto=false)
Definition: Abstract.php:959
query($sql, $bind=array())
Definition: Abstract.php:221
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ limit()

limit (   $sql,
  $count,
  $offset = 0 
)

Adds an adapter-specific LIMIT clause to the SELECT statement.

Parameters
string$sql
integer$count
integer$offsetOPTIONAL
Returns
string
See also
Zend_Db_Adapter_Exception
Zend_Db_Adapter_Exception

Definition at line 273 of file Sqlite.php.

274  {
275  $count = intval($count);
276  if ($count <= 0) {
278  #require_once 'Zend/Db/Adapter/Exception.php';
279  throw new Zend_Db_Adapter_Exception("LIMIT argument count=$count is not valid");
280  }
281 
282  $offset = intval($offset);
283  if ($offset < 0) {
285  #require_once 'Zend/Db/Adapter/Exception.php';
286  throw new Zend_Db_Adapter_Exception("LIMIT argument offset=$offset is not valid");
287  }
288 
289  $sql .= " LIMIT $count";
290  if ($offset > 0) {
291  $sql .= " OFFSET $offset";
292  }
293 
294  return $sql;
295  }
$count
Definition: recent.phtml:13

◆ listTables()

listTables ( )

Returns a list of the tables in the database.

Returns
array

Definition at line 161 of file Sqlite.php.

162  {
163  $sql = "SELECT name FROM sqlite_master WHERE type='table' "
164  . "UNION ALL SELECT name FROM sqlite_temp_master "
165  . "WHERE type='table' ORDER BY name";
166 
167  return $this->fetchCol($sql);
168  }
fetchCol($sql, $bind=array())
Definition: Abstract.php:792

Field Documentation

◆ $_numericDataTypes

$_numericDataTypes
protected

◆ $_pdoType

$_pdoType = 'sqlite'
protected

Definition at line 47 of file Sqlite.php.


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