createFunction abstract method

void createFunction({
  1. required String functionName,
  2. required ScalarFunction function,
  3. AllowedArgumentCount argumentCount = const AllowedArgumentCount.any(),
  4. bool deterministic = false,
  5. bool directOnly = true,
})

Creates a scalar function that can be called from sql queries sent against this database.

The functionName defines the (case insensitive) name of the function in sql. The utf8 encoding of functionName must not exceed a length of 255 bytes.

The argumentCount parameter can be used to declare how many arguments a function supports. If you need a function that can use multiple argument counts, you can call createFunction multiple times. The deterministic flag (defaults to false) can be set to indicate that the function always gives the same output when the input parameters are the same. This is a requirement for functions that are used in generated columns or partial indexes. It also allows the query planner for optimize by factoring invocations out of inner loops. The directOnly flag (defaults to true) is a security measure. When enabled, the function may only be invoked form top-level SQL, and cannot be used in VIEWs or TRIGGERs nor in schema structures (such as CHECK, DEFAULT, etc.). When directOnly is set to false, the function might be invoked when opening a malicious database file. sqlite3 recommends this flag for all application-defined functions, especially if they have side-effects or if they could potentially leak sensitive information.

The function can be any Dart closure, it's not restricted to top-level functions supported by Pointer.fromFunction. For more details on how the sql function behaves, see the documentation on ScalarFunction.

To register aggregate or window functions, see createAggregateFunction.

For more information, see https://www.sqlite.org/appfunc.html.

Implementation

void createFunction({
  required String functionName,
  required ScalarFunction function,
  AllowedArgumentCount argumentCount = const AllowedArgumentCount.any(),
  bool deterministic = false,
  bool directOnly = true,
});