47 lines
1.2 KiB
PHP
47 lines
1.2 KiB
PHP
<?php
|
|
namespace nulib\db\sqlite;
|
|
|
|
use nulib\db\_private\_base;
|
|
use nulib\db\_private\_create;
|
|
use nulib\db\_private\_delete;
|
|
use nulib\db\_private\_generic;
|
|
use nulib\db\_private\_insert;
|
|
use nulib\db\_private\_select;
|
|
use nulib\db\_private\_update;
|
|
use nulib\db\_private\Tbindings;
|
|
use nulib\output\msg;
|
|
use nulib\ValueException;
|
|
use SQLite3;
|
|
use SQLite3Stmt;
|
|
|
|
class _sqliteQuery extends _base {
|
|
use Tbindings;
|
|
|
|
const DEBUG_QUERIES = false;
|
|
|
|
function _use_stmt(SQLite3 $db, ?SQLite3Stmt &$stmt=null, ?string &$sql=null): bool {
|
|
if (static::DEBUG_QUERIES) {#XXX
|
|
msg::info($this->sql);
|
|
//msg::info(var_export($this->bindings, true));
|
|
}
|
|
if ($this->bindings !== null) {
|
|
/** @var SQLite3Stmt $stmt */
|
|
$stmt = SqliteException::check($db, $db->prepare($this->sql));
|
|
$close = true;
|
|
try {
|
|
foreach ($this->bindings as $param => $value) {
|
|
$this->verifixBindings($value);
|
|
SqliteException::check($db, $stmt->bindValue($param, $value));
|
|
}
|
|
$close = false;
|
|
return true;
|
|
} finally {
|
|
if ($close) $stmt->close();
|
|
}
|
|
} else {
|
|
$sql = $this->sql;
|
|
return false;
|
|
}
|
|
}
|
|
}
|