Skip to content

Commit 245cc86

Browse files
committed
Merge branch 3.3/release/3.3.3 into 3.3/master
2 parents 3d7a7cd + c352da3 commit 245cc86

File tree

16 files changed

+112
-19
lines changed

16 files changed

+112
-19
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
composer.lock
2+
vendor/*
3+
koharness_bootstrap.php
4+

.travis.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
language: php
2+
3+
php:
4+
- 5.3
5+
- 5.4
6+
- 5.5
7+
- 5.6
8+
- hhvm
9+
10+
before_script:
11+
- composer install --prefer-dist
12+
- vendor/bin/koharness
13+
14+
script:
15+
- cd /tmp/koharness && ./vendor/bin/phpunit --bootstrap=modules/unittest/bootstrap.php modules/unittest/tests.php
16+
17+
notifications:
18+
email: false

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Kohana - database access module
2+
3+
| ver | Stable | Develop |
4+
|-------|--------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------|
5+
| 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) |
6+
| 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) |

classes/Kohana/Config/Database.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* @copyright (c) 2012 Kohana Team
1010
* @license http://kohanaframework.org/license
1111
*/
12-
class Kohana_Config_Database extends Kohana_Config_Database_Writer
12+
class Kohana_Config_Database extends Config_Database_Writer
1313
{
1414

1515
}

classes/Kohana/Config/Database/Writer.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@
33
/**
44
* Database writer for the config system
55
*
6+
* Schema for configuration table:
7+
*
8+
* CREATE TABLE IF NOT EXISTS `config` (
9+
* `group_name` varchar(128) NOT NULL,
10+
* `config_key` varchar(128) NOT NULL,
11+
* `config_value` text,
12+
* PRIMARY KEY (`group_name`,`config_key`)
13+
* ) ENGINE=InnoDB;
14+
*
615
* @package Kohana
716
* @category Configuration
817
* @author Kohana Team

classes/Kohana/Database/MySQL/Result.php

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,42 @@ public function current()
5151
// Increment internal row for optimization assuming rows are fetched in order
5252
$this->_internal_row++;
5353

54+
// FIXME mysql_fetch_object has been deprecated as of php 5.5!
55+
// Please use mysqli_fetch_object or PDOStatement::fetch(PDO::FETCH_OBJ) instead.
56+
5457
if ($this->_as_object === TRUE)
5558
{
5659
// Return an stdClass
5760
return mysql_fetch_object($this->_result);
5861
}
5962
elseif (is_string($this->_as_object))
6063
{
61-
// Return an object of given class name
62-
return mysql_fetch_object($this->_result, $this->_as_object, $this->_object_params);
64+
/* The second and third argument for mysql_fetch_object are optional, but do
65+
* not have default values defined. Passing _object_params with a non-array value results
66+
* in undefined behavior that varies by PHP version. For example, if NULL is supplied on
67+
* PHP 5.3, the resulting behavior is identical to calling with array(), which results in the
68+
* classes __construct function being called with no arguments. This is only an issue when
69+
* the _as_object class does not have an explicit __construct method resulting in the
70+
* cryptic error "Class %s does not have a constructor hence you cannot use ctor_params."
71+
* In contrast, the same function call on PHP 5.5 will 'functionally' interpret
72+
* _object_params == NULL as an omission of the third argument, resulting in the original
73+
* intended functionally.
74+
*
75+
* Because the backing code for the mysql_fetch_object has not changed between 5.3 and 5.5,
76+
* I suspect this discrepancy is due to the way the classes are instantiated on a boarder
77+
* level. Additionally, mysql_fetch_object has been deprecated in 5.5 and should probably be
78+
* replaced by mysqli_fetch_object or PDOStatement::fetch(PDO::FETCH_OBJ) in Kohana 3.4.
79+
*/
80+
if ($this->_object_params !== NULL)
81+
{
82+
// Return an object of given class name with constructor params
83+
return mysql_fetch_object($this->_result, $this->_as_object, $this->_object_params);
84+
}
85+
else
86+
{
87+
// Return an object of given class name without constructor params
88+
return mysql_fetch_object($this->_result, $this->_as_object);
89+
}
6390
}
6491
else
6592
{

classes/Kohana/Database/PDO.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ public function connect()
6060
array(':error' => $e->getMessage()),
6161
$e->getCode());
6262
}
63+
64+
if ( ! empty($this->_config['charset']))
65+
{
66+
// Set the character set
67+
$this->set_charset($this->_config['charset']);
68+
}
6369
}
6470

