Skip to content

Commit

Permalink
Fix for ticket #62: Quoting in SqlBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
KrisJordan committed Feb 16, 2009
1 parent 077dc79 commit 2c3b1a0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions recess/lib/recess/database/sql/SqlBuilder.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function insert() {
foreach($this->assignments as $assignment) {
if($first) { $first = false; }
else { $columns .= ', '; $values .= ', '; }
$columns .= str_replace($table_prefix, '', $assignment->column);
$columns .= '`' . str_replace($table_prefix, '', $assignment->column) . '`';
$values .= $assignment->getQueryParameter();
}
$columns = ' (' . $columns . ')';
Expand Down Expand Up @@ -162,7 +162,7 @@ public function update() {
foreach($this->assignments as $assignment) {
if($first) { $first = false; }
else { $sql .= ', '; }
$sql .= str_replace($table_prefix, '', $assignment->column) . ' = ' . $assignment->getQueryParameter();
$sql .= '`' . str_replace($table_prefix, '', $assignment->column) . '` = ' . $assignment->getQueryParameter();;
}

$sql .= $this->whereHelper();
Expand Down Expand Up @@ -571,6 +571,7 @@ protected function whereHelper() {
protected function joinHelper() {
$sql = '';
if(!empty($this->joins)) {
$this->joins = array_reverse($this->joins, true);
foreach($this->joins as $join) {
$joinStatement = '';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ function testLeftOuterJoin() {

function testInsert() {
$this->builder->into('authors')->assign('first_name','Kris');
$expected = 'INSERT INTO authors (first_name) VALUES (:assgn_authors_first_name)';
$expected = 'INSERT INTO authors (`first_name`) VALUES (:assgn_authors_first_name)';
$this->assertEqual($this->builder->insert(),$expected);
}

function testUpdate() {
$this->builder->table('authors')->equal('id',1)->assign('first_name','John');
$expected = 'UPDATE authors SET first_name = :assgn_authors_first_name WHERE authors.id = 1';
$expected = 'UPDATE authors SET `first_name` = :assgn_authors_first_name WHERE authors.id = 1';
$this->assertEqual($this->builder->update(),$expected);
}

Expand Down

0 comments on commit 2c3b1a0

Please sign in to comment.