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; }
/** * Overrides the Stato active record populate function * @param array $values * @access public * @return void */ public function populate($values = array()) { if (isset($values['score'])) { $this->score = $values['score']; } parent::populate($values); }
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); } }
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; }
private function setSchemaVersion($version) { SActiveRecord::connection()->update('UPDATE ' . self::$schemaInfoTableName . ' SET version = ' . ($this->isDown() ? $version - 1 : $version)); }
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); }
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); }
private static function connection() { return SActiveRecord::connection(); }
protected function deleteRecord($record) { $sql = "DELETE FROM {$this->joinTable} WHERE " . "{$this->assocForeignKey} = '{$record->id}' AND " . "{$this->foreignKey} = '{$this->owner->id}'"; SActiveRecord::connection()->execute($sql); }
protected static function establishConnection($config = array()) { $config = (include ROOT_DIR . '/conf/database.php'); $driverClass = 'S' . $config[APP_MODE]['driver'] . 'Driver'; if (!class_exists($driverClass)) { throw new SException('Database driver not found !'); } self::$conn = new $driverClass($config[APP_MODE]); self::$conn->connect(); }