public function run() { if (count($this->arguments) < 2) { $this->error("to few arguments."); $this->usage(); exit; } $this->defineEnvironment($this->arguments[0]); Sabel_Db_Config::initialize(new Config_Database()); $directory = $this->defineMigrationDirectory(); $connectionName = $this->connectionName = $this->getConnectionName(); $this->stmt = Sabel_Db::createStatement($connectionName); $this->metadata = Sabel_Db::createMetadata($connectionName); // @todo //if ($this->arguments[1] === "export") { // $this->export(); // self::$execFinalize = false; //} else { $tblName = $this->arguments[1]; $this->currentVersion = $this->getCurrentVersion(); if (in_array($tblName, array("-v", "--version"), true)) { $this->success("CURRENT VERSION: " . $this->currentVersion); exit; } else { $this->execMigration(); } //} }
public function run() { if (count($this->arguments) < 2) { $this->error("to few arguments."); $this->usage(); exit; } if (!defined('_LEGACY_PREVENT_LOAD_CORE_')) { define('_LEGACY_PREVENT_LOAD_CORE_', 'suin.asia'); require_once dirname(dirname(RUN_BASE)) . '/mainfile.php'; } $this->defineEnvironment($this->arguments[0]); Sabel_Db_Config::initialize(new Config_Database()); $directory = $this->defineMigrationDirectory(); $connectionName = $this->connectionName = $this->getConnectionName(); $this->stmt = Sabel_Db::createStatement($connectionName); $this->metadata = Sabel_Db::createMetadata($connectionName); // @todo //if ($this->arguments[1] === "export") { // $this->export(); // self::$execFinalize = false; //} else { $tblName = $this->arguments[1]; $this->currentVersion = $this->getCurrentVersion(); if (in_array($tblName, array("-v", "--version"), true)) { $this->success("CURRENT VERSION: " . $this->currentVersion); exit; } else { $this->execMigration(); } //} }
public function testBuildSelectWhereQuery() { $stmt = Sabel_Db::createStatement("default"); $stmt->type(Sabel_Db_Statement::SELECT); $stmt->setMetadata(Sabel_Db_Metadata::getTableInfo("student")); $stmt->where('WHERE "ID" = 1'); $expected = 'SELECT "ID", "NAME" FROM "STUDENT" WHERE "ID" = 1'; $this->assertEquals($expected, $stmt->getQuery()); }
public function testBuildSelectOrderByQuery2() { $stmt = Sabel_Db::createStatement("default"); $stmt->type(Sabel_Db_Statement::SELECT); $stmt->setMetadata(Sabel_Db_Metadata::getTableInfo("student")); $stmt->constraints(array("order" => array("id" => "DESC", "name" => "ASC"))); $expected = 'SELECT "ID", "NAME" FROM "STUDENT" ORDER BY "ID" DESC, "NAME" ASC'; $this->assertEquals($expected, $stmt->getQuery()); }
private static function initTable() { if (extension_loaded("mysql")) { $params = array("package" => "sabel.db.mysql", "host" => "127.0.0.1", "user" => "root", "password" => "", "database" => "sdb_test"); } elseif (extension_loaded("pgsql")) { $params = array("package" => "sabel.db.pgsql", "host" => "127.0.0.1", "user" => "root", "password" => "", "database" => "sdb_test"); } elseif (extension_loaded("pdo_sqlite")) { $params = array("package" => "sabel.db.pdo.sqlite", "database" => SABEL_BASE . "/Test/data/sdb_test.sq3"); } else { Sabel_Console::message("skipped 'TemplateDb'."); return false; } Sabel_Db_Config::add("default", $params); $stmt = Sabel_Db::createStatement(); $tblName = $stmt->quoteIdentifier("sbl_template"); $nCol = $stmt->quoteIdentifier("name"); $nsCol = $stmt->quoteIdentifier("namespace"); $cCol = $stmt->quoteIdentifier("contents"); $stmt->setQuery("DELETE FROM {$tblName}")->execute(); $data = array(); $data[0]["path"] = "views" . DS . "serverError" . TPL_SUFFIX; $data[0]["cont"] = ""; $data[1]["path"] = "index" . DS . "views" . DS . "error" . TPL_SUFFIX; $data[1]["cont"] = ""; $data[2]["path"] = "index" . DS . "views" . DS . "hoge" . DS . "index" . TPL_SUFFIX; $data[2]["cont"] = "hoge/index.tpl"; $data[3]["path"] = "index" . DS . "views" . DS . "hoge" . DS . "hoge" . TPL_SUFFIX; $data[3]["cont"] = "hoge/hoge.tpl"; $data[4]["path"] = "index" . DS . "views" . DS . "fuga" . DS . "index" . TPL_SUFFIX; $data[4]["cont"] = "fuga/index.tpl"; $data[5]["path"] = "index" . DS . "views" . DS . "fuga" . DS . "fuga" . TPL_SUFFIX; $data[5]["cont"] = "fuga/fuga.tpl"; foreach ($data as $d) { $query = "INSERT INTO {$tblName}({$nCol}, {$nsCol}, {$cCol}) VALUES('{$d["path"]}', '', '{$d["cont"]}')"; $stmt->setQuery($query)->execute(); } return true; }
public function testEscapeString() { $stmt = Sabel_Db::createStatement("default"); $this->assertEquals(array("'a\\'b\\\\z'"), $stmt->escape(array("a'b\\z"))); }
public function destruct() { if ($this->newSession && empty($this->attributes)) { return; } $stmt = Sabel_Db::createStatement($this->connectionName); $value = str_replace("", "\\000", serialize($this->attributes)); $timeout = time() + $this->maxLifetime; $table = $stmt->quoteIdentifier($this->tableName); $idCol = $stmt->quoteIdentifier("id"); $dataCol = $stmt->quoteIdentifier("data"); $toutCol = $stmt->quoteIdentifier("timeout"); if ($this->sessionIdExists($this->sessionId)) { $query = "UPDATE {$table} SET {$dataCol} = @data@, {$toutCol} = {$timeout} " . "WHERE {$idCol} = '{$this->sessionId}'"; } else { $query = "INSERT INTO {$table} ({$idCol}, {$dataCol}, {$toutCol}) " . "VALUES ('{$this->sessionId}', @data@, {$timeout})"; } $stmt->setQuery($query)->setBindValue("data", $value)->execute(); }
private function createStatement() { $stmt = Sabel_Db::createStatement($this->connectionName); $stmt->setMetadata(Sabel_Db_Metadata::getTableInfo($this->tableName, $this->connectionName)); return $stmt; }
/** * @param const $type Sabel_Db_Statement * * @return Sabel_Db_Statement */ public function prepareStatement($type = Sabel_Db_Statement::QUERY) { $stmt = Sabel_Db::createStatement($this->connectionName); return $stmt->setMetadata($this->metadata)->type($type); }
<?php define("RUN_BASE", getcwd()); require_once "/usr/local/lib/php/Sabel/Sabel.php"; require_once RUN_BASE . "/config/INIT.php"; require_once RUN_BASE . "/config/environment.php"; $configs = array("sqlite" => array("package" => "sabel.db.pdo.sqlite", "database" => "/home/ebine/test.sq3"), "mysql" => array("package" => "sabel.db.mysql", "host" => "127.0.0.1", "database" => "sdb_test", "port" => "3306", "user" => "root", "password" => ""), "pgsql" => array("package" => "sabel.db.pgsql", "host" => "127.0.0.1", "database" => "sdb_test", "user" => "pgsql", "password" => "pgsql"), "oci" => array("package" => "sabel.db.oci", "host" => "127.0.0.1", "database" => "XE", "schema" => "DEVELOP", "user" => "DEVELOP", "password" => "DEVELOP")); foreach ($configs as $key => $param) { Sabel_Db_Config::add($key, $param); } $args = $_SERVER["argv"]; $path = $args[1]; $conName = $args[2]; $type = $args[3]; $schema = Sabel_Db::createMetadata($conName); $stmt = Sabel_Db::createStatement($conName); Sabel_Db_Migration_Manager::setSchema($schema); Sabel_Db_Migration_Manager::setStatement($stmt); Sabel_Db_Migration_Manager::setDirectory(RUN_BASE . "/migration/tmp"); Sabel_Db_Migration_Manager::setApplyMode($type); $dirs = explode(".", Sabel_Db_Config::getPackage($conName)); $className = implode("_", array_map("ucfirst", $dirs)) . "_Migration"; $mig = new $className(); $mig->execute($path);