/** * Tests that the storage location is a directory and is writable. */ public function __construct($filename) { // Get the directory name $directory = str_replace('\\', '/', realpath(pathinfo($filename, PATHINFO_DIRNAME))) . '/'; // Set the filename from the real directory path $filename = $directory . basename($filename); // Make sure the cache directory is writable if (!is_dir($directory) or !is_writable($directory)) { throw new KoException('Cache: Directory :name is unwritable.', array(':name' => $directory)); } // Make sure the cache database is writable if (is_file($filename) and !is_writable($filename)) { throw new KoException('Cache: File :name is unwritable.', array(':name' => $filename)); } // Open up an instance of the database $this->db = new SQLiteDatabase($filename, '0666', $error); // Throw an exception if there's an error if (!empty($error)) { throw new KoException('Cache: Driver error - ' . sqlite_error_string($error)); } $query = "SELECT name FROM sqlite_master WHERE type = 'table' AND name = 'caches'"; $tables = $this->db->query($query, SQLITE_BOTH, $error); // Throw an exception if there's an error if (!empty($error)) { throw new KoException('Cache: Driver error - ' . sqlite_error_string($error)); } if ($tables->numRows() == 0) { // Issue a CREATE TABLE command $this->db->unbufferedQuery('CREATE TABLE caches(id VARCHAR(127) PRIMARY KEY, expiration INTEGER, cache TEXT);'); } }
function _catch($msg = "") { if (!($this->error = sqlite_error_string(sqlite_last_error($this->conn)))) { return true; } $this->error($msg . "<br>{$this->query}\n {$this->error}"); }
/** * Tests that the storage location is a directory and is writable. */ public function __construct($filename) { // Get the directory name $directory = str_replace('\\', '/', realpath(pathinfo($filename, PATHINFO_DIRNAME))) . '/'; // Set the filename from the real directory path $filename = $directory . basename($filename); // Make sure the cache directory is writable if (!is_dir($directory) or !is_writable($directory)) { throw new Kohana_Exception('cache.unwritable', $directory); } // Make sure the cache database is writable if (is_file($filename) and !is_writable($filename)) { throw new Kohana_Exception('cache.unwritable', $filename); } // Open up an instance of the database $this->db = new SQLiteDatabase($filename, '0666', $error); // Throw an exception if there's an error if (!empty($error)) { throw new Kohana_Exception('cache.driver_error', sqlite_error_string($error)); } $query = "SELECT name FROM sqlite_master WHERE type = 'table' AND name = 'caches'"; $tables = $this->db->query($query, SQLITE_BOTH, $error); // Throw an exception if there's an error if (!empty($error)) { throw new Kohana_Exception('cache.driver_error', sqlite_error_string($error)); } if ($tables->numRows() == 0) { Kohana::log('error', 'Cache: Initializing new SQLite cache database'); // Issue a CREATE TABLE command $this->db->unbufferedQuery(Kohana::config('cache_sqlite.schema')); } }
protected function composeReader($o) { if (!($db = $this->getDb($o))) { return $o; } if ($sql = $this->get->sql) { $o->read_sql = pStudio_highlighter::highlight($sql, 'sql', false); if (self::isReadOnlyQuery($db, $sql, $o->error_msg)) { $sql = "{$sql}\n LIMIT {$this->get->start}, {$this->get->length}"; $rows = @$db->arrayQuery($sql, SQLITE_ASSOC); if (false !== $rows) { if ($rows) { $o->fields = new loop_array(array_keys($rows[0])); $o->rows = new loop_array($rows, array($this, 'filterRow')); $o->start = $this->get->start; $o->length = $this->get->length; } } else { $o->error_msg = sqlite_error_string($db->lastError()); } } } else { $sql = "SELECT name, type\n FROM sqlite_master\n WHERE type IN ('table', 'view')\n ORDER BY name"; $tables = $db->arrayQuery($sql, SQLITE_ASSOC); $o->tables = new loop_array($tables, 'filter_rawArray'); if (!$o->is_auth_edit) { $f = new pForm($o, '', false); $f->setPrefix(''); $f->add('hidden', 'low'); $f->add('hidden', 'high'); $f->add('textarea', 'sql'); } } return $o; }
protected function _doExec($query) { if ($qI = sqlite_query($query, $this->_connection)) { return sqlite_changes($this->_connection); } else { throw new jException('jelix~db.error.query.bad', sqlite_error_string($this->_connection) . '(' . $query . ')'); } }
public function real_execute_sql($sql) { $result_set_handle = sqlite_query($this->connection_handle, $sql); if (!$result_set_handle) { throw new AnewtDatabaseQueryException('SQLite error: %s', sqlite_error_string(sqlite_last_error($this->connection_handle))); } return new AnewtDatabaseResultSetSQLite($sql, $this->connection_handle, $result_set_handle); }
protected function _set_stmt_error($state = null, $mode = PDO::ERRMODE_SILENT, $func = '') { $errno = sqlite_last_error($this->_link); if ($state === null) { $state = 'HY000'; } $this->_set_error($errno, sqlite_error_string($errno), $state, $mode, $func); }
/** * Constructs a new SqliteResultSet * * \param $sql * The sql query to execute. * * \param $backend * A reference to the used backend. */ function SqliteResultSet($sql, &$backend) { assert('is_string($sql)'); $this->sql = $sql; $this->backend =& $backend; $this->rs = sqlite_query($this->backend->handle, $sql) or trigger_error(sprintf('Query failed (%s)', sqlite_error_string(sqlite_last_error($this->backend->handle))), E_USER_ERROR); $this->rows_affected = sqlite_changes($this->backend->handle); }
public function query($sql) { LogMaster::log($sql); $res = sqlite_query($this->connection, $sql); if ($res === false) { throw new Exception("SQLLite - sql execution failed\n" . sqlite_error_string(sqlite_last_error($this->connection))); } return $res; }
/** * query * * @param mixed $query * @access public * @return mixed * @throws AdapterException */ public function query($query) { $handle = @sqlite_query($query, $this->_dbHandle); if (!$handle) { $errorCode = sqlite_last_error($this->_dbHandle); throw new AdapterException(sqlite_error_string($errorCode), $errorCode); } return $handle; }
function _error_handler(array $errarray, $query = '') { $err = sprintf('%s on line %d.', $errarray[0], $errarray[1]); $errno = sqlite_last_error($this->con); if (defined('DEBUG') && DEBUG) { $err .= sprintf(PHP_EOL . "Description: #%d: %s" . PHP_EOL . "SQL: %s", $errno, sqlite_error_string($errno), $query); } throw new RuntimeException($err, $errno); }
/** * 执行数据库查询 * * @param string $query * @param mixed $handle * @param int $op * @param null $action * @return resource|SQLiteResult * @throws Typecho_Db_Query_Exception */ public function query($query, $handle, $op = Typecho_Db::READ, $action = NULL) { if ($resource = @sqlite_query($query instanceof Typecho_Db_Query ? $query->__toString() : $query, $handle)) { return $resource; } /** 数据库异常 */ $errorCode = sqlite_last_error($this->_dbHandle); throw new Typecho_Db_Query_Exception(sqlite_error_string($errorCode), $errorCode); }
function safe_query($query) { $res = sqlite_query($query, sqlite_r); if (!$res) { $err_code = sqlite_last_error(sqlite_r); printf("Query Failed %d:%s\n", $err_code, sqlite_error_string($err_code)); exit; } return $res; }
/** * This function initializes the class. * * @access public * @override * @param DB_Connection_Driver $connection the connection to be used * @param string $sql the SQL statement to be queried * @param integer $mode the execution mode to be used * @throws Throwable_SQL_Exception indicates that the query failed */ public function __construct(DB_Connection_Driver $connection, $sql, $mode = NULL) { $resource = $connection->get_resource(); $command = @sqlite_query($resource, $sql); if ($command === FALSE) { throw new Throwable_SQL_Exception('Message: Failed to query SQL statement. Reason: :reason', array(':reason' => sqlite_error_string(sqlite_last_error($resource)))); } $this->command = $command; $this->record = FALSE; }
function query($sql) { global $page; if (!($this->result = sqlite_query($this->dbres, $sql))) { print "Query failed, <span style=\"color: blue;\"><pre>{$sql}</pre></style>\n"; print sqlite_error_string(sqlite_last_error($this->dbres)); $page->footer(); exit; } }
function getError($errorCode = null) { if (!$this->error) { $this->error = sqlite_last_error($this->connId); } if ($errorCode == null) { $errorCode = $this->error; } $this->errorMessage = sqlite_error_string($errorCode); return $this->errorMessage; }
function getError() { if ($this->sqlite_error) { return $this->sqlite_error; } if ($this->error) { return $this->error; } $last_error = sqlite_last_error($this->db); return sqlite_error_string($last_error); }
function DriverSqliteExec($conn, $sql, $check_result = true) { if ($check_result) { if (!($result = sqlite_query($conn, $sql))) { throw new lmbDbException('SQLite error happened: ' . sqlite_error_string(sqlite_last_error($conn))); } } else { $result = @sqlite_query($conn, $sql); } return $result; }
public function error($status = '') { $error = sqlite_last_error($this->connection); if ($status = 'show') { return sqlite_error_string($error); } elseif ($error != 0) { return true; } else { return false; } }
function sql_error() { global $con; if (defined('DB_TYPE')) { if (DB_TYPE == 'mysql') { $sql = mysql_error(); } elseif (DB_TYPE == 'sqlite') { $sql = sqlite_error_string($con); } return $sql; } }
/** * Execute a query. * * @param string $sql query * @return bool|\SQLiteResult */ public function executeQuery($sql) { $err = ''; $res = @sqlite_query($this->db, $sql, SQLITE_ASSOC, $err); if ($err) { msg($err . ':<br /><pre>' . hsc($sql) . '</pre>', -1); return false; } elseif (!$res) { msg(sqlite_error_string(sqlite_last_error($this->db)) . ':<br /><pre>' . hsc($sql) . '</pre>', -1); return false; } return $res; }
function rawExec($s) { # var_dump($s); $errorMsg = ''; $tmpRes = @$this->_conn->unbufferedQuery($s, SQLITE_BOTH, $errorMsg); if ($tmpRes === false) { if (empty($errorMsg)) { $errorMsg = sqlite_error_string($this->_conn->lastError()); } # if throw new Exception("Error executing query: " . $errorMsg); } # if return $tmpRes; } # rawExec
/** * query methods **/ public function queryRaw($queryString) { try { return sqlite_query($queryString, $this->link); } catch (BaseException $e) { $code = sqlite_last_error($this->link); if ($code == 19) { $e = 'DuplicateObjectException'; } else { $e = 'DatabaseException'; } throw new $e(sqlite_error_string($code) . ' - ' . $queryString, $code); } }
function sql_errorno($link = null) { global $SQLStat; if (isset($link)) { $result = sqlite_last_error($link) . ": " . sqlite_error_string(sqlite_last_error($link)); } if (!isset($link)) { $result = sqlite_last_error($SQLStat) . ": " . sqlite_error_string(sqlite_last_error($SQLStat)); } if ($result == "") { return ""; } return $result; }
function _raiseError($sql = null) { if (!$this->connectionId) { throw new lmbDbException('Could not connect to database "' . $this->config['database'] . '"'); } $errno = sqlite_last_error($this->connectionId); $info = array('driver' => 'sqlite'); $info['errorno'] = $errno; $info['db'] = $this->config['database']; if (!is_null($sql)) { $info['sql'] = $sql; } throw new lmbDbException(sqlite_error_string($errno) . ' SQL: ' . $sql, $info); }
/** Does the sqlite-dependent work of the execute method. @param $sQuery The query to execute. @return weeSQLiteResult A result set for SELECT queries. */ protected function doQuery($sQuery) { // SQLiteDatabase::query triggers a warning when the query could not be executed. $m = @$this->oSQLiteDb->query($sQuery, SQLITE_ASSOC, $sLastError); if ($m === false) { if ($sLastError === null) { $sLastError = sqlite_error_string($this->oSQLiteDb->lastError()); } burn('DatabaseException', sprintf(_WT("Failed to execute the query with the following error:\n%s"), $sLastError)); } $this->iNumAffectedRows = $this->oSQLiteDb->changes(); if ($m->numFields()) { return new weeSQLiteResult($m); } }
protected function _query($sql) { $result = sqlite_query($this->_connection, $sql); $error = sqlite_last_error($this->_connection); $this->_errorHandler($error, $error != 0 ? sqlite_error_string($error) : ''); if ($result && $this->queryHasResultSet($sql)) { $this->_numRows = sqlite_num_rows($result); $resultObject = $this->createRecordsetObject(); $resultObject->setResult($result); } else { $this->_numRows = sqlite_changes($this->_connection); $resultObject = $this->createResultObject(); } return $resultObject; }
function savePost($name, $email, $msg) { $dt_tm = time(); $user_ip = $_SERVER['REMOTE_ADDR']; $sql = "INSERT INTO msgs (name,email,msg,datetime,ip)\n\t\t\t\tVALUES ('{$name}','{$email}','{$msg}',{$dt_tm},'{$user_ip}')"; try { $res = $this->_db->query($sql); if (!$res) { throw new SQLiteException(sqlite_error_string($this->_db->lastError())); } return true; } catch (SQLiteException $err) { return $err; } }
function query($cmd) { if (!$this->connected) { return 0; } $this->totalqueries++; $this->lastcmd = $cmd; $this->error(""); # print $this->lastcmd . ";<br><br>\n\n"; $this->res = sqlite_query($this->dbh, $cmd, $this->errcode); if (!$this->res) { $this->error("<b>SQLITE Error:</b> " . @sqlite_error_string(sqlite_last_error($this->dbh))); $this->_fatal("<b>SQL Error in query string:</b> \n\n{$cmd}"); } return $this->res; }
function query($query) { parent::query($query); if ($this->db != null) { // submit query $this->result = @sqlite_unbuffered_query($this->db, $query); if ($this->result != false) { return true; // save error msg } else { $this->error = @sqlite_error_string(sqlite_last_error($this->db)); $this->result = null; return false; } } else { return false; } }