且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在 SQLite 中创建自定义函数

更新时间:2022-06-27 05:53:47

SQLite 没有存储函数/存储过程语言.所以 CREATE FUNCTION 不起作用.您可以做的是将函数从 c 库映射到 SQL 函数(用户定义的函数).为此,请使用 SQLite 的 C API(请参阅:http://www.sqlite.org/c3ref/create_function.html)

SQLite does not have a stored function/stored procedure language. So CREATE FUNCTION does not work. What you can do though is map functions from a c library to SQL functions (user-defined functions). To do that, use SQLite's C API (see: http://www.sqlite.org/c3ref/create_function.html)

如果您不使用 C API,您的包装器 API 可能会定义一些允许您访问此功能的内容,例如:

If you're not using the C API, your wrapper API may define something that allows you access to this feature, see for example:

  • PHP sqlite_create_function() (http://www.php.net/manual/en/function.sqlite-create-function.php)
  • Python sqlite3.create_function() (http://docs.python.org/3/library/sqlite3.html#sqlite3.Connection.create_function)
  • Perl $dbh->sqlite_create_function($name,$argc,$code_ref,$flags) (https://metacpan.org/pod/DBD::SQLite#$dbh-%3Esqlite_create_function(-$name,-$argc,-$code_ref,-$flags-))