2

I am trying to load an Sqlite3 extension in a Doctrine 2 project (specifically, the pcre extension that I have installed via the debian package sqlite3-pcre).

In a plain PHP project, I would do something similar to

$db = new SQLite3('mysqlitedb.db');
$db->loadExtension('pcre.so');

(as per http://php.net/manual/en/sqlite3.loadextension.php).

My issue is that I do not know where to tell Doctrine to call loadExtension, or any other way to load that extension.


Side notes :

  • The project is a Symfony 4 project. The reason I use Sqlite3 is for my functional tests (the dev and prod environments use Postgresql).
  • I have implemented two Doctrine Extensions similar to what is done in the (semi-official ?) DoctrineExtensions project (e.g., the one at https://github.com/beberlei/DoctrineExtensions/blob/master/src/Query/Mysql/Regexp.php):
    • One for Postgresql using the ~ operator. This one works perfectly.
    • One for Sqlite3 using the REGEXP operator from the pcre extension. This one complains that REGEXP is undefined, since I have not managed to load the pcre extension.

I'd be thankful to hear any idea about how to tackle the issue.

NicolasB
  • 966
  • 5
  • 9
  • 1
    Surely its not a valid test if you are not using all that same tools in the test – RiggsFolly Sep 24 '18 at 16:38
  • 1
    @RiggsFolly It is not uncommon in the Symfony universe to have functional tests that run on a test database, depending on what you're testing. Consider them to be in-between unit and functional tests (and you can of course have "real-world" tests as well on a prod-like database). The bundle we're using for our tests is https://github.com/liip/LiipFunctionalTestBundle, and follows that philosophy. It advises using an in-memory sqlite3 database for speed, which is what we're doing. The Postgres Doctrine Extension for regexps that is not used in these functional tests is unit-tested separately. – NicolasB Sep 24 '18 at 16:56
  • @NicolasB Have you had any luck finding a solution since you posted this question? I run into the problem of wanting to test a REGEXP query on a sqlite database. – Boschman Oct 06 '20 at 11:22
  • 1
    @Boschman Unfortunately no. Two possible solutions are given in https://stackoverflow.com/questions/8756146/how-to-load-sqlite-extension-in-pdo but they were a bit overkill for our problem, so we chose to gave up on this. – NicolasB Oct 06 '20 at 12:23
  • @NicolasB Thanks! I'm working on a solution without sqlite in the test environment now. – Boschman Oct 06 '20 at 16:23

0 Answers0