-
-
Notifications
You must be signed in to change notification settings - Fork 184
Fix on FetchMode getting lost between instances #183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,7 +23,7 @@ class QueryBuilderHandler | |
| protected $statements = array(); | ||
|
|
||
| /** | ||
| * @var \PDO | ||
| * @var PDO | ||
| */ | ||
| protected $pdo; | ||
|
|
||
|
|
@@ -47,14 +47,15 @@ class QueryBuilderHandler | |
| * | ||
| * @var array | ||
| */ | ||
| protected $fetchParameters = array(\PDO::FETCH_OBJ); | ||
| protected $fetchParameters = array(PDO::FETCH_OBJ); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @TCB13 and this is the same thing, as you are using |
||
|
|
||
| /** | ||
| * @param null|\Pixie\Connection $connection | ||
| * | ||
| * @throws \Pixie\Exception | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you mean this @TCB13 ? |
||
| * @param int $fetchMode | ||
| * @throws Exception | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why replace
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use is already specifying that the |
||
| */ | ||
| public function __construct(Connection $connection = null) | ||
| public function __construct(Connection $connection = null, $fetchMode = PDO::FETCH_OBJ) | ||
| { | ||
| if (is_null($connection)) { | ||
| if (!$connection = Connection::getStoredConnection()) { | ||
|
|
@@ -68,6 +69,8 @@ public function __construct(Connection $connection = null) | |
| $this->adapter = $this->connection->getAdapter(); | ||
| $this->adapterConfig = $this->connection->getAdapterConfig(); | ||
|
|
||
| $this->setFetchMode($fetchMode); | ||
|
|
||
| if (isset($this->adapterConfig['prefix'])) { | ||
| $this->tablePrefix = $this->adapterConfig['prefix']; | ||
| } | ||
|
|
@@ -102,21 +105,21 @@ public function setFetchMode($mode) | |
| */ | ||
| public function asObject($className, $constructorArgs = array()) | ||
| { | ||
| return $this->setFetchMode(\PDO::FETCH_CLASS, $className, $constructorArgs); | ||
| return $this->setFetchMode(PDO::FETCH_CLASS, $className, $constructorArgs); | ||
| } | ||
|
|
||
| /** | ||
| * @param null|\Pixie\Connection $connection | ||
| * | ||
| * @return static | ||
| * @return QueryBuilderHandler | ||
| * @throws Exception | ||
| */ | ||
| public function newQuery(Connection $connection = null) | ||
| { | ||
| if (is_null($connection)) { | ||
| $connection = $this->connection; | ||
| } | ||
|
|
||
| return new static($connection); | ||
| return new static($connection, $this->getFetchMode()); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -156,7 +159,8 @@ public function statement($sql, $bindings = array()) | |
| /** | ||
| * Get all rows | ||
| * | ||
| * @return \stdClass|null | ||
| * @return \stdClass|array | ||
| * @throws Exception | ||
| */ | ||
| public function get() | ||
| { | ||
|
|
@@ -259,17 +263,17 @@ protected function aggregate($type) | |
| } | ||
|
|
||
| if (is_array($row[0])) { | ||
| return (int) $row[0]['field']; | ||
| return (int)$row[0]['field']; | ||
| } elseif (is_object($row[0])) { | ||
| return (int) $row[0]->field; | ||
| return (int)$row[0]->field; | ||
| } | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| /** | ||
| * @param string $type | ||
| * @param array $dataToBePassed | ||
| * @param array $dataToBePassed | ||
| * | ||
| * @return mixed | ||
| * @throws Exception | ||
|
|
@@ -291,7 +295,7 @@ public function getQuery($type = 'select', $dataToBePassed = array()) | |
|
|
||
| /** | ||
| * @param QueryBuilderHandler $queryBuilder | ||
| * @param null $alias | ||
| * @param null $alias | ||
| * | ||
| * @return Raw | ||
| */ | ||
|
|
@@ -440,10 +444,10 @@ public function delete() | |
| } | ||
|
|
||
| /** | ||
| * @param $tables Single table or multiple tables as an array or as | ||
| * multiple parameters | ||
| * @param string|array $tables Single table or array of tables | ||
| * | ||
| * @return static | ||
| * @return QueryBuilderHandler | ||
| * @throws Exception | ||
| */ | ||
| public function table($tables) | ||
| { | ||
|
|
@@ -453,7 +457,7 @@ public function table($tables) | |
| $tables = func_get_args(); | ||
| } | ||
|
|
||
| $instance = new static($this->connection); | ||
| $instance = new static($this->connection, $this->getFetchMode()); | ||
| $tables = $this->addTablePrefix($tables, false); | ||
| $instance->addStatement('tables', $tables); | ||
| return $instance; | ||
|
|
@@ -791,7 +795,7 @@ public function join($table, $key, $operator = null, $value = null, $type = 'inn | |
| // Build a new JoinBuilder class, keep it by reference so any changes made | ||
| // in the closure should reflect here | ||
| $joinBuilder = $this->container->build('\\Pixie\\QueryBuilder\\JoinBuilder', array($this->connection)); | ||
| $joinBuilder = & $joinBuilder; | ||
| $joinBuilder = &$joinBuilder; | ||
| // Call the closure with our new joinBuilder object | ||
| $key($joinBuilder); | ||
| $table = $this->addTablePrefix($table, false); | ||
|
|
@@ -1012,7 +1016,7 @@ public function getEvent($event, $table = ':any') | |
|
|
||
| /** | ||
| * @param $event | ||
| * @param string $table | ||
| * @param string $table | ||
| * @param callable $action | ||
| * | ||
| * @return void | ||
|
|
@@ -1030,7 +1034,7 @@ public function registerEvent($event, $table, \Closure $action) | |
|
|
||
| /** | ||
| * @param $event | ||
| * @param string $table | ||
| * @param string $table | ||
| * | ||
| * @return void | ||
| */ | ||
|
|
@@ -1061,4 +1065,13 @@ public function getStatements() | |
| { | ||
| return $this->statements; | ||
| } | ||
|
|
||
| /** | ||
| * @return int will return PDO Fetch mode | ||
| */ | ||
| public function getFetchMode() | ||
| { | ||
| return !empty($this->fetchParameters) ? | ||
| current($this->fetchParameters) : PDO::FETCH_OBJ; | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@usmanhalalit need your view in there. This can potentially break some setups.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it will not, as
use PDO;on this file make\PDOandPDOthe same thing