From b65268cea3ecd96f278e51a2936d0d7ab0286c18 Mon Sep 17 00:00:00 2001 From: Kunio Murasawa Date: Tue, 24 Jun 2014 10:37:35 +0900 Subject: [PATCH 01/19] Support named placeholders logging and test --- idiorm.php | 38 ++++++++++++++++++--------------- test/QueryBuilderPsr1Test53.php | 6 ++++++ test/QueryBuilderTest.php | 6 ++++++ test/bootstrap.php | 7 +++--- 4 files changed, 36 insertions(+), 21 deletions(-) diff --git a/idiorm.php b/idiorm.php index 80e9a4de..49b400ff 100644 --- a/idiorm.php +++ b/idiorm.php @@ -456,29 +456,33 @@ protected static function _log_query($query, $parameters, $connection_name, $que self::$_query_log[$connection_name] = array(); } - // Strip out any non-integer indexes from the parameters - foreach($parameters as $key => $value) { - if (!is_int($key)) unset($parameters[$key]); - } - - if (count($parameters) > 0) { + if (empty($parameters)) { + $bound_query = $query; + } else { // Escape the parameters $parameters = array_map(array(self::get_db($connection_name), 'quote'), $parameters); - // Avoid %format collision for vsprintf - $query = str_replace("%", "%%", $query); + if (array_values($parameters) === $parameters) { + // ? placeholders + // Avoid %format collision for vsprintf + $query = str_replace("%", "%%", $query); - // Replace placeholders in the query for vsprintf - if(false !== strpos($query, "'") || false !== strpos($query, '"')) { - $query = IdiormString::str_replace_outside_quotes("?", "%s", $query); + // Replace placeholders in the query for vsprintf + if(false !== strpos($query, "'") || false !== strpos($query, '"')) { + $query = IdiormString::str_replace_outside_quotes("?", "%s", $query); + } else { + $query = str_replace("?", "%s", $query); + } + + // Replace the question marks in the query with the parameters + $bound_query = vsprintf($query, $parameters); } else { - $query = str_replace("?", "%s", $query); + // named placeholders + foreach ($parameters as $key => $val) { + $query = str_replace($key, $val, $query); + } + $bound_query = $query; } - - // Replace the question marks in the query with the parameters - $bound_query = vsprintf($query, $parameters); - } else { - $bound_query = $query; } self::$_last_query = $bound_query; diff --git a/test/QueryBuilderPsr1Test53.php b/test/QueryBuilderPsr1Test53.php index 0aa89303..3b267eba 100644 --- a/test/QueryBuilderPsr1Test53.php +++ b/test/QueryBuilderPsr1Test53.php @@ -274,6 +274,12 @@ public function testRawQueryWithParameters() { $this->assertEquals($expected, ORM::getLastQuery()); } + public function testRawQueryWithNamedPlaceholders() { + ORM::forTable('widget')->rawQuery('SELECT `w`.* FROM `widget` w WHERE `name` = :name AND `age` = :age', array(':name' => 'Fred', ':age' => 5))->findMany(); + $expected = "SELECT `w`.* FROM `widget` w WHERE `name` = 'Fred' AND `age` = '5'"; + $this->assertEquals($expected, ORM::getLastQuery()); + } + public function testSimpleResultColumn() { ORM::forTable('widget')->select('name')->findMany(); $expected = "SELECT `name` FROM `widget`"; diff --git a/test/QueryBuilderTest.php b/test/QueryBuilderTest.php index 9c4ef973..54320d00 100644 --- a/test/QueryBuilderTest.php +++ b/test/QueryBuilderTest.php @@ -304,6 +304,12 @@ public function testRawQueryWithParameters() { $this->assertEquals($expected, ORM::get_last_query()); } + public function testRawQueryWithNamedPlaceholders() { + ORM::for_table('widget')->raw_query('SELECT `w`.* FROM `widget` w WHERE `name` = :name AND `age` = :age', array(':name' => 'Fred', ':age' => 5))->find_many(); + $expected = "SELECT `w`.* FROM `widget` w WHERE `name` = 'Fred' AND `age` = '5'"; + $this->assertEquals($expected, ORM::get_last_query()); + } + public function testSimpleResultColumn() { ORM::for_table('widget')->select('name')->find_many(); $expected = "SELECT `name` FROM `widget`"; diff --git a/test/bootstrap.php b/test/bootstrap.php index 3b3cacea..02d97252 100644 --- a/test/bootstrap.php +++ b/test/bootstrap.php @@ -46,15 +46,14 @@ public function execute($params = NULL) { /** * Add data to arrays */ - public function bindParam($index, $value, $type) + public function bindParam($key, $value, $type) { - // Do check on index, and type - if (!is_int($index)) throw new Exception('Incorrect parameter type. Expected $index to be an integer.'); + // Do check on type if (!is_int($type) || ($type != PDO::PARAM_STR && $type != PDO::PARAM_NULL && $type != PDO::PARAM_BOOL && $type != PDO::PARAM_INT)) throw new Exception('Incorrect parameter type. Expected $type to be an integer.'); // Add param to array - $this->bindParams[$index - 1] = $value; + $this->bindParams[is_int($key) ? --$key : $key] = $value; } /** From a7f20ee1b89123b68d47e9d17e9964c495c183d2 Mon Sep 17 00:00:00 2001 From: Simon Holywell Date: Fri, 27 Jun 2014 13:45:39 +0100 Subject: [PATCH 02/19] Issue #224 having_id_is undefined variable $value --- idiorm.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/idiorm.php b/idiorm.php index 80e9a4de..b3f3fb7c 100644 --- a/idiorm.php +++ b/idiorm.php @@ -1469,8 +1469,8 @@ public function having_not_equal($column_name, $value=null) { */ public function having_id_is($id) { return (is_array($this->_get_id_column_name())) ? - $this->having($this->_get_compound_id_column_values($value)) : - $this->having($this->_get_id_column_name(), $id); + $this->where($this->_get_compound_id_column_values($id), null) : + $this->where($this->_get_id_column_name(), $id); } /** From 22b1d3a793ed486c816d24fc25dce960797d1f38 Mon Sep 17 00:00:00 2001 From: Simon Holywell Date: Fri, 27 Jun 2014 13:54:38 +0100 Subject: [PATCH 03/19] Update the changelog --- README.markdown | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/README.markdown b/README.markdown index 7ca91275..c00d4034 100644 --- a/README.markdown +++ b/README.markdown @@ -75,12 +75,16 @@ foreach ($tweets as $tweet) { Changelog --------- +#### 1.5.2 - released 2014-06-27 -#### 1.5.1 - release 2014-06-23 +* Support named placeholders logging and test [[m92o](https://github.com/m92o)] - [issue #223](https://github.com/j4mie/idiorm/issues/223) +* `having_id_is()` reference undefined variable `$value` [[Treffynnon](https://github.com/treffynnon)] - [issue #224](https://github.com/j4mie/idiorm/issues/224) + +#### 1.5.1 - released 2014-06-23 * Binding of named parameters was broken [[cainmi](https://github.com/cainmi)] - [issue #221](https://github.com/j4mie/idiorm/pull/221) -#### 1.5.0 - release 2014-06-22 +#### 1.5.0 - released 2014-06-22 * Multiple OR'ed conditions support [[lrlopez](https://github.com/lrlopez)] - [issue #201](https://github.com/j4mie/idiorm/issues/201) * `where_id_in()` for selecting multiple records by primary key [[lrlopez](https://github.com/lrlopez)] - [issue #202](https://github.com/j4mie/idiorm/issues/202) @@ -100,13 +104,13 @@ Changelog * Improve where statement precendence documentation [[thomasahle](https://github.com/thomasahle)] - [issue #190](https://github.com/j4mie/idiorm/issues/190) * Improve testing checks [[charsleysa](https://github.com/charsleysa)] - [issue #173](https://github.com/j4mie/idiorm/issues/173) -#### 1.4.1 - release 2013-12-12 +#### 1.4.1 - released 2013-12-12 **Patch update to remove a broken pull request** - may have consequences for users of 1.4.0 that exploited the "`find_many()` now returns an associative array with the databases primary ID as the array keys" change that was merged in 1.4.0. * Back out pull request/issue [#133](https://github.com/j4mie/idiorm/pull/133) as it breaks backwards compatibility in previously unexpected ways (see [#162](https://github.com/j4mie/idiorm/pull/162), [#156](https://github.com/j4mie/idiorm/issues/156) and [#133](https://github.com/j4mie/idiorm/pull/133#issuecomment-29063108)) - sorry for merging this change into Idiorm - closes [issue 156](https://github.com/j4mie/idiorm/issues/156) -#### 1.4.0 - release 2013-09-05 +#### 1.4.0 - released 2013-09-05 * `find_many()` now returns an associative array with the databases primary ID as the array keys [[Surt](https://github.com/Surt)] - [issue #133](https://github.com/j4mie/idiorm/issues/133) * Calls to `set()` and `set_expr()` return `$this` allowing them to be chained [[Surt](https://github.com/Surt)] @@ -123,7 +127,7 @@ Changelog * Fix docblock [[ulrikjohansson](https://github.com/ulrikjohansson)] - [issue #147](https://github.com/j4mie/idiorm/issues/147) * Fix incorrect variable name in querying documentation [[fridde](https://github.com/fridde)] - [issue #146](https://github.com/j4mie/idiorm/issues/146) -#### 1.3.0 - release 2013-01-31 +#### 1.3.0 - released 2013-01-31 * Documentation moved to [idiorm.rtfd.org](http://idiorm.rtfd.org) and now built using [Sphinx](http://sphinx-doc.org/) * Add support for multiple database connections - closes [issue #15](https://github.com/j4mie/idiorm/issues/15) [[tag](https://github.com/tag)] @@ -143,19 +147,19 @@ Changelog * Fix issue with aggregate functions always returning `int` when is `float` sometimes required - closes [issue #92](https://github.com/j4mie/idiorm/issues/92) * Move testing into PHPUnit to unify method testing and query generation testing -#### 1.2.3 - release 2012-11-28 +#### 1.2.3 - released 2012-11-28 * Fix [issue #78](https://github.com/j4mie/idiorm/issues/78) - remove use of PHP 5.3 static call -#### 1.2.2 - release 2012-11-15 +#### 1.2.2 - released 2012-11-15 * Fix bug where input parameters were sent as part-indexed, part associative -#### 1.2.1 - release 2012-11-15 +#### 1.2.1 - released 2012-11-15 * Fix minor bug caused by IdiormStringException not extending Exception -#### 1.2.0 - release 2012-11-14 +#### 1.2.0 - released 2012-11-14 * Setup composer for installation via packagist (j4mie/idiorm) * Add `order_by_expr` method [[sandermarechal](http://github.com/sandermarechal)] @@ -173,7 +177,7 @@ Changelog * Add `find_array` to get the records as associative arrays [[Surt](https://github.com/Surt)] - closes [issue #17](https://github.com/j4mie/idiorm/issues/17) * Fix bug in `_log_query` with `?` and `%` supplied in raw where statements etc. - closes [issue #57](https://github.com/j4mie/idiorm/issues/57) [[ridgerunner](https://github.com/ridgerunner)] -#### 1.1.1 - release 2011-01-30 +#### 1.1.1 - released 2011-01-30 * Fix bug in quoting column wildcard. j4mie/paris#12 * Small documentation improvements From 2ff8cd553598ae6fd0f516696489b4552068255d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20Ram=C3=B3n=20L=C3=B3pez?= Date: Sat, 20 Sep 2014 20:13:42 +0200 Subject: [PATCH 04/19] Fix autoincremented compound keys inserts When inserting new records on a autoincremented compound keys table, a bug would prevent updating the autoincremented value. Fixes #233 --- idiorm.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/idiorm.php b/idiorm.php index 0e305fd9..39eaabd8 100644 --- a/idiorm.php +++ b/idiorm.php @@ -2027,7 +2027,7 @@ public function save() { // if the primary key is compound, assign the last inserted id // to the first column if (is_array($column)) { - $column = array_slice($column, 0, 1); + $column = reset($column); } $this->_data[$column] = $db->lastInsertId(); } From eea28fa89d47560979a9b16e3bc752a537b07d05 Mon Sep 17 00:00:00 2001 From: Stephen Tellis Date: Wed, 1 Oct 2014 05:56:36 -0400 Subject: [PATCH 05/19] Added @method tags for magic methods --- README.markdown | 4 +++ idiorm.php | 71 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) diff --git a/README.markdown b/README.markdown index c00d4034..6a789cc1 100644 --- a/README.markdown +++ b/README.markdown @@ -75,6 +75,10 @@ foreach ($tweets as $tweet) { Changelog --------- +#### 1.5.3 - released 2014-10-01 + +* Add @method tags for magic methods [[stellis](https://github.com/stellis)] + #### 1.5.2 - released 2014-06-27 * Support named placeholders logging and test [[m92o](https://github.com/m92o)] - [issue #223](https://github.com/j4mie/idiorm/issues/223) diff --git a/idiorm.php b/idiorm.php index 0e305fd9..e5d57233 100644 --- a/idiorm.php +++ b/idiorm.php @@ -36,6 +36,75 @@ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * + * @method static array|string getConfig($key = null, $connection_name = self::DEFAULT_CONNECTION) + * @method static null resetConfig() + * @method static \ORM forTable($table_name, $connection_name = self::DEFAULT_CONNECTION) + * @method static null setDb($db, $connection_name = self::DEFAULT_CONNECTION) + * @method static null resetDb() + * @method static null setupLimitClauseStyle($connection_name) + * @method static \PDO getDb($connection_name = self::DEFAULT_CONNECTION) + * @method static bool rawExecute($query, $parameters = array()) + * @method static \PDOStatement getLastStatement() + * @method static string getLastQuery($connection_name = null) + * @method static array getQueryLog($connection_name = self::DEFAULT_CONNECTION) + * @method array getConnectionNames() + * @method $this useIdColumn($id_column) + * @method \ORM|bool findOne($id=null) + * @method array|\IdiormResultSet findMany() + * @method \IdiormResultSet findResultSet() + * @method array findArray() + * @method $this forceAllDirty() + * @method $this rawQuery($query, $parameters = array()) + * @method $this tableAlias($alias) + * @method int countNullIdColumns() + * @method $this selectExpr($expr, $alias=null) + * @method \ORM selectMany() + * @method \ORM selectManyExpr() + * @method $this rawJoin($table, $constraint, $table_alias, $parameters = array()) + * @method $this innerJoin($table, $constraint, $table_alias=null) + * @method $this leftOuterJoin($table, $constraint, $table_alias=null) + * @method $this rightOuterJoin($table, $constraint, $table_alias=null) + * @method $this fullOuterJoin($table, $constraint, $table_alias=null) + * @method $this whereEqual($column_name, $value=null) + * @method $this whereNotEqual($column_name, $value=null) + * @method $this whereIdIs($id) + * @method $this whereAnyIs($values, $operator='=') + * @method array|string whereIdIn($ids) + * @method $this whereLike($column_name, $value=null) + * @method $this whereNotLike($column_name, $value=null) + * @method $this whereGt($column_name, $value=null) + * @method $this whereLt($column_name, $value=null) + * @method $this whereGte($column_name, $value=null) + * @method $this whereLte($column_name, $value=null) + * @method $this whereIn($column_name, $values) + * @method $this whereNotIn($column_name, $values) + * @method $this whereNull($column_name) + * @method $this whereNotNull($column_name) + * @method $this whereRaw($clause, $parameters=array()) + * @method $this orderByDesc($column_name) + * @method $this orderByAsc($column_name) + * @method $this orderByExpr($clause) + * @method $this groupBy($column_name) + * @method $this groupByExpr($expr) + * @method $this havingEqual($column_name, $value=null) + * @method $this havingNotEqual($column_name, $value=null) + * @method $this havingIdIs($id) + * @method $this havingLike($column_name, $value=null) + * @method $this havingNotLike($column_name, $value=null) + * @method $this havingGt($column_name, $value=null) + * @method $this havingLt($column_name, $value=null) + * @method $this havingGte($column_name, $value=null) + * @method $this havingLte($column_name, $value=null) + * @method $this havingIn($column_name, $values=null) + * @method $this havingNotIn($column_name, $values=null) + * @method $this havingNull($column_name) + * @method $this havingNotNull($column_name) + * @method $this havingRaw($clause, $parameters=array()) + * @method static this clearCache($table_name = null, $connection_name = self::DEFAULT_CONNECTION) + * @method array asArray() + * @method bool setExpr($key, $value = null) + * @method bool isDirty($key) + * @method bool isNew() */ class ORM implements ArrayAccess { @@ -2317,6 +2386,8 @@ protected function _str_replace_outside_quotes_cb($matches) { /** * A result set class for working with collections of model instances * @author Simon Holywell + * @method null setResults(array $results) + * @method array getResults() */ class IdiormResultSet implements Countable, IteratorAggregate, ArrayAccess, Serializable { /** From 7bf5c34b9fc11e5c260befc4bbbf051dea277816 Mon Sep 17 00:00:00 2001 From: Stephen Tellis Date: Wed, 1 Oct 2014 07:11:49 -0400 Subject: [PATCH 06/19] Added note about the purpose of the magic-method documentation --- idiorm.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/idiorm.php b/idiorm.php index e5d57233..6a824517 100644 --- a/idiorm.php +++ b/idiorm.php @@ -36,6 +36,11 @@ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * + * + * The methods documented below are magic methods that conform to PSR-1. + * This documentation exposes these methods to doc generators and IDEs. + * @see http://www.php-fig.org/psr/psr-1/ + * * @method static array|string getConfig($key = null, $connection_name = self::DEFAULT_CONNECTION) * @method static null resetConfig() * @method static \ORM forTable($table_name, $connection_name = self::DEFAULT_CONNECTION) From 1630a801ea94a1d9f9473428caf62ad9e473ebe7 Mon Sep 17 00:00:00 2001 From: Simon Holywell Date: Fri, 31 Oct 2014 13:03:52 +0000 Subject: [PATCH 07/19] Issue #224 having_id_is undefined variable $value Correct incorrect copy and paste --- idiorm.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/idiorm.php b/idiorm.php index 0e305fd9..ac62c90f 100644 --- a/idiorm.php +++ b/idiorm.php @@ -1473,8 +1473,8 @@ public function having_not_equal($column_name, $value=null) { */ public function having_id_is($id) { return (is_array($this->_get_id_column_name())) ? - $this->where($this->_get_compound_id_column_values($id), null) : - $this->where($this->_get_id_column_name(), $id); + $this->having($this->_get_compound_id_column_values($id), null) : + $this->having($this->_get_id_column_name(), $id); } /** From 391eb8aa27b107a79286e3c21f5f30580f20ae5e Mon Sep 17 00:00:00 2001 From: Simon Holywell Date: Mon, 19 Jan 2015 13:04:08 +0000 Subject: [PATCH 08/19] Add merges to the changelog --- README.markdown | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/README.markdown b/README.markdown index 6a789cc1..c4da420b 100644 --- a/README.markdown +++ b/README.markdown @@ -75,12 +75,11 @@ foreach ($tweets as $tweet) { Changelog --------- -#### 1.5.3 - released 2014-10-01 - -* Add @method tags for magic methods [[stellis](https://github.com/stellis)] - -#### 1.5.2 - released 2014-06-27 +#### 1.5.2 - released 2014-XX-XX +* Add @method tags for magic methods [[stellis](https://github.com/stellis)] - [issue #237](https://github.com/j4mie/idiorm/issues/237) +* Adding Code Climate badge to the readme file [[e3betht](https://github.com/e3betht)] - [issue #260](https://github.com/j4mie/idiorm/issues/260) +* Typo in navigation [[leongersen](https://github.com/leongersen)] - [issue #257](https://github.com/j4mie/idiorm/issues/257) * Support named placeholders logging and test [[m92o](https://github.com/m92o)] - [issue #223](https://github.com/j4mie/idiorm/issues/223) * `having_id_is()` reference undefined variable `$value` [[Treffynnon](https://github.com/treffynnon)] - [issue #224](https://github.com/j4mie/idiorm/issues/224) From 431684ffe8469cd41c4b2ace98666578cc6ae9af Mon Sep 17 00:00:00 2001 From: blair Date: Tue, 7 Apr 2015 09:46:11 -0700 Subject: [PATCH 09/19] Update ORM#is_dirty - swapped isset() for array_key_exists() - isset() will return false when fields have been set null. Update ORMTest#testIsDirty - added tests for filed set to '' and null --- idiorm.php | 2 +- test/ORMTest.php | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/idiorm.php b/idiorm.php index 80e9a4de..ea5f1a0b 100644 --- a/idiorm.php +++ b/idiorm.php @@ -1964,7 +1964,7 @@ protected function _set_orm_property($key, $value = null, $expr = false) { * object was saved. */ public function is_dirty($key) { - return isset($this->_dirty_fields[$key]); + return array_key_exists($key, $this->_dirty_fields); } /** diff --git a/test/ORMTest.php b/test/ORMTest.php index f244f120..b85b0f65 100644 --- a/test/ORMTest.php +++ b/test/ORMTest.php @@ -43,9 +43,15 @@ public function testIsNew() { public function testIsDirty() { $model = ORM::for_table('test')->create(); $this->assertFalse($model->is_dirty('test')); - + $model = ORM::for_table('test')->create(array('test' => 'test')); $this->assertTrue($model->is_dirty('test')); + + $model->test = null; + $this->assertTrue($model->is_dirty('test')); + + $model->test = ''; + $this->assertTrue($model->is_dirty('test')); } public function testArrayAccess() { From 1a2e87ec2b76a299b9731b47a587dca282dbdae7 Mon Sep 17 00:00:00 2001 From: Ovidiu Ungureanu Date: Thu, 22 Sep 2016 13:53:22 +0100 Subject: [PATCH 10/19] typo on operator --- docs/querying.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/querying.rst b/docs/querying.rst index bf140a12..be7d5592 100644 --- a/docs/querying.rst +++ b/docs/querying.rst @@ -344,7 +344,7 @@ column using a second parameter: ->find_many(); // Creates SQL: - SELECT * FROM `widget` WHERE (( `name` = 'Joe' AND `age` > '10' ) OR ( `name` = 'Fred' AND `age` > '20' )); + SELECT * FROM `widget` WHERE (( `name` = 'Joe' AND `age` = '10' ) OR ( `name` = 'Fred' AND `age` > '20' )); If you want to set the default operator for all the columns, just pass it as the second parameter: From 61863c1499b5b8bc5c9b99c7ecf06f78cc53f24b Mon Sep 17 00:00:00 2001 From: Michael Keck Date: Wed, 14 Dec 2016 14:12:49 +1000 Subject: [PATCH 11/19] #301 nested loop shouldn't override parent var --- idiorm.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/idiorm.php b/idiorm.php index 080ef5d5..cd01b0da 100644 --- a/idiorm.php +++ b/idiorm.php @@ -1333,14 +1333,14 @@ public function where_any_is($values, $operator='=') { $data = array(); $query = array("(("); $first = true; - foreach ($values as $item) { + foreach ($values as $value) { if ($first) { $first = false; } else { $query[] = ") OR ("; } $firstsub = true; - foreach($item as $key => $item) { + foreach($value as $key => $item) { $op = is_string($operator) ? $operator : (isset($operator[$key]) ? $operator[$key] : '='); if ($firstsub) { $firstsub = false; From 02b9b7954a4f8162ce1dd2485c7adbd790f147f7 Mon Sep 17 00:00:00 2001 From: Simon Holywell Date: Wed, 14 Dec 2016 15:23:39 +1000 Subject: [PATCH 12/19] #307 document query logging shortcomings --- docs/configuration.rst | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/docs/configuration.rst b/docs/configuration.rst index b40cbe12..fb90dfa0 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -254,6 +254,17 @@ the log. ``ORM::get_last_query()`` returns the most recent query executed. ``ORM::get_query_log()`` returns an array of all queries executed. +.. note:: + + The code that does the query log is an approximation of that provided by PDO/the + database (see the Idiorm source code for detail). The actual query isn't even available + to idiorm to log as the database/PDO handles the binding outside of idiorm's reach and + doesn't pass it back. + + This means that you might come across some inconsistencies between what is logged and + what is actually run. In these case you'll need to look at the query log provided by + your database vendor (eg. MySQL). + Query logger ^^^^^^^^^^^^ From 9d82f2ac06e85fc8c58b427a2000b3b1183bf259 Mon Sep 17 00:00:00 2001 From: Simon Holywell Date: Wed, 14 Dec 2016 15:33:00 +1000 Subject: [PATCH 13/19] Document merged code in changelog --- README.markdown | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.markdown b/README.markdown index 6ccc5182..11665a79 100644 --- a/README.markdown +++ b/README.markdown @@ -75,13 +75,18 @@ foreach ($tweets as $tweet) { Changelog --------- -#### 1.5.2 - released 2014-XX-XX +#### 1.5.2 - released 2016-XX-XX +* Fix autoincremented compound keys inserts [[lrlopez](https://github.com/lrlopez)] - [issue #233](https://github.com/j4mie/idiorm/issues/233) and [pull #235](https://github.com/j4mie/idiorm/pull/235) * Add @method tags for magic methods [[stellis](https://github.com/stellis)] - [issue #237](https://github.com/j4mie/idiorm/issues/237) +* Ensure `is_dirty()` returns correctly when fed null or an empty string [[tentwofour](https://github.com/tentwofour)] - [issue #268](https://github.com/j4mie/idiorm/issues/268) * Adding Code Climate badge to the readme file [[e3betht](https://github.com/e3betht)] - [issue #260](https://github.com/j4mie/idiorm/issues/260) * Typo in navigation [[leongersen](https://github.com/leongersen)] - [issue #257](https://github.com/j4mie/idiorm/issues/257) * Support named placeholders logging and test [[m92o](https://github.com/m92o)] - [issue #223](https://github.com/j4mie/idiorm/issues/223) * `having_id_is()` reference undefined variable `$value` [[Treffynnon](https://github.com/treffynnon)] - [issue #224](https://github.com/j4mie/idiorm/issues/224) +* Documentation fix - ORM query output for `where_any_is()` [[uovidiu](https://github.com/uovidiu)] - [issue #306](https://github.com/j4mie/idiorm/issues/306) +* Code style fix preventing nested loops from using the same variable names [[mkkeck](https://github.com/mkkeck)] - [issue #301](https://github.com/j4mie/idiorm/issues/301) +* Document shortcomings of the built in query logger [[Treffynnon](https://github.com/treffynnon)] - [issue #307](https://github.com/j4mie/idiorm/issues/307) #### 1.5.1 - released 2014-06-23 From d3a0e7905daf2908bd9db7e9a9122d96187800d9 Mon Sep 17 00:00:00 2001 From: Simon Holywell Date: Wed, 14 Dec 2016 15:35:08 +1000 Subject: [PATCH 14/19] Fix up test procedures for idiorm --- README.markdown | 1 + composer.json | 6 ++++++ test/bootstrap.php | 4 ++-- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/README.markdown b/README.markdown index 11665a79..a5d35c81 100644 --- a/README.markdown +++ b/README.markdown @@ -87,6 +87,7 @@ Changelog * Documentation fix - ORM query output for `where_any_is()` [[uovidiu](https://github.com/uovidiu)] - [issue #306](https://github.com/j4mie/idiorm/issues/306) * Code style fix preventing nested loops from using the same variable names [[mkkeck](https://github.com/mkkeck)] - [issue #301](https://github.com/j4mie/idiorm/issues/301) * Document shortcomings of the built in query logger [[Treffynnon](https://github.com/treffynnon)] - [issue #307](https://github.com/j4mie/idiorm/issues/307) +* Add phpunit to dev dependencies, add `composer test` script shortcut and fix PDO mock in test bootstrap [[Treffynnon](https://github.com/treffynnon)] #### 1.5.1 - released 2014-06-23 diff --git a/composer.json b/composer.json index 23088737..22009a92 100644 --- a/composer.json +++ b/composer.json @@ -28,6 +28,12 @@ "role": "Maintainer" } ], + "scripts": { + "test": "vendor/bin/phpunit" + }, + "require-dev": { + "phpunit/phpunit": "^5.6" + }, "license": [ "BSD-2-Clause", "BSD-3-Clause", diff --git a/test/bootstrap.php b/test/bootstrap.php index 02d97252..7fa1c48b 100644 --- a/test/bootstrap.php +++ b/test/bootstrap.php @@ -46,14 +46,14 @@ public function execute($params = NULL) { /** * Add data to arrays */ - public function bindParam($key, $value, $type) + public function bindParam($paramno, &$param, $type = NULL, $maxlen = NULL, $driverdata = NULL) { // Do check on type if (!is_int($type) || ($type != PDO::PARAM_STR && $type != PDO::PARAM_NULL && $type != PDO::PARAM_BOOL && $type != PDO::PARAM_INT)) throw new Exception('Incorrect parameter type. Expected $type to be an integer.'); // Add param to array - $this->bindParams[is_int($key) ? --$key : $key] = $value; + $this->bindParams[is_int($paramno) ? --$paramno : $paramno] = $param; } /** From d2f845b3195818b678dfefbeebfd44f352289c84 Mon Sep 17 00:00:00 2001 From: Simon Holywell Date: Wed, 14 Dec 2016 16:02:45 +1000 Subject: [PATCH 15/19] Looks like travis-ci dropped support for php5.2 --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 48e22545..3557c023 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,8 @@ language: php php: - - 5.2 - 5.3 - 5.4 + - 5.6 + - 7.0 - hhvm script: "phpunit --colors --coverage-text" From 2c0758bf1212f18bec74cbe7b2dd8ef9feed7b80 Mon Sep 17 00:00:00 2001 From: Simon Holywell Date: Wed, 14 Dec 2016 16:08:48 +1000 Subject: [PATCH 16/19] Add composer stuff to gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 29263bc2..ac0f57b1 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ *.sqlite docs/_build /phpunit.phar +/vendor +/composer.lock From fc234a6c1177b879ac064d4421136945f561dc1a Mon Sep 17 00:00:00 2001 From: Simon Holywell Date: Wed, 14 Dec 2016 16:13:47 +1000 Subject: [PATCH 17/19] #236 add test proving multiple raw wheres work --- test/QueryBuilderTest.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/QueryBuilderTest.php b/test/QueryBuilderTest.php index 54320d00..bbd5831f 100644 --- a/test/QueryBuilderTest.php +++ b/test/QueryBuilderTest.php @@ -292,6 +292,12 @@ public function testRawWhereClauseInMethodChain() { $this->assertEquals($expected, ORM::get_last_query()); } + public function testRawWhereClauseMultiples() { + ORM::for_table('widget')->where('age', 18)->where_raw('(`name` = ? OR `name` = ?)', array('Fred', 'Bob'))->where_raw('(`name` = ? OR `name` = ?)', array('Sarah', 'Jane'))->where('size', 'large')->find_many(); + $expected = "SELECT * FROM `widget` WHERE `age` = '18' AND (`name` = 'Fred' OR `name` = 'Bob') AND (`name` = 'Sarah' OR `name` = 'Jane') AND `size` = 'large'"; + $this->assertEquals($expected, ORM::get_last_query()); + } + public function testRawQuery() { ORM::for_table('widget')->raw_query('SELECT `w`.* FROM `widget` w')->find_many(); $expected = "SELECT `w`.* FROM `widget` w"; From bdce17e208eb8ca9b1077922fcd6348e7ed57f43 Mon Sep 17 00:00:00 2001 From: Simon Holywell Date: Wed, 14 Dec 2016 16:21:11 +1000 Subject: [PATCH 18/19] Document changes in log --- README.markdown | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.markdown b/README.markdown index a5d35c81..17c4eaa5 100644 --- a/README.markdown +++ b/README.markdown @@ -88,6 +88,8 @@ Changelog * Code style fix preventing nested loops from using the same variable names [[mkkeck](https://github.com/mkkeck)] - [issue #301](https://github.com/j4mie/idiorm/issues/301) * Document shortcomings of the built in query logger [[Treffynnon](https://github.com/treffynnon)] - [issue #307](https://github.com/j4mie/idiorm/issues/307) * Add phpunit to dev dependencies, add `composer test` script shortcut and fix PDO mock in test bootstrap [[Treffynnon](https://github.com/treffynnon)] +* New test for multiple raw where clauses [[Treffynnon](https://github.com/treffynnon)] - [issue #236](https://github.com/j4mie/idiorm/issues/236) +* Remove PHP 5.2 from travis-ci containers to test against (**note** Idiorm still supports PHP 5.2 despite this) [[Treffynnon](https://github.com/treffynnon)] #### 1.5.1 - released 2014-06-23 From b479cad74142624f05429476a4f902d6498d3b50 Mon Sep 17 00:00:00 2001 From: Simon Holywell Date: Wed, 14 Dec 2016 16:23:22 +1000 Subject: [PATCH 19/19] Set a release date --- README.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.markdown b/README.markdown index 17c4eaa5..4f06f95b 100644 --- a/README.markdown +++ b/README.markdown @@ -75,7 +75,7 @@ foreach ($tweets as $tweet) { Changelog --------- -#### 1.5.2 - released 2016-XX-XX +#### 1.5.2 - released 2016-12-14 * Fix autoincremented compound keys inserts [[lrlopez](https://github.com/lrlopez)] - [issue #233](https://github.com/j4mie/idiorm/issues/233) and [pull #235](https://github.com/j4mie/idiorm/pull/235) * Add @method tags for magic methods [[stellis](https://github.com/stellis)] - [issue #237](https://github.com/j4mie/idiorm/issues/237)