Exemplo n.º 1
0
 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();
     }
     //}
 }
Exemplo n.º 2
0
 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();
     }
     //}
 }
Exemplo n.º 3
0
 public function run()
 {
     clearstatcache();
     $this->checkInputs();
     $outputDir = RUN_BASE . DS . LIB_DIR_NAME . DS . "schema";
     $this->defineEnvironment($this->arguments[0]);
     Sabel_Db_Config::initialize(new Config_Database());
     $isAll = false;
     $tables = $this->getOutputTables();
     if (isset($tables[0]) && strtolower($tables[0]) === "all") {
         $isAll = count($tables) === 1;
     }
     $tList = new TableListWriter($outputDir);
     foreach (Sabel_Db_Config::get() as $connectionName => $params) {
         Sabel_Db_Config::add($connectionName, $params);
         $db = Sabel_Db::createMetadata($connectionName);
         foreach ($db->getTableList() as $tblName) {
             if ($isAll || in_array($tblName, $tables, true)) {
                 $writer = new Sabel_Db_Metadata_FileWriter($outputDir);
                 $writer->write($db->getTable($tblName));
                 $this->success("generate Schema 'Schema_" . convert_to_modelname($tblName) . "'");
             }
             $tList->add($connectionName, $tblName);
         }
         if (Sabel_Console::hasOption("l", $this->arguments)) {
             $tList->write($connectionName);
         }
     }
 }
Exemplo n.º 4
0
 public static function initialize(Sabel_Config $config)
 {
     if (self::$initialized) {
         return;
     }
     foreach ($config->configure() as $connectionName => $params) {
         self::$configs[$connectionName] = $params;
     }
     self::$initialized = true;
 }
Exemplo n.º 5
0
 public function execute(Sabel_Bus $bus)
 {
     Sabel_Db_Config::initialize($bus->getConfig("database"));
     if (!is_cli() && ($session = $bus->get("session")) !== null) {
         $session->start();
         l("START SESSION: " . $session->getName() . "=" . $session->getId());
     }
     // default page title.
     if ($response = $bus->get("response")) {
         $response->setResponse("pageTitle", "Sabel");
     }
 }
Exemplo n.º 6
0
 public function testSchemaNameOfCustomPackage()
 {
     $params = array("package" => "my.db.org", "database" => "mydb", "schema" => "hoge");
     Sabel_Db_Config::add("configtest", $params);
     $this->assertEquals("hoge", Sabel_Db_Config::getSchemaName("configtest"));
     $params = array("package" => "my.db.org", "database" => "mydb");
     Sabel_Db_Config::add("configtest", $params);
     try {
         Sabel_Db_Config::getSchemaName("configtest");
     } catch (Sabel_Db_Exception $e) {
         return;
     }
     $this->fail();
 }
Exemplo n.º 7
0
 public function execute($bus)
 {
     Sabel_Db_Config::initialize($bus->getConfig("database"));
     Sabel::fileUsing(RUN_BASE . DS . LIB_DIR_NAME . DS . "db" . DS . "utility.php", true);
     if (!defined("SBL_BATCH")) {
         // start session.
         $session = $bus->get("session");
         $session->start();
         l("START SESSION: " . $session->getName() . "=" . $session->getId());
     }
     // default page title.
     $bus->get("response")->setResponse("pageTitle", "Phwittr");
     // $request = $bus->get("request");
     // if ($request->isPost()) $this->trim($request);
 }
Exemplo n.º 8
0
 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 'Test_Session_Database'.");
         return false;
     }
     Sabel_Db_Config::add("default", $params);
     Sabel_Db::createDriver("default")->execute("DELETE FROM session");
     return true;
 }
Exemplo n.º 9
0
 public function run()
 {
     Sabel_Db_Config::initialize(new Config_Database());
     $runner = Sabel_Test_Runner::create();
     $runner->setClassPrefix("Unit_");
     $testsDir = RUN_BASE . DS . "tests" . DS . "unit";
     if (count($this->arguments) === 0) {
         foreach (scandir($testsDir) as $file) {
             if (preg_match("/^[A-Z].+\\.php\$/", $file)) {
                 $testName = str_replace(".php", "", $file);
                 $runner->start($testName, $testsDir . DS . $file);
             }
         }
     } else {
         $testName = $this->arguments[0];
         $runner->start($testName, $testsDir . DS . $testName . ".php");
     }
 }
Exemplo n.º 10
0
 public function run()
 {
     if (count($this->arguments) < 2) {
         $this->usage();
         exit;
     }
     $method = $this->getFixtureMethod();
     $this->defineEnvironment($this->arguments[0]);
     Sabel_Db_Config::initialize(new Config_Database());
     if (Sabel_Console::hasOption("export", $this->arguments)) {
         unset($this->arguments[array_search("--export", $this->arguments, true)]);
         return $this->export("fixture");
     } elseif (Sabel_Console::hasOption("export-csv", $this->arguments)) {
         $dir = Sabel_Console::getOption("export-csv", $this->arguments);
         if ($dir === null) {
             $dir = RUN_BASE . DS . "data";
         }
         return $this->export("csv", $dir);
     }
     $fixtureName = $this->arguments[1];
     if ($fixtureName === "all") {
         foreach (scandir(FIXTURE_DIR) as $item) {
             if ($item === "." || $item === "..") {
                 continue;
             }
             Sabel::fileUsing(FIXTURE_DIR . DS . $item, true);
             $className = "Fixture_" . substr($item, 0, strlen($item) - 4);
             $instance = new $className();
             $instance->initialize();
             $instance->{$method}();
         }
     } else {
         $filePath = FIXTURE_DIR . DS . $fixtureName . ".php";
         if (Sabel::fileUsing($filePath, true)) {
             $className = "Fixture_" . $fixtureName;
             $instance = new $className();
             $instance->initialize();
             $instance->{$method}();
             $this->success(ucfirst($method) . " " . $fixtureName);
         } else {
             $this->error("no such fixture file. '{$filePath}'");
         }
     }
 }
