Skip to content

Commit

Permalink
Add SQL IN statement and its test. (But not test yet wait for Sandbox…
Browse files Browse the repository at this point in the history
… setting up on slow internet)
  • Loading branch information
die-tech committed Aug 29, 2009
1 parent c626be5 commit a8b7f0c
Show file tree
Hide file tree
Showing 7 changed files with 450 additions and 408 deletions.
6 changes: 6 additions & 0 deletions recess/recess/database/pdo/PdoDataSet.class.php
Expand Up @@ -341,5 +341,11 @@ function range($start, $finish) { $copy = clone $this; $copy->sqlBuilder->range(
* @return PdoDataSet
*/
function orderBy($clause) { $copy = clone $this; $copy->sqlBuilder->orderBy($clause); return $copy; }

/**
* @see SqlBuilder::in
* @return PdoDataSet
*/
function in($lhs, $rhs) { $copy = clone $this; $copy->sqlBuilder->in($lhs,$rhs); return $copy; }
}
?>
1 change: 1 addition & 0 deletions recess/recess/database/sql/ISqlConditions.class.php
Expand Up @@ -19,6 +19,7 @@ function lessThan($column, $value);
function lessThanOrEqualTo($column, $value);
function like($column, $value);
function notLike($column, $value);
function in($column, $value);

}
?>
16 changes: 16 additions & 0 deletions recess/recess/database/sql/SqlBuilder.class.php
Expand Up @@ -338,6 +338,16 @@ public function isNull($column) { return $this->addCondition($column, nul
*/
public function isNotNull($column) { return $this->addCondition($column, null, Criterion::IS_NOT_NULL); }

/**
* IN to expression for WHERE clause of update, delete, or select statements.
*
* @param string $column
* @param array $value
* @return SqlBuilder
*/
public function in($column, $value) { return $this->addCondition($column, $value, Criterion::IN); }


/**
* Add a condition to the SqlBuilder statement. Additional logic here to prepend
* a table name and also keep track of which columns have already been assigned conditions
Expand Down Expand Up @@ -703,6 +713,12 @@ public function getQueryParameter() {
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
2 changes: 1 addition & 1 deletion 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', 'recess', 'recess', 'recess');
$_ENV['dsn.mysql'] = array('mysql:host=localhost;dbname=recess', 'root', 'root', 'root');
$_ENV['dsn.sqlite'] = array('sqlite::memory:','','','');
?>

0 comments on commit a8b7f0c

Please sign in to comment.