mirror of
https://github.com/silverstripe/silverstripe-sqlite3
synced 2024-10-22 17:05:37 +02:00
Update API for 3.2 release
See https://github.com/silverstripe/silverstripe-framework/pull/4288
This commit is contained in:
parent
dda4c3ab48
commit
b06bff09bf
@ -111,58 +111,42 @@ 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
|
// Prepare statement
|
||||||
$conn = $this->dbConn;
|
$statement = @$this->dbConn->prepare($sql);
|
||||||
$handle = $this->benchmarkQuery($sql, function($sql) use($conn, $parsedParameters) {
|
if($statement) {
|
||||||
|
// Bind and run to statement
|
||||||
// Prepare statement
|
|
||||||
$statement = @$conn->prepare($sql);
|
|
||||||
if(empty($statement)) return null;
|
|
||||||
|
|
||||||
// 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
|
}
|
||||||
if (!$handle) {
|
|
||||||
$values = $this->parameterValues($parameters);
|
|
||||||
$this->databaseError($this->getLastError(), $errorLevel, $sql, $values);
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new SQLite3Query($this, $handle);
|
// Handle error
|
||||||
|
$values = $this->parameterValues($parameters);
|
||||||
|
$this->databaseError($this->getLastError(), $errorLevel, $sql, $values);
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function query($sql, $errorLevel = E_USER_ERROR) {
|
public function query($sql, $errorLevel = E_USER_ERROR) {
|
||||||
// Check if we should only preview this query
|
// Return successful result
|
||||||
if ($this->previewWrite($sql)) return;
|
$handle = @$this->dbConn->query($sql);
|
||||||
|
if ($handle) {
|
||||||
// Benchmark query
|
return new SQLite3Query($this, $handle);
|
||||||
$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);
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new SQLite3Query($this, $handle);
|
// Handle error
|
||||||
|
$this->databaseError($this->getLastError(), $errorLevel, $sql);
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function quoteString($value) {
|
public function quoteString($value) {
|
||||||
|
Loading…
Reference in New Issue
Block a user