Exemplo n.º 11
0
 /**
  * @param Sabel_Db_Driver $driver
  *
  * @throws Sabel_Db_Exception_Connection
  * @return Sabel_Db_Driver
  */
 protected static function _connect(Sabel_Db_Driver $driver)
 {
     $connectionName = $driver->getConnectionName();
     $names = Sabel_Db_Config::getConnectionNamesOfSameSetting($connectionName);
     foreach ($names as $name) {
         if (isset(self::$connections[$name])) {
             $driver->setConnection(self::$connections[$name]);
             return $driver;
         }
     }
     if (!isset(self::$connections[$connectionName])) {
         $result = $driver->connect(Sabel_Db_Config::get($connectionName));
         if (is_string($result)) {
             throw new Sabel_Db_Exception_Connection($result);
         } else {
             self::$connections[$connectionName] = $result;
         }
     }
     $driver->setConnection(self::$connections[$connectionName]);
     return $driver;
 }
Exemplo n.º 12
0
 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;
 }
Exemplo n.º 13
0
 public function testInit()
 {
     Sabel_Db_Config::add("default", Test_DB_TestConfig::getIbaseConfig());
 }
Exemplo n.º 14
0
 public function testInit()
 {
     Sabel_Db_Config::add("default", Test_DB_TestConfig::getPdoSqliteConfig());
     Test_DB_Test::$db = "SQLITE";
 }
Exemplo n.º 15
0
 protected function dropDefaultConstraint($tblName, $colName)
 {
     $connectionName = $this->getStatement()->getDriver()->getConnectionName();
     $schemaName = Sabel_Db_Config::getSchemaName($connectionName);
     $cName = $this->getDefaultConstraintName($schemaName, $tblName, $colName);
     if ($cName === null) {
         return;
     }
     $quotedTblName = $this->quoteIdentifier($tblName);
     $this->executeQuery("ALTER TABLE {$quotedTblName} DROP CONSTRAINT {$cName}");
 }
Exemplo n.º 16
0
 public function testInit()
 {
     Sabel_Db_Config::add("default", self::$params1);
     Test_DB_Test::$db = "PDO_ORACLE";
 }
Exemplo n.º 17
0
 public function testInit()
 {
     Sabel_Db_Config::add("default", Test_DB_TestConfig::getMysqlConfig());
     Test_DB_Test::$db = "MYSQL";
 }
Exemplo n.º 18
0
<?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);
Exemplo n.º 19
0
 public function testInit()
 {
     Sabel_Db_Config::add("default", Test_DB_TestConfig::getIbaseConfig());
     MODEL("SblKvs")->delete();
 }
Exemplo n.º 20
0
 public function __construct()
 {
     Sabel_Db_Config::initialize(new Config_Database());
 }
Exemplo n.º 21
0
 /**
  * @param string $connectionName
  * @param string $className
  *
  * @return mixed
  */
 protected static function getBaseClassName($connectionName, $className)
 {
     $packageName = Sabel_Db_Config::getPackage($connectionName);
     $reserved = array("mysql", "pgsql", "oci", "ibase");
     foreach ($reserved as $part) {
         if (strpos($packageName, $part) !== false) {
             return "Sabel_Db_" . ucfirst($part) . "_" . $className;
         }
     }
     return false;
 }
Exemplo n.º 22
0
 public function testInit()
 {
     Sabel_Db_Config::add("default", Test_DB_TestConfig::getOciConfig());
     Test_DB_Test::$db = "ORACLE";
 }
Exemplo n.º 23
0
function isNull($arg1)
{
    if ($arg1 === null) {
        echo ".";
    } else {
        echo "F ( {$arg1} )";
    }
    if (Counter::$count !== 0 && Counter::$count % 40 === 0) {
        echo "\n";
    }
    Counter::$count++;
}
define("CONNAME", $_SERVER["argv"][1]);
$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);
}
echo "[ " . CONNAME . " ]\n";
$path = RUN_BASE . "/migration/tmp/1_Hoge_create.php";
system("php exec.php {$path} " . CONNAME . " upgrade");
$accessor = Sabel_Db::createMetadata(CONNAME);
$hoge = $accessor->getTable("hoge");
$id = $hoge->id;
$name = $hoge->name;
$test = $hoge->test;
$body = $hoge->body;
$bool = $hoge->bool;
isTrue($id->isInt(true));
isTrue($id->primary);
isTrue($id->increment);
isNull($id->default);