Skip to content

Commit

Permalink
BackwardsCompatibilityBreak - removed support for date function trans…
Browse files Browse the repository at this point in the history
…lation in fDatabase/fSQLTranslation.

InternalBackwardsCompatibilityBreak - Removed fORMDatabase::addTableToKeys(), fORMDatabase::addTableToValues(), fORMDatabase::escapeBySchema() and fORMDatabase::escapeByType(); rewrote fORMDatabase::createHavingClause() to fORMDatabase::addHavingClause(); rewrote fORMDatabase::createOrderByClause() to fORMDatabase::addOrderByClause(); rewrote fORMDatabase::insertFromAndGroupByClauses() to fORMDatabase::injectFromAndGroupByClauses(); added the `$schema` parameter to the beginning of fORMSchema::getRouteName(), fORMSchema::getRouteName(), fORMSchema::getRoutes() and fORMSchema::isOneToOne(); added the `$class` parameter to the beginning of fORMRelated::storeManyToMany().

Fixed tickets #319 and #308. Rewrote the ORM to use quoted identifiers and placeholder escaping. Added support for PostgreSQL, Oracle and SQL Server schemas.

Added tests for fActiveRecord, fRecordSet, fORMRelated and fORMOrdering
  • Loading branch information
wbond committed Apr 12, 2012
1 parent 855bde9 commit 30b7765
Show file tree
Hide file tree
Showing 11 changed files with 2,060 additions and 1,687 deletions.
279 changes: 172 additions & 107 deletions classes/fActiveRecord.php

Large diffs are not rendered by default.

409 changes: 286 additions & 123 deletions classes/fDatabase.php

Large diffs are not rendered by default.

44 changes: 27 additions & 17 deletions classes/fORMColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
* @package Flourish
* @link http://flourishlib.com/fORMColumn
*
* @version 1.0.0b5
* @version 1.0.0b6
* @changes 1.0.0b6 Changed SQL statements to use value placeholders, identifier escaping and schema support [wb, 2009-10-22]
* @changes 1.0.0b5 Updated to use new fORM::registerInspectCallback() method [wb, 2009-07-13]
* @changes 1.0.0b4 Updated code for new fORM API [wb, 2009-06-15]
* @changes 1.0.0b3 Updated code to use new fValidationException::formatField() method [wb, 2009-06-04]
Expand Down Expand Up @@ -99,7 +100,8 @@ static public function configureEmailColumn($class, $column)
{
$class = fORM::getClass($class);
$table = fORM::tablize($class);
$data_type = fORMSchema::retrieve()->getColumnInfo($table, $column, 'type');
$schema = fORMSchema::retrieve();
$data_type = $schema->getColumnInfo($table, $column, 'type');

$valid_data_types = array('varchar', 'char', 'text');
if (!in_array($data_type, $valid_data_types)) {
Expand Down Expand Up @@ -136,7 +138,8 @@ static public function configureLinkColumn($class, $column)
{
$class = fORM::getClass($class);
$table = fORM::tablize($class);
$data_type = fORMSchema::retrieve()->getColumnInfo($table, $column, 'type');
$schema = fORMSchema::retrieve();
$data_type = $schema->getColumnInfo($table, $column, 'type');

$valid_data_types = array('varchar', 'char', 'text');
if (!in_array($data_type, $valid_data_types)) {
Expand Down Expand Up @@ -180,7 +183,8 @@ static public function configureNumberColumn($class, $column)
{
$class = fORM::getClass($class);
$table = fORM::tablize($class);
$data_type = fORMSchema::retrieve()->getColumnInfo($table, $column, 'type');
$schema = fORMSchema::retrieve();
$data_type = $schema->getColumnInfo($table, $column, 'type');

$valid_data_types = array('integer', 'float');
if (!in_array($data_type, $valid_data_types)) {
Expand Down Expand Up @@ -231,7 +235,8 @@ static public function configureRandomColumn($class, $column, $type, $length)
{
$class = fORM::getClass($class);
$table = fORM::tablize($class);
$data_type = fORMSchema::retrieve()->getColumnInfo($table, $column, 'type');
$schema = fORMSchema::retrieve();
$data_type = $schema->getColumnInfo($table, $column, 'type');

$valid_data_types = array('varchar', 'char', 'text');
if (!in_array($data_type, $valid_data_types)) {
Expand Down Expand Up @@ -298,7 +303,9 @@ static public function encodeNumberColumn($object, &$values, &$old_values, &$rel
list ($action, $column) = fORM::parseMethod($method_name);

$class = get_class($object);
$column_info = fORMSchema::retrieve()->getColumnInfo(fORM::tablize($class), $column);
$schema = fORMSchema::retrieve();
$table = fORM::tablize($class);
$column_info = $schema->getColumnInfo($table, $column);
$value = $values[$column];

if ($value instanceof fNumber) {
Expand Down Expand Up @@ -332,24 +339,24 @@ static public function generate($object, &$values, &$old_values, &$related_recor
{
list ($action, $column) = fORM::parseMethod($method_name);

$class = get_class($object);
$table = fORM::tablize($class);
$class = get_class($object);
$table = fORM::tablize($class);

$schema = fORMSchema::retrieve();
$db = fORMDatabase::retrieve();

$settings = self::$random_columns[$class][$column];

// Check to see if this is a unique column
$unique_keys = fORMSchema::retrieve()->getKeys($table, 'unique');
$unique_keys = $schema->getKeys($table, 'unique');
$is_unique_column = FALSE;
foreach ($unique_keys as $unique_key) {
if ($unique_key == array($column)) {
$is_unique_column = TRUE;
$sql = "SELECT %r FROM %r WHERE %r = %s";
do {
$value = fCryptography::randomString($settings['length'], $settings['type']);

// See if this is unique
$sql = "SELECT " . $column . " FROM " . $table . " WHERE " . $column . " = " . fORMDatabase::retrieve()->escape('string', $value);

} while (fORMDatabase::retrieve()->query($sql)->countReturnedRows());
} while ($db->query($sql, $column, $table, $column, $value)->countReturnedRows());
}
}

Expand Down Expand Up @@ -472,7 +479,9 @@ static public function prepareNumberColumn($object, &$values, &$old_values, &$re
list ($action, $column) = fORM::parseMethod($method_name);

$class = get_class($object);
$column_info = fORMSchema::retrieve()->getColumnInfo(fORM::tablize($class), $column);
$table = fORM::tablize($class);
$schema = fORMSchema::retrieve();
$column_info = $schema->getColumnInfo($table, $column);
$value = $values[$column];

if ($value instanceof fNumber) {
Expand Down Expand Up @@ -527,11 +536,12 @@ static public function reflect($class, &$signatures, $include_doc_comments)

if (isset(self::$number_columns[$class])) {

$table = fORM::tablize($class);
$table = fORM::tablize($class);
$schema = fORMSchema::retrieve();

foreach(self::$number_columns[$class] as $column => $enabled) {
$camelized_column = fGrammar::camelize($column, TRUE);
$type = fORMSchema::retrieve()->getColumnInfo($table, $column, 'type');
$type = $schema->getColumnInfo($table, $column, 'type');

// Get and set methods
$signature = '';
Expand Down
Loading

0 comments on commit 30b7765

Please sign in to comment.