mirror of
https://github.com/silverstripe/silverstripe-sqlite3
synced 2024-10-22 17:05:37 +02:00
API Apply SilverStripe\SQLite namespace to module
This commit is contained in:
parent
0bd28649f5
commit
e36e74ab2f
7
.upgrade.yml
Normal file
7
.upgrade.yml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
mappings:
|
||||||
|
SQLite3Connector: SilverStripe\SQLite\SQLite3Connector
|
||||||
|
SQLite3Database: SilverStripe\SQLite\SQLite3Database
|
||||||
|
SQLite3Query: SilverStripe\SQLite\SQLite3Query
|
||||||
|
SQLite3QueryBuilder: SilverStripe\SQLite\SQLite3QueryBuilder
|
||||||
|
SQLite3SchemaManager: SilverStripe\SQLite\SQLite3SchemaManager
|
||||||
|
SQLiteDatabaseConfigurationHelper: SilverStripe\SQLite\SQLiteDatabaseConfigurationHelper
|
@ -3,27 +3,34 @@ name: sqlite3connectors
|
|||||||
---
|
---
|
||||||
Injector:
|
Injector:
|
||||||
SQLite3PDODatabase:
|
SQLite3PDODatabase:
|
||||||
class: 'SQLite3Database'
|
class: 'SilverStripe\SQLite\SQLite3Database'
|
||||||
properties:
|
properties:
|
||||||
connector: %$PDOConnector
|
connector: %$PDOConnector
|
||||||
schemaManager: %$SQLite3SchemaManager
|
schemaManager: %$SQLite3SchemaManager
|
||||||
queryBuilder: %$SQLite3QueryBuilder
|
queryBuilder: %$SQLite3QueryBuilder
|
||||||
SQLite3Database:
|
SQLite3Database:
|
||||||
class: 'SQLite3Database'
|
class: 'SilverStripe\SQLite\SQLite3Database'
|
||||||
properties:
|
properties:
|
||||||
connector: %$SQLite3Connector
|
connector: %$SQLite3Connector
|
||||||
schemaManager: %$SQLite3SchemaManager
|
schemaManager: %$SQLite3SchemaManager
|
||||||
queryBuilder: %$SQLite3QueryBuilder
|
queryBuilder: %$SQLite3QueryBuilder
|
||||||
# Legacy connector names
|
# Legacy connector names
|
||||||
SQLiteDatabase:
|
SQLiteDatabase:
|
||||||
class: 'SQLite3Database'
|
class: 'SilverStripe\SQLite\SQLite3Database'
|
||||||
properties:
|
properties:
|
||||||
connector: %$SQLite3Connector
|
connector: %$SQLite3Connector
|
||||||
schemaManager: %$SQLite3SchemaManager
|
schemaManager: %$SQLite3SchemaManager
|
||||||
queryBuilder: %$SQLite3QueryBuilder
|
queryBuilder: %$SQLite3QueryBuilder
|
||||||
SQLitePDODatabase:
|
SQLitePDODatabase:
|
||||||
class: 'SQLite3Database'
|
class: 'SilverStripe\SQLite\SQLite3Database'
|
||||||
properties:
|
properties:
|
||||||
connector: %$SQLite3Connector
|
connector: %$SQLite3Connector
|
||||||
schemaManager: %$SQLite3SchemaManager
|
schemaManager: %$SQLite3SchemaManager
|
||||||
queryBuilder: %$SQLite3QueryBuilder
|
queryBuilder: %$SQLite3QueryBuilder
|
||||||
|
SQLite3Connector:
|
||||||
|
class: 'SilverStripe\SQLite\SQLite3Connector'
|
||||||
|
type: prototype
|
||||||
|
SQLite3SchemaManager:
|
||||||
|
class: 'SilverStripe\SQLite\SQLite3SchemaManager'
|
||||||
|
SQLite3QueryBuilder:
|
||||||
|
class: 'SilverStripe\SQLite\SQLite3QueryBuilder'
|
||||||
|
@ -1,5 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
namespace SilverStripe\SQLite;
|
||||||
|
|
||||||
|
use SilverStripe\ORM\Connect\DBConnector;
|
||||||
|
use SQLite3;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SQLite connector class
|
* SQLite connector class
|
||||||
*
|
*
|
||||||
|
@ -1,5 +1,16 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
namespace SilverStripe\SQLite;
|
||||||
|
|
||||||
|
use SilverStripe\ORM\DataList;
|
||||||
|
use SilverStripe\ORM\ArrayList;
|
||||||
|
use SilverStripe\ORM\Connect\SS_Database;
|
||||||
|
use Config;
|
||||||
|
use Deprecation;
|
||||||
|
use PaginatedList;
|
||||||
|
use SilverStripe\ORM\Queries\SQLSelect;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SQLite database controller class
|
* SQLite database controller class
|
||||||
*
|
*
|
||||||
@ -171,8 +182,8 @@ class SQLite3Database extends SS_Database
|
|||||||
/**
|
/**
|
||||||
* Execute PRAGMA commands.
|
* Execute PRAGMA commands.
|
||||||
*
|
*
|
||||||
* @param string pragma name
|
* @param string $pragma name
|
||||||
* @param string value to set
|
* @param string $value to set
|
||||||
*/
|
*/
|
||||||
public function setPragma($pragma, $value)
|
public function setPragma($pragma, $value)
|
||||||
{
|
{
|
||||||
@ -182,7 +193,7 @@ class SQLite3Database extends SS_Database
|
|||||||
/**
|
/**
|
||||||
* Gets pragma value.
|
* Gets pragma value.
|
||||||
*
|
*
|
||||||
* @param string pragma name
|
* @param string $pragma name
|
||||||
* @return string the pragma value
|
* @return string the pragma value
|
||||||
*/
|
*/
|
||||||
public function getPragma($pragma)
|
public function getPragma($pragma)
|
||||||
@ -237,8 +248,16 @@ class SQLite3Database extends SS_Database
|
|||||||
* - the fts3 extension needs to be available
|
* - the fts3 extension needs to be available
|
||||||
* for now we use the MySQL implementation with the MATCH()AGAINST() uglily replaced with LIKE
|
* for now we use the MySQL implementation with the MATCH()AGAINST() uglily replaced with LIKE
|
||||||
*
|
*
|
||||||
|
* @param array $classesToSearch
|
||||||
* @param string $keywords Keywords as a space separated string
|
* @param string $keywords Keywords as a space separated string
|
||||||
* @return object DataObjectSet of result pages
|
* @param int $start
|
||||||
|
* @param int $pageLength
|
||||||
|
* @param string $sortBy
|
||||||
|
* @param string $extraFilter
|
||||||
|
* @param bool $booleanSearch
|
||||||
|
* @param string $alternativeFileFilter
|
||||||
|
* @param bool $invertedMatch
|
||||||
|
* @return PaginatedList DataObjectSet of result pages
|
||||||
*/
|
*/
|
||||||
public function searchEngine($classesToSearch, $keywords, $start, $pageLength, $sortBy = "Relevance DESC",
|
public function searchEngine($classesToSearch, $keywords, $start, $pageLength, $sortBy = "Relevance DESC",
|
||||||
$extraFilter = "", $booleanSearch = false, $alternativeFileFilter = "", $invertedMatch = false
|
$extraFilter = "", $booleanSearch = false, $alternativeFileFilter = "", $invertedMatch = false
|
||||||
@ -291,7 +310,10 @@ class SQLite3Database extends SS_Database
|
|||||||
$baseClasses = array('SiteTree' => '', 'File' => '');
|
$baseClasses = array('SiteTree' => '', 'File' => '');
|
||||||
$queries = array();
|
$queries = array();
|
||||||
foreach ($classesToSearch as $class) {
|
foreach ($classesToSearch as $class) {
|
||||||
$queries[$class] = DataList::create($class)->where($notMatch . $match[$class] . $extraFilters[$class], "")->dataQuery()->query();
|
$queries[$class] = DataList::create($class)
|
||||||
|
->where($notMatch . $match[$class] . $extraFilters[$class])
|
||||||
|
->dataQuery()
|
||||||
|
->query();
|
||||||
$fromArr = $queries[$class]->getFrom();
|
$fromArr = $queries[$class]->getFrom();
|
||||||
$baseClasses[$class] = reset($fromArr);
|
$baseClasses[$class] = reset($fromArr);
|
||||||
}
|
}
|
||||||
@ -348,6 +370,7 @@ class SQLite3Database extends SS_Database
|
|||||||
$queryParameters = array();
|
$queryParameters = array();
|
||||||
$totalCount = 0;
|
$totalCount = 0;
|
||||||
foreach ($queries as $query) {
|
foreach ($queries as $query) {
|
||||||
|
/** @var SQLSelect $query */
|
||||||
$querySQLs[] = $query->sql($parameters);
|
$querySQLs[] = $query->sql($parameters);
|
||||||
$queryParameters = array_merge($queryParameters, $parameters);
|
$queryParameters = array_merge($queryParameters, $parameters);
|
||||||
$totalCount += $query->unlimitedRowCount();
|
$totalCount += $query->unlimitedRowCount();
|
||||||
@ -368,7 +391,7 @@ class SQLite3Database extends SS_Database
|
|||||||
}
|
}
|
||||||
$list = new PaginatedList($doSet);
|
$list = new PaginatedList($doSet);
|
||||||
$list->setPageStart($start);
|
$list->setPageStart($start);
|
||||||
$list->setPageLEngth($pageLength);
|
$list->setPageLength($pageLength);
|
||||||
$list->setTotalItems($totalCount);
|
$list->setTotalItems($totalCount);
|
||||||
return $list;
|
return $list;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
namespace SilverStripe\SQLite;
|
||||||
|
|
||||||
|
use SilverStripe\ORM\Connect\SS_Query;
|
||||||
|
use SQLite3Result;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A result-set from a SQLite3 database.
|
* A result-set from a SQLite3 database.
|
||||||
*
|
*
|
||||||
|
@ -1,5 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
namespace SilverStripe\SQLite;
|
||||||
|
|
||||||
|
use SilverStripe\ORM\Queries\SQLAssignmentRow;
|
||||||
|
use SilverStripe\ORM\Queries\SQLInsert;
|
||||||
|
use SilverStripe\ORM\Queries\SQLSelect;
|
||||||
|
use SilverStripe\ORM\Connect\DBQueryBuilder;
|
||||||
|
use InvalidArgumentException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds a SQL query string from a SQLExpression object
|
* Builds a SQL query string from a SQLExpression object
|
||||||
*
|
*
|
||||||
@ -28,6 +36,7 @@ class SQLite3QueryBuilder extends DBQueryBuilder
|
|||||||
$rowParts = array();
|
$rowParts = array();
|
||||||
foreach ($query->getRows() as $row) {
|
foreach ($query->getRows() as $row) {
|
||||||
// Build all columns in this row
|
// Build all columns in this row
|
||||||
|
/** @var SQLAssignmentRow $row */
|
||||||
$assignments = $row->getAssignments();
|
$assignments = $row->getAssignments();
|
||||||
// Join SET components together, considering parameters
|
// Join SET components together, considering parameters
|
||||||
$parts = array();
|
$parts = array();
|
||||||
|
@ -1,5 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
namespace SilverStripe\SQLite;
|
||||||
|
|
||||||
|
use SilverStripe\ORM\Connect\DBSchemaManager;
|
||||||
|
use Exception;
|
||||||
|
use SapphireTest;
|
||||||
|
use Debug;
|
||||||
|
use Director;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SQLite schema manager class
|
* SQLite schema manager class
|
||||||
*
|
*
|
||||||
@ -129,7 +137,7 @@ class SQLite3SchemaManager extends DBSchemaManager
|
|||||||
public function clearTable($table)
|
public function clearTable($table)
|
||||||
{
|
{
|
||||||
if ($table != 'SQLiteEnums') {
|
if ($table != 'SQLiteEnums') {
|
||||||
$this->dbConn->query("DELETE FROM \"$table\"");
|
$this->query("DELETE FROM \"$table\"");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -328,7 +336,7 @@ class SQLite3SchemaManager extends DBSchemaManager
|
|||||||
public function fieldList($table)
|
public function fieldList($table)
|
||||||
{
|
{
|
||||||
$sqlCreate = $this->preparedQuery(
|
$sqlCreate = $this->preparedQuery(
|
||||||
'SELECT sql FROM sqlite_master WHERE type = ? AND name = ?',
|
'SELECT "sql" FROM "sqlite_master" WHERE "type" = ? AND "name" = ?',
|
||||||
array('table', $table)
|
array('table', $table)
|
||||||
)->record();
|
)->record();
|
||||||
|
|
||||||
@ -450,7 +458,7 @@ class SQLite3SchemaManager extends DBSchemaManager
|
|||||||
/**
|
/**
|
||||||
* Return a boolean type-formatted string
|
* Return a boolean type-formatted string
|
||||||
*
|
*
|
||||||
* @params array $values Contains a tokenised list of info about this data type
|
* @param array $values Contains a tokenised list of info about this data type
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function boolean($values)
|
public function boolean($values)
|
||||||
@ -462,7 +470,7 @@ class SQLite3SchemaManager extends DBSchemaManager
|
|||||||
/**
|
/**
|
||||||
* Return a date type-formatted string
|
* Return a date type-formatted string
|
||||||
*
|
*
|
||||||
* @params array $values Contains a tokenised list of info about this data type
|
* @param array $values Contains a tokenised list of info about this data type
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function date($values)
|
public function date($values)
|
||||||
@ -473,10 +481,10 @@ class SQLite3SchemaManager extends DBSchemaManager
|
|||||||
/**
|
/**
|
||||||
* Return a decimal type-formatted string
|
* Return a decimal type-formatted string
|
||||||
*
|
*
|
||||||
* @params array $values Contains a tokenised list of info about this data type
|
* @param array $values Contains a tokenised list of info about this data type
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function decimal($values, $asDbValue = false)
|
public function decimal($values)
|
||||||
{
|
{
|
||||||
$default = isset($values['default']) && is_numeric($values['default']) ? $values['default'] : 0;
|
$default = isset($values['default']) && is_numeric($values['default']) ? $values['default'] : 0;
|
||||||
return "NUMERIC NOT NULL DEFAULT $default";
|
return "NUMERIC NOT NULL DEFAULT $default";
|
||||||
@ -494,7 +502,7 @@ class SQLite3SchemaManager extends DBSchemaManager
|
|||||||
*
|
*
|
||||||
* enums are not supported. as a workaround to store allowed values we creates an additional table
|
* enums are not supported. as a workaround to store allowed values we creates an additional table
|
||||||
*
|
*
|
||||||
* @params array $values Contains a tokenised list of info about this data type
|
* @param array $values Contains a tokenised list of info about this data type
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function enum($values)
|
public function enum($values)
|
||||||
@ -531,7 +539,7 @@ class SQLite3SchemaManager extends DBSchemaManager
|
|||||||
*
|
*
|
||||||
* @see SQLite3SchemaManager::enum()
|
* @see SQLite3SchemaManager::enum()
|
||||||
*
|
*
|
||||||
* @params array $values Contains a tokenised list of info about this data type
|
* @param array $values Contains a tokenised list of info about this data type
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function set($values)
|
public function set($values)
|
||||||
@ -542,10 +550,10 @@ class SQLite3SchemaManager extends DBSchemaManager
|
|||||||
/**
|
/**
|
||||||
* Return a float type-formatted string
|
* Return a float type-formatted string
|
||||||
*
|
*
|
||||||
* @params array $values Contains a tokenised list of info about this data type
|
* @param array $values Contains a tokenised list of info about this data type
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function float($values, $asDbValue = false)
|
public function float($values)
|
||||||
{
|
{
|
||||||
return "REAL";
|
return "REAL";
|
||||||
}
|
}
|
||||||
@ -553,10 +561,10 @@ class SQLite3SchemaManager extends DBSchemaManager
|
|||||||
/**
|
/**
|
||||||
* Return a Double type-formatted string
|
* Return a Double type-formatted string
|
||||||
*
|
*
|
||||||
* @params array $values Contains a tokenised list of info about this data type
|
* @param array $values Contains a tokenised list of info about this data type
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function double($values, $asDbValue = false)
|
public function double($values)
|
||||||
{
|
{
|
||||||
return "REAL";
|
return "REAL";
|
||||||
}
|
}
|
||||||
@ -564,10 +572,10 @@ class SQLite3SchemaManager extends DBSchemaManager
|
|||||||
/**
|
/**
|
||||||
* Return a int type-formatted string
|
* Return a int type-formatted string
|
||||||
*
|
*
|
||||||
* @params array $values Contains a tokenised list of info about this data type
|
* @param array $values Contains a tokenised list of info about this data type
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function int($values, $asDbValue = false)
|
public function int($values)
|
||||||
{
|
{
|
||||||
return "INTEGER({$values['precision']}) " . strtoupper($values['null']) . " DEFAULT " . (int)$values['default'];
|
return "INTEGER({$values['precision']}) " . strtoupper($values['null']) . " DEFAULT " . (int)$values['default'];
|
||||||
}
|
}
|
||||||
@ -575,22 +583,22 @@ class SQLite3SchemaManager extends DBSchemaManager
|
|||||||
/**
|
/**
|
||||||
* Return a bigint type-formatted string
|
* Return a bigint type-formatted string
|
||||||
*
|
*
|
||||||
* @params array $values Contains a tokenised list of info about this data type
|
* @param array $values Contains a tokenised list of info about this data type
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function bigint($values, $asDbValue = false)
|
public function bigint($values)
|
||||||
{
|
{
|
||||||
return $this->int($values, $asDbValue);
|
return $this->int($values);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a datetime type-formatted string
|
* Return a datetime type-formatted string
|
||||||
* For SQLite3, we simply return the word 'TEXT', no other parameters are necessary
|
* For SQLite3, we simply return the word 'TEXT', no other parameters are necessary
|
||||||
*
|
*
|
||||||
* @params array $values Contains a tokenised list of info about this data type
|
* @param array $values Contains a tokenised list of info about this data type
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function ss_datetime($values, $asDbValue = false)
|
public function datetime($values)
|
||||||
{
|
{
|
||||||
return "DATETIME";
|
return "DATETIME";
|
||||||
}
|
}
|
||||||
@ -598,10 +606,10 @@ class SQLite3SchemaManager extends DBSchemaManager
|
|||||||
/**
|
/**
|
||||||
* Return a text type-formatted string
|
* Return a text type-formatted string
|
||||||
*
|
*
|
||||||
* @params array $values Contains a tokenised list of info about this data type
|
* @param array $values Contains a tokenised list of info about this data type
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function text($values, $asDbValue = false)
|
public function text($values)
|
||||||
{
|
{
|
||||||
return 'TEXT';
|
return 'TEXT';
|
||||||
}
|
}
|
||||||
@ -609,7 +617,7 @@ class SQLite3SchemaManager extends DBSchemaManager
|
|||||||
/**
|
/**
|
||||||
* Return a time type-formatted string
|
* Return a time type-formatted string
|
||||||
*
|
*
|
||||||
* @params array $values Contains a tokenised list of info about this data type
|
* @param array $values Contains a tokenised list of info about this data type
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function time($values)
|
public function time($values)
|
||||||
@ -620,10 +628,10 @@ class SQLite3SchemaManager extends DBSchemaManager
|
|||||||
/**
|
/**
|
||||||
* Return a varchar type-formatted string
|
* Return a varchar type-formatted string
|
||||||
*
|
*
|
||||||
* @params array $values Contains a tokenised list of info about this data type
|
* @param array $values Contains a tokenised list of info about this data type
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function varchar($values, $asDbValue = false)
|
public function varchar($values)
|
||||||
{
|
{
|
||||||
return "VARCHAR({$values['precision']}) COLLATE NOCASE";
|
return "VARCHAR({$values['precision']}) COLLATE NOCASE";
|
||||||
}
|
}
|
||||||
@ -645,7 +653,7 @@ class SQLite3SchemaManager extends DBSchemaManager
|
|||||||
public function hasTable($tableName)
|
public function hasTable($tableName)
|
||||||
{
|
{
|
||||||
return (bool)$this->preparedQuery(
|
return (bool)$this->preparedQuery(
|
||||||
'SELECT name FROM sqlite_master WHERE type = ? AND name = ?',
|
'SELECT "name" FROM "sqlite_master" WHERE "type" = ? AND "name" = ?',
|
||||||
array('table', $tableName)
|
array('table', $tableName)
|
||||||
)->first();
|
)->first();
|
||||||
}
|
}
|
||||||
@ -653,6 +661,8 @@ class SQLite3SchemaManager extends DBSchemaManager
|
|||||||
/**
|
/**
|
||||||
* Return enum values for the given field
|
* Return enum values for the given field
|
||||||
*
|
*
|
||||||
|
* @param string $tableName
|
||||||
|
* @param string $fieldName
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function enumValuesForField($tableName, $fieldName)
|
public function enumValuesForField($tableName, $fieldName)
|
||||||
|
@ -1,5 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
namespace SilverStripe\SQLite;
|
||||||
|
|
||||||
|
use DatabaseConfigurationHelper;
|
||||||
|
use SQLite3;
|
||||||
|
use PDO;
|
||||||
|
use Exception;
|
||||||
|
use DatabaseAdapterRegistry;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is a helper class for the SS installer.
|
* This is a helper class for the SS installer.
|
||||||
*
|
*
|
||||||
|
@ -24,6 +24,11 @@
|
|||||||
"dev-master": "2.0.x-dev"
|
"dev-master": "2.0.x-dev"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"SilverStripe\\SQLite\\": "code/"
|
||||||
|
}
|
||||||
|
},
|
||||||
"minimum-stability": "dev",
|
"minimum-stability": "dev",
|
||||||
"prefer-stable": true
|
"prefer-stable": true
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user