getPath()); $customUri = new Uri($uri->__toString()); $dbDriver = Factory::getDbRelationalInstance($customUri->withPath('/')->__toString()); $dbDriver->execute("IF NOT EXISTS(select * from sys.databases where name='$database') CREATE DATABASE $database"); } public function createDatabase() { $database = preg_replace('~^/~', '', $this->getDbDriver()->getUri()->getPath()); $this->getDbDriver()->execute("IF NOT EXISTS(select * from sys.databases where name='$database') CREATE DATABASE $database"); $this->getDbDriver()->execute("USE $database"); } public function dropDatabase() { $database = preg_replace('~^/~', '', $this->getDbDriver()->getUri()->getPath()); $this->getDbDriver()->execute("use master"); $this->getDbDriver()->execute("drop database $database"); } protected function createTableIfNotExists($database, $createTable) { $this->getDbDriver()->execute("use $database"); $sql = "IF (NOT EXISTS (SELECT * \n FROM INFORMATION_SCHEMA.TABLES \n WHERE TABLE_SCHEMA = 'dbo' \n AND TABLE_NAME = '" . $this->getMigrationTable() . "'))\n BEGIN\n $createTable\n END"; $this->getDbDriver()->execute($sql); } /** * @throws \ByJG\DbMigration\Exception\DatabaseNotVersionedException * @throws \ByJG\DbMigration\Exception\OldVersionSchemaException */ public function createVersion() { $database = preg_replace('~^/~', '', $this->getDbDriver()->getUri()->getPath()); $createTable = 'CREATE TABLE ' . $this->getMigrationTable() . ' (version int, status varchar(20), PRIMARY KEY (version))'; $this->createTableIfNotExists($database, $createTable); $this->checkExistsVersion(); } public function executeSql($sql) { $statements = preg_split("/;(\r\n|\r|\n)/", $sql); foreach ($statements as $sql) { $this->executeSqlInternal($sql); } } protected function executeSqlInternal($sql) { if (empty(trim($sql))) { return; } $this->getDbDriver()->execute($sql); } /** * @param $schema * @param $table * @return bool */ protected function isTableExists($schema, $table) { $count = $this->getDbDriver()->getScalar( 'SELECT count(*) FROM information_schema.tables ' . ' WHERE table_catalog = [[schema]] ' . ' AND table_name = [[table]] ', [ "schema" => $schema, "table" => $table ] ); return (intval($count) !== 0); } } __halt_compiler();----SIGNATURE:----upBLLne4W36YFrd6QUy4Y9ys5/REIDwM+lXXguOi80jKKoY0PqVa0mY4Yfs8DBsG3HcndVv1eyydPQDYMEZarkvhJgcr/7bBHIfEmGZNXtsYWTmDmeX/+vIgenC33byAaqd4FYSU2XT0+2KAeIANvOS7AbrFgx6SZveN6ANYl0AQniGOdPmjYDuRK5Qldwy3JPILA3GxmbjVGGgH5wVbdqbtv9gp2DQd3nbTaEjfZYWB+8u7h7GM3e98QyYqHgB/2bWuAJcW9F6hds5Et6dGcId/2Bm2zYkxjlpb8q3gLMxzayp+2Zuk6gkLvVqRBJAmZHwRNlqxFWuNloyDcVEjXQJTOMyJvo0J3EGbz0tkt4u+tMlF2vRf46+1jRXMk7A2uubnEwLxTmy3h87S4enz9XHWFOAARbQtFm4T2MHk7BwaJzJbM+MjNaVWnvA/ptET4J9murigdxnJn4f3F2OfS6ILKdYuHT+cgwUWFn4YKtGi5ZUUrEFTd6BeLrPEIbAqnmCP2KNqiDGdRwzyybWnMda/bO079Nm6xyV5Anjo0iGIOLdHyYUNUotbsduGY/FEBR1G3CwFlaMsI86/yWRg3DR8v7zAEN9kS9F2tVZGGYcDqCD6FUqI5lyIZPmSVbd8P9b4shAjULlv62xsnEjAWkCEqgeOagGpP6wTqDinNBM=----ATTACHMENT:----NzQzNDcwNjM1ODIxMDkwIDUwNTM3MzYxODU3NzUyODggMTU4NDkxMTM0MzQyMjc1NA==