/** * Test for the edge case that there is data that looks like a placeholder * but it is not */ public function testPlaceholdersWithFixedData() { $expected = array('age'); $query = PDOFactory::Get("INSERT INTO owners (name, age) VALUES (':name', :age)"); $this->assertEquals($expected, $query->placeholders(), "Failed on ':name'"); $query = PDOFactory::Get("INSERT INTO owners (name, age) VALUES (':name is weird', :age)"); $this->assertEquals($expected, $query->placeholders(), "Failed on ':name is weird'"); $query = PDOFactory::Get("INSERT INTO owners (name, age) VALUES (\"my:name\", :age)"); $this->assertEquals($expected, $query->placeholders(), "Failed on \"my:name\""); $query = PDOFactory::Get("INSERT INTO owners (name, age) VALUES ('This is my :name and not yours', :age)"); $this->assertEquals($expected, $query->placeholders(), "Failed on 'This is my :name and not yours'"); $query = PDOFactory::Get("INSERT INTO owners (age, name) VALUES (:age, 'This is my :name and not yours')"); $this->assertEquals($expected, $query->placeholders(), "Failed on 'This is my :name and not yours' as last parameter"); $query = PDOFactory::Get("INSERT INTO `cars` (\n `id` ,\n `brand` ,\n `colour` ,\n `doors` ,\n `owner_id` ,\n `name` ,\n `age`\n ) VALUES (\n :id ,\n \"My fancy brand\" ,\n :colour ,\n :doors ,\n :owner_id ,\n 'peter',\n :age)"); $expected = array('id', 'colour', 'doors', 'owner_id', 'age'); $this->assertEquals($expected, $query->placeholders(), "Failed on complex multi-line, multiple quotes query"); }
/** * @expectedException ORM\Exceptions\ORMFetchIntoRelatedClassNotFoundException */ public function testFindWithInvalidForeignClass() { $query = PDOFactory::Get("SELECT Owner.*, NoClass.* FROM owners AS Owner, cars AS NoClass WHERE NoClass.owner_id = Owner.id"); $query->execute(); $owner = $query->fetchInto('\\FlexibleORMTests\\Mock\\Owner'); }
public function tearDown() { PDOFactory::Get("TRUNCATE TABLE `cars`")->execute(); }
/** * Get the possible values of an ENUM field * * \note Only works for MySQL ENUM datatypes * * This is useful for rapid development as it allows you to only change the * ENUM values at the SQL side, but it is going to be slightly slower and * cause higer database load. If using this in production cache the result. * * @param string $fieldName * The name of the database field you wish to check. If it is not an * ENUM field, an empty array will be returned. * @return array * Array of strings containing the valid field values. Is indexed from 1 * to match the MYSQL index. Will be empty if it cannot determine values * (ie it's not a MySQL table or it's not an ENUM field). */ public static function PossibleValues($fieldName) { $fieldName = static::TranslatePropertyToField($fieldName); $query = PDOFactory::Get('SHOW COLUMNS FROM `' . static::TableName() . '` LIKE "' . $fieldName . '"'); $query->execute(); $results = $query->fetch(); $fields = array(); if (preg_match_all('/\'(.*?)\'/', $results[1], $fieldsZeroIndexed)) { // Convert to 1-indexed array $fields = array_combine(range(1, count($fieldsZeroIndexed[1])), $fieldsZeroIndexed[1]); } return $fields; }