Merge pull request #23 from open-sausages/pulls/4.0/namespace

API Apply SilverStripe\SQLite namespace to module
This commit is contained in:
Ingo Schommer 2016-07-01 15:10:06 +12:00 committed by GitHub
commit d09ab6bea4
9 changed files with 224 additions and 145 deletions

7
.upgrade.yml Normal file
View 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

View File

@ -3,27 +3,34 @@ name: sqlite3connectors
---
Injector:
SQLite3PDODatabase:
class: 'SQLite3Database'
class: 'SilverStripe\SQLite\SQLite3Database'
properties:
connector: %$PDOConnector
schemaManager: %$SQLite3SchemaManager
queryBuilder: %$SQLite3QueryBuilder
SQLite3Database:
class: 'SQLite3Database'
class: 'SilverStripe\SQLite\SQLite3Database'
properties:
connector: %$SQLite3Connector
schemaManager: %$SQLite3SchemaManager
queryBuilder: %$SQLite3QueryBuilder
# Legacy connector names
SQLiteDatabase:
class: 'SQLite3Database'
class: 'SilverStripe\SQLite\SQLite3Database'
properties:
connector: %$SQLite3Connector
schemaManager: %$SQLite3SchemaManager
queryBuilder: %$SQLite3QueryBuilder
SQLitePDODatabase:
class: 'SQLite3Database'
class: 'SilverStripe\SQLite\SQLite3Database'
properties:
connector: %$SQLite3Connector
schemaManager: %$SQLite3SchemaManager
queryBuilder: %$SQLite3QueryBuilder
SQLite3Connector:
class: 'SilverStripe\SQLite\SQLite3Connector'
type: prototype
SQLite3SchemaManager:
class: 'SilverStripe\SQLite\SQLite3SchemaManager'
SQLite3QueryBuilder:
class: 'SilverStripe\SQLite\SQLite3QueryBuilder'

View File

@ -1,5 +1,10 @@
<?php
namespace SilverStripe\SQLite;
use SilverStripe\ORM\Connect\DBConnector;
use SQLite3;
/**
* SQLite connector class
*

View File

@ -1,5 +1,16 @@
<?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
*
@ -171,8 +182,8 @@ class SQLite3Database extends SS_Database
/**
* Execute PRAGMA commands.
*
* @param string pragma name
* @param string value to set
* @param string $pragma name
* @param string $value to set
*/
public function setPragma($pragma, $value)
{
@ -182,7 +193,7 @@ class SQLite3Database extends SS_Database
/**
* Gets pragma value.
*
* @param string pragma name
* @param string $pragma name
* @return string the pragma value
*/
public function getPragma($pragma)
@ -237,8 +248,16 @@ class SQLite3Database extends SS_Database
* - the fts3 extension needs to be available
* 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
* @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",
$extraFilter = "", $booleanSearch = false, $alternativeFileFilter = "", $invertedMatch = false
@ -291,7 +310,10 @@ class SQLite3Database extends SS_Database
$baseClasses = array('SiteTree' => '', 'File' => '');
$queries = array();
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();
$baseClasses[$class] = reset($fromArr);
}
@ -348,6 +370,7 @@ class SQLite3Database extends SS_Database
$queryParameters = array();
$totalCount = 0;
foreach ($queries as $query) {
/** @var SQLSelect $query */
$querySQLs[] = $query->sql($parameters);
$queryParameters = array_merge($queryParameters, $parameters);
$totalCount += $query->unlimitedRowCount();
@ -368,7 +391,7 @@ class SQLite3Database extends SS_Database
}
$list = new PaginatedList($doSet);
$list->setPageStart($start);
$list->setPageLEngth($pageLength);
$list->setPageLength($pageLength);
$list->setTotalItems($totalCount);
return $list;
}

View File

