Skip to content

[BUG]: SQLite tableExists() does not find a view #17768

Open

Description

@niden

Describe the bug
On SQLite, tableExists() gives false for a view. On MySQL, MariaDB and PostgreSQL it gives true for a view: those dialects read information_schema.tables, which also lists the views. The SQLite dialect reads only type='table' from sqlite_master (phalcon/Db/Dialect/Sqlite.zep, tableExists()).

The fix changes the result of tableExists() on SQLite, so it is for 7.0.

To Reproduce

$connection->execute('CREATE TABLE t1 (id INTEGER PRIMARY KEY)');
$connection->execute('CREATE VIEW v1 AS SELECT id FROM t1');

var_dump($connection->tableExists('v1')); // SQLite: false
var_dump($connection->viewExists('v1'));  // SQLite: true

The query of the MySQL dialect gives 1 for v1 on MariaDB 10.6.28, and the query of the PostgreSQL dialect gives 1 on PostgreSQL 18.7.

Expected behavior
tableExists() gives the same result for a view on each adapter. A possible fix: type IN ('table', 'view') in the SQLite dialect.

Details

  • Phalcon version: 5.0.x (cfcf481836). phalcon/phalcon v6.0.x has the same query (src/Db/Dialect/Sqlite.php).

Additional context
Found in phalcon/crest#88: crest make:model <view> stops on SQLite only. Until this changes, crest also calls viewExists().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

7.0bugstatus: low

Type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions