What are you trying to achieve?
In the Db module, specify an Sqlite3 DSN that uses an absolute path.
What do you get instead?
In Db.php line 560:
[Codeception\Exception\ModuleException]
Db: SQLSTATE[HY000] [14] unable to open database file while creating PDO connection
The problem I have found is that in the documentation for the Db module, it gives a link through to the Sqlite DSN documentation on PHP.net
https://codeception.com/docs/modules/Db#SQL-data-dump
https://www.php.net/manual/en/ref.pdo-sqlite.connection.php
The PHP documentation states that the syntax is
The DSN prefix is sqlite:.
To access a database on disk, append the absolute path to the DSN prefix.
The example given is sqlite:/opt/databases/mydb.sq3
However, what is not clear at all without poking in to the source of the Db module is that Codeception silently prefixes the project root path to the DSN filename. To get it to work in Codeception, you must use a relative file path - e.g. sqlite:../../../../opt/databases/mydb.sq3 to get it to work.
What is the desired behaviour? If relative paths, as is currently the case, are expected, the documentation should state this as it's contrary to the specification on the PHP.net.
I would have thought Codeception should be able to detect an absolute path and use it if found, otherwise prefix the project dir to build an absolute path from the relative path as it does currently.
Happy to submit a PR if you agree with me.
Details
- Codeception version: 4.1.1
- PHP Version: 7.4
- Operating System: Linux
- Installation type: Composer
What are you trying to achieve?
In the Db module, specify an Sqlite3 DSN that uses an absolute path.
What do you get instead?
In Db.php line 560: [Codeception\Exception\ModuleException] Db: SQLSTATE[HY000] [14] unable to open database file while creating PDO connectionThe problem I have found is that in the documentation for the Db module, it gives a link through to the Sqlite DSN documentation on PHP.net
https://codeception.com/docs/modules/Db#SQL-data-dump
https://www.php.net/manual/en/ref.pdo-sqlite.connection.php
The PHP documentation states that the syntax is
The example given is
sqlite:/opt/databases/mydb.sq3However, what is not clear at all without poking in to the source of the Db module is that Codeception silently prefixes the project root path to the DSN filename. To get it to work in Codeception, you must use a relative file path - e.g.
sqlite:../../../../opt/databases/mydb.sq3to get it to work.What is the desired behaviour? If relative paths, as is currently the case, are expected, the documentation should state this as it's contrary to the specification on the PHP.net.
I would have thought Codeception should be able to detect an absolute path and use it if found, otherwise prefix the project dir to build an absolute path from the relative path as it does currently.
Happy to submit a PR if you agree with me.
Details