0

I didn't understand how sqlite3 works with custom functions. Simply I don't get how to add any custom function to a database.

Do I really need to compile the C code file under my machine and use the resulting DLL (I'm under windows) as an sqlite extension? If so, how about using this extension under other OS (mac/linux...)? I know sqlite is os-independent but...

I currently have: udf_xxx.c (not compiled), mysqlite3.db (populated); I'm running on windows10.

I'm going to use php + sqlite, probably under linux. I cannot make a custom sqlite build.

The main question is: how to implement a UDF cross-platform in an existent sqlite3 database?

Nereo Costacurta
  • 7,693
  • 4
  • 21
  • 27

1 Answers1

0

Using a C function is possible only by

  • calling sqlite3_create_function from C, or by
  • creating a DLL/shared library and loading it dynamically with the load_extension SQL function. This is disabled by default for security reasons, and it is very likely that your PHP does not have explicitly enabled it.

The easiest way to create a user-defined SQL function usable from PHP is to register a PHP function with PDO::sqliteCreateFunction (or the outdated SQLiteDatabase::createFunction).

CL.
  • 173,858
  • 17
  • 217
  • 259
  • that's wonderfull! So I need only to implement the script in php language (instead of C) and register it (presumably on every connection to the database) this function. Hoping this "experimental" pdo function will not cange so much in future. I'll test asap and be back, thank you for now! – Nereo Costacurta Mar 15 '16 at 09:47