Merge pull request #11 from silverstripe-labs/pulls/1.4/update-api

Update API for 3.2 release
This commit is contained in:
Sam Minnée 2015-06-17 15:47:31 +01:00
commit 85f82c2517

View File

@ -111,60 +111,44 @@ class SQLite3Connector extends DBConnector {
} }
public function preparedQuery($sql, $parameters, $errorLevel = E_USER_ERROR) { public function preparedQuery($sql, $parameters, $errorLevel = E_USER_ERROR) {
// Check if we should only preview this query
if ($this->previewWrite($sql)) return;
// Type check, identify, and prepare parameters for passing to the statement bind function // Type check, identify, and prepare parameters for passing to the statement bind function
$parsedParameters = $this->parsePreparedParameters($parameters); $parsedParameters = $this->parsePreparedParameters($parameters);
// Benchmark query
$conn = $this->dbConn;
$handle = $this->benchmarkQuery($sql, function($sql) use($conn, $parsedParameters) {
// Prepare statement // Prepare statement
$statement = @$conn->prepare($sql); $statement = @$this->dbConn->prepare($sql);
if(empty($statement)) return null; if($statement) {
// Bind and run to statement
// Bind all variables
for($i = 0; $i < count($parsedParameters); $i++) { for($i = 0; $i < count($parsedParameters); $i++) {
$value = $parsedParameters[$i]['value']; $value = $parsedParameters[$i]['value'];
$type = $parsedParameters[$i]['type']; $type = $parsedParameters[$i]['type'];
$statement->bindValue($i+1, $value, $type); $statement->bindValue($i+1, $value, $type);
} }
// Run // Return successful result
return $statement->execute(); $handle = $statement->execute();
}); if ($handle) {
return new SQLite3Query($this, $handle);
}
}
// Check for errors // Handle error
if (!$handle) {
$values = $this->parameterValues($parameters); $values = $this->parameterValues($parameters);
$this->databaseError($this->getLastError(), $errorLevel, $sql, $values); $this->databaseError($this->getLastError(), $errorLevel, $sql, $values);
return null; return null;
} }
public function query($sql, $errorLevel = E_USER_ERROR) {
// Return successful result
$handle = @$this->dbConn->query($sql);
if ($handle) {
return new SQLite3Query($this, $handle); return new SQLite3Query($this, $handle);
} }
public function query($sql, $errorLevel = E_USER_ERROR) { // Handle error
// Check if we should only preview this query
if ($this->previewWrite($sql)) return;
// Benchmark query
$conn = $this->dbConn;
$handle = $this->benchmarkQuery($sql, function($sql) use($conn) {
return @$conn->query($sql);
});
// Check for errors
if (!$handle) {
$this->databaseError($this->getLastError(), $errorLevel, $sql); $this->databaseError($this->getLastError(), $errorLevel, $sql);
return null; return null;
} }
return new SQLite3Query($this, $handle);
}
public function quoteString($value) { public function quoteString($value) {
return "'".$this->escapeString($value)."'"; return "'".$this->escapeString($value)."'";
} }