コード例 #1
0
 public function toSql()
 {
     $db = SActiveRecord::connection();
     $sql = $db->quoteColumnName($this->name) . ' ' . $db->typeToSql($this->type, $this->limit);
     $sql = $db->addColumnOptions($sql, $this->type, array('null' => $this->null, 'default' => $this->default));
     return $sql;
 }
コード例 #2
0
 private function recreateDatabase()
 {
     $db = SActiveRecord::connection();
     $dbname = $db->config['dbname'];
     $db->execute("DROP DATABASE IF EXISTS {$dbname}");
     $db->execute("CREATE DATABASE {$dbname}");
     $db->execute("USE {$dbname}");
     $sql = file_get_contents(FIXTURES_DIR . '/test_framework.sql');
     $requetes = explode(';', $sql);
     array_pop($requetes);
     foreach ($requetes as $req) {
         $db->execute($req);
     }
 }
コード例 #3
0
 public static function createFixtures($fixturesDir, $tableNames)
 {
     $db = SActiveRecord::connection();
     $fixtures = array();
     foreach ($tableNames as $table) {
         $fixturePath = $fixturesDir . '/' . $table;
         if (file_exists($fixturePath . '.csv')) {
             $mode = SFixture::CSV_MODE;
         } else {
             $mode = SFixture::INI_MODE;
         }
         $fixtures[$table] = new SFixture($db, $table, $fixturePath, $mode);
     }
     return $fixtures;
 }
コード例 #4
0
 private function setSchemaVersion($version)
 {
     SActiveRecord::connection()->update('UPDATE ' . self::$schemaInfoTableName . ' SET version = ' . ($this->isDown() ? $version - 1 : $version));
 }
コード例 #5
0
 protected function deleteRecord($record)
 {
     // si 'dependent', on delete l'entity ... (to do)
     $sql = 'UPDATE ' . $this->assocTableName . ' SET ' . $this->foreignKey . ' = \'NULL\'' . ' WHERE ' . $this->foreignKey . ' = \'' . $this->owner->id . '\'' . ' AND ' . $this->assocPrimaryKey . ' = \'' . $record->id . '\'';
     SActiveRecord::connection()->execute($sql);
 }
コード例 #6
0
 public function testMigratorGoingDownDueToVersionTarget()
 {
     SMigrator::up(dirname(__FILE__) . '/fixtures/migrate', 1);
     SMigrator::migrate(dirname(__FILE__) . '/fixtures/migrate', 0);
     $this->assertFalse(in_array('last_name', array_keys(SActiveRecord::connection()->columns('people'))));
     $this->assertFalse(SActiveStore::tableExists('reminders'));
     SMigrator::migrate(dirname(__FILE__) . '/fixtures/migrate');
     $this->assertEqual(2, SMigrator::currentVersion());
     SActiveStore::resetAttributeInformation('people');
     $this->assertTrue(in_array('last_name', array_keys(SActiveRecord::connection()->columns('people'))));
     $r = new Reminder(array('content' => 'hello world', 'remind_at' => SDateTime::today()));
     $r->save();
     $this->assertEqual('hello world', SActiveStore::findFirst('reminder')->content);
 }
コード例 #7
0
 private static function connection()
 {
     return SActiveRecord::connection();
 }
コード例 #8
0
 protected function deleteRecord($record)
 {
     $sql = "DELETE FROM {$this->joinTable} WHERE " . "{$this->assocForeignKey} = '{$record->id}' AND " . "{$this->foreignKey} = '{$this->owner->id}'";
     SActiveRecord::connection()->execute($sql);
 }