@ -1,5 +1,10 @@
<?php
namespace SilverStripe\SQLite;
use SilverStripe\ORM\Connect\SS_Query;
use SQLite3Result;
/**
* A result-set from a SQLite3 database.
*

View File

@ -1,5 +1,13 @@
<?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
*
@ -28,6 +36,7 @@ class SQLite3QueryBuilder extends DBQueryBuilder
$rowParts = array();
foreach ($query->getRows() as $row) {
// Build all columns in this row
/** @var SQLAssignmentRow $row */
$assignments = $row->getAssignments();
// Join SET components together, considering parameters
$parts = array();

View File

@ -1,5 +1,13 @@
<?php
namespace SilverStripe\SQLite;
use SilverStripe\ORM\Connect\DBSchemaManager;
use Exception;
use SapphireTest;
use Debug;
use Director;
/**
* SQLite schema manager class
*
@ -129,7 +137,7 @@ class SQLite3SchemaManager extends DBSchemaManager
public function clearTable($table)
{
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)
{
$sqlCreate = $this->preparedQuery(
'SELECT sql FROM sqlite_master WHERE type = ? AND name = ?',
'SELECT "sql" FROM "sqlite_master" WHERE "type" = ? AND "name" = ?',
array('table', $table)
)->record();
@ -450,7 +458,7 @@ class SQLite3SchemaManager extends DBSchemaManager
/**
* 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
*/
public function boolean($values)
@ -462,7 +470,7 @@ class SQLite3SchemaManager extends DBSchemaManager
/**
* 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
*/
public function date($values)
@ -473,10 +481,10 @@ class SQLite3SchemaManager extends DBSchemaManager
/**
* 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
*/
public function decimal($values, $asDbValue = false)
public function decimal($values)
{
$default = isset($values['default']) && is_numeric($values['default']) ? $values['default'] : 0;
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
*
* @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
*/
public function enum($values)
@ -531,7 +539,7 @@ class SQLite3SchemaManager extends DBSchemaManager
*
* @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
*/
public function set($values)
@ -542,10 +550,10 @@ class SQLite3SchemaManager extends DBSchemaManager
/**
* 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
*/
public function float($values, $asDbValue = false)
public function float($values)
{
return "REAL";
}
@ -553,10 +561,10 @@ class SQLite3SchemaManager extends DBSchemaManager
/**
* 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
*/
public function double($values, $asDbValue = false)
public function double($values)
{
return "REAL";
}
@ -564,10 +572,10 @@ class SQLite3SchemaManager extends DBSchemaManager
/**
* 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
*/
public function int($values, $asDbValue = false)
public function int($values)
{
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
*
* @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
*/
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
* 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
*/
public function ss_datetime($values, $asDbValue = false)
public function datetime($values)
{
return "DATETIME";
}
@ -598,10 +606,10 @@ class SQLite3SchemaManager extends DBSchemaManager
/**
* 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
*/
public function text($values, $asDbValue = false)
public function text($values)
{
return 'TEXT';
}
@ -609,7 +617,7 @@ class SQLite3SchemaManager extends DBSchemaManager
/**
* 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
*/
public function time($values)
@ -620,10 +628,10 @@ class SQLite3SchemaManager extends DBSchemaManager
/**
* 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
*/
public function varchar($values, $asDbValue = false)
public function varchar($values)
{
return "VARCHAR({$values['precision']}) COLLATE NOCASE";
}
@ -645,7 +653,7 @@ class SQLite3SchemaManager extends DBSchemaManager
public function hasTable($tableName)
{
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)
)->first();
}
@ -653,6 +661,8 @@ class SQLite3SchemaManager extends DBSchemaManager
/**
* Return enum values for the given field
*
* @param string $tableName
* @param string $fieldName
* @return array
*/
public function enumValuesForField($tableName, $fieldName)

View File

@ -1,5 +1,13 @@
<?php
namespace SilverStripe\SQLite;
use DatabaseConfigurationHelper;
use SQLite3;
use PDO;
use Exception;
use DatabaseAdapterRegistry;
/**
* This is a helper class for the SS installer.
*

View File

@ -24,6 +24,11 @@
"dev-master": "2.0.x-dev"
}
},
"autoload": {
"psr-4": {
"SilverStripe\\SQLite\\": "code/"
}
},
"minimum-stability": "dev",
"prefer-stable": true
}