From aabb47467882230b1c43780a2bdf304cc6e8d5f6 Mon Sep 17 00:00:00 2001 From: nine-rec Date: Fri, 27 May 2016 00:47:45 +0800 Subject: [PATCH 01/12] Update README.md Fix syntax error of README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 82ca0ed..1314a3b 100644 --- a/README.md +++ b/README.md @@ -159,7 +159,7 @@ new \Pixie\Connection('mysql', $config, 'MyAlias'); When not using an alias you can instantiate the QueryBuilder handler separately, helpful for Dependency Injection and Testing. ```PHP -$connection = new \Pixie\Connection('mysql', $config)); +$connection = new \Pixie\Connection('mysql', $config); $qb = new \Pixie\QueryBuilder\QueryBuilderHandler($connection); $query = $qb->table('my_table')->where('name', '=', 'Sana'); From 37d18fbc38626b3a856f36c12f764afa1b5e8287 Mon Sep 17 00:00:00 2001 From: antoiba86 Date: Thu, 27 Jul 2017 10:56:07 +0200 Subject: [PATCH 02/12] Update README.md Added $ to variable on line 492 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 82ca0ed..5d6be64 100644 --- a/README.md +++ b/README.md @@ -489,7 +489,7 @@ If you wish to manually commit or rollback your changes, you can use the `commit()` and `rollback()` methods accordingly: ```PHP -QB::transaction(function (qb) { +QB::transaction(function ($qb) { $qb->table('my_table')->insert(array(/* data... */)); $qb->commit(); // to commit the changes (data would be saved) From c82c6344b62997329efa48d2e7c51545cf050e98 Mon Sep 17 00:00:00 2001 From: Shahjahan Jewel Date: Sun, 27 Aug 2017 12:14:01 +0600 Subject: [PATCH 03/12] Update BaseAdapter.php Remove Extra parameters from concatenateQuery($sqlArray) method calling --- src/Pixie/QueryBuilder/Adapters/BaseAdapter.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Pixie/QueryBuilder/Adapters/BaseAdapter.php b/src/Pixie/QueryBuilder/Adapters/BaseAdapter.php index ade1a1b..5b1e0a4 100644 --- a/src/Pixie/QueryBuilder/Adapters/BaseAdapter.php +++ b/src/Pixie/QueryBuilder/Adapters/BaseAdapter.php @@ -164,7 +164,7 @@ private function doInsert($statements, array $data, $type) $bindings = array_merge($bindings, $updateBindings); } - $sql = $this->concatenateQuery($sqlArray, ' ', false); + $sql = $this->concatenateQuery($sqlArray); return compact('sql', 'bindings'); } @@ -272,7 +272,7 @@ public function update($statements, array $data) $limit ); - $sql = $this->concatenateQuery($sqlArray, ' ', false); + $sql = $this->concatenateQuery($sqlArray); $bindings = array_merge($bindings, $whereBindings); return compact('sql', 'bindings'); @@ -301,7 +301,7 @@ public function delete($statements) $limit = isset($statements['limit']) ? 'LIMIT ' . $statements['limit'] : ''; $sqlArray = array('DELETE FROM', $this->wrapSanitizer($table), $whereCriteria); - $sql = $this->concatenateQuery($sqlArray, ' ', false); + $sql = $this->concatenateQuery($sqlArray); $bindings = $whereBindings; return compact('sql', 'bindings'); From 6dc9ee651f77866dee8c09d69c765b32ca296683 Mon Sep 17 00:00:00 2001 From: Pablo Tejada Date: Mon, 25 Sep 2017 23:26:21 -0400 Subject: [PATCH 04/12] Corrects a typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 82ca0ed..dc0c951 100644 --- a/README.md +++ b/README.md @@ -621,7 +621,7 @@ QB::registerEvent('after-delete', 'my_table', function($queryBuilder, $queryObje Pixie passes the current instance of query builder as first parameter of your closure so you can build queries with this object, you can do anything like usual query builder (`QB`). -If something other than `null` is returned from the `before-*` query handler, the value will be result of execution and DB will not be actually queried (and thus, corresponding `after-*` handler will not be called ether). +If something other than `null` is returned from the `before-*` query handler, the value will be result of execution and DB will not be actually queried (and thus, corresponding `after-*` handler will not be called either). Only on `after-*` events you get three parameters: **first** is the query builder, **third** is the execution time as float and **the second** varies: From 220b920904b9f60a7d61eba9554d936f4fda7977 Mon Sep 17 00:00:00 2001 From: Vincenzo Ciaccio Date: Wed, 11 Apr 2018 14:58:02 +0100 Subject: [PATCH 05/12] Fix on FetchMode getting lost between instances (#183) Fix on FetchMode getting lost between instances, closes #183 #185 --- README.md | 2 +- .../QueryBuilder/QueryBuilderHandler.php | 53 ++++++++++++------- tests/Pixie/QueryBuilderBehaviorTest.php | 17 +++++- 3 files changed, 50 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 8de32d7..0028acc 100644 --- a/README.md +++ b/README.md @@ -86,7 +86,7 @@ Library on [Packagist](https://packagist.org/packages/usmanhalalit/pixie). - [Connection](#connection) - [Alias](#alias) - [Multiple Connection](#alias) - - [SQLite and PostgreSQL Config Sample](sqlite-and-postgresql-config-sample) + - [SQLite and PostgreSQL Config Sample](#sqlite-and-postgresql-config-sample) - [Query](#query) - [**Select**](#select) - [Get Easily](#get-easily) diff --git a/src/Pixie/QueryBuilder/QueryBuilderHandler.php b/src/Pixie/QueryBuilder/QueryBuilderHandler.php index 134fba0..f7fd976 100644 --- a/src/Pixie/QueryBuilder/QueryBuilderHandler.php +++ b/src/Pixie/QueryBuilder/QueryBuilderHandler.php @@ -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); /** * @param null|\Pixie\Connection $connection * - * @throws \Pixie\Exception + * @param int $fetchMode + * @throws Exception */ - 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,13 +105,13 @@ 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) { @@ -116,7 +119,7 @@ public function newQuery(Connection $connection = null) $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,9 +263,9 @@ 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; @@ -269,7 +273,7 @@ protected function aggregate($type) /** * @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; + } } diff --git a/tests/Pixie/QueryBuilderBehaviorTest.php b/tests/Pixie/QueryBuilderBehaviorTest.php index 40030d9..e1c3a88 100644 --- a/tests/Pixie/QueryBuilderBehaviorTest.php +++ b/tests/Pixie/QueryBuilderBehaviorTest.php @@ -1,6 +1,6 @@ getQuery()->getRawSql() ); } + + public function testYouCanSetFetchModeFromConstructorAsOptionalParameter() + { + $selectedFetchMode = \PDO::FETCH_ASSOC; + $builder = new QueryBuilderHandler($this->mockConnection, $selectedFetchMode); + $this->assertEquals($selectedFetchMode, $builder->getFetchMode()); + } + + public function testFetchModeSelectedWillBeMaintainedBetweenInstances(){ + $selectedFetchMode = \PDO::FETCH_ASSOC; + $builder = new QueryBuilderHandler($this->mockConnection, $selectedFetchMode); + $newBuilder = $builder->table('stuff'); + + $this->assertEquals($selectedFetchMode, $newBuilder->getFetchMode()); + } } From d35ae8f49ab1c28326e2c5c675545f1b95b1727d Mon Sep 17 00:00:00 2001 From: Muhammad Usman Date: Wed, 12 Sep 2018 13:15:26 +0600 Subject: [PATCH 06/12] Update README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 0028acc..039b9bc 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ +**This project is Not Actively Maintained but most of the features are fully working and there are no major security issues, I'm just not giving it much time.** + + # Pixie Query Builder [![Build Status](https://travis-ci.org/usmanhalalit/pixie.png?branch=master)](https://travis-ci.org/usmanhalalit/pixie) A lightweight, expressive, framework agnostic query builder for PHP it can also be referred as a Database Abstraction Layer. Pixie supports MySQL, SQLite and PostgreSQL and it takes care of query sanitization, table prefixing and many other things with a unified API. At least PHP 5.3 is required. From 9bd991021abbcbfb19347a07dca8b7e518b8abc9 Mon Sep 17 00:00:00 2001 From: Muhammad Usman Date: Sat, 16 Nov 2019 12:20:50 +0000 Subject: [PATCH 07/12] Security fix for SQL Injection vulnerability Thanks to https://snyk.io/ for finding the bug. --- README.md | 10 +++++----- src/Pixie/QueryBuilder/Adapters/BaseAdapter.php | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 039b9bc..caba054 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ The syntax is quite similar to Laravel's query builder. require 'vendor/autoload.php'; // Create a connection, once only. -$config = array( +$config = [ 'driver' => 'mysql', // Db driver 'host' => 'localhost', 'database' => 'your-database', @@ -29,11 +29,11 @@ $config = array( 'charset' => 'utf8', // Optional 'collation' => 'utf8_unicode_ci', // Optional 'prefix' => 'cb_', // Table prefix, optional - 'options' => array( // PDO constructor options, optional + 'options' => [ // PDO constructor options, optional PDO::ATTR_TIMEOUT => 5, PDO::ATTR_EMULATE_PREPARES => false, - ), - ); + ], + ]; new \Pixie\Connection('mysql', $config, 'QB'); ``` @@ -659,4 +659,4 @@ Here are some cases where Query Events can be extremely helpful: ___ If you find any typo then please edit and send a pull request. -© 2016 [Muhammad Usman](http://usman.it/). Licensed under MIT license. +© 2020 [Muhammad Usman](http://usman.it/). Licensed under MIT license. diff --git a/src/Pixie/QueryBuilder/Adapters/BaseAdapter.php b/src/Pixie/QueryBuilder/Adapters/BaseAdapter.php index 5b1e0a4..d6248c1 100644 --- a/src/Pixie/QueryBuilder/Adapters/BaseAdapter.php +++ b/src/Pixie/QueryBuilder/Adapters/BaseAdapter.php @@ -65,8 +65,8 @@ public function select($statements) } // Limit and offset - $limit = isset($statements['limit']) ? 'LIMIT ' . $statements['limit'] : ''; - $offset = isset($statements['offset']) ? 'OFFSET ' . $statements['offset'] : ''; + $limit = isset($statements['limit']) ? 'LIMIT ' . (int) $statements['limit'] : ''; + $offset = isset($statements['offset']) ? 'OFFSET ' . (int) $statements['offset'] : ''; // Having list($havingCriteria, $havingBindings) = $this->buildCriteriaWithType($statements, 'havings', 'HAVING'); From 7552c8eae6b0495bace1a4f9d6216dac6bff0bcf Mon Sep 17 00:00:00 2001 From: Muhammad Usman Date: Sat, 16 Nov 2019 12:26:55 +0000 Subject: [PATCH 08/12] Remove PHP 5.4 from travis --- .travis.yml | 1 - README.md | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index aa02544..5f20177 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,6 @@ sudo: false language: php php: - - 5.4 - 5.5 - 7.0 diff --git a/README.md b/README.md index caba054..f340c5b 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ # Pixie Query Builder [![Build Status](https://travis-ci.org/usmanhalalit/pixie.png?branch=master)](https://travis-ci.org/usmanhalalit/pixie) -A lightweight, expressive, framework agnostic query builder for PHP it can also be referred as a Database Abstraction Layer. Pixie supports MySQL, SQLite and PostgreSQL and it takes care of query sanitization, table prefixing and many other things with a unified API. At least PHP 5.3 is required. +A lightweight, expressive, framework agnostic query builder for PHP it can also be referred as a Database Abstraction Layer. Pixie supports MySQL, SQLite and PostgreSQL and it takes care of query sanitization, table prefixing and many other things with a unified API. It has some advanced features like: From 873e70e63b6802634050d9fb3d38a9bc0c5d23fc Mon Sep 17 00:00:00 2001 From: Muhammad Usman Date: Sat, 16 Nov 2019 12:29:06 +0000 Subject: [PATCH 09/12] Fix travis build --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 5f20177..ad693f3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,7 @@ +dist: trusty sudo: false + language: php php: From 74f9d03f7862ad483f029a978b818af8c9c6c7be Mon Sep 17 00:00:00 2001 From: Muhammad Usman Date: Sat, 14 Mar 2020 15:49:14 +0000 Subject: [PATCH 10/12] Create FUNDING.yml --- .github/FUNDING.yml | 1 + 1 file changed, 1 insertion(+) create mode 100644 .github/FUNDING.yml diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..5a9af3c --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1 @@ +github: USERNAME From c3346a7b72c1a8e20281d1ad65acf9cb12f97ebd Mon Sep 17 00:00:00 2001 From: Muhammad Usman Date: Sat, 14 Mar 2020 15:51:34 +0000 Subject: [PATCH 11/12] Update FUNDING.yml --- .github/FUNDING.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index 5a9af3c..fe0f243 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1 +1 @@ -github: USERNAME +github: usmanhalalit From 4ea93b064b0b460120d16659654a523625797456 Mon Sep 17 00:00:00 2001 From: Muhammad Usman Date: Tue, 7 Apr 2020 08:35:32 +0100 Subject: [PATCH 12/12] Update README.md --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f340c5b..ed731cd 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,13 @@ **This project is Not Actively Maintained but most of the features are fully working and there are no major security issues, I'm just not giving it much time.** -# Pixie Query Builder [![Build Status](https://travis-ci.org/usmanhalalit/pixie.png?branch=master)](https://travis-ci.org/usmanhalalit/pixie) +# Pixie Query Builder + +[![Build Status](https://travis-ci.org/usmanhalalit/pixie.svg?branch=master)](https://travis-ci.org/usmanhalalit/pixie) +[![Total Downloads](https://poser.pugx.org/usmanhalalit/pixie/downloads)](https://packagist.org/packages/usmanhalalit/pixie) +[![Daily Downloads](https://poser.pugx.org/usmanhalalit/pixie/d/daily)](https://packagist.org/packages/usmanhalalit/pixie) + + A lightweight, expressive, framework agnostic query builder for PHP it can also be referred as a Database Abstraction Layer. Pixie supports MySQL, SQLite and PostgreSQL and it takes care of query sanitization, table prefixing and many other things with a unified API. It has some advanced features like: