Unable to resolve table 'sqlite_master'
I have a seeder I'm working on in laravel that is doing conversions on a large amount of data. To make things go easier, I'm using a cache database as a middle-step to house the converted data prior to seeding. I am having the seeder check if the cache database (sqlite3) exists then it creates it if it doesn't. It then looks for a script file that includes conditional table definitions which will create the tables needed only if they don't already exist.
In the event the table definitions script did not exist, I added one final condition that just checks when an sqlite file does already exist if it has any tables in it before attempting to insert data or bail out with an error (if there are no tables).
To do this, requires checking the built-in sqlite3 schema table ‘sqlite master’, but as soon as I add the sql to do this, PhpStorm marks the table name as an error saying: Unable to resolve table 'sqlite_master' $table_count = count(DB::connection('sqlcache')->select("SELECT name FROM `sqlite_master` WHERE type='table';"));
$table_sql = realpath($seedsdir . DIRECTORY_SEPARATOR . self::SQLITE_TABLES);
// throw error if there are no tables and is no sql code to create tables
if($table_sql == false) {
if ($table_count == 0)
throw new FException("Database is empty, but could not find sqlite tables script");
I see there is an option to ignore quoted identifiers, but I'd prefer not turn that on as it's useful in other queries. Is there any way to get PhpStorm to stop reporting this query as an error seeing as how it runs just find in sqlite3 on any sqlite database? I tried setting the dialect for the whole file to sqlite and that didn't work either. (there is also mysql based SQL in this same seeder that runs from the cached data to populate the final database)
SW
Please sign in to leave a comment.
I think I found a working solution. I am guessing part of the problem is that this is prior to my trying to use the laravel api to instantiate an Eloquent Connection for the sqlite file, as I'm just trying to establish the sqlite file exists and isn't empty. Thus I'm using the more abstract DB::connection at that point.
After looking through the long list of ‘suggestions’ in the pop-up there was one for specifying the language in phpdoc which it placed right before the quoted query:
/** @lang sqlite */ "SELECT name FROM `sqlite_master` WHERE type='table';"
This seems to have made the error go away. If there's a better way to do this, I appreciate feedback.
If you do not use any other SQL injections in this specific file, you may also set a separate SQLite dialect for this file only:
Also, as a workaround of some sort, it should be possible to quickly create a local dummy SQLite database in Data Sources; that might work too: