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