Skip to content

Sqlite DSN specification does not work with absolute paths #5887

@benr77

Description

@benr77

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions