Skip to content

Commit

Permalink
Merge pull request #45 from efcor/master
Browse files Browse the repository at this point in the history
Update for laravel 6
  • Loading branch information
jfelder authored May 12, 2020
2 parents f7b9d55 + 68ae99f commit 8cfbf4a
Show file tree
Hide file tree
Showing 12 changed files with 131 additions and 151 deletions.
13 changes: 3 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,20 @@
language: php

php:
- 5.6
- 7.0
- 7.1
- 7.2
- 7.3
- 7.4

env:
global:
- setup=basic

matrix:
fast_finish: true
include:
- php: 5.6
env: setup=lowest
- php: 5.6
env: setup=stable

sudo: false

install:
- if [[ $setup = 'basic' ]]; then travis_retry composer install --no-interaction --prefer-dist --no-suggest; fi
- if [[ $setup = 'stable' ]]; then travis_retry composer update --prefer-dist --no-interaction --prefer-stable --no-suggest; fi
- if [[ $setup = 'lowest' ]]; then travis_retry composer update --prefer-dist --no-interaction --prefer-lowest --prefer-stable --no-suggest; fi

script: vendor/bin/phpunit
53 changes: 26 additions & 27 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
{
"name": "jfelder/oracledb",
"description": "Oracle DB driver for Laravel 5",
"keywords": ["oracle", "laravel", "laravel 5", "pdo_oci", "oci8"],
"license": "MIT",
"authors": [
{
"name": "Jimmy Felder",
"email": "[email protected]"
}
],
"require": {
"php": ">=5.6.4",
"illuminate/support": "5.4.*",
"illuminate/database": "5.4.*",
"illuminate/pagination": "5.4.*"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
"mockery/mockery": "~0.9.4",
"phpunit/phpunit": "~4.0",
"phpspec/phpspec": "~2.1"
},
"autoload": {
"psr-4": {
"Jfelder\\": "src/Jfelder"
"name": "jfelder/oracledb",
"description": "Oracle DB driver for Laravel",
"keywords": ["oracle", "laravel", "laravel 6", "pdo_oci", "oci8"],
"license": "MIT",
"authors": [
{
"name": "Jimmy Felder",
"email": "[email protected]"
}
},
"minimum-stability": "stable"
],
"require": {
"php": "^7.2",
"illuminate/support": "^6.0",
"illuminate/database": "^6.0",
"illuminate/pagination": "^6.0"
},
"require-dev": {
"fzaninotto/faker": "^1.9.1",
"mockery/mockery": "^1.0",
"phpunit/phpunit": "^8.0"
},
"autoload": {
"psr-4": {
"Jfelder\\": "src/Jfelder"
}
},
"minimum-stability": "stable"
}
1 change: 0 additions & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
>
<testsuites>
<testsuite name="Package Test Suite">
Expand Down
12 changes: 6 additions & 6 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Laravel Oracle Database Package

### OracleDB (updated for 5.4)
### OracleDB (updated for Laravel 6.x)

[![Latest Stable Version](https://poser.pugx.org/jfelder/oracledb/v/stable.png)](https://packagist.org/packages/jfelder/oracledb) [![Total Downloads](https://poser.pugx.org/jfelder/oracledb/downloads.png)](https://packagist.org/packages/jfelder/oracledb) [![Build Status](https://travis-ci.org/jfelder/Laravel-OracleDB.png)](https://travis-ci.org/jfelder/Laravel-OracleDB)

Expand All @@ -24,7 +24,7 @@ Add `jfelder/oracledb` as a requirement to composer.json:
```json
{
"require": {
"jfelder/oracledb": "5.4.*"
"jfelder/oracledb": "6.*"
}
}
```
Expand Down Expand Up @@ -56,14 +56,14 @@ Once you have configured the OracleDB database connection(s), you may run querie
#### NEW: The oci8 library in now the default library. If you want to use the pdo library, enter "pdo" as the driver and the code will automatically use the pdo library instead of the oci8 library. Any other value will result in the oci8 library being used.

```php
$results = DB::select('select * from users where id = ?', array(1));
$results = DB::select('select * from users where id = ?', [1]);
```

The above statement assumes you have set the default connection to be the oracle connection you setup in
config/database.php file and will always return an 'array' of results.

```php
$results = DB::connection('oracle')->select('select * from users where id = ?', array(1));
$results = DB::connection('oracle')->select('select * from users where id = ?', [1]);
```

Just like the built-in database drivers, you can use the connection method to access the oracle database(s) you setup
Expand All @@ -73,14 +73,14 @@ in config/oracledb.php file.

```php
$id = DB::connection('oracle')->table('users')->insertGetId(
array('email' => '[email protected]', 'votes' => 0), 'userid'
['email' => '[email protected]', 'votes' => 0], 'userid'
);
```

> **Note:** When using the insertGetId method, you can specify the auto-incrementing column name as the second
parameter in insertGetId function. It will default to "id" if not specified.

See [Laravel Database Basic Docs](http://four.laravel.com/docs/database) for more information.
See [Laravel Database Basic Docs](https://laravel.com/docs/6.x/database) for more information.

### License

Expand Down
30 changes: 25 additions & 5 deletions src/Jfelder/OracleDB/Query/Grammars/OracleGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,36 @@ protected function dateBasedWhere($type, Builder $query, $where)
*/
public function compileSelect(Builder $query)
{
if ($query->unions && $query->aggregate) {
return $this->compileUnionAggregate($query);
}

// If the query does not have any columns set, we'll set the columns to the
// * character to just get all of the columns from the database. Then we
// can build the query and concatenate all the pieces together as one.
$original = $query->columns;

if (is_null($query->columns)) {
$query->columns = ['*'];
}

// To compile the query, we'll spin through each component of the query and
// see if that component exists. If it does we'll just call the compiler
// function for the component which is responsible for making the SQL.
$components = $this->compileComponents($query);
$sql = trim($this->concatenate($components));

if ($query->unions) {
$sql = $this->wrapUnion($sql).' '.$this->compileUnions($query);
}

// If an offset is present on the query, we will need to wrap the query in
// a big "ANSI" offset syntax block. This is very nasty compared to the
// other database systems but is necessary for implementing features.
if ($query->limit > 0 || $query->offset > 0) {
return $this->compileAnsiOffset($query, $components);
$sql = $this->compileAnsiOffset($query, $components);
}

return trim($this->concatenate($components));
$query->columns = $original;

return $sql;
}

/**
Expand Down Expand Up @@ -184,6 +200,10 @@ protected function compileAnsiOffset(Builder $query, $components)

$sql = $this->concatenate($components);

if ($query->unions) {
$sql = $this->wrapUnion($sql).' '.$this->compileUnions($query);
}

// We are now ready to build the final SQL query so we'll create a common table
// expression from the query and get the records with row numbers within our
// given limit and offset value that we just put on as a query constraint.
Expand Down
9 changes: 5 additions & 4 deletions tests/OracleDBConnectorTest.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?php

use Mockery as m;
use PHPUnit\Framework\TestCase;

class OracleDBConnectorTest extends PHPUnit_Framework_TestCase
class OracleDBConnectorTest extends TestCase
{
public function tearDown()
public function tearDown(): void
{
m::close();
}
Expand All @@ -21,10 +22,11 @@ public function testOptionResolution()
*/
public function testOracleConnectCallsCreateConnectionWithProperArguments($dsn, $config)
{
$connector = $this->getMock('Jfelder\OracleDB\Connectors\OracleConnector', ['createConnection', 'getOptions']);
$connection = m::mock('stdClass');
$connector = $this->getMockBuilder('Jfelder\OracleDB\Connectors\OracleConnector')->setMethods(['createConnection', 'getOptions'])->getMock();
$connector->expects($this->once())->method('getOptions')->with($this->equalTo($config))->will($this->returnValue(['options']));
$connector->expects($this->once())->method('createConnection')->with($this->equalTo($dsn), $this->equalTo($config), $this->equalTo(['options']))->will($this->returnValue($connection));

$result = $connector->connect($config);

$this->assertSame($result, $connection);
Expand All @@ -41,7 +43,6 @@ public function OracleConnectProvider()
['driver' => 'oci8', 'tns' => '(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 6789))(CONNECT_DATA =(SID = ORCL)))'], ],
['(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 9876))(CONNECT_DATA =(SID = ORCL)))',
['driver' => 'oci8', 'host' => 'localhost', 'port' => '9876', 'database' => 'ORCL', 'tns' => ''], ],

];
}
}
9 changes: 4 additions & 5 deletions tests/OracleDBOCIProcessorTest.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
<?php

use Mockery as m;
use PHPUnit\Framework\TestCase;

include 'mocks/OCIMocks.php';

class OracleDBOCIProcessorTest extends PHPUnit_Framework_TestCase
class OracleDBOCIProcessorTest extends TestCase
{
// defining here in case oci8 extension not installed

protected function setUp()
protected function setUp(): void
{
if (! extension_loaded('oci8')) {
$this->markTestSkipped('The oci8 extension is not available.');
}
}

public function tearDown()
public function tearDown(): void
{
m::close();
}
Expand Down
Loading

0 comments on commit 8cfbf4a

Please sign in to comment.