harrygulliford / laravel-firebird

Firebird database driver for the Laravel Framework
65 stars 30 forks source link

Error getting table columns listing #26

Closed gilles6 closed 3 years ago

gilles6 commented 3 years ago

When I check if a table exists in a Firebird(1.5) database:

Illuminate\Support\Facades\Schema::connection('my_connection')->hasTable('my_table');

I get true, it works fine.

However, when I check if a column exists in a table like this:

Illuminate\Support\Facades\Schema::connection('my_connection')->hasColumn('my_table', 'my_column');

I get the following error message:

Illuminate\Database\QueryException with message 'SQLSTATE[HY000]: General error: -804 Dynamic SQL Error SQL error code = -804 Function unknown TRIM  (SQL: SELECT TRIM(RDB$FIELD_NAME) AS "column_name" FROM RDB$RELATION_FIELDS WHERE RDB$RELATION_NAME = 'my_table')'

Is it a bug (or limitation) or am I using a wrong syntax ?

Is there an alternative to get column listing from eloquent model ?

harrygulliford commented 3 years ago

This is something that has not been implemented in the package yet for Firebird 1.5.

You can still run a raw query to check if the column exists: http://www.firebirdfaq.org/faq373/

I'm considering dropping Firebird 1.5 support soon, to focus on supporting newer versions of Firebird.

gilles6 commented 3 years ago

I was finally able to get columns list with this command:

DB::connection('my_connection')
  ->table('RDB$RELATION_FIELDS')
  ->select('RDB$FIELD_NAME')
  ->where('RDB$RELATION_NAME', 'MYTABLE')
  ->pluck('RDB$FIELD_NAME')
  ->toArray()
harrygulliford commented 3 years ago

Take a look at the v3 beta on the next branch. It adds support for Schema::hasColumn('users', 'id');. Only caveat is that Firebird 1.5 is not officially supported anymore from the v3 release.