6571
/**

classes/Kohana/Database/Query/Builder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ protected function _compile_conditions(Database $db, array $conditions)
8080
// Convert "val = NULL" to "val IS NULL"
8181
$op = 'IS';
8282
}
83-
elseif ($op === '!=')
83+
elseif ($op === '!=' OR $op === '<>')
8484
{
8585
// Convert "val != NULL" to "valu IS NOT NULL"
8686
$op = 'IS NOT';

classes/Kohana/Database/Query/Builder/Insert.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function __construct($table = NULL, array $columns = NULL)
3131
if ($table)
3232
{
3333
// Set the inital table name
34-
$this->_table = $table;
34+
$this->table($table);
3535
}
3636

3737
if ($columns)
@@ -47,11 +47,14 @@ public function __construct($table = NULL, array $columns = NULL)
4747
/**
4848
* Sets the table to insert into.
4949
*
50-
* @param mixed $table table name or array($table, $alias) or object
50+
* @param string $table table name
5151
* @return $this
5252
*/
5353
public function table($table)
5454
{
55+
if ( ! is_string($table))
56+
throw new Kohana_Exception('INSERT INTO syntax does not allow table aliasing');
57+
5558
$this->_table = $table;
5659

5760
return $this;

classes/Kohana/Database/Query/Builder/Select.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ public function union($select, $all = TRUE)
309309
*/
310310
public function offset($number)
311311
{
312-
$this->_offset = $number;
312+
$this->_offset = ($number === NULL) ? NULL : (int) $number;
313313

314314
return $this;
315315
}
@@ -404,13 +404,14 @@ public function compile($db = NULL)
404404

405405
if ( ! empty($this->_union))
406406
{
407+
$query = '('.$query.')';
407408
foreach ($this->_union as $u) {
408409
$query .= ' UNION ';
409410
if ($u['all'] === TRUE)
410411
{
411412
$query .= 'ALL ';
412413
}
413-
$query .= $u['select']->compile($db);
414+
$query .= '('.$u['select']->compile($db).')';
414415
}
415416
}
416417

classes/Kohana/Database/Query/Builder/Where.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public function order_by($column, $direction = NULL)
172172
*/
173173
public function limit($number)
174174
{
175-
$this->_limit = $number;
175+
$this->_limit = ($number === NULL) ? NULL : (int) $number;
176176

177177
return $this;
178178
}

composer.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,13 @@
2222
"require": {
2323
"composer/installers": "~1.0",
2424
"kohana/core": ">=3.3",
25-
"php": ">=5.3.3"
25+
"php": ">=5.3.6"
2626
},
27+
"require-dev": {
28+
"kohana/core": "3.3.*@dev",
29+
"kohana/unittest": "3.3.*@dev",
30+
"kohana/koharness": "*@dev"
31+
},
2732
"suggest": {
2833
"ext-mysql": "*",
2934
"ext-pdo": "*"
@@ -32,6 +37,9 @@
3237
"branch-alias": {
3338
"dev-3.3/develop": "3.3.x-dev",
3439
"dev-3.4/develop": "3.4.x-dev"
35-
}
40+
},
41+
"installer-paths": {
42+
"vendor/{$vendor}/{$name}": ["type:kohana-module"]
43+
}
3644
}
3745
}

