/** * @param string $table * @param string|array $idColumn * @param string $class * @param \PDO|null $dbh */ public function __construct($table, $idColumn, $class = 'stdClass', PDO $dbh = null) { parent::__construct($class, $dbh); $this->table = $table; $this->idColumn = is_array($idColumn) ? $idColumn : array($idColumn); $this->quoteIdentifier = Rorm::getIdentifierQuoter($this->dbh); }
/** * @depends testModels */ public function testQuoteIdentifier() { $quoter = Rorm::getIdentifierQuoter(Rorm::getDatabase('sqlite')); $this->assertEquals('"sqlite"', $quoter('sqlite')); }
/** * @return bool */ public function delete() { $dbh = static::getDatabase(); $quoteIdentifier = Rorm::getIdentifierQuoter($dbh); $idColumns = static::$_idColumn; if (!is_array($idColumns)) { $idColumns = array($idColumns); } $where = array(); foreach ($idColumns as $columnName) { $where[] = $quoteIdentifier($columnName) . ' = ' . Rorm::quote($dbh, $this->{$columnName}); } $sql = 'DELETE FROM ' . $quoteIdentifier(static::getTable()) . ' WHERE ' . implode(' AND ', $where); return $dbh->exec($sql) > 0; }
/** * @param $value * @param $expected * * @dataProvider providerQuoteIdentifier * @fixme this test requires the sqlite connection */ public function testQuoteIdentifier($value, $expected) { $quoter = Rorm::getIdentifierQuoter(Rorm::getDatabase('sqlite')); $this->assertEquals($expected, $quoter($value)); }