From ecba8b0b037cf10bf65e2114dc3f8c501455a78f Mon Sep 17 00:00:00 2001 From: Maxime Rault Date: Wed, 24 Aug 2016 09:41:28 +0200 Subject: [PATCH 1/3] clean code --- README.md | 2 +- src/DB2ServiceProvider.php | 2 +- src/Query/Grammars/DB2Grammar.php | 2 +- src/Query/Processors/DB2Processor.php | 3 +-- src/Schema/Blueprint.php | 1 - src/Schema/Builder.php | 2 +- src/Schema/Grammars/DB2Grammar.php | 2 +- src/config/config.php | 2 +- 8 files changed, 7 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 8e84a23..fe99a41 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ Add the laravel-db2 Service Provider to your config in ``app/config/app.php``: There are two ways to configure laravel-db2. You can choose the most convenient way for you. You can put your DB2 credentials into ``app/config/database.php`` (option 1) file or use package config file which you can be generated through command line by artisan (option 2). -#### Option 1: Configure DB2 using ``app/config/database.php`` file +#### Option 1: Configure DB2 using ``app/config/database.php`` file Simply add this code at the end of your ``app/config/database.php`` file: diff --git a/src/DB2ServiceProvider.php b/src/DB2ServiceProvider.php index e5e385f..61e2d5a 100644 --- a/src/DB2ServiceProvider.php +++ b/src/DB2ServiceProvider.php @@ -52,7 +52,7 @@ class DB2ServiceProvider extends ServiceProvider { //Create a connector $this->app['db']->extend($conn, function($config) - { + { switch ($config['driver']) { case 'odbc': $connector = new ODBCConnector(); diff --git a/src/Query/Grammars/DB2Grammar.php b/src/Query/Grammars/DB2Grammar.php index 0a48521..21b54ac 100644 --- a/src/Query/Grammars/DB2Grammar.php +++ b/src/Query/Grammars/DB2Grammar.php @@ -6,7 +6,7 @@ use Illuminate\Database\Query\Builder; class DB2Grammar extends Grammar { - + /** * Wrap a single string in keyword identifiers. * diff --git a/src/Query/Processors/DB2Processor.php b/src/Query/Processors/DB2Processor.php index 44cf247..571bfa0 100644 --- a/src/Query/Processors/DB2Processor.php +++ b/src/Query/Processors/DB2Processor.php @@ -48,7 +48,7 @@ class DB2Processor extends Processor { $sequenceStr = $grammar->columnize($sequence); } $sql = 'select ' . $sequenceStr . ' from new table (' . $sql; - $sql .= ')'; + $sql .= ')'; $results = $query->getConnection()->select($sql, $values); if (is_array($sequence)) { @@ -60,7 +60,6 @@ class DB2Processor extends Processor { $id = $result[$sequenceStr]; return is_numeric($id) ? (int) $id : $id; } - } } diff --git a/src/Schema/Blueprint.php b/src/Schema/Blueprint.php index b8aea3f..b7a4907 100644 --- a/src/Schema/Blueprint.php +++ b/src/Schema/Blueprint.php @@ -46,7 +46,6 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint { $index = $this->createIndexName($type, $columns); return $this->addCommand($type, compact('index', 'indexSystem', 'columns')); break; - default: break; } diff --git a/src/Schema/Builder.php b/src/Schema/Builder.php index cedc7e8..ded353f 100644 --- a/src/Schema/Builder.php +++ b/src/Schema/Builder.php @@ -20,7 +20,7 @@ class Builder extends \Illuminate\Database\Schema\Builder { if (count($schemaTable) > 1) { $schema = $schemaTable[0]; - $table = $this->connection->getTablePrefix().$schemaTable[1]; + $table = $this->connection->getTablePrefix().$schemaTable[1]; } else { diff --git a/src/Schema/Grammars/DB2Grammar.php b/src/Schema/Grammars/DB2Grammar.php index 15ae737..18d0a95 100644 --- a/src/Schema/Grammars/DB2Grammar.php +++ b/src/Schema/Grammars/DB2Grammar.php @@ -92,7 +92,7 @@ class DB2Grammar extends Grammar { * @return string */ public function compileLabel(Blueprint $blueprint, Fluent $command, Connection $connection) - { + { return 'label on table '.$this->wrapTable($blueprint).' is \'' . $command->label . '\''; } diff --git a/src/config/config.php b/src/config/config.php index 5c00d5f..6957b58 100644 --- a/src/config/config.php +++ b/src/config/config.php @@ -57,7 +57,7 @@ PDO::CASE_NATURAL */ return [ - + 'connections' => [ 'ibmi' => [ From 5b8fa9da427d1a47c3e8b67e440a902764c7982d Mon Sep 17 00:00:00 2001 From: Maxime Rault Date: Wed, 24 Aug 2016 09:59:00 +0200 Subject: [PATCH 2/3] Fix missing select clause on some queries. --- src/Query/Grammars/DB2Grammar.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Query/Grammars/DB2Grammar.php b/src/Query/Grammars/DB2Grammar.php index 21b54ac..57332e6 100644 --- a/src/Query/Grammars/DB2Grammar.php +++ b/src/Query/Grammars/DB2Grammar.php @@ -40,6 +40,8 @@ class DB2Grammar extends Grammar */ public function compileSelect(Builder $query) { + if (is_null($query->columns)) $query->columns = array('*'); + $components = $this->compileComponents($query); // If an offset is present on the query, we will need to wrap the query in From ed43908a2da2bd47e85e047b1002410297ccf73a Mon Sep 17 00:00:00 2001 From: Maxime Rault Date: Wed, 24 Aug 2016 10:10:24 +0200 Subject: [PATCH 3/3] Qualify * with table name when row_number() follows --- src/Query/Grammars/DB2Grammar.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Query/Grammars/DB2Grammar.php b/src/Query/Grammars/DB2Grammar.php index 57332e6..0eecfc7 100644 --- a/src/Query/Grammars/DB2Grammar.php +++ b/src/Query/Grammars/DB2Grammar.php @@ -81,6 +81,11 @@ class DB2Grammar extends Grammar $columns = (!empty($components['columns']) ? $components['columns'] . ', ': 'select'); + if($columns == 'select *, ' && $query->from) + { + $columns = 'select ' . $this->tablePrefix . $query->from . '.*, '; + } + $components['columns'] = $this->compileOver($orderings, $columns); unset($components['orders']);