thrownewException("Configuration parameter missing: \$Config['DocumentStorage']['File']. Expected value for this parameter is the path to the SQLite database file.");
* @return mixed If the query doesn't return any result, null. If the query return a row with one field, the scalar value. Otherwise, an associative array, the fields as keys, the row as values.
*/
publicfunctionquery($sql){
$client=static::getClient();
if(static::isStatement($sql)){
if(!$client->exec($sql)){
thrownewException(
"Can't execute collection query. "
.$client->lastErrorMsg()
);
}
returnnull;
}
$result=$client->query($sql);
if($result===true){
returnnull;
}
if($result===false){
thrownewException(
"Can't execute collection query. "
.$client->lastErrorMsg()
);
}
$row=$result->fetchArray(SQLITE3_ASSOC);
$scalar=($result->numColumns()==1);
$result->finalize();
if($scalar){
returnarray_shift($row);
}else{
return$row;
}
}
/**
* Escapes the SQL string
*
* @param string $value The value to escape
* @return string The escaped value
*/
publicfunctionescape($value){
returnSQLite3::escapeString($value);
}
/**
* Gets all the documents from the collection
*
* @return Iterator An iterator to the documents, each item an instance of CollectionDocument
*/
publicfunctiongetAll(){
$collectionId=$this->escape($this->id);
$sql="SELECT document_value FROM $this->table WHERE collection_id = '$collectionId'";