Skip to content

Commit

Permalink
A couple of fixes to zdk's 'in' code. All tests now passing.
Browse files Browse the repository at this point in the history
  • Loading branch information
KrisJordan committed Sep 1, 2009
1 parent d5b7d4f commit e27f851
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 18 deletions.
9 changes: 8 additions & 1 deletion recess/recess/database/orm/Model.class.php
Expand Up @@ -491,6 +491,13 @@ function isNull($column) { return $this->select()->isNull($column); }
*/
function isNotNull($column) { return $this->select()->isNotNull($column); }

/**
* SQL IN criteria
* @param string $column Column name
* @param array $values An array of values to test
* @return PdoDataSet
*/
function in($column, $values) { return $this->select()->in($column,$values); }
}

/**
Expand Down Expand Up @@ -598,4 +605,4 @@ function __set_state($array) {
return $prop;
}
}
?>
?>
15 changes: 9 additions & 6 deletions recess/recess/database/pdo/MysqlDataSourceProvider.class.php
Expand Up @@ -373,10 +373,12 @@ function getStatementForBuilder(SqlBuilder $builder, $action, PdoDataSource $sou
$criterion->value = $criterion->value == true ? 1 : 0;
break;
case RecessType::INTEGER:
if(!is_numeric($criterion->value)) {
$criterion->value = null;
} else {
if(is_array($criterion->value)) {
break;
} else if (is_numeric($criterion->value)) {
$criterion->value = (int)$criterion->value;
} else {
$criterion->value = null;
}
break;
case RecessType::FLOAT:
Expand All @@ -393,11 +395,12 @@ function getStatementForBuilder(SqlBuilder $builder, $action, PdoDataSource $sou
$arguments = $builder->getPdoArguments();
foreach($arguments as &$argument) {
// Begin workaround for PDO's poor numeric binding
$queryParameter = $argument->getQueryParameter();
if(is_numeric($queryParameter)) { continue; }
$param = $argument->getQueryParameter();
if(is_numeric($param)) { continue; }
if(is_string($param) && strlen($param) > 0 && substr($param,0,1) !== ':') { continue; }
// End Workaround

// Ignore parameters that aren't used in this $action (i.e. assignments in select)
$param = $argument->getQueryParameter();
if(''===$param || strpos($sql, $param) === false) { continue; }
$statement->bindValue($param, $argument->value);
}
Expand Down
6 changes: 3 additions & 3 deletions recess/recess/database/pdo/SqliteDataSourceProvider.class.php
Expand Up @@ -222,12 +222,12 @@ function getStatementForBuilder(SqlBuilder $builder, $action, PdoDataSource $sou
$arguments = $builder->getPdoArguments();
foreach($arguments as &$argument) {
// Begin workaround for PDO's poor numeric binding
$queryParameter = $argument->getQueryParameter();
if(is_numeric($queryParameter)) { continue; }
$param = $argument->getQueryParameter();
if(is_numeric($param)) { continue; }
if(is_string($param) && strlen($param) > 0 && substr($param,0,1) !== ':') { continue; }
// End Workaround

// Ignore parameters that aren't used in this $action (i.e. assignments in select)
$param = $argument->getQueryParameter();
if(''===$param || strpos($sql, $param) === false) { continue; }
$statement->bindValue($param, $argument->value);
}
Expand Down
11 changes: 5 additions & 6 deletions recess/recess/database/sql/SqlBuilder.class.php
Expand Up @@ -755,15 +755,14 @@ public function __construct($column, $value, $operator, $pdoLabel = null){

public function getQueryParameter() {
// Begin workaround for PDO's poor numeric binding
if(is_array($this->value)) {
$value = '('.implode(',', $this->value).')';
return $value;
}

if(is_numeric($this->value)) {
return $this->value;
}

if(is_array($this->value)) {
$hack_value = '('.join(',', $this->value).')';
return $hack_value;
}

// End workaround

if($this->operator == self::ASSIGNMENT) {
Expand Down
4 changes: 2 additions & 2 deletions recess/test/recess/database/PdoDsnSettings.php
@@ -1,5 +1,5 @@
<?php
// DSN, Database Name, Username, Password
$_ENV['dsn.mysql'] = array('mysql:host=localhost;dbname=recess', 'root', 'root', 'root');
$_ENV['dsn.mysql'] = array('mysql:host=localhost;dbname=recess', 'recess', 'recess', 'recess');
$_ENV['dsn.sqlite'] = array('sqlite::memory:','','','');
?>
?>

0 comments on commit e27f851

Please sign in to comment.