2012-03-15 09:25:18 -04:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Query
|
|
|
|
*
|
|
|
|
* Free Query Builder / Database Abstraction Layer
|
|
|
|
*
|
2012-04-20 13:17:39 -04:00
|
|
|
* @package Query
|
|
|
|
* @author Timothy J. Warren
|
2014-01-02 12:36:50 -05:00
|
|
|
* @copyright Copyright (c) 2012 - 2014
|
2012-03-15 09:25:18 -04:00
|
|
|
* @link https://github.com/aviat4ion/Query
|
2012-04-20 13:17:39 -04:00
|
|
|
* @license http://philsturgeon.co.uk/code/dbad-license
|
2012-03-15 09:25:18 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
2012-04-10 14:06:34 -04:00
|
|
|
* SQLite specific class
|
2012-03-15 09:25:18 -04:00
|
|
|
*
|
2012-04-20 13:17:39 -04:00
|
|
|
* @package Query
|
|
|
|
* @subpackage Drivers
|
2012-03-15 09:25:18 -04:00
|
|
|
*/
|
|
|
|
class SQLite extends DB_PDO {
|
|
|
|
|
2012-04-19 11:42:50 -04:00
|
|
|
/**
|
|
|
|
* Reference to the last executed sql query
|
2012-04-23 13:28:49 -04:00
|
|
|
*
|
|
|
|
* @var PDOStatement
|
2012-04-19 11:42:50 -04:00
|
|
|
*/
|
2012-03-15 09:25:18 -04:00
|
|
|
protected $statement;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Open SQLite Database
|
2012-04-10 14:06:34 -04:00
|
|
|
*
|
|
|
|
* @param string $dsn
|
2012-04-19 11:42:50 -04:00
|
|
|
* @param string $user
|
|
|
|
* @param string $pass
|
2012-03-15 09:25:18 -04:00
|
|
|
*/
|
|
|
|
public function __construct($dsn, $user=NULL, $pass=NULL)
|
2012-07-05 14:19:49 -04:00
|
|
|
{
|
2012-03-15 09:25:18 -04:00
|
|
|
// DSN is simply `sqlite:/path/to/db`
|
|
|
|
parent::__construct("sqlite:{$dsn}", $user, $pass);
|
|
|
|
}
|
2012-04-10 14:06:34 -04:00
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
2012-03-15 09:25:18 -04:00
|
|
|
/**
|
|
|
|
* Empty a table
|
|
|
|
*
|
|
|
|
* @param string $table
|
|
|
|
*/
|
|
|
|
public function truncate($table)
|
|
|
|
{
|
|
|
|
// SQLite has a TRUNCATE optimization,
|
|
|
|
// but no support for the actual command.
|
|
|
|
$sql = 'DELETE FROM "'.$table.'"';
|
|
|
|
|
|
|
|
$this->statement = $this->query($sql);
|
2012-04-10 14:06:34 -04:00
|
|
|
|
2012-03-15 09:25:18 -04:00
|
|
|
return $this->statement;
|
|
|
|
}
|
2012-04-10 14:06:34 -04:00
|
|
|
|
2012-03-15 09:25:18 -04:00
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* List tables for the current database
|
2012-04-10 14:06:34 -04:00
|
|
|
*
|
2012-03-15 09:25:18 -04:00
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function get_tables()
|
2012-04-10 14:06:34 -04:00
|
|
|
{
|
2012-03-15 09:25:18 -04:00
|
|
|
$tables = array();
|
2013-12-09 20:11:49 -05:00
|
|
|
$sql = $this->sql->table_list();
|
2012-03-15 09:25:18 -04:00
|
|
|
|
|
|
|
$res = $this->query($sql);
|
2012-04-10 14:06:34 -04:00
|
|
|
return db_filter($res->fetchAll(PDO::FETCH_ASSOC), 'name');
|
2012-03-15 09:25:18 -04:00
|
|
|
}
|
|
|
|
|
2012-04-03 16:54:33 -04:00
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
2012-03-15 09:25:18 -04:00
|
|
|
/**
|
|
|
|
* List system tables for the current database
|
2012-04-10 14:06:34 -04:00
|
|
|
*
|
2012-03-15 09:25:18 -04:00
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function get_system_tables()
|
|
|
|
{
|
|
|
|
//SQLite only has the sqlite_master table
|
|
|
|
// that is of any importance.
|
|
|
|
return array('sqlite_master');
|
|
|
|
}
|
2013-05-03 13:07:34 -04:00
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create sql for batch insert
|
|
|
|
*
|
|
|
|
* @param string $table
|
|
|
|
* @param array $data
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function insert_batch($table, $data=array())
|
|
|
|
{
|
|
|
|
// This is not very applicable to the firebird database
|
|
|
|
return NULL;
|
|
|
|
}
|
2012-03-15 09:25:18 -04:00
|
|
|
}
|
2014-02-07 14:16:39 -05:00
|
|
|
//End of sqlite_driver.php
|