SQLite Forum

Decimal extension in amalgamation?
Login

Decimal extension in amalgamation?

(1) By Jay (poundifdef) on 2022-07-19 13:47:42 [link] [source]

Hello! I am writing to ask how, or if, (or when?) the decimal functions might be added to the amalgamation. It would be handy to be able to invoke them from a client library rather than just via the shell. I didn't see any compile flags for this (I suspect there are none) but would love to know the process for allowing this to happen.

(2) By Larry Brasfield (larrybr) on 2022-07-19 17:01:08 in reply to 1 [link] [source]

You can study the shell.c source to see how the ext/misc/decimal.c extension is statically added to the SQLite CLI.

As for if/when it might be added to the amalgamation: My prediction is that this will not happen anytime soon. SQLite is valued for being "light" in resource-constrained applications such as small devices.

(3) By SeverKetor on 2022-07-19 17:18:02 in reply to 1 [link] [source]

Can you just load it as an extension? Or is there something stopping you from loading extensions (I know Python requires an extra compilation flag to do so)?

(4.1) By Keith Medcalf (kmedcalf) on 2022-07-19 22:15:39 edited from 4.0 in reply to 1 [link] [source]

Append the extension source file(s) to the amalgamation.

Append the following code after all the extension source files have been appended (you need to edit it so that the initializers you want called are added to the auto_extension list):

int core_init(const char* dummy)
{
    int nErr = 0;

    nErr += sqlite3_auto_extension((void*)sqlite3_decimal_init);            // SQLite3 misc extension
    nErr += sqlite3_auto_extension((void*)sqlite3_eval_init);               // SQLite3 misc extension
    nErr += sqlite3_auto_extension((void*)sqlite3_fileio_init);             // SQLite3 misc extension
    nErr += sqlite3_auto_extension((void*)sqlite3_ieee_init);               // SQLite3 misc extension
    nErr += sqlite3_auto_extension((void*)sqlite3_nextchar_init);           // SQLite3 misc extension
    nErr += sqlite3_auto_extension((void*)sqlite3_percentile_init);         // SQLite3 misc extension
    nErr += sqlite3_auto_extension((void*)sqlite3_regexp_init);             // SQLite3 misc extension
    nErr += sqlite3_auto_extension((void*)sqlite3_rot_init);                // SQLite3 misc extension
    nErr += sqlite3_auto_extension((void*)sqlite3_totype_init);             // SQLite3 misc extension
    nErr += sqlite3_auto_extension((void*)sqlite3_uint_init);               // SQLite3 misc extension
    nErr += sqlite3_auto_extension((void*)sqlite3_zorder_init);             // SQLite3 misc extension

    nErr += sqlite3_auto_extension((void*)sqlite3_fossildelta_init);        // SQLite3 misc extension

#ifndef SQLITE_OMIT_VIRTUALTABLE
    nErr += sqlite3_auto_extension((void*)sqlite3_amatch_init);             // SQLite3 misc extension
    nErr += sqlite3_auto_extension((void*)sqlite3_btreeinfo_init);          // SQLite3 misc extension
    nErr += sqlite3_auto_extension((void*)sqlite3_carray_init);             // SQLite3 misc extension
    nErr += sqlite3_auto_extension((void*)sqlite3_closure_init);            // SQLite3 misc extension
    nErr += sqlite3_auto_extension((void*)sqlite3_csv_init);                // SQLite3 misc extension
    nErr += sqlite3_auto_extension((void*)sqlite3_fuzzer_init);             // SQLite3 misc extension
    nErr += sqlite3_auto_extension((void*)sqlite3_memstat_init);            // SQLite3 misc extension
    nErr += sqlite3_auto_extension((void*)sqlite3_prefixes_init);           // SQLite3 misc extension
    nErr += sqlite3_auto_extension((void*)sqlite3_series_init);             // SQLite3 misc extension
    nErr += sqlite3_auto_extension((void*)sqlite3_spellfix_init);           // SQLite3 misc extension
    nErr += sqlite3_auto_extension((void*)sqlite3_unionvtab_init);          // SQLite3 misc extension
    nErr += sqlite3_auto_extension((void*)sqlite3_vtshim_init);             // SQLite3 misc extension
    nErr += sqlite3_auto_extension((void*)sqlite3_wholenumber_init);        // SQLite3 misc extension
#ifdef SQLITE_ENABLE_VFSSTAT
    nErr += sqlite3_vfsstat_init((void*)dummy, (void*)0, (void*)0);         // SQLite3 misc extension
#endif
#endif

    return nErr ? SQLITE_ERROR : SQLITE_OK;
}

Then, when compiling the resulting amalgamation file, append the option -DSQLITE_EXTRA_INIT=core_init to the compiler command tail.

(5) By Jay (poundifdef) on 2022-07-22 02:28:45 in reply to 4.1 [source]

Understood - thank you for taking the time to write this out!