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}"); }
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); }
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); }
/** * 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); }
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); }
/** * 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; }
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; }
/** * 执行数据库查询 * * @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); }
/** * 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 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; }
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 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 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; }
/** * @throws SQLException * @return void */ protected function initTables() { include_once 'creole/drivers/sqlite/metadata/SQLiteTableInfo.php'; $sql = "SELECT name FROM sqlite_master WHERE type='table' UNION ALL SELECT name FROM sqlite_temp_master WHERE type='table' ORDER BY name;"; $result = sqlite_query($this->dblink, $sql); if (!$result) { throw new SQLException("Could not list tables", sqlite_last_error($this->dblink)); } while ($row = sqlite_fetch_array($result)) { $this->tables[strtoupper($row[0])] = new SQLiteTableInfo($this, $row[0]); } }
/** * 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; }
/** * 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 _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); }
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 isError() { if ($this->sqlite_error) { return TRUE; } if (!empty($this->error)) { return TRUE; } $last_error = sqlite_last_error($this->db); if ($last_error == 0) { return FALSE; } return $last_error; }
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 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; } }
function dbQuery($query, $show_errors = true, $all_results = true, $show_output = true) { if ($show_errors) { error_reporting(E_ALL); } else { error_reporting(E_PARSE); } // Connect to the SQLite database file $link = sqlite_open('/var/www/sqlmap/dbs/sqlite/testdb.sqlite', 0666, $sqliteerror); if (!$link) { die($sqliteerror); } // Print results in HTML print "<html><body>\n"; // Print SQL query to test sqlmap '--string' command line option //print "<b>SQL query:</b> " . $query . "<br>\n"; // Perform SQL injection affected query $result = sqlite_query($link, $query); if (!$result) { if ($show_errors) { print "<b>SQL error:</b> " . sqlite_error_string(sqlite_last_error($link)) . "<br>\n"; } exit(1); } if (!$show_output) { exit(1); } print "<b>SQL results:</b>\n"; print "<table border=\"1\">\n"; while ($line = sqlite_fetch_array($result, SQLITE_ASSOC)) { print "<tr>"; foreach ($line as $col_value) { print "<td>" . $col_value . "</td>"; } print "</tr>\n"; if (!$all_results) { break; } } print "</table>\n"; print "</body></html>"; }
function query($sql, $unbuffered = false) { if ($unbuffered) { $this->query_result = @sqlite_unbuffered_query($this->link_id, $sql); } else { $this->query_result = @sqlite_query($this->link_id, $sql); } if ($this->query_result) { if (defined('EPS_DEBUG')) { $this->saved_queries[] = array($sql, sprintf('%.5f', get_microtime() - $q_start)); } return $this->query_result; } else { if (defined('EPS_DEBUG')) { $this->saved_queries[] = array($sql, 0); } $this->error_no = @sqlite_last_error($this->link_id); $this->error_msg = @sqlite_error_string($this->error_no); return false; } }
public function initialize(IConfigParameter $configuration) { if (!extension_loaded('sqlite_open')) { throw new SoftwareSupportException('SQL extension not loaded'); } if ($this->_file === null) { // TODO:: need getting directory to storing file and check permissions $this->_file = 'sqlite.cache'; } $error = ''; if (($this->_db = new SQLiteDatabase($this->_file, 0666, $error)) === false) { throw new CacheException('Error connection to sqlite server', $error); } if (@$this->_db->query('DELETE FROM ' . $this->_cache_table . ' WHERE expire<>0 AND expire<' . time()) === false) { if ($this->_db->query('CREATE TABLE ' . $this->_cache_table . ' (key CHAR(128) PRIMARY KEY, value BLOB, expire INT)') === false) { throw new CacheException('Errir creation sqlite table', sqlite_error_string(sqlite_last_error())); } } $this->_initialized = true; parent::initialize($configuration); Project::getCacheManager()->set($configuration->get('id'), $this); }
function DataOpen(&$Query,&$PageSize,&$PageNum,&$RecStop) { // Init values $this->CurrRec =& tbs_Misc_UnlinkVar(true); // Just to unlink if ($this->RecSaved) { $this->FirstRec = true; $this->RecKey =& tbs_Misc_UnlinkVar(''); $this->RecNum = $this->RecNumInit; return true; } $this->RecSet =& tbs_Misc_UnlinkVar(false); $this->RecNumInit = 0; $this->RecNum = 0; if ($this->OnDataInfo!==false) { $this->OnDataOk = true; $this->OnDataPrm[0] =& $this->BlockName; $this->OnDataPrm[1] =& $this->CurrRec; $this->OnDataPrm[2] =& $this->RecNum; } switch ($this->Type) { case 0: // Array if (($this->SubType===1) and (is_string($Query))) $this->SubType = 2; if ($this->SubType===0) { $this->RecSet =& $this->SrcId; } elseif ($this->SubType===1) { if (is_array($Query)) { $this->RecSet =& $Query; } else { $this->DataAlert('Type \''.gettype($Query).'\' not supported for the Query Parameter going with \'array\' Source Type.'); } } elseif ($this->SubType===2) { //Found the global variable name and the sub-keys $Pos = strpos($Query,'['); if ($Pos===false) { $VarName = $Query; $Keys = array(); } else { $VarName = substr($Query,0,$Pos); $Keys = substr($Query,$Pos+1,strlen($Query)-$Pos-2); $Keys = explode('][',$Keys); } // Check variable and sub-keys if (isset($GLOBALS[$VarName])) { $Var =& $GLOBALS[$VarName]; if (is_array($Var)) { $Ok = true; $KeyMax = count($Keys)-1; $KeyNum = 0; while ($Ok and ($KeyNum<=$KeyMax)) { if (isset($Var[$Keys[$KeyNum]])) { $Var =& $Var[$Keys[$KeyNum]]; $KeyNum++; if (!is_array($Var)) $Ok = $this->DataAlert('Invalid query \''.$Query.'\' because item \''.$VarName.'['.implode('][',array_splice($Keys,0,$KeyNum)).']\' is not an array.'); } else { $Ok = false; // Item not found => not an error, considered as a query with empty result. $this->RecSet = array(); } } if ($Ok) $this->RecSet =& $Var; } else { $this->DataAlert('Invalid query \''.$Query.'\' because global variable \''.$VarName.'\' is not an array.'); } } else { $this->DataAlert('Invalid query \''.$Query.'\' because global variable \''.$VarName.'\' is not found.'); } } elseif ($this->SubType===3) { // Clear $this->RecSet = array(); } // First record if ($this->RecSet!==false) { $this->RecNbr = $this->RecNumInit + count($this->RecSet); $this->FirstRec = true; $this->RecSaved = true; $this->RecSaving = false; } break; case 1: // MySQL switch ($this->SubType) { case 0: $this->RecSet = @mysql_query($Query,$this->SrcId); break; case 1: $this->RecSet = $this->SrcId; break; case 2: $this->RecSet = @mysql_query($Query); break; } if ($this->RecSet===false) $this->DataAlert('MySql error message when opening the query: '.mysql_error()); break; case 4: // Text if (is_string($Query)) { $this->RecSet =& $Query; } else { $this->RecSet = ''.$Query; } $PageSize = 0; break; case 6: // Num $this->RecSet = true; $this->NumMin = 1; $this->NumMax = 1; $this->NumStep = 1; if (is_array($Query)) { if (isset($Query['min'])) $this->NumMin = $Query['min']; if (isset($Query['step'])) $this->NumStep = $Query['step']; if (isset($Query['max'])) { $this->NumMax = $Query['max']; } else { $this->RecSet = $this->DataAlert('The \'num\' source is an array that has no value for the \'max\' key.'); } if ($this->NumStep==0) $this->RecSet = $this->DataAlert('The \'num\' source is an array that has a step value set to zero.'); } else { $this->NumMax = ceil($Query); } if ($this->RecSet) { if ($this->NumStep>0) { $this->NumVal = $this->NumMin; } else { $this->NumVal = $this->NumMax; } } break; case 7: // Custom function $FctOpen = $this->FctOpen; $this->RecSet = $FctOpen($this->SrcId,$Query); break; case 8: // PostgreSQL switch ($this->SubType) { case 0: $this->RecSet = @pg_query($this->SrcId,$Query); break; case 1: $this->RecSet = $this->SrcId; break; } if ($this->RecSet===false) $this->DataAlert('PostgreSQL error message when opening the query: '.pg_last_error($this->SrcId)); break; case 9: // SQLite switch ($this->SubType) { case 0: $this->RecSet = @sqlite_query($this->SrcId,$Query); break; case 1: $this->RecSet = $this->SrcId; break; } if ($this->RecSet===false) $this->DataAlert('SQLite error message when opening the query:'.sqlite_error_string(sqlite_last_error($this->SrcId))); break; case 10: // Custom method $this->RecSet = $this->SrcId->tbsdb_open($this->SrcId,$Query); break; case 11: // ObjectRef $this->RecSet = call_user_func_array($this->FctOpen,array(&$this->SrcId,&$Query)); break; } if ($this->Type===0) { $this->RecKey =& tbs_Misc_UnlinkVar(''); } else { if ($this->RecSaving) $this->RecBuffer =& tbs_Misc_UnlinkVar(array()); $this->RecKey =& $this->RecNum; // Not array: RecKey = RecNum } //Goto the page if (($this->RecSet!==false) and ($PageSize>0)) { if ($PageNum==-1) { // Goto end of the recordset if ($this->RecSaved) { // Data source is array $PageNum = intval(ceil($this->RecNbr/$PageSize)); } else { // Read records, saving the last page in $this->RecBuffer $i = 0; $this->RecBuffer =& tbs_Misc_UnlinkVar(array()); $this->RecSaving = true; $this->DataFetch(); while ($this->CurrRec!==false) { if ($i===$PageSize) { $this->RecBuffer = array($this->RecKey => $this->CurrRec); $i = 0; $this->RecNumInit += $PageSize; } $i++; $this->DataFetch(); } $this->DataClose(); // Close the real recordset source $this->RecNum =& tbs_Misc_UnlinkVar(0+$this->RecNumInit); $this->FirstRec = true; } } if ($PageNum>0) { // We pass all record until the asked page $RecStop = ($PageNum-1) * $PageSize; while ($this->RecNum<$RecStop) { $this->DataFetch(); if ($this->CurrRec===false) $RecStop=$this->RecNum; } if ($this->CurrRec!==false) $RecStop = $PageNum * $PageSize; $this->RecNumInit = $this->RecNum; // Useful if RecSaved } else { $RecStop = 1; } } return ($this->RecSet!==false); }
/** * Error * * Returns an array containing code and message of the last * database error that has occured. * * @return array */ public function error() { $error = array('code' => sqlite_last_error($this->conn_id)); $error['message'] = sqlite_error_string($error['code']); return $error; }
/** * The error message number * * @access private * @return integer */ function _error_number() { return sqlite_last_error($this->conn_id); }
/** * Retourne le numero de la dernière erreur SQL * * Le numéro (en sqlite3/pdo) est un retour ODBC tel que (très souvent) HY000 * http://www.easysoft.com/developer/interfaces/odbc/sqlstate_status_return_codes.html * * @param string $serveur * nom de la connexion * @return int|string * 0 pas d'erreur * 1 ou autre erreur (en sqlite 2) * 'HY000/1' : numéro de l'erreur SQLState / numéro d'erreur interne SQLite (en sqlite 3) **/ function spip_sqlite_errno($serveur = '') { $link = _sqlite_link($serveur); if (_sqlite_is_version(3, $link)) { $t = $link->errorInfo(); $s = ltrim($t[0], '0'); // 00000 si pas d'erreur if ($s) { $s .= ' / ' . $t[1]; } // ajoute l'erreur du moteur SQLite } elseif ($link) { $s = sqlite_last_error($link); } else { $s = ": aucune ressource sqlite (link)"; } if ($s) { spip_log("Erreur sqlite {$s}", 'sqlite.' . _LOG_ERREUR); } return $s ? $s : 0; }