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:----YhPp0hasT8+ojoWdDdPQGqq4gQC4AtQCZvIohtovFXgWuRL4g4BXjjUxSKB6c33pKyOLzi2EAqfx5orDPiDe9W149dijYg6B4O6fQ9yInwJ9tPIlO2JZnsXeazDtqLsH+9B8mW0qHdUfy+947j9lXVQeVXtDPrjhozn+1MeUnfHPToyXaLWoyRGGlHwfzPrIq8yW5UX54D+d6eUCadudQyFFB3vYwy+fnVkY2FeaxPWKyQYHMmFLK4l2KCT6TKTX0bhw1AKIn0CEb3aOf6rujEDK3pl8+/rw58O35dSosnX4MH7pt3zNmigXWG1T3Nhj/iuDWvSCMs/E3KIWHwo9LSFC8Oig6CmZFxQOJ7U4VHYF6jQNxQogOQppvaqAuwThTtFO0V7Ns7Ro2fAFvaWCIVzzvmxI1BT3rjZH0f7XhOnwE/3wlzahypzySrbLaxYDBYCKAiVpKLBozD4Yf9w5nt2au730dzjPsQA8LyUN0fxujll5q6QuOs25wCPKPazsGskj/wHKLq0xbYoPnkaQ/71QVQ6BeDE1ylgXO0qdv606edW8CdkQblbE2auMqVzmXFRismAS72JFEZlKdk5uSA88ewtM7dQFEPrZmlead5NF/0As/OOeuQLyWRrk40Az450Wwhs9UhtZ64x2NUAu4F2dLZU0QnwXP+tvr9z3850=----ATTACHMENT:----MzA5NjQ5NTk1NzMwMjI5OCAzNTgyMzA4ODk3NzQ0OTEwIDQ0MDIwNDE5MTQ0NjkwNTQ=