From 088002da2c31ee47c35276c315725d920e062c6c Mon Sep 17 00:00:00 2001 From: vintuwei Date: Thu, 19 Jul 2012 12:39:33 +0300 Subject: [PATCH 01/17] Updated guide to use case sensitive 'type' parameter. --- guide/database/config.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/guide/database/config.md b/guide/database/config.md index 240a6bb..9a65777 100644 --- a/guide/database/config.md +++ b/guide/database/config.md @@ -10,6 +10,7 @@ The database configuration file contains an array of configuration groups. The s 'table_prefix' => string TABLE_PREFIX, 'charset' => string CHARACTER_SET, ), + Understanding each of these settings is important. @@ -17,7 +18,7 @@ INSTANCE_NAME : Connections can be named anything you want, but you should always have at least one connection called "default". DATABASE_TYPE -: One of the installed database drivers. Kohana comes with "mysql" and "pdo" drivers. Drivers must extend the Database class. +: One of the installed database drivers. Kohana comes with "MySQL" and "pdo" drivers. Drivers must extend the Database class. CONNECTION_ARRAY : Specific driver options for connecting to your database. (Driver options are explained [below](#connection-settings).) @@ -34,7 +35,7 @@ The example file below shows 2 MySQL connections, one local and one remote. ( 'default' => array ( - 'type' => 'mysql', + 'type' => 'MySQL', 'connection' => array( 'hostname' => 'localhost', 'username' => 'dbuser', @@ -46,7 +47,7 @@ The example file below shows 2 MySQL connections, one local and one remote. 'charset' => 'utf8', ), 'remote' => array( - 'type' => 'mysql', + 'type' => 'MySQL', 'connection' => array( 'hostname' => '55.55.55.55', 'username' => 'remote_user', @@ -59,6 +60,8 @@ The example file below shows 2 MySQL connections, one local and one remote. ), ); +Note that the 'type' parameter is case sensitive (eg 'MySQL', 'PDO'). + ## Connections and Instances Each configuration group is referred to as a database instance. Each instance can be accessed by calling [Database::instance]. If you don't provide a parameter, the default instance is used. From 4dbacbd1658bd1559d828db46fcb0bf494be7702 Mon Sep 17 00:00:00 2001 From: "Chris M. Welsh" Date: Tue, 12 Feb 2013 11:53:08 -0700 Subject: [PATCH 02/17] Fix typo in order_by() syntax in documentation It was using backticks instead of single quotes. --- guide/database/query/builder.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/guide/database/query/builder.md b/guide/database/query/builder.md index d2fd893..2b03b19 100644 --- a/guide/database/query/builder.md +++ b/guide/database/query/builder.md @@ -76,7 +76,7 @@ This query would generate the following SQL: Often you will want the results in a particular order and rather than sorting the results, it's better to have the results returned to you in the correct order. You can do this by using the order_by() method. It takes the column name and an optional direction string as the parameters. Multiple `order_by()` methods can be used to add additional sorting capability. - $query = DB::select()->from(`posts`)->order_by(`published`, `DESC`); + $query = DB::select()->from('posts')->order_by('published', 'DESC'); This query would generate the following SQL: @@ -248,4 +248,4 @@ Once you are done building, you can execute the query using `execute()` and use To use a different database [config group](config) pass either the name or the config object to `execute()`. - $result = $query->execute('config_name') \ No newline at end of file + $result = $query->execute('config_name') From f01ed633a7ff9d2c4e651c3d5e0abea2fe3f0882 Mon Sep 17 00:00:00 2001 From: Jason Zdan Date: Tue, 30 Jul 2013 16:37:51 -0600 Subject: [PATCH 03/17] Sanitize input to offset() and limit() --- classes/Kohana/Database/Query/Builder/Select.php | 2 +- classes/Kohana/Database/Query/Builder/Where.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/classes/Kohana/Database/Query/Builder/Select.php b/classes/Kohana/Database/Query/Builder/Select.php index 3492a71..8bcb79f 100644 --- a/classes/Kohana/Database/Query/Builder/Select.php +++ b/classes/Kohana/Database/Query/Builder/Select.php @@ -309,7 +309,7 @@ public function union($select, $all = TRUE) */ public function offset($number) { - $this->_offset = $number; + $this->_offset = $number === null ? null : (int) $number; return $this; } diff --git a/classes/Kohana/Database/Query/Builder/Where.php b/classes/Kohana/Database/Query/Builder/Where.php index 58f6b5d..0cbe57d 100644 --- a/classes/Kohana/Database/Query/Builder/Where.php +++ b/classes/Kohana/Database/Query/Builder/Where.php @@ -172,7 +172,7 @@ public function order_by($column, $direction = NULL) */ public function limit($number) { - $this->_limit = $number; + $this->_limit = $number === null ? null : (int) $number; return $this; } From 6465093bacc386b40356abf61a78e34fa390d7d5 Mon Sep 17 00:00:00 2001 From: Jason Zdan Date: Wed, 31 Jul 2013 10:37:44 -0600 Subject: [PATCH 04/17] Coding standards fixes --- classes/Kohana/Database/Query/Builder/Select.php | 2 +- classes/Kohana/Database/Query/Builder/Where.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/classes/Kohana/Database/Query/Builder/Select.php b/classes/Kohana/Database/Query/Builder/Select.php index 8bcb79f..0884865 100644 --- a/classes/Kohana/Database/Query/Builder/Select.php +++ b/classes/Kohana/Database/Query/Builder/Select.php @@ -309,7 +309,7 @@ public function union($select, $all = TRUE) */ public function offset($number) { - $this->_offset = $number === null ? null : (int) $number; + $this->_offset = ($number === NULL) ? NULL : (int) $number; return $this; } diff --git a/classes/Kohana/Database/Query/Builder/Where.php b/classes/Kohana/Database/Query/Builder/Where.php index 0cbe57d..a6589e4 100644 --- a/classes/Kohana/Database/Query/Builder/Where.php +++ b/classes/Kohana/Database/Query/Builder/Where.php @@ -172,7 +172,7 @@ public function order_by($column, $direction = NULL) */ public function limit($number) { - $this->_limit = $number === null ? null : (int) $number; + $this->_limit = ($number === NULL) ? NULL : (int) $number; return $this; } From 508f8aafddf811b8c6ff924dc76e648f7ae6a618 Mon Sep 17 00:00:00 2001 From: misterx Date: Mon, 23 Sep 2013 12:02:02 +0300 Subject: [PATCH 05/17] Incorrect usage of UNION and ORDER BY without parenthesis When use ORDER BY with UNION, give error Incorrect usage of UNION and ORDER BY. http://stackoverflow.com/a/6732697 --- classes/Kohana/Database/Query/Builder/Select.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/classes/Kohana/Database/Query/Builder/Select.php b/classes/Kohana/Database/Query/Builder/Select.php index 3492a71..e36a3be 100644 --- a/classes/Kohana/Database/Query/Builder/Select.php +++ b/classes/Kohana/Database/Query/Builder/Select.php @@ -404,13 +404,14 @@ public function compile($db = NULL) if ( ! empty($this->_union)) { + $query = '('.$query.')'; foreach ($this->_union as $u) { $query .= ' UNION '; if ($u['all'] === TRUE) { $query .= 'ALL '; } - $query .= $u['select']->compile($db); + $query .= '('.$u['select']->compile($db).')'; } } From be193d14a87e53acbe0fa69600a118a0970d0c1e Mon Sep 17 00:00:00 2001 From: biakaveron Date: Sun, 12 Jan 2014 00:07:19 +0400 Subject: [PATCH 06/17] handle both <> NULL and != NULL as IS NOT NULL --- classes/kohana/database/query/builder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/kohana/database/query/builder.php b/classes/kohana/database/query/builder.php index 3e1bdb5..c0915dc 100644 --- a/classes/kohana/database/query/builder.php +++ b/classes/kohana/database/query/builder.php @@ -80,7 +80,7 @@ protected function _compile_conditions(Database $db, array $conditions) // Convert "val = NULL" to "val IS NULL" $op = 'IS'; } - elseif ($op === '!=') + elseif ($op === '!=' OR $op === '<>') { // Convert "val != NULL" to "valu IS NOT NULL" $op = 'IS NOT'; From f5d6ee728fcfe03510f106978544939c9e68ff4f Mon Sep 17 00:00:00 2001 From: Liu Jie Date: Mon, 13 Jan 2014 11:47:12 +0800 Subject: [PATCH 07/17] PDO driver should call set_charset in connect method PDO driver should call set_charset in connect method. --- classes/Kohana/Database/PDO.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/classes/Kohana/Database/PDO.php b/classes/Kohana/Database/PDO.php index 573f8d3..ba6de22 100644 --- a/classes/Kohana/Database/PDO.php +++ b/classes/Kohana/Database/PDO.php @@ -60,6 +60,12 @@ public function connect() array(':error' => $e->getMessage()), $e->getCode()); } + + if ( ! empty($this->_config['charset'])) + { + // Set the character set + $this->set_charset($this->_config['charset']); + } } /** From b0f53afb36903a0fc9847f375bce057f96737410 Mon Sep 17 00:00:00 2001 From: Woody Gilk Date: Tue, 29 Apr 2014 10:17:13 -0500 Subject: [PATCH 08/17] Bump required PHP to 5.3.6 in composer.json Because of character setting for PDO, see #66. --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 33b1962..742bde7 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ "require": { "composer/installers": "~1.0", "kohana/core": ">=3.3", - "php": ">=5.3.3" + "php": ">=5.3.6" }, "suggest": { "ext-mysql": "*", From d3fdb88246ce8670d192fbeffee70e9908915617 Mon Sep 17 00:00:00 2001 From: Woody Gilk Date: Tue, 29 Apr 2014 10:31:42 -0500 Subject: [PATCH 09/17] Add schema to Database_Writer, fixes #61 --- classes/Kohana/Config/Database/Writer.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/classes/Kohana/Config/Database/Writer.php b/classes/Kohana/Config/Database/Writer.php index f6b6738..3b77851 100644 --- a/classes/Kohana/Config/Database/Writer.php +++ b/classes/Kohana/Config/Database/Writer.php @@ -3,6 +3,15 @@ /** * Database writer for the config system * + * Schema for configuration table: + * + * CREATE TABLE IF NOT EXISTS `config` ( + * `group_name` varchar(128) NOT NULL, + * `config_key` varchar(128) NOT NULL, + * `config_value` text, + * PRIMARY KEY (`group_name`,`config_key`) + * ) ENGINE=InnoDB; + * * @package Kohana * @category Configuration * @author Kohana Team From 2d0fd7502828582ea0636d687fb754134e6e74fc Mon Sep 17 00:00:00 2001 From: Alexander Barker Date: Sat, 7 Jun 2014 09:38:42 -0700 Subject: [PATCH 10/17] Passing NULL to argument 3 of mysql_fetch_object has undefined behavior. --- classes/Kohana/Database/MySQL/Result.php | 31 ++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/classes/Kohana/Database/MySQL/Result.php b/classes/Kohana/Database/MySQL/Result.php index 22a5d14..8c84765 100644 --- a/classes/Kohana/Database/MySQL/Result.php +++ b/classes/Kohana/Database/MySQL/Result.php @@ -51,6 +51,9 @@ public function current() // Increment internal row for optimization assuming rows are fetched in order $this->_internal_row++; + // FIXME mysql_fetch_object has been deprecated as of php 5.5! + // Please use mysqli_fetch_object or PDOStatement::fetch(PDO::FETCH_OBJ) instead. + if ($this->_as_object === TRUE) { // Return an stdClass @@ -58,8 +61,32 @@ public function current() } elseif (is_string($this->_as_object)) { - // Return an object of given class name - return mysql_fetch_object($this->_result, $this->_as_object, $this->_object_params); + /* The second and third argument for mysql_fetch_object are optional, but do + * not have default values defined. Passing _object_params with a non-array value results + * in undefined behavior that varies by PHP version. For example, if NULL is supplied on + * PHP 5.3, the resulting behavior is identical to calling with array(), which results in the + * classes __construct function being called with no arguments. This is only an issue when + * the _as_object class does not have an explicit __construct method resulting in the + * cryptic error "Class %s does not have a constructor hence you cannot use ctor_params." + * In contrast, the same function call on PHP 5.5 will 'functionally' interpret + * _object_params == NULL as an omission of the third argument, resulting in the original + * intended functionally. + * + * Because the backing code for the mysql_fetch_object has not changed between 5.3 and 5.5, + * I suspect this discrepancy is due to the way the classes are instantiated on a boarder + * level. Additionally, mysql_fetch_object has been deprecated in 5.5 and should probably be + * replaced by mysqli_fetch_object or PDOStatement::fetch(PDO::FETCH_OBJ) in Kohana 3.4. + */ + if ($this->_object_params !== NULL) + { + // Return an object of given class name with constructor params + return mysql_fetch_object($this->_result, $this->_as_object, $this->_object_params); + } + else + { + // Return an object of given class name without constructor params + return mysql_fetch_object($this->_result, $this->_as_object); + } } else { From 3664639dbf8f83aff24fd433feb1558592e21c7d Mon Sep 17 00:00:00 2001 From: Andrew Coulton Date: Wed, 17 Sep 2014 17:38:25 +0100 Subject: [PATCH 11/17] Configure standalone travis build Adds and configures kohana/koharness to build a skeleton Kohana application and then uses that environment to run the unit tests on travis (and locally, if required). Continues kohana/kohana#50 --- .gitignore | 4 ++++ .travis.yml | 24 ++++++++++++++++++++++++ composer.json | 10 +++++++++- koharness.php | 8 ++++++++ 4 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 100644 .travis.yml create mode 100644 koharness.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c359b56 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +composer.lock +vendor/* +koharness_bootstrap.php + diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..8f9e0fc --- /dev/null +++ b/.travis.yml @@ -0,0 +1,24 @@ +language: php + +php: + - 5.3 + - 5.4 + - 5.5 + - 5.6 + - hhvm + +before_script: + - composer install --prefer-dist + - vendor/bin/koharness + +script: + - cd /tmp/koharness && ./vendor/bin/phpunit --bootstrap=modules/unittest/bootstrap.php modules/unittest/tests.php + +notifications: + irc: + channels: + - "irc.freenode.org#kohana" + template: + - "%{repository}/%{branch} (%{commit}) - %{author}: %{message}" + - "Build details: %{build_url}" + email: false diff --git a/composer.json b/composer.json index 742bde7..8a3ddd2 100644 --- a/composer.json +++ b/composer.json @@ -24,6 +24,11 @@ "kohana/core": ">=3.3", "php": ">=5.3.6" }, + "require-dev": { + "kohana/core": "3.3.*@dev", + "kohana/unittest": "3.3.*@dev", + "kohana/koharness": "*@dev" + }, "suggest": { "ext-mysql": "*", "ext-pdo": "*" @@ -32,6 +37,9 @@ "branch-alias": { "dev-3.3/develop": "3.3.x-dev", "dev-3.4/develop": "3.4.x-dev" - } + }, + "installer-paths": { + "vendor/{$vendor}/{$name}": ["type:kohana-module"] + } } } diff --git a/koharness.php b/koharness.php new file mode 100644 index 0000000..fd2366d --- /dev/null +++ b/koharness.php @@ -0,0 +1,8 @@ + array( + 'database' => __DIR__, + 'unittest' => __DIR__ . '/vendor/kohana/unittest' + ), +); From 43f1fdcde0ead6c6338d1553c2423e33fae28903 Mon Sep 17 00:00:00 2001 From: Andrew Coulton Date: Mon, 22 Sep 2014 17:58:51 +0100 Subject: [PATCH 12/17] Disable IRC notifications for kohana builds --- .travis.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8f9e0fc..1313e37 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,10 +15,4 @@ script: - cd /tmp/koharness && ./vendor/bin/phpunit --bootstrap=modules/unittest/bootstrap.php modules/unittest/tests.php notifications: - irc: - channels: - - "irc.freenode.org#kohana" - template: - - "%{repository}/%{branch} (%{commit}) - %{author}: %{message}" - - "Build details: %{build_url}" email: false From 1eaa5851f7e4959bd81cd8dfc311de6112555d5a Mon Sep 17 00:00:00 2001 From: Samuel Demirdjian Date: Wed, 1 Oct 2014 17:21:42 +0300 Subject: [PATCH 13/17] the type parameter is case-sensitive --- guide/database/config.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/guide/database/config.md b/guide/database/config.md index 9a67236..0d9ecf9 100644 --- a/guide/database/config.md +++ b/guide/database/config.md @@ -18,7 +18,7 @@ INSTANCE_NAME : Connections can be named anything you want, but you should always have at least one connection called "default". DATABASE_TYPE -: One of the installed database drivers. Kohana comes with "MySQL" and "pdo" drivers. Drivers must extend the Database class. +: One of the installed database drivers. Kohana comes with "MySQL" and "PDO" drivers. Drivers must extend the Database class. This parameter is case sensitive. CONNECTION_ARRAY : Specific driver options for connecting to your database. (Driver options are explained [below](#connection-settings).) @@ -75,7 +75,7 @@ The example file below shows 2 MySQL connections, one local and one remote. ), ); -Note that the 'type' parameter is case sensitive (eg 'MySQL', 'PDO'). +[!!] Note that the 'type' parameter is case sensitive (eg 'MySQL', 'PDO'). ## Connections and Instances @@ -131,4 +131,4 @@ Type | Option | Description | Default value The connection character set should be configured using the DSN string or `options` array. -[!!] If you are using PDO and are not sure what to use for the `dsn` option, review [PDO::__construct](http://php.net/pdo.construct). \ No newline at end of file +[!!] If you are using PDO and are not sure what to use for the `dsn` option, review [PDO::__construct](http://php.net/pdo.construct). From 84ddadbc37f8aed80618c4019736ebf764795b12 Mon Sep 17 00:00:00 2001 From: Andrew Coulton Date: Fri, 10 Oct 2014 15:38:27 +0100 Subject: [PATCH 14/17] Add travis build badges [skip ci] --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..6a40ee8 --- /dev/null +++ b/README.md @@ -0,0 +1,6 @@ +# Kohana - database access module + +| ver | Stable | Develop | +|-------|--------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------| +| 3.3.x | [![Build Status - 3.3/master](https://travis-ci.org/kohana/database.svg?branch=3.3%2Fmaster)](https://travis-ci.org/kohana/database) | [![Build Status - 3.3/develop](https://travis-ci.org/kohana/database.svg?branch=3.3%2Fdevelop)](https://travis-ci.org/kohana/database) | +| 3.4.x | [![Build Status - 3.4/master](https://travis-ci.org/kohana/database.svg?branch=3.4%2Fmaster)](https://travis-ci.org/kohana/database) | [![Build Status - 3.4/develop](https://travis-ci.org/kohana/database.svg?branch=3.4%2Fdevelop)](https://travis-ci.org/kohana/database) | From f86aff3f49bd5152cf2bba460f9496add168941c Mon Sep 17 00:00:00 2001 From: Erik Aybar Date: Mon, 27 Oct 2014 15:11:37 -0600 Subject: [PATCH 15/17] Fixes misplaced ")" within Database example --- guide/database/examples.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/guide/database/examples.md b/guide/database/examples.md index 6a9d1b5..ff14ec5 100644 --- a/guide/database/examples.md +++ b/guide/database/examples.md @@ -25,7 +25,7 @@ In this example, we loop through an array of whitelisted input fields and for ea //copy the query & execute it $pagination_query = clone $query; - $count = $pagination_query->select(DB::expr('COUNT(*)) AS mycount')->execute()->get('mycount'); + $count = $pagination_query->select(DB::expr('COUNT(*) AS mycount'))->execute()->get('mycount'); //pass the total item count to Pagination $config = Kohana::$config->load('pagination'); @@ -49,4 +49,4 @@ In this example, we loop through an array of whitelisted input fields and for ea TODO: example goes here -[!!] We could use more examples on this page. \ No newline at end of file +[!!] We could use more examples on this page. From 23c9db0f9716bfd910d56fe630e7fe5739838f95 Mon Sep 17 00:00:00 2001 From: Samuel Demirdjian Date: Wed, 29 Oct 2014 15:12:23 +0200 Subject: [PATCH 16/17] INSERT INTO syntax does not allow table aliasing --- classes/Kohana/Database/Query/Builder/Insert.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/classes/Kohana/Database/Query/Builder/Insert.php b/classes/Kohana/Database/Query/Builder/Insert.php index aa3c807..8d116da 100644 --- a/classes/Kohana/Database/Query/Builder/Insert.php +++ b/classes/Kohana/Database/Query/Builder/Insert.php @@ -31,7 +31,7 @@ public function __construct($table = NULL, array $columns = NULL) if ($table) { // Set the inital table name - $this->_table = $table; + $this->table($table); } if ($columns) @@ -47,11 +47,14 @@ public function __construct($table = NULL, array $columns = NULL) /** * Sets the table to insert into. * - * @param mixed $table table name or array($table, $alias) or object + * @param string $table table name * @return $this */ public function table($table) { + if ( ! is_string($table)) + throw new Kohana_Exception('INSERT INTO syntax does not allow table aliasing'); + $this->_table = $table; return $this; From 4e33d1a6ce8a43ab377ca1010d5801f3b1507869 Mon Sep 17 00:00:00 2001 From: Samuel Demirdjian Date: Thu, 6 Nov 2014 12:14:12 +0200 Subject: [PATCH 17/17] Kohana_Config_Database should extend Config_Database_Writer `Kohana_Config_Database` should extend `Config_Database_Writer` but not `Kohana_Config_Database_Writer`. This is to ensure that changes to Config_Database_Writer affect Kohana_Config_Database when transparently extending through the Kohana CFS. --- classes/Kohana/Config/Database.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/Kohana/Config/Database.php b/classes/Kohana/Config/Database.php index f03a201..e344761 100644 --- a/classes/Kohana/Config/Database.php +++ b/classes/Kohana/Config/Database.php @@ -9,7 +9,7 @@ * @copyright (c) 2012 Kohana Team * @license http://kohanaframework.org/license */ -class Kohana_Config_Database extends Kohana_Config_Database_Writer +class Kohana_Config_Database extends Config_Database_Writer { }