Skip to content
Open

4.x #52

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 8 additions & 18 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,16 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
php: [8.2, 8.1, 8.0, 7.4]
laravel: [10.*, 9.*, 8.*]
php: [8.4, 8.3, 8.2]
laravel: [12.*, 11.*]
stability: [prefer-lowest, prefer-stable]
firebird: [v4.0, v3.0, v2.5.9-sc]
include:
- laravel: 8.*
testbench: ^6.19
- laravel: 9.*
testbench: ^7.0
- laravel: 10.*
testbench: ^8.0
exclude:
- laravel: 8.*
php: 8.2
- laravel: 9.*
php: 7.4
- laravel: 10.*
php: 8.0
- laravel: 10.*
php: 7.4
- laravel: 11.*
testbench: ^9.0
- laravel: 12.*
testbench: ^10.0
fail-fast: false

name: PHP ${{ matrix.php }}, Laravel ${{ matrix.laravel }}, Firebird ${{ matrix.firebird }}, ${{ matrix.stability }}

Expand All @@ -44,7 +34,7 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.idea
.php_cs
.php_cs.cache
.phpunit.cache
.phpunit.result.cache
.DS_Store
build
Expand Down
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
"license": "MIT",
"require": {
"php": "^7.4|^8.0",
"illuminate/support": "^8.65|^9.33|^10.0",
"illuminate/container": "^8.65|^9.33|^10.0",
"illuminate/database": "^8.65|^9.33|^10.0",
"illuminate/events": "^8.65|^9.33|^10.0"
"illuminate/support": "^8.65|^9.33|^10.0|^11.0|^12.0",
"illuminate/container": "^8.65|^9.33|^10.0|^11.0|^12.0",
"illuminate/database": "^8.65|^9.33|^10.0|^11.0|^12.0",
"illuminate/events": "^8.65|^9.33|^10.0|^11.0|^12.0"
},
"require-dev": {
"mockery/mockery": "^1.4",
"phpunit/phpunit": "^9.5.10",
"orchestra/testbench": "^6.19|^7.0|^8.0",
"phpunit/phpunit": "^9.6.11|^10.0|^11.0",
"orchestra/testbench": "^6.19|^7.0|^8.0|^9.0|^10.0",
"fakerphp/faker": "^1.15"
},
"archive": {
Expand Down
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ This package adds support for the Firebird PDO Database Driver in Laravel applic

## Version Support

- **PHP:** 7.4, 8.0, 8.1, 8.2
- **Laravel:** 8.x, 9.x, 10.x
- **PHP:** 7.4, 8.0, 8.1, 8.2, 8.3
- **Laravel:** 8.x, 9.x, 10.x, 11.x
- **Firebird:** 2.5, 3.0, 4.0

## Installation
Expand Down
4 changes: 2 additions & 2 deletions src/FirebirdConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class FirebirdConnection extends DatabaseConnection
*/
protected function getDefaultQueryGrammar()
{
return new FirebirdQueryGrammar;
return new FirebirdQueryGrammar($this);
}

/**
Expand Down Expand Up @@ -52,7 +52,7 @@ public function getSchemaBuilder()
*/
protected function getDefaultSchemaGrammar()
{
return $this->withTablePrefix(new FirebirdSchemaGrammar);
return $this->withTablePrefix(new FirebirdSchemaGrammar($this));
}

/**
Expand Down
42 changes: 42 additions & 0 deletions src/Schema/Grammars/FirebirdGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@ class FirebirdGrammar extends Grammar
*/
protected $serials = ['bigInteger', 'integer', 'mediumInteger', 'smallInteger', 'tinyInteger'];

/**
* Compile the query to determine the tables.
*
* @return string
*/
public function compileTables()
{
return 'select trim(trailing from rdb$relation_name) as "name" '
.'from rdb$relations '
.'where rdb$relation_type = 0 '
.'and (rdb$system_flag is null or rdb$system_flag = 0) '
.'order by rdb$relation_name';
}

/**
* Compile the query to determine if a table exists.
*
Expand All @@ -32,6 +46,34 @@ public function compileTableExists()
return 'select rdb$relation_name from rdb$relations where rdb$relation_name = ?';
}

/**
* Compile the query to determine the views.
*
* @return string
*/
public function compileViews()
{
return 'select trim(trailing from rdb$relation_name) as "name", '
.'rdb$view_source as "definition" '
.'from rdb$relations '
.'where rdb$view_blr is not null '
.'and (rdb$system_flag is null or rdb$system_flag = 0)';
}

/**
* Compile the query to determine the columns.
*
* @param string $table
* @return string
*/
public function compileColumns($table)
{
return 'select trim(trailing from rdb$field_name) as "name" '
.'from rdb$relation_fields '
.'where rdb$relation_name = '.$this->quoteString($table).' '
.'order by rdb$relation_name';
}

/**
* Compile the query to determine the list of columns.
*
Expand Down
32 changes: 16 additions & 16 deletions tests/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ public function it_can_select()

$this->assertCount(3, (array) $result);

$this->assertObjectHasAttribute('name', $result);
$this->assertObjectHasAttribute('city', $result);
$this->assertObjectHasAttribute('country', $result);
$this->assertObjectHasProperty('name', $result);
$this->assertObjectHasProperty('city', $result);
$this->assertObjectHasProperty('country', $result);

$this->assertEquals('Anna', $result->name);
$this->assertEquals('Sydney', $result->city);
Expand All @@ -82,9 +82,9 @@ public function it_can_select_with_aliases()

$this->assertCount(3, (array) $result);

$this->assertObjectHasAttribute('USER_NAME', $result);
$this->assertObjectHasAttribute('user_city', $result);
$this->assertObjectHasAttribute('User_Country', $result);
$this->assertObjectHasProperty('USER_NAME', $result);
$this->assertObjectHasProperty('user_city', $result);
$this->assertObjectHasProperty('User_Country', $result);

$this->assertEquals('Anna', $result->USER_NAME);
$this->assertEquals('Sydney', $result->user_city);
Expand Down Expand Up @@ -1050,11 +1050,11 @@ public function it_can_add_inner_join()
->get();

$this->assertCount(10, $results);
$this->assertObjectHasAttribute('name', $results->first());
$this->assertObjectHasAttribute('email', $results->first());
$this->assertObjectHasAttribute('state', $results->first());
$this->assertObjectHasAttribute('price', $results->first());
$this->assertObjectHasAttribute('quantity', $results->first());
$this->assertObjectHasProperty('name', $results->first());
$this->assertObjectHasProperty('email', $results->first());
$this->assertObjectHasProperty('state', $results->first());
$this->assertObjectHasProperty('price', $results->first());
$this->assertObjectHasProperty('quantity', $results->first());
}

/** @test */
Expand All @@ -1073,11 +1073,11 @@ public function it_can_add_inner_join_where()
$this->assertCount(2, $results);
$this->assertEquals(100, $results->first()->price);

$this->assertObjectHasAttribute('name', $results->first());
$this->assertObjectHasAttribute('email', $results->first());
$this->assertObjectHasAttribute('state', $results->first());
$this->assertObjectHasAttribute('price', $results->first());
$this->assertObjectHasAttribute('quantity', $results->first());
$this->assertObjectHasProperty('name', $results->first());
$this->assertObjectHasProperty('email', $results->first());
$this->assertObjectHasProperty('state', $results->first());
$this->assertObjectHasProperty('price', $results->first());
$this->assertObjectHasProperty('quantity', $results->first());
}

