add sqlsrv and fix system escaping

This commit is contained in:
Dennis Eichhorn 2020-10-11 18:57:21 +02:00
parent fd211cd949
commit 8fc34ef870
11 changed files with 90 additions and 13 deletions

View File

@ -48,7 +48,15 @@ abstract class GrammarAbstract
* @var string
* @since 1.0.0
*/
protected string $systemIdentifier = '"';
protected string $systemIdentifierStart = '"';
/**
* System identifier.
*
* @var string
* @since 1.0.0
*/
protected string $systemIdentifierEnd = '"';
/**
* And operator.
@ -201,11 +209,13 @@ abstract class GrammarAbstract
*/
protected function compileSystem(string $system) : string
{
$identifier = $this->systemIdentifier;
$identifierStart = $this->systemIdentifierStart;
$identifierEnd = $this->systemIdentifierEnd;
foreach ($this->specialKeywords as $keyword) {
if (\strrpos($system, $keyword, -\strlen($system)) !== false) {
$identifier = '';
$identifierStart = '';
$identifierEnd = '';
break;
}
@ -216,9 +226,9 @@ abstract class GrammarAbstract
foreach ($split as $key => $system) {
$fullSystem .= '.'
. ($system !== '*' ? $identifier : '')
. ($system !== '*' ? $identifierStart : '')
. $system
. ($system !== '*' ? $identifier : '');
. ($system !== '*' ? $identifierEnd : '');
}
return \ltrim($fullSystem, '.');

View File

@ -32,7 +32,15 @@ class MysqlGrammar extends Grammar
* @var string
* @since 1.0.0
*/
protected string $systemIdentifier = '`';
protected string $systemIdentifierStart = '`';
/**
* System identifier.
*
* @var string
* @since 1.0.0
*/
protected string $systemIdentifierEnd = '`';
/**
* Compile random.

View File

@ -32,7 +32,15 @@ class SQLiteGrammar extends Grammar
* @var string
* @since 1.0.0
*/
public string $systemIdentifier = '`';
public string $systemIdentifierStart = '`';
/**
* System identifier.
*
* @var string
* @since 1.0.0
*/
protected string $systemIdentifierEnd = '`';
/**
* Compile random.

View File

@ -26,6 +26,22 @@ use phpOMS\DataStorage\Database\Query\Builder;
*/
class SqlServerGrammar extends Grammar
{
/**
* System identifier.
*
* @var string
* @since 1.0.0
*/
protected string $systemIdentifierStart = '[';
/**
* System identifier.
*
* @var string
* @since 1.0.0
*/
protected string $systemIdentifierEnd = ']';
/**
* Compile random.
*

View File

@ -37,7 +37,15 @@ class MysqlGrammar extends Grammar
* @var string
* @since 1.0.0
*/
protected string $systemIdentifier = '`';
protected string $systemIdentifierStart = '`';
/**
* System identifier.
*
* @var string
* @since 1.0.0
*/
protected string $systemIdentifierEnd = '`';
/**
* Compile remove

View File

@ -30,5 +30,13 @@ class SQLiteGrammar extends Grammar
* @var string
* @since 1.0.0
*/
protected string $systemIdentifier = '`';
protected string $systemIdentifierStart = '`';
/**
* System identifier.
*
* @var string
* @since 1.0.0
*/
protected string $systemIdentifierEnd = '`';
}

View File

@ -24,4 +24,19 @@ namespace phpOMS\DataStorage\Database\Schema\Grammar;
*/
class SqlServerGrammar extends Grammar
{
/**
* System identifier.
*
* @var string
* @since 1.0.0
*/
protected string $systemIdentifierStart = '[';
/**
* System identifier.
*
* @var string
* @since 1.0.0
*/
protected string $systemIdentifierEnd = ']';
}

View File

@ -31,6 +31,7 @@ class MysqlGrammarTest extends \PHPUnit\Framework\TestCase
public function testDefault() : void
{
self::assertInstanceOf('\phpOMS\DataStorage\Database\Query\Grammar\Grammar', new MysqlGrammar());
self::assertEquals('`', TestUtils::getMember(new MysqlGrammar(), 'systemIdentifier'));
self::assertEquals('`', TestUtils::getMember(new MysqlGrammar(), 'systemIdentifierStart'));
self::assertEquals('`', TestUtils::getMember(new MysqlGrammar(), 'systemIdentifierEnd'));
}
}

View File

@ -31,6 +31,7 @@ class SQLiteGrammarTest extends \PHPUnit\Framework\TestCase
public function testDefault() : void
{
self::assertInstanceOf('\phpOMS\DataStorage\Database\Query\Grammar\Grammar', new SqliteGrammar());
self::assertEquals('`', TestUtils::getMember(new SqliteGrammar(), 'systemIdentifier'));
self::assertEquals('`', TestUtils::getMember(new SqliteGrammar(), 'systemIdentifierStart'));
self::assertEquals('`', TestUtils::getMember(new SqliteGrammar(), 'systemIdentifierEnd'));
}
}

View File

@ -42,7 +42,8 @@ class MysqlGrammarTest extends \PHPUnit\Framework\TestCase
public function testDefault() : void
{
self::assertInstanceOf('\phpOMS\DataStorage\Database\Schema\Grammar\Grammar', new MysqlGrammar());
self::assertEquals('`', TestUtils::getMember(new MysqlGrammar(), 'systemIdentifier'));
self::assertEquals('`', TestUtils::getMember(new MysqlGrammar(), 'systemIdentifierStart'));
self::assertEquals('`', TestUtils::getMember(new MysqlGrammar(), 'systemIdentifierEnd'));
}
/**

View File

@ -30,6 +30,7 @@ class SQLiteGrammarTest extends \PHPUnit\Framework\TestCase
public function testDefault() : void
{
self::assertInstanceOf('\phpOMS\DataStorage\Database\Schema\Grammar\Grammar', new SQLiteGrammar());
self::assertEquals('`', TestUtils::getMember(new SQLiteGrammar(), 'systemIdentifier'));
self::assertEquals('`', TestUtils::getMember(new SQLiteGrammar(), 'systemIdentifierStart'));
self::assertEquals('`', TestUtils::getMember(new SQLiteGrammar(), 'systemIdentifierEnd'));
}
}