From 3507d15323edb56befbd4c900e3b277b9aa42894 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 17 Feb 2012 14:38:25 -0600 Subject: [PATCH] fix charset in mysql and pgsql connectors. --- laravel/database/connectors/mysql.php | 2 +- laravel/database/connectors/postgres.php | 2 +- laravel/database/query.php | 26 ++++++++++++++---------- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/laravel/database/connectors/mysql.php b/laravel/database/connectors/mysql.php index 78d35917..ad4cc12e 100644 --- a/laravel/database/connectors/mysql.php +++ b/laravel/database/connectors/mysql.php @@ -32,7 +32,7 @@ public function connect($config) if (isset($config['charset'])) { - $connection->prepare("SET NAMES '{$charset}'")->execute(); + $connection->prepare("SET NAMES '{$config['charset']}'")->execute(); } return $connection; diff --git a/laravel/database/connectors/postgres.php b/laravel/database/connectors/postgres.php index 0ac9f832..d128583c 100644 --- a/laravel/database/connectors/postgres.php +++ b/laravel/database/connectors/postgres.php @@ -32,7 +32,7 @@ public function connect($config) if (isset($config['charset'])) { - $connection->prepare("SET NAMES '{$charset}'")->execute(); + $connection->prepare("SET NAMES '{$config['charset']}'")->execute(); } return $connection; diff --git a/laravel/database/query.php b/laravel/database/query.php index d63704d4..e189dc1f 100644 --- a/laravel/database/query.php +++ b/laravel/database/query.php @@ -157,6 +157,7 @@ public function join($table, $column1, $operator = null, $column2 = null, $type call_user_func($column1, end($this->joins)); } + // If the column is just a string, we can assume that the join just // has a simple on clause, and we'll create the join instance and // add the clause automatically for the develoepr. @@ -648,15 +649,18 @@ public function get($columns = array('*')) */ public function aggregate($aggregator, $columns) { + // We'll set the aggregate value so the grammar does not try to compile + // a SELECT clause on the query. If an aggregator is present, it's own + // grammar function will be used to build the SQL syntax. $this->aggregate = compact('aggregator', 'columns'); $sql = $this->grammar->select($this); $result = $this->connection->only($sql, $this->bindings); - // Reset the aggregate so more queries can be performed using - // the same instance. This is helpful for getting aggregates - // and then getting actual results from the query. + // Reset the aggregate so more queries can be performed using the same + // instance. This is helpful for getting aggregates and then getting + // actual results from the query such as during paging. $this->aggregate = null; return $result; @@ -673,8 +677,7 @@ public function paginate($per_page = 20, $columns = array('*')) { // Because some database engines may throw errors if we leave orderings // on the query when retrieving the total number of records, we'll drop - // all of the ordreings and put them back on the query after we have - // retrieved the count from the table. + // all of the ordreings and put them back on the query. list($orderings, $this->orderings) = array($this->orderings, null); $total = $this->count(reset($columns)); @@ -685,8 +688,7 @@ public function paginate($per_page = 20, $columns = array('*')) // Now we're ready to get the actual pagination results from the table // using the for_page and get methods. The "for_page" method provides - // a convenient way to set the limit and offset so we get the correct - // span of results from the table. + // a convenient way to set the paging limit and offset. $results = $this->for_page($page, $per_page)->get($columns); return Paginator::make($results, $total, $per_page); @@ -773,10 +775,12 @@ public function decrement($column, $amount = 1) */ protected function adjust($column, $amount, $operator) { - // To make the adjustment to the column, we'll wrap the expression - // in an Expression instance, which forces the adjustment to be - // injected into the query as a string instead of bound. - $value = Database::raw($this->grammar->wrap($column).$operator.$amount); + $wrapped = $this->grammar->wrap($column); + + // To make the adjustment to the column, we'll wrap the expression in + // an Expression instance, which forces the adjustment to be injected + // into the query as a string instead of bound. + $value = Database::raw($wrapped.$operator.$amount); return $this->update(array($column => $value)); }