21 private $dbConnection =
false;
23 private $preparedStmt = array();
25 private $varPrefix =
':var';
27 public function __construct($dbConnection)
29 $this->dbConnection = $dbConnection;
37 public function prepare($statementName, $sqlStatement)
40 $pgStyleVar =
'$' . ($paramCnt + 1);
41 while (
false !== strpos($sqlStatement, $pgStyleVar)) {
43 $sqlStatement = str_replace($pgStyleVar, $this->varPrefix . chr(64 + $paramCnt), $sqlStatement);
44 $pgStyleVar =
'$' . ($paramCnt + 1);
49 $sqlStatementWithoutPostgresKeyWord = str_replace(
' ONLY ',
' ',$sqlStatement);
50 $stmt = $this->dbConnection->prepare($sqlStatementWithoutPostgresKeyWord);
51 $this->preparedStmt[$statementName] = & $stmt;
60 public function execute($statementName, $parameters)
62 if (! array_key_exists($statementName, $this->preparedStmt)) {
65 $params = array_values($parameters);
67 $stmt = $this->preparedStmt[$statementName];
68 for ($idx = 0; $idx < $stmt->paramCount(); $idx++) {
69 $variableName = $this->varPrefix . chr(65 + $idx);
70 $stmt->bindValue($variableName, $params[$idx]);
72 return $stmt->execute();
79 public function query($sqlStatement)
81 return $this->dbConnection->query($sqlStatement);
89 return (
false !== $this->dbConnection);
97 return SQLite3::lastErrorMsg();
106 return $res->finalize();
115 return $res->fetchArray(SQLITE3_ASSOC);
125 while ($row = $res->fetchArray(SQLITE3_ASSOC)) {
136 $this->dbConnection->query(
"BEGIN");
145 $this->dbConnection->query(
"COMMIT");
154 $this->dbConnection->query(
"ROLLBACK");
164 return $booleanValue === 1;
173 return $booleanValue ? 1 : 0;
182 return SQLite3::escapeString($string);
191 $sql =
"SELECT count(*) cnt FROM sqlite_master WHERE type='table' AND name='$tableName'";
192 $row = SQLite3::querySingle($sql);
196 throw new \Exception(
'DB connection lost');
198 return($row[
'cnt']>0);
209 throw new \Exception(
"Method not implemented yet!");
221 $res = $this->
execute($stmt,$params);
223 return SQLiteDatabase::lastInsertRowid();
booleanToDb($booleanValue)
execute($statementName, $parameters)
prepare($statementName, $sqlStatement)
insertPreparedAndReturn($stmt, $sql, $params, $colName)
existsColumn($tableName, $columnName)
booleanFromDb($booleanValue)