32 private $dbConnection =
false;
34 private $preparedStmt = array();
36 private $varPrefix =
':var';
38 public function __construct($dbConnection)
40 $this->dbConnection = $dbConnection;
48 public function prepare($statementName, $sqlStatement)
51 $pgStyleVar =
'$' . ($paramCnt + 1);
52 while (
false !== strpos($sqlStatement, $pgStyleVar)) {
54 $sqlStatement = str_replace($pgStyleVar, $this->varPrefix . chr(64 + $paramCnt), $sqlStatement);
55 $pgStyleVar =
'$' . ($paramCnt + 1);
60 $sqlStatementWithoutPostgresKeyWord = str_replace(
' ONLY ',
' ',$sqlStatement);
61 $stmt = $this->dbConnection->prepare($sqlStatementWithoutPostgresKeyWord);
62 $this->preparedStmt[$statementName] = & $stmt;
71 public function execute($statementName, $parameters)
73 if (! array_key_exists($statementName, $this->preparedStmt)) {
76 $params = array_values($parameters);
78 $stmt = $this->preparedStmt[$statementName];
79 for ($idx = 0; $idx < $stmt->paramCount(); $idx++) {
80 $variableName = $this->varPrefix . chr(65 + $idx);
81 $stmt->bindValue($variableName, $params[$idx]);
83 return $stmt->execute();
90 public function query($sqlStatement)
92 return $this->dbConnection->query($sqlStatement);
100 return (
false !== $this->dbConnection);
108 return SQLite3::lastErrorMsg();
117 return $res->finalize();
126 return $res->fetchArray(SQLITE3_ASSOC);
136 while ($row = $res->fetchArray(SQLITE3_ASSOC)) {
147 $this->dbConnection->query(
"BEGIN");
156 $this->dbConnection->query(
"COMMIT");
165 $this->dbConnection->query(
"ROLLBACK");
175 return $booleanValue === 1;
184 return $booleanValue ? 1 : 0;
193 return SQLite3::escapeString($string);
202 $sql =
"SELECT count(*) cnt FROM sqlite_master WHERE type='table' AND name='$tableName'";
203 $row = SQLite3::querySingle($sql);
207 throw new \Exception(
'DB connection lost');
209 return($row[
'cnt']>0);
220 throw new \Exception(
"Method not implemented yet!");
232 $res = $this->
execute($stmt,$params);
234 return SQLiteDatabase::lastInsertRowid();
insertPreparedAndReturn($stmt, $sql, $params, $colName)
booleanFromDb($booleanValue)
existsColumn($tableName, $columnName)
booleanToDb($booleanValue)
prepare($statementName, $sqlStatement)
execute($statementName, $parameters)