本文整理汇总了PHP中SQLite3::lastErrorCode方法的典型用法代码示例。如果您正苦于以下问题:PHP SQLite3::lastErrorCode方法的具体用法?PHP SQLite3::lastErrorCode怎么用?PHP SQLite3::lastErrorCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SQLite3
的用法示例。
在下文中一共展示了SQLite3::lastErrorCode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* The primary method a driver needs to implement is the execute method, which takes an array of query options.
* The options in the array varies, but the key type will always be supplied, which will be either SELECT, UPDATE,
* INSERT, REPLACE or DELETE.
*
* @param array $options An array of options that were generated through use of the Query class.
* @return object It is expected to return an instance of an \Queryer\Driver\DatabaseDriverResult class.
* @see \Queryer\Query, \Queryer\Driver\DatabaseDriverResult
*/
public function execute(array $options)
{
$query = self::generateQuery($options);
$query = DatabaseTools::replaceVariables($query, $options['variables']);
$result = $this->sqlite->query($query);
return new Sqlite3DriverResult($result, $this->sqlite->changes(), $this->sqlite->lastInsertRowID(), $result === false ? $this->sqlite->lastErrorCode() : null, $result === false ? $this->sqlite->lastErrorMsg() : null, $query);
}
示例2: executeQuery
/**
* {@inheritdoc}
*/
protected function executeQuery($query, array $parameters)
{
if (isset($this->statements[$query])) {
$statement = $this->statements[$query];
} else {
// Temporary set the error reporting level to 0 to avoid any warning.
$errorReportingLevel = error_reporting(0);
$statement = $this->sqlite3->prepare($query);
// Restore the original error reporting level.
error_reporting($errorReportingLevel);
$errorCode = $this->sqlite3->lastErrorCode();
if ($errorCode !== 0) {
$exception = new SQLite3Exception($this->sqlite3->lastErrorMsg(), $errorCode);
if ($errorCode === 1) {
// SQL error cause by a missing function, this must be reported with a GeometryEngineException.
throw GeometryEngineException::operationNotSupportedByEngine($exception);
} else {
// Other SQLite3 error; we cannot trigger the original E_WARNING, so we throw this exception instead.
throw $exception;
}
} else {
$this->statements[$query] = $statement;
}
}
$index = 1;
foreach ($parameters as $parameter) {
if ($parameter instanceof Geometry) {
if ($parameter->isEmpty()) {
$statement->bindValue($index++, $parameter->asText(), SQLITE3_TEXT);
$statement->bindValue($index++, $parameter->SRID(), SQLITE3_INTEGER);
} else {
$statement->bindValue($index++, $parameter->asBinary(), SQLITE3_BLOB);
$statement->bindValue($index++, $parameter->SRID(), SQLITE3_INTEGER);
}
} else {
if ($parameter === null) {
$type = SQLITE3_NULL;
} elseif (is_int($parameter)) {
$type = SQLITE3_INTEGER;
} elseif (is_float($parameter)) {
$type = SQLITE3_FLOAT;
} else {
$type = SQLITE3_TEXT;
}
$statement->bindValue($index++, $parameter, $type);
}
}
$result = $statement->execute();
return $result->fetchArray(SQLITE3_NUM);
}
示例3: connect
/**
* Establishes a connection to the defined database.
*
* @return void
*/
public function connect()
{
if ($this->connected === TRUE) {
return;
}
if ($this->configuration['db']['driver'] != 'sqlite3') {
$this->logger->error('Cannot connect to a non-sqlite3 database connection!');
return;
}
$flag = $this->readonly ? SQLITE3_OPEN_READONLY : SQLITE3_OPEN_READWRITE;
$this->sqlite3->open($this->db, $flag | SQLITE3_OPEN_CREATE, '');
if ($this->sqlite3->lastErrorCode() === 0) {
$this->connected = TRUE;
}
}
示例4: __construct
/**
* @param string $dbname database name
* @param OutputInterface $output standard verbode output
* @param boolean $renew if true delete and recreate database
*
* @throws \Exception
*/
public function __construct($dbname, OutputInterface $output, $renew = false)
{
$this->fs = new Filesystem();
$this->output = $output;
$this->dbname = $dbname;
if ($renew) {
if ($this->fs->exists($this->dbname)) {
$this->fs->remove($this->dbname);
}
}
$this->db = new \SQLite3($this->dbname);
if ($this->db->exec('PRAGMA encoding = "UTF-8";') === false) {
$this->output->writeln($this->db->lastErrorCode() . " : " . $this->db->lastErrorMsg());
throw new \Exception("cannot set encoding UTF-8");
}
}
示例5: error
/**
* Returns the error string.
*
* @return string
*/
public function error()
{
if (0 === $this->conn->lastErrorCode()) {
return '';
}
return $this->conn->lastErrorMsg();
}
示例6: __construct
/**
* @param string $databaseFilename
*/
public function __construct($databaseFilename, $tableName = 'events')
{
$databaseFilename = strval($databaseFilename);
$tableName = strval($tableName);
$this->_tableName = $tableName;
$this->_databaseHandle = new SQLite3($databaseFilename);
if ($this->_databaseHandle->lastErrorCode() != 0) {
throw new Exception('Unable to connect to DB.');
}
$this->_databaseHandle->exec(<<<EOT
CREATE TABLE IF NOT EXISTS {$tableName} (
id INTEGER PRIMARY KEY,
headers STRING,
body STRING
)
EOT
);
}
示例7: execute
function execute($query)
{
if (!$this->isConnected()) {
throw new NotConnectedException();
}
Connection::startMeasuring($this);
if (func_num_args() > 1) {
$query = call_user_func_array('sprintf', func_get_args());
}
$result = $this->connection->query($query);
Connection::endMeasuring($this);
if (!$result) {
throw new QueryException($this->connection->lastErrorMsg(), $this->connection->lastErrorCode());
}
if ($result instanceof \SQLite3Result) {
return new RecordSet($result);
}
return $result;
}
示例8: testError
/**
* Test if a error exist, if yes than throw error
*
* @throws CHOQ_Exception
* @param string $query
*/
public function testError($query = null)
{
if ($this->sqlite->lastErrorCode()) {
$error = $this->sqlite->lastErrorMsg();
if ($query) {
$error .= "\nSQL Query: {$query}";
}
error($error);
}
}
示例9: checkError
/**
* Checks the last error code and decide if and what kind of exception to throw.
* @return true if nothing is wrong
* @throws CoreXEngine\Cache\AccessException if we want to write a read-only file
* @throws CoreXEngine\Cache\Exception for no special typed problem
*/
protected function checkError()
{
switch ($code = $this->database->lastErrorCode()) {
case 8:
throw new AccessException($this->database->lastErrorMsg(), $this->database->lastErrorCode());
break;
default:
if (0 < $code) {
throw new Exception($this->database->lastErrorMsg(), $this->database->lastErrorCode());
}
}
return true;
}
示例10: create_table_if_not_exist
public function create_table_if_not_exist($tablename, $fieldsdefinition)
{
// check if tablename is already present
$check = @parent::querySingle("SELECT count(*) FROM {$tablename}");
$code = @parent::lastErrorCode();
if (0 < $check || 0 == $check && 0 == $code) {
return true;
} else {
$sql = "CREATE TABLE {$tablename} ({$fieldsdefinition})";
$res = $this->exec($sql);
return $res !== false ? true : false;
}
}
示例11: query
/**
* Execute the SQL query.
*
* @param string $sql
* @throws Exception
* @return void
*/
public function query($sql)
{
if ($this->isPdo) {
$sth = $this->sqlite->prepare($sql);
if (!$sth->execute()) {
throw new Exception($sth->errorCode() . ': ' . $sth->errorInfo());
} else {
$this->result = $sth;
}
} else {
if (!($this->result = $this->sqlite->query($sql))) {
throw new Exception('Error: ' . $this->sqlite->lastErrorCode() . ': ' . $this->sqlite->lastErrorMsg() . '.');
}
}
}
示例12: execute
/**
* Wykonanie zapytania bazy danych
*
* @param string $query
* @return \SQLite3Result
* @throws Exception
*/
public function execute($query)
{
if (!$this->connected) {
$this->connect();
}
if ($this->dbHandle == null) {
return false;
}
$this->queryCount += 1;
$tResult = $this->dbHandle->query($query);
if (!$tResult) {
throw new Exception($this->dbHandle->lastErrorMsg(), $this->dbHandle->lastErrorCode());
}
/**
* logowanie zapytań do pliku
*/
if ($this->writeToFile) {
$this->writeLog($query);
}
return $tResult;
}
示例13: import
/**
* @param int $id
* @param array $data
* @param callable $callback
*
* @throws \Exception
*/
public function import(&$id, array $data, callable $callback)
{
foreach ($data as $uid => $elem) {
$valuesFullText = $this->valuesFullText($elem);
$valuesFilter = $this->valuesFilter($elem);
if (sizeof($valuesFullText) > 0) {
$json = json_encode($elem);
$num = 1;
$this->stmtInsertFilter->bindValue($num++, $id, SQLITE3_INTEGER);
if ($this->useuid) {
$this->stmtInsertFilter->bindValue($num++, $uid, SQLITE3_TEXT);
}
$this->stmtInsertFilter->bindValue($num++, $json, SQLITE3_TEXT);
foreach ($valuesFilter as $valueFilter) {
$this->stmtInsertFilter->bindValue($num++, $valueFilter);
}
if (@$this->stmtInsertFilter->execute() === false) {
$lasterror = $this->db->lastErrorCode();
if ($lasterror != self::SQLITE_ERROR_CODE_CONSTRAINT) {
$this->output->writeln($lasterror . " : " . $this->db->lastErrorMsg());
throw new \Exception("cannot insert filter fields");
} else {
@$this->stmtInsertFilter->reset();
continue;
}
}
$num = 1;
$this->stmtInsertFullText->bindValue($num++, $id, SQLITE3_INTEGER);
foreach ($valuesFullText as $valueFullText) {
$this->stmtInsertFullText->bindValue($num++, $valueFullText, SQLITE3_TEXT);
}
if ($this->stmtInsertFullText->execute() === false) {
$this->output->writeln($this->db->lastErrorCode() . " : " . $this->db->lastErrorMsg());
throw new \Exception("cannot insert full text fields");
}
$id++;
}
$callback();
}
}
示例14: errorCode
public function errorCode()
{
return $this->handler->lastErrorCode();
}
示例15: open
/**
* function to establish a database connection
*
* @return bool
* @throws \RuntimeException if something went wrong establishing the connection
*/
public function open()
{
$conn = new \SQLite3($this->path, SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE, $this->password);
if ($conn->lastErrorCode()) {
throw new \RuntimeException('Failed to connect: #' . $conn->lastErrorCode() . ' | ' . $conn->lastErrorMsg());
}
$this->conn = $conn;
$this->status = 'open';
return true;
}