mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-30 09:48:41 +00:00
impl. sqlsrv and fix 64bit bugs
This commit is contained in:
parent
b2415446a1
commit
d1e8a0800f
|
|
@ -17,8 +17,8 @@ namespace phpOMS\DataStorage\Database\Connection;
|
||||||
use phpOMS\DataStorage\Database\DatabaseStatus;
|
use phpOMS\DataStorage\Database\DatabaseStatus;
|
||||||
use phpOMS\DataStorage\Database\DatabaseType;
|
use phpOMS\DataStorage\Database\DatabaseType;
|
||||||
use phpOMS\DataStorage\Database\Exception\InvalidConnectionConfigException;
|
use phpOMS\DataStorage\Database\Exception\InvalidConnectionConfigException;
|
||||||
use phpOMS\DataStorage\Database\Query\Grammar\MysqlGrammar;
|
use phpOMS\DataStorage\Database\Query\Grammar\SqlServerGrammar;
|
||||||
use phpOMS\DataStorage\Database\Schema\Grammar\MysqlGrammar as MysqlSchemaGrammar;
|
use phpOMS\DataStorage\Database\Schema\Grammar\SqlServerGrammar as SqlServerSchemaGrammar;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Database handler.
|
* Database handler.
|
||||||
|
|
@ -45,8 +45,8 @@ final class SqlServerConnection extends ConnectionAbstract
|
||||||
public function __construct(array $dbdata)
|
public function __construct(array $dbdata)
|
||||||
{
|
{
|
||||||
$this->type = DatabaseType::SQLSRV;
|
$this->type = DatabaseType::SQLSRV;
|
||||||
$this->grammar = new MysqlGrammar();
|
$this->grammar = new SqlServerGrammar();
|
||||||
$this->schemaGrammar = new MysqlSchemaGrammar();
|
$this->schemaGrammar = new SqlServerSchemaGrammar();
|
||||||
|
|
||||||
$this->dbdata = $dbdata;
|
$this->dbdata = $dbdata;
|
||||||
}
|
}
|
||||||
|
|
@ -79,6 +79,7 @@ final class SqlServerConnection extends ConnectionAbstract
|
||||||
} catch (\PDOException $e) {
|
} catch (\PDOException $e) {
|
||||||
$this->con = null;
|
$this->con = null;
|
||||||
$this->status = DatabaseStatus::MISSING_DATABASE;
|
$this->status = DatabaseStatus::MISSING_DATABASE;
|
||||||
|
throw new InvalidConnectionConfigException((string) \json_encode($this->dbdata));
|
||||||
} finally {
|
} finally {
|
||||||
$this->dbdata['password'] = '****';
|
$this->dbdata['password'] = '****';
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ use phpOMS\DataStorage\Database\Query\Builder;
|
||||||
* @link https://orange-management.org
|
* @link https://orange-management.org
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
class MicrosoftGrammar extends Grammar
|
class SqlServerGrammar extends Grammar
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Compile random.
|
* Compile random.
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
\ini_set('display_errors', '1');
|
\ini_set('display_errors', '1');
|
||||||
\ini_set('display_startup_errors', '1');
|
\ini_set('display_startup_errors', '1');
|
||||||
\error_reporting(\E_ALL);
|
\error_reporting(\E_ALL);
|
||||||
|
setlocale(LC_ALL, 'en_US.UTF-8');
|
||||||
|
|
||||||
if (\is_file('vendor/autoload.php')) {
|
if (\is_file('vendor/autoload.php')) {
|
||||||
include_once 'vendor/autoload.php';
|
include_once 'vendor/autoload.php';
|
||||||
|
|
@ -168,54 +169,54 @@ $CONFIG = [
|
||||||
'admin' => [
|
'admin' => [
|
||||||
'db' => 'mssql', /* db type */
|
'db' => 'mssql', /* db type */
|
||||||
'host' => '127.0.0.1', /* db host address */
|
'host' => '127.0.0.1', /* db host address */
|
||||||
'port' => '5432', /* db host port */
|
'port' => '1433', /* db host port */
|
||||||
'login' => 'postgres', /* db login name */
|
'login' => 'sa', /* db login name */
|
||||||
'password' => 'root', /* db login password */
|
'password' => 'R00troot', /* db login password */
|
||||||
'database' => 'oms', /* db name */
|
'database' => 'oms', /* db name */
|
||||||
'weight' => 1000, /* db table prefix */
|
'weight' => 1000, /* db table prefix */
|
||||||
],
|
],
|
||||||
'insert' => [
|
'insert' => [
|
||||||
'db' => 'mssql', /* db type */
|
'db' => 'mssql', /* db type */
|
||||||
'host' => '127.0.0.1', /* db host address */
|
'host' => '127.0.0.1', /* db host address */
|
||||||
'port' => '5432', /* db host port */
|
'port' => '1433', /* db host port */
|
||||||
'login' => 'postgres', /* db login name */
|
'login' => 'sa', /* db login name */
|
||||||
'password' => 'root', /* db login password */
|
'password' => 'R00troot', /* db login password */
|
||||||
'database' => 'oms', /* db name */
|
'database' => 'oms', /* db name */
|
||||||
'weight' => 1000, /* db table prefix */
|
'weight' => 1000, /* db table prefix */
|
||||||
],
|
],
|
||||||
'select' => [
|
'select' => [
|
||||||
'db' => 'mssql', /* db type */
|
'db' => 'mssql', /* db type */
|
||||||
'host' => '127.0.0.1', /* db host address */
|
'host' => '127.0.0.1', /* db host address */
|
||||||
'port' => '5432', /* db host port */
|
'port' => '1433', /* db host port */
|
||||||
'login' => 'postgres', /* db login name */
|
'login' => 'sa', /* db login name */
|
||||||
'password' => 'root', /* db login password */
|
'password' => 'R00troot', /* db login password */
|
||||||
'database' => 'oms', /* db name */
|
'database' => 'oms', /* db name */
|
||||||
'weight' => 1000, /* db table prefix */
|
'weight' => 1000, /* db table prefix */
|
||||||
],
|
],
|
||||||
'update' => [
|
'update' => [
|
||||||
'db' => 'mssql', /* db type */
|
'db' => 'mssql', /* db type */
|
||||||
'host' => '127.0.0.1', /* db host address */
|
'host' => '127.0.0.1', /* db host address */
|
||||||
'port' => '5432', /* db host port */
|
'port' => '1433', /* db host port */
|
||||||
'login' => 'postgres', /* db login name */
|
'login' => 'sa', /* db login name */
|
||||||
'password' => 'root', /* db login password */
|
'password' => 'R00troot', /* db login password */
|
||||||
'database' => 'oms', /* db name */
|
'database' => 'oms', /* db name */
|
||||||
'weight' => 1000, /* db table prefix */
|
'weight' => 1000, /* db table prefix */
|
||||||
],
|
],
|
||||||
'delete' => [
|
'delete' => [
|
||||||
'db' => 'mssql', /* db type */
|
'db' => 'mssql', /* db type */
|
||||||
'host' => '127.0.0.1', /* db host address */
|
'host' => '127.0.0.1', /* db host address */
|
||||||
'port' => '5432', /* db host port */
|
'port' => '1433', /* db host port */
|
||||||
'login' => 'postgres', /* db login name */
|
'login' => 'sa', /* db login name */
|
||||||
'password' => 'root', /* db login password */
|
'password' => 'R00troot', /* db login password */
|
||||||
'database' => 'oms', /* db name */
|
'database' => 'oms', /* db name */
|
||||||
'weight' => 1000, /* db table prefix */
|
'weight' => 1000, /* db table prefix */
|
||||||
],
|
],
|
||||||
'schema' => [
|
'schema' => [
|
||||||
'db' => 'mssql', /* db type */
|
'db' => 'mssql', /* db type */
|
||||||
'host' => '127.0.0.1', /* db host address */
|
'host' => '127.0.0.1', /* db host address */
|
||||||
'port' => '5432', /* db host port */
|
'port' => '1433', /* db host port */
|
||||||
'login' => 'postgres', /* db login name */
|
'login' => 'sa', /* db login name */
|
||||||
'password' => 'root', /* db login password */
|
'password' => 'R00troot', /* db login password */
|
||||||
'database' => 'oms', /* db name */
|
'database' => 'oms', /* db name */
|
||||||
'weight' => 1000, /* db table prefix */
|
'weight' => 1000, /* db table prefix */
|
||||||
],
|
],
|
||||||
|
|
@ -273,23 +274,44 @@ $CONFIG = [
|
||||||
];
|
];
|
||||||
|
|
||||||
// Reset database
|
// Reset database
|
||||||
$db = new \PDO($CONFIG['db']['core']['masters']['admin']['db'] . ':host=' .
|
try {
|
||||||
$CONFIG['db']['core']['masters']['admin']['host'],
|
$db = new \PDO($CONFIG['db']['core']['masters']['admin']['db'] . ':host=' .
|
||||||
$CONFIG['db']['core']['masters']['admin']['login'],
|
$CONFIG['db']['core']['masters']['admin']['host'],
|
||||||
$CONFIG['db']['core']['masters']['admin']['password']
|
$CONFIG['db']['core']['masters']['admin']['login'],
|
||||||
);
|
$CONFIG['db']['core']['masters']['admin']['password']
|
||||||
$db->exec('DROP DATABASE IF EXISTS ' . $CONFIG['db']['core']['masters']['admin']['database']);
|
);
|
||||||
$db->exec('CREATE DATABASE IF NOT EXISTS ' . $CONFIG['db']['core']['masters']['admin']['database']);
|
$db->exec('DROP DATABASE IF EXISTS ' . $CONFIG['db']['core']['masters']['admin']['database']);
|
||||||
$db = null;
|
$db->exec('CREATE DATABASE IF NOT EXISTS ' . $CONFIG['db']['core']['masters']['admin']['database']);
|
||||||
|
$db = null;
|
||||||
|
} catch (\Throwable $t) {
|
||||||
|
echo "\nCouldn't connect to MYSQL DB\n";
|
||||||
|
}
|
||||||
|
|
||||||
$db = new \PDO($CONFIG['db']['core']['postgresql']['admin']['db'] . ':host=' .
|
try {
|
||||||
$CONFIG['db']['core']['postgresql']['admin']['host'],
|
$db = new \PDO($CONFIG['db']['core']['postgresql']['admin']['db'] . ':host=' .
|
||||||
$CONFIG['db']['core']['postgresql']['admin']['login'],
|
$CONFIG['db']['core']['postgresql']['admin']['host'],
|
||||||
$CONFIG['db']['core']['postgresql']['admin']['password']
|
$CONFIG['db']['core']['postgresql']['admin']['login'],
|
||||||
);
|
$CONFIG['db']['core']['postgresql']['admin']['password']
|
||||||
$db->exec('DROP DATABASE ' . $CONFIG['db']['core']['postgresql']['admin']['database']);
|
);
|
||||||
$db->exec('CREATE DATABASE ' . $CONFIG['db']['core']['postgresql']['admin']['database']);
|
$db->exec('DROP DATABASE IF EXISTS ' . $CONFIG['db']['core']['postgresql']['admin']['database']);
|
||||||
$db = null;
|
$db->exec('CREATE DATABASE ' . $CONFIG['db']['core']['postgresql']['admin']['database']);
|
||||||
|
$db = null;
|
||||||
|
} catch (\Throwable $t) {
|
||||||
|
echo "\nCouldn't connect to POSTGRESQL DB\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$db = new \PDO($CONFIG['db']['core']['mssql']['admin']['db'] . ':host=' .
|
||||||
|
$CONFIG['db']['core']['mssql']['admin']['host'],
|
||||||
|
$CONFIG['db']['core']['mssql']['admin']['login'],
|
||||||
|
$CONFIG['db']['core']['mssql']['admin']['password']
|
||||||
|
);
|
||||||
|
$db->exec('DROP DATABASE IF EXISTS ' . $CONFIG['db']['core']['mssql']['admin']['database']);
|
||||||
|
$db->exec('CREATE DATABASE ' . $CONFIG['db']['core']['mssql']['admin']['database']);
|
||||||
|
$db = null;
|
||||||
|
} catch (\Throwable $t) {
|
||||||
|
echo "\nCouldn't connect to MSSQL DB\n";
|
||||||
|
}
|
||||||
|
|
||||||
$httpSession = new HttpSession();
|
$httpSession = new HttpSession();
|
||||||
$GLOBALS['session'] = $httpSession;
|
$GLOBALS['session'] = $httpSession;
|
||||||
|
|
|
||||||
|
|
@ -75,6 +75,7 @@ class SqlServerConnectionTest extends \PHPUnit\Framework\TestCase
|
||||||
$db = $GLOBALS['CONFIG']['db']['core']['mssql']['admin'];
|
$db = $GLOBALS['CONFIG']['db']['core']['mssql']['admin'];
|
||||||
unset($db['host']);
|
unset($db['host']);
|
||||||
$ssql = new SqlServerConnection($db);
|
$ssql = new SqlServerConnection($db);
|
||||||
|
$ssql->connect();
|
||||||
self::assertEquals(DatabaseStatus::FAILURE, $ssql->getStatus());
|
self::assertEquals(DatabaseStatus::FAILURE, $ssql->getStatus());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,19 +14,19 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace phpOMS\tests\DataStorage\Database\Query\Grammar;
|
namespace phpOMS\tests\DataStorage\Database\Query\Grammar;
|
||||||
|
|
||||||
use phpOMS\DataStorage\Database\Query\Grammar\MicrosoftGrammar;
|
use phpOMS\DataStorage\Database\Query\Grammar\SqlServerGrammar;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
class MicrosoftGrammarTest extends \PHPUnit\Framework\TestCase
|
class SqlServerGrammarTest extends \PHPUnit\Framework\TestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @covers phpOMS\DataStorage\Database\Query\Grammar\MicrosoftGrammar
|
* @covers phpOMS\DataStorage\Database\Query\Grammar\SqlServerGrammar
|
||||||
* @group framework
|
* @group framework
|
||||||
*/
|
*/
|
||||||
public function testDefault() : void
|
public function testDefault() : void
|
||||||
{
|
{
|
||||||
self::assertInstanceOf('\phpOMS\DataStorage\Database\Query\Grammar\Grammar', new MicrosoftGrammar());
|
self::assertInstanceOf('\phpOMS\DataStorage\Database\Query\Grammar\Grammar', new SqlServerGrammar());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -34,15 +34,15 @@ class DateTimeTest extends \PHPUnit\Framework\TestCase
|
||||||
$dateMin = new \DateTime();
|
$dateMin = new \DateTime();
|
||||||
$dateMax = new \DateTime();
|
$dateMax = new \DateTime();
|
||||||
|
|
||||||
$min = \mt_rand(0, \PHP_INT_MAX - 2);
|
$min = \mt_rand(0, (int) (2147483647 / 2));
|
||||||
$max = \mt_rand($min + 1, \PHP_INT_MAX);
|
$max = \mt_rand($min + 10, 2147483647);
|
||||||
|
|
||||||
$dateMin->setTimestamp($min);
|
$dateMin->setTimestamp($min);
|
||||||
$dateMax->setTimestamp($max);
|
$dateMax->setTimestamp($max);
|
||||||
|
|
||||||
$rng = DateTime::generateDateTime($dateMin, $dateMax);
|
$rng = DateTime::generateDateTime($dateMin, $dateMax);
|
||||||
|
|
||||||
if (!($rng->getTimestamp() >= $min && $rng->getTimestamp() <= $max)) {
|
if ($rng->getTimestamp() < $min || $rng->getTimestamp() > $max) {
|
||||||
self::assertTrue(false);
|
self::assertTrue(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user