示例#1
0
 public function testSql()
 {
     $update = new Kwf_Update_Sql(123, 'abc');
     $tableName = uniqid("updatesql");
     $update->sql = "CREATE TABLE {$tableName} (\n                            `id` INT NOT NULL ,\n                            PRIMARY KEY ( `id` ) \n                            ) ENGINE = INNODB";
     $update->preUpdate();
     $update->update();
     $update->postUpdate();
     $tables = array();
     foreach (Kwf_Registry::get('db')->query("SHOW TABLES")->fetchAll() as $t) {
         reset($t);
         $tables[] = current($t);
     }
     $this->assertContains($tableName, $tables);
     Kwf_Registry::get('db')->query("DROP TABLE {$tableName}");
 }
 public function update()
 {
     if (file_exists($this->_dumpFile)) {
         $this->sql = file_get_contents($this->_dumpFile);
         parent::update();
     }
 }
 public static function createUpdate($class, $filename = null)
 {
     $file = str_replace('_', '/', $class);
     $isSql = false;
     if (!$filename) {
         if (is_file($file . '.sql')) {
             $filename = $file . '.sql';
             $isSql = true;
         } else {
             if (is_file(KWF_PATH . '/' . $file . '.sql')) {
                 $filename = KWF_PATH . '/' . $file . '.sql';
                 $isSql = true;
             }
         }
     } else {
         $isSql = substr($filename, -4) == '.sql';
     }
     $update = null;
     if ($isSql) {
         $update = new Kwf_Update_Sql($class);
         $update->sql = file_get_contents($filename);
         if (preg_match("#\\#\\s*tags:(.*)#", $update->sql, $m)) {
             $update->setTags(explode(' ', trim($m[1])));
         }
     } else {
         $update = new $class($class);
         if (!$update instanceof Kwf_Update) {
             throw new Kwf_Exception("Invalid update class: '{$class}'");
         }
     }
     return $update;
 }