mirror of
https://github.com/silverstripe/silverstripe-mssql
synced 2024-10-22 08:05:53 +02:00
Merge pull request #37 from open-sausages/pulls/4.0/namespace-everything
Upgrade code for core namespaces
This commit is contained in:
commit
bdc3197351
@ -1,9 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use SilverStripe\Dev\Install\DatabaseAdapterRegistry;
|
||||||
|
use SilverStripe\MSSQL\MSSQLDatabaseConfigurationHelper;
|
||||||
|
|
||||||
// PDO connector for MS SQL Server
|
// PDO connector for MS SQL Server
|
||||||
/** @skipUpgrade */
|
/** @skipUpgrade */
|
||||||
use SilverStripe\MSSQL\MSSQLDatabaseConfigurationHelper;
|
|
||||||
|
|
||||||
DatabaseAdapterRegistry::register(array(
|
DatabaseAdapterRegistry::register(array(
|
||||||
'class' => 'MSSQLPDODatabase',
|
'class' => 'MSSQLPDODatabase',
|
||||||
'title' => 'SQL Server 2008 (using PDO)',
|
'title' => 'SQL Server 2008 (using PDO)',
|
||||||
|
@ -18,7 +18,6 @@ namespace SilverStripe\MSSQL;
|
|||||||
* Fulltext indexes are not supported.
|
* Fulltext indexes are not supported.
|
||||||
*
|
*
|
||||||
* @author Sean Harvey <sean at silverstripe dot com>
|
* @author Sean Harvey <sean at silverstripe dot com>
|
||||||
* @package mssql
|
|
||||||
*/
|
*/
|
||||||
class MSSQLAzureDatabase extends MSSQLDatabase
|
class MSSQLAzureDatabase extends MSSQLDatabase
|
||||||
{
|
{
|
||||||
|
@ -2,14 +2,14 @@
|
|||||||
|
|
||||||
namespace SilverStripe\MSSQL;
|
namespace SilverStripe\MSSQL;
|
||||||
|
|
||||||
|
use SilverStripe\Core\Config\Config;
|
||||||
|
use SilverStripe\Core\ClassInfo;
|
||||||
use SilverStripe\ORM\ArrayList;
|
use SilverStripe\ORM\ArrayList;
|
||||||
|
use SilverStripe\ORM\Connect\SS_Database;
|
||||||
use SilverStripe\ORM\DataList;
|
use SilverStripe\ORM\DataList;
|
||||||
use SilverStripe\ORM\DB;
|
use SilverStripe\ORM\DB;
|
||||||
use SilverStripe\ORM\DataObject;
|
use SilverStripe\ORM\DataObject;
|
||||||
use SilverStripe\ORM\Connect\SS_Database;
|
use SilverStripe\ORM\PaginatedList;
|
||||||
use Config;
|
|
||||||
use ClassInfo;
|
|
||||||
use PaginatedList;
|
|
||||||
use SilverStripe\ORM\Queries\SQLSelect;
|
use SilverStripe\ORM\Queries\SQLSelect;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -48,8 +48,6 @@ use SilverStripe\ORM\Queries\SQLSelect;
|
|||||||
*
|
*
|
||||||
* References:
|
* References:
|
||||||
* @see http://freetds.org
|
* @see http://freetds.org
|
||||||
*
|
|
||||||
* @package mssql
|
|
||||||
*/
|
*/
|
||||||
class MSSQLDatabase extends SS_Database
|
class MSSQLDatabase extends SS_Database
|
||||||
{
|
{
|
||||||
@ -217,14 +215,10 @@ class MSSQLDatabase extends SS_Database
|
|||||||
*/
|
*/
|
||||||
public function searchEngine($classesToSearch, $keywords, $start, $pageLength, $sortBy = "Relevance DESC", $extraFilter = "", $booleanSearch = false, $alternativeFileFilter = "", $invertedMatch = false)
|
public function searchEngine($classesToSearch, $keywords, $start, $pageLength, $sortBy = "Relevance DESC", $extraFilter = "", $booleanSearch = false, $alternativeFileFilter = "", $invertedMatch = false)
|
||||||
{
|
{
|
||||||
if (isset($objects)) {
|
$results = new ArrayList();
|
||||||
$results = new ArrayList($objects);
|
|
||||||
} else {
|
|
||||||
$results = new ArrayList();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$this->fullTextEnabled()) {
|
if (!$this->fullTextEnabled()) {
|
||||||
return $results;
|
return new PaginatedList($results);
|
||||||
}
|
}
|
||||||
if (!in_array(substr($sortBy, 0, 9), array('"Relevanc', 'Relevance'))) {
|
if (!in_array(substr($sortBy, 0, 9), array('"Relevanc', 'Relevance'))) {
|
||||||
user_error("Non-relevance sort not supported.", E_USER_ERROR);
|
user_error("Non-relevance sort not supported.", E_USER_ERROR);
|
||||||
@ -262,14 +256,14 @@ class MSSQLDatabase extends SS_Database
|
|||||||
$class = DataObject::getSchema()->tableClass($tableName);
|
$class = DataObject::getSchema()->tableClass($tableName);
|
||||||
$join = $this->fullTextSearchMSSQL($tableName, $keywords);
|
$join = $this->fullTextSearchMSSQL($tableName, $keywords);
|
||||||
if (!$join) {
|
if (!$join) {
|
||||||
return $results;
|
return new PaginatedList($results);
|
||||||
} // avoid "Null or empty full-text predicate"
|
} // avoid "Null or empty full-text predicate"
|
||||||
|
|
||||||
// Check if we need to add ShowInSearch
|
// Check if we need to add ShowInSearch
|
||||||
$where = null;
|
$where = null;
|
||||||
if ($class === 'SiteTree') {
|
if ($class === 'SilverStripe\\CMS\\Model\\SiteTree') {
|
||||||
$where = array("\"$tableName\".\"ShowInSearch\"!=0");
|
$where = array("\"$tableName\".\"ShowInSearch\"!=0");
|
||||||
} elseif ($class === 'File') {
|
} elseif ($class === 'SilverStripe\\Assets\\File') {
|
||||||
// File.ShowInSearch was added later, keep the database driver backwards compatible
|
// File.ShowInSearch was added later, keep the database driver backwards compatible
|
||||||
// by checking for its existence first
|
// by checking for its existence first
|
||||||
$fields = $this->getSchemaManager()->fieldList($tableName);
|
$fields = $this->getSchemaManager()->fieldList($tableName);
|
||||||
|
@ -2,18 +2,16 @@
|
|||||||
|
|
||||||
namespace SilverStripe\MSSQL;
|
namespace SilverStripe\MSSQL;
|
||||||
|
|
||||||
use DatabaseConfigurationHelper;
|
use SilverStripe\Dev\Install\DatabaseAdapterRegistry;
|
||||||
|
use SilverStripe\Dev\Install\DatabaseConfigurationHelper;
|
||||||
use PDO;
|
use PDO;
|
||||||
use Exception;
|
use Exception;
|
||||||
use DatabaseAdapterRegistry;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is a helper class for the SS installer.
|
* This is a helper class for the SS installer.
|
||||||
*
|
*
|
||||||
* It does all the specific checking for MSSQLDatabase
|
* It does all the specific checking for MSSQLDatabase
|
||||||
* to ensure that the configuration is setup correctly.
|
* to ensure that the configuration is setup correctly.
|
||||||
*
|
|
||||||
* @package mssql
|
|
||||||
*/
|
*/
|
||||||
class MSSQLDatabaseConfigurationHelper implements DatabaseConfigurationHelper
|
class MSSQLDatabaseConfigurationHelper implements DatabaseConfigurationHelper
|
||||||
{
|
{
|
||||||
@ -111,7 +109,7 @@ class MSSQLDatabaseConfigurationHelper implements DatabaseConfigurationHelper
|
|||||||
*
|
*
|
||||||
* @param mixed $conn Connection object/resource
|
* @param mixed $conn Connection object/resource
|
||||||
* @param string $value Value to quote
|
* @param string $value Value to quote
|
||||||
* @return string Quoted strieng
|
* @return string Quoted string
|
||||||
*/
|
*/
|
||||||
protected function quote($conn, $value)
|
protected function quote($conn, $value)
|
||||||
{
|
{
|
||||||
@ -124,6 +122,7 @@ class MSSQLDatabaseConfigurationHelper implements DatabaseConfigurationHelper
|
|||||||
} else {
|
} else {
|
||||||
user_error('Invalid database connection', E_USER_ERROR);
|
user_error('Invalid database connection', E_USER_ERROR);
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2,25 +2,20 @@
|
|||||||
|
|
||||||
namespace SilverStripe\MSSQL;
|
namespace SilverStripe\MSSQL;
|
||||||
|
|
||||||
|
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
use SilverStripe\ORM\Queries\SQLSelect;
|
use SilverStripe\ORM\Queries\SQLSelect;
|
||||||
use SilverStripe\ORM\Connect\DBQueryBuilder;
|
use SilverStripe\ORM\Connect\DBQueryBuilder;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds a SQL query string from a SQLExpression object
|
* Builds a SQL query string from a SQLExpression object
|
||||||
*
|
|
||||||
* @package mssql
|
|
||||||
*/
|
*/
|
||||||
class MSSQLQueryBuilder extends DBQueryBuilder
|
class MSSQLQueryBuilder extends DBQueryBuilder
|
||||||
{
|
{
|
||||||
|
|
||||||
protected function buildSelectQuery(SQLSelect $query, array &$parameters)
|
protected function buildSelectQuery(SQLSelect $query, array &$parameters)
|
||||||
{
|
{
|
||||||
list($limit, $offset) = $this->parseLimit($query);
|
list($limit, $offset) = $this->parseLimit($query);
|
||||||
|
|
||||||
// If not using ofset then query generation is quite straightforward
|
// If not using ofset then query generation is quite straightforward
|
||||||
if (empty($offset)) {
|
if (empty($offset)) {
|
||||||
$sql = parent::buildSelectQuery($query, $parameters);
|
$sql = parent::buildSelectQuery($query, $parameters);
|
||||||
@ -30,7 +25,7 @@ class MSSQLQueryBuilder extends DBQueryBuilder
|
|||||||
}
|
}
|
||||||
return $sql;
|
return $sql;
|
||||||
}
|
}
|
||||||
|
|
||||||
// When using offset we must use a subselect
|
// When using offset we must use a subselect
|
||||||
// @see http://stackoverflow.com/questions/2135418/equivalent-of-limit-and-offset-for-sql-server
|
// @see http://stackoverflow.com/questions/2135418/equivalent-of-limit-and-offset-for-sql-server
|
||||||
$orderby = $query->getOrderBy();
|
$orderby = $query->getOrderBy();
|
||||||
@ -58,13 +53,13 @@ class MSSQLQueryBuilder extends DBQueryBuilder
|
|||||||
$firstCol = reset($selects);
|
$firstCol = reset($selects);
|
||||||
$orderByClause = "ORDER BY $firstCol";
|
$orderByClause = "ORDER BY $firstCol";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build main query SQL
|
// Build main query SQL
|
||||||
$sql = parent::buildSelectQuery($query, $parameters);
|
$sql = parent::buildSelectQuery($query, $parameters);
|
||||||
|
|
||||||
// Inject row number into selection
|
// Inject row number into selection
|
||||||
$sql = preg_replace('/^(SELECT (DISTINCT)?)/i', '${1} ROW_NUMBER() OVER ('.$orderByClause.') AS Number, ', $sql);
|
$sql = preg_replace('/^(SELECT (DISTINCT)?)/i', '${1} ROW_NUMBER() OVER ('.$orderByClause.') AS Number, ', $sql);
|
||||||
|
|
||||||
// Sub-query this SQL
|
// Sub-query this SQL
|
||||||
if (empty($limit)) {
|
if (empty($limit)) {
|
||||||
$limitCondition = "Number > ?";
|
$limitCondition = "Number > ?";
|
||||||
@ -76,13 +71,13 @@ class MSSQLQueryBuilder extends DBQueryBuilder
|
|||||||
}
|
}
|
||||||
return "SELECT * FROM ($sql) AS Numbered WHERE $limitCondition ORDER BY Number";
|
return "SELECT * FROM ($sql) AS Numbered WHERE $limitCondition ORDER BY Number";
|
||||||
}
|
}
|
||||||
|
|
||||||
public function buildLimitFragment(SQLSelect $query, array &$parameters)
|
public function buildLimitFragment(SQLSelect $query, array &$parameters)
|
||||||
{
|
{
|
||||||
// Limit is handled at the buildSelectQuery level
|
// Limit is handled at the buildSelectQuery level
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function buildOrderByFragment(SQLSelect $query, array &$parameters)
|
public function buildOrderByFragment(SQLSelect $query, array &$parameters)
|
||||||
{
|
{
|
||||||
// If doing a limit/offset at the same time then don't build the orde by fragment here
|
// If doing a limit/offset at the same time then don't build the orde by fragment here
|
||||||
@ -92,10 +87,10 @@ class MSSQLQueryBuilder extends DBQueryBuilder
|
|||||||
}
|
}
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extracts the limit and offset from the limit clause
|
* Extracts the limit and offset from the limit clause
|
||||||
*
|
*
|
||||||
* @param SQLSelect $query
|
* @param SQLSelect $query
|
||||||
* @return array Two item array with $limit and $offset as values
|
* @return array Two item array with $limit and $offset as values
|
||||||
* @throws InvalidArgumentException
|
* @throws InvalidArgumentException
|
||||||
|
@ -2,15 +2,10 @@
|
|||||||
|
|
||||||
namespace SilverStripe\MSSQL;
|
namespace SilverStripe\MSSQL;
|
||||||
|
|
||||||
|
|
||||||
use SilverStripe\ORM\Connect\DBSchemaManager;
|
use SilverStripe\ORM\Connect\DBSchemaManager;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents and handles all schema management for a MS SQL database
|
* Represents and handles all schema management for a MS SQL database
|
||||||
*
|
|
||||||
* @package mssql
|
|
||||||
*/
|
*/
|
||||||
class MSSQLSchemaManager extends DBSchemaManager
|
class MSSQLSchemaManager extends DBSchemaManager
|
||||||
{
|
{
|
||||||
@ -697,6 +692,7 @@ class MSSQLSchemaManager extends DBSchemaManager
|
|||||||
* For a given table name, get all the internal index names,
|
* For a given table name, get all the internal index names,
|
||||||
* except for those that are primary keys and fulltext indexes.
|
* except for those that are primary keys and fulltext indexes.
|
||||||
*
|
*
|
||||||
|
* @param string $tableName
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function indexNames($tableName)
|
public function indexNames($tableName)
|
||||||
@ -786,6 +782,9 @@ class MSSQLSchemaManager extends DBSchemaManager
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @todo Make this work like {@link MySQLDatabase::set()}
|
* @todo Make this work like {@link MySQLDatabase::set()}
|
||||||
|
*
|
||||||
|
* @param array $values
|
||||||
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function set($values)
|
public function set($values)
|
||||||
{
|
{
|
||||||
|
@ -2,15 +2,10 @@
|
|||||||
|
|
||||||
namespace SilverStripe\MSSQL;
|
namespace SilverStripe\MSSQL;
|
||||||
|
|
||||||
|
|
||||||
use SilverStripe\ORM\Connect\DBConnector;
|
use SilverStripe\ORM\Connect\DBConnector;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Database connector driver for sqlsrv_ library
|
* Database connector driver for sqlsrv_ library
|
||||||
*
|
|
||||||
* @package mssql
|
|
||||||
*/
|
*/
|
||||||
class SQLServerConnector extends DBConnector
|
class SQLServerConnector extends DBConnector
|
||||||
{
|
{
|
||||||
|
@ -2,29 +2,25 @@
|
|||||||
|
|
||||||
namespace SilverStripe\MSSQL;
|
namespace SilverStripe\MSSQL;
|
||||||
|
|
||||||
|
|
||||||
use SilverStripe\ORM\Connect\SS_Query;
|
|
||||||
use DateTime;
|
use DateTime;
|
||||||
|
use SilverStripe\ORM\Connect\SS_Query;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A result-set from a MSSQL database.
|
* A result-set from a MSSQL database.
|
||||||
*
|
|
||||||
* @package mssql
|
|
||||||
*/
|
*/
|
||||||
class SQLServerQuery extends SS_Query
|
class SQLServerQuery extends SS_Query
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The SQLServerConnector object that created this result set.
|
* The SQLServerConnector object that created this result set.
|
||||||
*
|
*
|
||||||
* @var SQLServerConnector
|
* @var SQLServerConnector
|
||||||
*/
|
*/
|
||||||
private $connector;
|
private $connector;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The internal MSSQL handle that points to the result set.
|
* The internal MSSQL handle that points to the result set.
|
||||||
*
|
*
|
||||||
* @var resource
|
* @var resource
|
||||||
*/
|
*/
|
||||||
private $handle;
|
private $handle;
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use SilverStripe\ORM\DataObject;
|
use SilverStripe\ORM\DataObject;
|
||||||
|
use SilverStripe\Dev\SapphireTest;
|
||||||
|
use SilverStripe\Dev\TestOnly;
|
||||||
|
|
||||||
class MSSQLDatabaseQueryTest extends SapphireTest
|
class MSSQLDatabaseQueryTest extends SapphireTest
|
||||||
{
|
{
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user