/** @test */
Expand Down
14 changes: 14 additions & 0 deletions tests/SchemaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@ public function it_has_column()
$this->assertFalse(Schema::hasColumn('users', 'foo'));
}

/** @test */
public function it_has_view(): void
{
if (version_compare($this->app->version(), '10.34.0', '<')) {
$this->markTestSkipped('The hasView method is only available in Laravel 10.34.0 and above.');
}

$this->createViews();

$this->assertTrue(Schema::hasView('view_all_users'));

$this->assertFalse(Schema::hasView(uniqid('view_')));
}

/** @test */
public function it_has_columns()
{
Expand Down
21 changes: 21 additions & 0 deletions tests/Support/MigrateDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public function setUp(): void
parent::setUp();

if (! MigrationState::$migrated) {
$this->dropViews();

$this->dropTables();
$this->createTables();

Expand Down Expand Up @@ -100,4 +102,23 @@ public function dropProcedure()
}
}
}

public function createViews(): void
{
DB::select('CREATE VIEW "view_all_users" AS SELECT * FROM "users"');
}

public function dropViews(): void
{
try {
DB::select('DROP VIEW "view_all_users"');
} catch (QueryException $e) {
// Suppress the "view does not exist" exception, as we want to
// replicate dropIfExists() functionality without using the Schema
// class.
if (! Str::contains($e->getMessage(), 'does not exist')) {
throw $e;
}
}
}
}