guide/database/config.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@ The database configuration file contains an array of configuration groups. The s
1010
'table_prefix' => string TABLE_PREFIX,
1111
'charset' => string CHARACTER_SET,
1212
),
13+
1314

1415
Understanding each of these settings is important.
1516

1617
INSTANCE_NAME
1718
: Connections can be named anything you want, but you should always have at least one connection called "default".
1819

1920
DATABASE_TYPE
20-
: One of the installed database drivers. Kohana comes with "mysql" and "pdo" drivers. Drivers must extend the Database class.
21+
: One of the installed database drivers. Kohana comes with "MySQL" and "PDO" drivers. Drivers must extend the Database class. This parameter is case sensitive.
2122

2223
CONNECTION_ARRAY
2324
: Specific driver options for connecting to your database. (Driver options are explained [below](#connection-settings).)
@@ -49,7 +50,7 @@ The example file below shows 2 MySQL connections, one local and one remote.
4950
(
5051
'default' => array
5152
(
52-
'type' => 'mysql',
53+
'type' => 'MySQL',
5354
'connection' => array(
5455
'hostname' => 'localhost',
5556
'username' => 'dbuser',
@@ -61,7 +62,7 @@ The example file below shows 2 MySQL connections, one local and one remote.
6162
'charset' => 'utf8',
6263
),
6364
'remote' => array(
64-
'type' => 'mysql',
65+
'type' => 'MySQL',
6566
'connection' => array(
6667
'hostname' => '55.55.55.55',
6768
'username' => 'remote_user',
@@ -74,6 +75,8 @@ The example file below shows 2 MySQL connections, one local and one remote.
7475
),
7576
);
7677

78+
[!!] Note that the 'type' parameter is case sensitive (eg 'MySQL', 'PDO').
79+
7780
## Connections and Instances
7881

7982
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.
@@ -128,4 +131,4 @@ Type | Option | Description | Default value
128131

129132
The connection character set should be configured using the DSN string or `options` array.
130133

131-
[!!] If you are using PDO and are not sure what to use for the `dsn` option, review [PDO::__construct](http://php.net/pdo.construct).
134+
[!!] If you are using PDO and are not sure what to use for the `dsn` option, review [PDO::__construct](http://php.net/pdo.construct).

guide/database/examples.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ In this example, we loop through an array of whitelisted input fields and for ea
2525

2626
//copy the query & execute it
2727
$pagination_query = clone $query;
28-
$count = $pagination_query->select(DB::expr('COUNT(*)) AS mycount')->execute()->get('mycount');
28+
$count = $pagination_query->select(DB::expr('COUNT(*) AS mycount'))->execute()->get('mycount');
2929

3030
//pass the total item count to Pagination
3131
$config = Kohana::$config->load('pagination');
@@ -49,4 +49,4 @@ In this example, we loop through an array of whitelisted input fields and for ea
4949

5050
TODO: example goes here
5151

52-
[!!] We could use more examples on this page.
52+
[!!] We could use more examples on this page.

guide/database/query/builder.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ This query would generate the following SQL:
7676

7777
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.
7878

79-
$query = DB::select()->from(`posts`)->order_by(`published`, `DESC`);
79+
$query = DB::select()->from('posts')->order_by('published', 'DESC');
8080

8181
This query would generate the following SQL:
8282

@@ -248,4 +248,4 @@ Once you are done building, you can execute the query using `execute()` and use
248248

249249
To use a different database [config group](config) pass either the name or the config object to `execute()`.
250250

251-
$result = $query->execute('config_name')
251+
$result = $query->execute('config_name')

koharness.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
// Configuration for koharness - builds a standalone skeleton Kohana app for running unit tests
3+
return array(
4+
'modules' => array(
5+
'database' => __DIR__,
6+
'unittest' => __DIR__ . '/vendor/kohana/unittest'
7+
),
8+
);

0 commit comments

Comments
 (0)