diff --git a/Package.swift b/Package.swift index fcf48fe..a01d319 100644 --- a/Package.swift +++ b/Package.swift @@ -109,6 +109,7 @@ let package = Package( name: "CSQLite", targets: [ "CSQLite", + "CSQLiteExtensions", ]), ], traits: [ @@ -249,6 +250,35 @@ let package = Package( name: "ENABLE_STAT4", description: "Enables the sqlite_stat4 table" ), + // Statically linked extensions + .trait( + name: "CSQLITE_ENABLE_CARRAY_EXTENSION", + description: "Enables the statically linked carray extension" + ), + .trait( + name: "CSQLITE_ENABLE_DECIMAL_EXTENSION", + description: "Enables the statically linked decimal extension" + ), + .trait( + name: "CSQLITE_ENABLE_IEEE754_EXTENSION", + description: "Enables the statically linked ieee754 extension" + ), + .trait( + name: "CSQLITE_ENABLE_PERCENTILE_EXTENSION", + description: "Enables the statically linked percentile extension" + ), + .trait( + name: "CSQLITE_ENABLE_SERIES_EXTENSION", + description: "Enables the statically linked series extension" + ), + .trait( + name: "CSQLITE_ENABLE_SHA3_EXTENSION", + description: "Enables the statically linked sha3 extension" + ), + .trait( + name: "CSQLITE_ENABLE_UUID_EXTENSION", + description: "Enables the statically linked uuid extension" + ), // Default traits .default(enabledTraits: [ "DQS_0", @@ -270,6 +300,13 @@ let package = Package( "ENABLE_SNAPSHOT", "ENABLE_STMTVTAB", "ENABLE_STAT4", + "CSQLITE_ENABLE_CARRAY_EXTENSION", + "CSQLITE_ENABLE_DECIMAL_EXTENSION", + "CSQLITE_ENABLE_IEEE754_EXTENSION", + "CSQLITE_ENABLE_PERCENTILE_EXTENSION", + "CSQLITE_ENABLE_SERIES_EXTENSION", + "CSQLITE_ENABLE_SHA3_EXTENSION", + "CSQLITE_ENABLE_UUID_EXTENSION", ]), ], targets: [ @@ -277,19 +314,108 @@ let package = Package( // Targets can depend on other targets in this package and products from dependencies. .target( name: "CSQLite", - cSettings: compileTimeOptions + platformConfiguration + features + [ + cSettings: compileTimeOptions + platformConfiguration + features, + linkerSettings: [ + .linkedLibrary("m"), + ]), + .target( + name: "CSQLiteExtensions", + dependencies: [ + .targetItem(name: "CSQLiteCArrayExtension", condition: .when(traits: ["CSQLITE_ENABLE_CARRAY_EXTENSION"])), + .targetItem(name: "CSQLiteDecimalExtension", condition: .when(traits: ["CSQLITE_ENABLE_DECIMAL_EXTENSION"])), + .targetItem(name: "CSQLiteIEEE754Extension", condition: .when(traits: ["CSQLITE_ENABLE_IEEE754_EXTENSION"])), + .targetItem(name: "CSQLitePercentileExtension", condition: .when(traits: ["CSQLITE_ENABLE_PERCENTILE_EXTENSION"])), + .targetItem(name: "CSQLiteSeriesExtension", condition: .when(traits: ["CSQLITE_ENABLE_SERIES_EXTENSION"])), + .targetItem(name: "CSQLiteSHA3Extension", condition: .when(traits: ["CSQLITE_ENABLE_SHA3_EXTENSION"])), + .targetItem(name: "CSQLiteUUIDExtension", condition: .when(traits: ["CSQLITE_ENABLE_UUID_EXTENSION"])), + ]), + .target( + name: "CSQLiteCArrayExtension", + dependencies: [ + "CSQLite", + ], + path: "Sources/extensions/carray", + cSettings: [ // For statically linking extensions // https://sqlite.org/loadext.html#statically_linking_a_run_time_loadable_extension .define("SQLITE_CORE", to: "1"), + ]), + .target( + name: "CSQLiteDecimalExtension", + dependencies: [ + "CSQLite", ], - linkerSettings: [ - .linkedLibrary("m"), + path: "Sources/extensions/decimal", + cSettings: [ + // For statically linking extensions + // https://sqlite.org/loadext.html#statically_linking_a_run_time_loadable_extension + .define("SQLITE_CORE", to: "1"), + ]), + .target( + name: "CSQLiteIEEE754Extension", + dependencies: [ + "CSQLite", + ], + path: "Sources/extensions/ieee754", + cSettings: [ + // For statically linking extensions + // https://sqlite.org/loadext.html#statically_linking_a_run_time_loadable_extension + .define("SQLITE_CORE", to: "1"), + ]), + .target( + name: "CSQLitePercentileExtension", + dependencies: [ + "CSQLite", + ], + path: "Sources/extensions/percentile", + cSettings: [ + // For statically linking extensions + // https://sqlite.org/loadext.html#statically_linking_a_run_time_loadable_extension + .define("SQLITE_CORE", to: "1"), + ]), + .target( + name: "CSQLiteSeriesExtension", + dependencies: [ + "CSQLite", + ], + path: "Sources/extensions/series", + cSettings: [ + // For statically linking extensions + // https://sqlite.org/loadext.html#statically_linking_a_run_time_loadable_extension + .define("SQLITE_CORE", to: "1"), + ]), + .target( + name: "CSQLiteSHA3Extension", + dependencies: [ + "CSQLite", + ], + path: "Sources/extensions/sha3", + cSettings: [ + // For statically linking extensions + // https://sqlite.org/loadext.html#statically_linking_a_run_time_loadable_extension + .define("SQLITE_CORE", to: "1"), + ]), + .target( + name: "CSQLiteUUIDExtension", + dependencies: [ + "CSQLite", + ], + path: "Sources/extensions/uuid", + cSettings: [ + // For statically linking extensions + // https://sqlite.org/loadext.html#statically_linking_a_run_time_loadable_extension + .define("SQLITE_CORE", to: "1"), ]), .testTarget( name: "CSQLiteTests", dependencies: [ "CSQLite", - ]) + ]), + .testTarget( + name: "CSQLiteExtensionsTests", + dependencies: [ + "CSQLiteExtensions", + ]), ], cLanguageStandard: .gnu11 ) diff --git a/Package@swift-5.3.swift b/Package@swift-5.3.swift index eacc02b..6992968 100644 --- a/Package@swift-5.3.swift +++ b/Package@swift-5.3.swift @@ -92,6 +92,7 @@ let package = Package( name: "CSQLite", targets: [ "CSQLite", + "CSQLiteExtensions", ]), ], targets: [ @@ -99,19 +100,108 @@ let package = Package( // Targets can depend on other targets in this package and products from dependencies. .target( name: "CSQLite", - cSettings: compileTimeOptions + platformConfiguration + features + [ + cSettings: compileTimeOptions + platformConfiguration + features, + linkerSettings: [ + .linkedLibrary("m"), + ]), + .target( + name: "CSQLiteExtensions", + dependencies: [ + "CSQLiteCArrayExtension", + "CSQLiteDecimalExtension", + "CSQLiteIEEE754Extension", + "CSQLitePercentileExtension", + "CSQLiteSeriesExtension", + "CSQLiteSHA3Extension", + "CSQLiteUUIDExtension", + ]), + .target( + name: "CSQLiteCArrayExtension", + dependencies: [ + "CSQLite", + ], + path: "Sources/extensions/carray", + cSettings: [ // For statically linking extensions // https://sqlite.org/loadext.html#statically_linking_a_run_time_loadable_extension .define("SQLITE_CORE", to: "1"), + ]), + .target( + name: "CSQLiteDecimalExtension", + dependencies: [ + "CSQLite", ], - linkerSettings: [ - .linkedLibrary("m"), + path: "Sources/extensions/decimal", + cSettings: [ + // For statically linking extensions + // https://sqlite.org/loadext.html#statically_linking_a_run_time_loadable_extension + .define("SQLITE_CORE", to: "1"), + ]), + .target( + name: "CSQLiteIEEE754Extension", + dependencies: [ + "CSQLite", + ], + path: "Sources/extensions/ieee754", + cSettings: [ + // For statically linking extensions + // https://sqlite.org/loadext.html#statically_linking_a_run_time_loadable_extension + .define("SQLITE_CORE", to: "1"), + ]), + .target( + name: "CSQLitePercentileExtension", + dependencies: [ + "CSQLite", + ], + path: "Sources/extensions/percentile", + cSettings: [ + // For statically linking extensions + // https://sqlite.org/loadext.html#statically_linking_a_run_time_loadable_extension + .define("SQLITE_CORE", to: "1"), + ]), + .target( + name: "CSQLiteSeriesExtension", + dependencies: [ + "CSQLite", + ], + path: "Sources/extensions/series", + cSettings: [ + // For statically linking extensions + // https://sqlite.org/loadext.html#statically_linking_a_run_time_loadable_extension + .define("SQLITE_CORE", to: "1"), + ]), + .target( + name: "CSQLiteSHA3Extension", + dependencies: [ + "CSQLite", + ], + path: "Sources/extensions/sha3", + cSettings: [ + // For statically linking extensions + // https://sqlite.org/loadext.html#statically_linking_a_run_time_loadable_extension + .define("SQLITE_CORE", to: "1"), + ]), + .target( + name: "CSQLiteUUIDExtension", + dependencies: [ + "CSQLite", + ], + path: "Sources/extensions/uuid", + cSettings: [ + // For statically linking extensions + // https://sqlite.org/loadext.html#statically_linking_a_run_time_loadable_extension + .define("SQLITE_CORE", to: "1"), ]), .testTarget( name: "CSQLiteTests", dependencies: [ "CSQLite", - ]) + ]), + .testTarget( + name: "CSQLiteExtensionsTests", + dependencies: [ + "CSQLiteExtensions", + ]), ], cLanguageStandard: .gnu11 ) diff --git a/README.md b/README.md index 676d3c1..1dc443a 100644 --- a/README.md +++ b/README.md @@ -81,6 +81,20 @@ The following traits enable commonly-used SQLite features: > [!NOTE] > The `ENABLE_SESSION` trait also sets the `ENABLE_PREUPDATE_HOOK` trait. +### Statically Linked Extensions + +The following traits enable statically linked SQLite extensions and helper functions for automatic extension registration: + +| Package Trait | Default | SQLite Extension | +| --- | :---: | --- | +| CSQLITE_ENABLE_CARRAY_EXTENSION | Y | [carray](https://sqlite.org/carray.html) | +| CSQLITE_ENABLE_DECIMAL_EXTENSION | Y | [decimal](https://sqlite.org/floatingpoint.html#the_decimal_c_extension) | +| CSQLITE_ENABLE_IEEE754_EXTENSION | Y | [ieee754](https://sqlite.org/floatingpoint.html#the_ieee754_c_extension) | +| CSQLITE_ENABLE_PERCENTILE_EXTENSION | Y | [percentile](https://www.sqlite.org/src/file/ext/misc/percentile.c) | +| CSQLITE_ENABLE_SERIES_EXTENSION | Y | [series](https://www.sqlite.org/src/file/ext/misc/series.c) | +| CSQLITE_ENABLE_SHA3_EXTENSION | Y | [sha3](https://www.sqlite.org/src/file/ext/misc/shathree.c) | +| CSQLITE_ENABLE_UUID_EXTENSION | Y | [uuid](https://www.sqlite.org/src/file/ext/misc/uuid.c) | + ## License SQLite is in the [public domain](https://sqlite.org/copyright.html). diff --git a/Sources/CSQLite/csqlite_shims.c b/Sources/CSQLite/csqlite_shims.c index e5a444d..5d83d8d 100644 --- a/Sources/CSQLite/csqlite_shims.c +++ b/Sources/CSQLite/csqlite_shims.c @@ -290,82 +290,3 @@ int csqlite_sqlite3_vtab_uses_all_schemas(sqlite3 *db) { return sqlite3_vtab_config(db, SQLITE_VTAB_USES_ALL_SCHEMAS); } - -// MARK: - Database extensions - -void sqlite3_carray_init(void); -int csqlite_sqlite3_auto_extension_carray() -{ - return sqlite3_auto_extension(sqlite3_carray_init); -} - -int csqlite_sqlite3_cancel_auto_extension_carray() -{ - return sqlite3_cancel_auto_extension(sqlite3_carray_init); -} - -void sqlite3_decimal_init(void); -int csqlite_sqlite3_auto_extension_decimal() -{ - return sqlite3_auto_extension(sqlite3_decimal_init); -} - -int csqlite_sqlite3_cancel_auto_extension_decimal() -{ - return sqlite3_cancel_auto_extension(sqlite3_decimal_init); -} - -void sqlite3_ieee_init(void); -int csqlite_sqlite3_auto_extension_ieee754() -{ - return sqlite3_auto_extension(sqlite3_ieee_init); -} - -int csqlite_sqlite3_cancel_auto_extension_ieee754() -{ - return sqlite3_cancel_auto_extension(sqlite3_ieee_init); -} - -void sqlite3_percentile_init(void); -int csqlite_sqlite3_auto_extension_percentile() -{ - return sqlite3_auto_extension(sqlite3_percentile_init); -} - -int csqlite_sqlite3_cancel_auto_extension_percentile() -{ - return sqlite3_cancel_auto_extension(sqlite3_percentile_init); -} - -void sqlite3_series_init(void); -int csqlite_sqlite3_auto_extension_series() -{ - return sqlite3_auto_extension(sqlite3_series_init); -} - -int csqlite_sqlite3_cancel_auto_extension_series() -{ - return sqlite3_cancel_auto_extension(sqlite3_series_init); -} - -void sqlite3_shathree_init(void); -int csqlite_sqlite3_auto_extension_sha3() -{ - return sqlite3_auto_extension(sqlite3_shathree_init); -} - -int csqlite_sqlite3_cancel_auto_extension_sha3() -{ - return sqlite3_cancel_auto_extension(sqlite3_shathree_init); -} - -void sqlite3_uuid_init(void); -int csqlite_sqlite3_auto_extension_uuid() -{ - return sqlite3_auto_extension(sqlite3_uuid_init); -} - -int csqlite_sqlite3_cancel_auto_extension_uuid() -{ - return sqlite3_cancel_auto_extension(sqlite3_uuid_init); -} diff --git a/Sources/CSQLite/include/csqlite_shims.h b/Sources/CSQLite/include/csqlite_shims.h index b07fa9f..d0676ce 100644 --- a/Sources/CSQLite/include/csqlite_shims.h +++ b/Sources/CSQLite/include/csqlite_shims.h @@ -139,41 +139,3 @@ int csqlite_sqlite3_vtab_config_innocuous(sqlite3 *db); int csqlite_sqlite3_vtab_config_directonly(sqlite3 *db); /// Equivalent to `sqlite3_vtab_config(db, SQLITE_VTAB_USES_ALL_SCHEMAS)` int csqlite_sqlite3_vtab_uses_all_schemas(sqlite3 *db); - -// MARK: - Database extensions -// See https://sqlite.org/loadext.html - -/// Equivalent to `sqlite3_auto_extension(sqlite3_carray_init)` -int csqlite_sqlite3_auto_extension_carray(void); -/// Equivalent to `sqlite3_cancel_auto_extension(sqlite3_carray_init)` -int csqlite_sqlite3_cancel_auto_extension_carray(void); - -/// Equivalent to `sqlite3_auto_extension(sqlite3_decimal_init)` -int csqlite_sqlite3_auto_extension_decimal(void); -/// Equivalent to `sqlite3_cancel_auto_extension(sqlite3_decimal_init)` -int csqlite_sqlite3_cancel_auto_extension_decimal(void); - -/// Equivalent to `sqlite3_auto_extension(sqlite3_ieee_init)` -int csqlite_sqlite3_auto_extension_ieee754(void); -/// Equivalent to `sqlite3_cancel_auto_extension(sqlite3_ieee_init)` -int csqlite_sqlite3_cancel_auto_extension_ieee754(void); - -/// Equivalent to `sqlite3_auto_extension(sqlite3_percentile_init)` -int csqlite_sqlite3_auto_extension_percentile(void); -/// Equivalent to `sqlite3_cancel_auto_extension(sqlite3_percentile_init)` -int csqlite_sqlite3_cancel_auto_extension_percentile(void); - -/// Equivalent to `sqlite3_auto_extension(sqlite3_series_init)` -int csqlite_sqlite3_auto_extension_series(void); -/// Equivalent to `sqlite3_cancel_auto_extension(sqlite3_series_init)` -int csqlite_sqlite3_cancel_auto_extension_series(void); - -/// Equivalent to `sqlite3_auto_extension(sqlite3_shathree_init)` -int csqlite_sqlite3_auto_extension_sha3(void); -/// Equivalent to `sqlite3_cancel_auto_extension(sqlite3_shathree_init)` -int csqlite_sqlite3_cancel_auto_extension_sha3(void); - -/// Equivalent to `sqlite3_auto_extension(sqlite3_uuid_init)` -int csqlite_sqlite3_auto_extension_uuid(void); -/// Equivalent to `sqlite3_cancel_auto_extension(sqlite3_uuid_init)` -int csqlite_sqlite3_cancel_auto_extension_uuid(void); diff --git a/Sources/CSQLite/include/module.modulemap b/Sources/CSQLite/include/module.modulemap index a569ebe..d64a094 100644 --- a/Sources/CSQLite/include/module.modulemap +++ b/Sources/CSQLite/include/module.modulemap @@ -1,7 +1,6 @@ module CSQLite { header "sqlite3.h" header "sqlite3ext.h" - header "carray.h" header "csqlite_shims.h" export * } diff --git a/Sources/CSQLiteExtensions/CSQLiteExtensions.swift b/Sources/CSQLiteExtensions/CSQLiteExtensions.swift new file mode 100644 index 0000000..22a5e5d --- /dev/null +++ b/Sources/CSQLiteExtensions/CSQLiteExtensions.swift @@ -0,0 +1,46 @@ +/* + ** 2025-05-30 + ** + ** The author disclaims copyright to this source code. In place of + ** a legal notice, here is a blessing: + ** + ** May you do good and not evil. + ** May you find forgiveness for yourself and forgive others. + ** May you share freely, never taking more than you give. + ** + ****************************************************************************** + ** + ** Functions to manage automatic database extension registration from Swift. + */ + +#if false +@_exported import CSQLite +#endif + +#if swift(<6.1) || CSQLITE_ENABLE_CARRAY_EXTENSION +@_exported import CSQLiteCArrayExtension +#endif + +#if swift(<6.1) || CSQLITE_ENABLE_DECIMAL_EXTENSION +@_exported import CSQLiteDecimalExtension +#endif + +#if swift(<6.1) || CSQLITE_ENABLE_IEEE754_EXTENSION +@_exported import CSQLiteIEEE754Extension +#endif + +#if swift(<6.1) || CSQLITE_ENABLE_PERCENTILE_EXTENSION +@_exported import CSQLitePercentileExtension +#endif + +#if swift(<6.1) || CSQLITE_ENABLE_SERIES_EXTENSION +@_exported import CSQLiteSeriesExtension +#endif + +#if swift(<6.1) || CSQLITE_ENABLE_SHA3_EXTENSION +@_exported import CSQLiteSHA3Extension +#endif + +#if swift(<6.1) || CSQLITE_ENABLE_UUID_EXTENSION +@_exported import CSQLiteUUIDExtension +#endif diff --git a/Sources/CSQLite/carray.c b/Sources/extensions/carray/carray.c similarity index 100% rename from Sources/CSQLite/carray.c rename to Sources/extensions/carray/carray.c diff --git a/Sources/extensions/carray/csqlite_carray_extension.c b/Sources/extensions/carray/csqlite_carray_extension.c new file mode 100644 index 0000000..6bc3b95 --- /dev/null +++ b/Sources/extensions/carray/csqlite_carray_extension.c @@ -0,0 +1,28 @@ +/* + ** 2025-05-30 + ** + ** The author disclaims copyright to this source code. In place of + ** a legal notice, here is a blessing: + ** + ** May you do good and not evil. + ** May you find forgiveness for yourself and forgive others. + ** May you share freely, never taking more than you give. + ** + ****************************************************************************** + ** + ** Functions to manage automatic database extension registration from Swift. + */ + +#include "csqlite_carray_extension.h" +#include "sqlite3.h" + +void sqlite3_carray_init(void); +int csqlite_sqlite3_auto_extension_carray() +{ + return sqlite3_auto_extension(sqlite3_carray_init); +} + +int csqlite_sqlite3_cancel_auto_extension_carray() +{ + return sqlite3_cancel_auto_extension(sqlite3_carray_init); +} diff --git a/Sources/CSQLite/include/carray.h b/Sources/extensions/carray/include/carray.h similarity index 100% rename from Sources/CSQLite/include/carray.h rename to Sources/extensions/carray/include/carray.h diff --git a/Sources/extensions/carray/include/csqlite_carray_extension.h b/Sources/extensions/carray/include/csqlite_carray_extension.h new file mode 100644 index 0000000..0a6e54d --- /dev/null +++ b/Sources/extensions/carray/include/csqlite_carray_extension.h @@ -0,0 +1,22 @@ +/* + ** 2025-05-30 + ** + ** The author disclaims copyright to this source code. In place of + ** a legal notice, here is a blessing: + ** + ** May you do good and not evil. + ** May you find forgiveness for yourself and forgive others. + ** May you share freely, never taking more than you give. + ** + ****************************************************************************** + ** + ** Functions to manage automatic database extension registration from Swift. + */ + +// MARK: - Database extensions +// See https://sqlite.org/loadext.html + +/// Equivalent to `sqlite3_auto_extension(sqlite3_carray_init)` +int csqlite_sqlite3_auto_extension_carray(void); +/// Equivalent to `sqlite3_cancel_auto_extension(sqlite3_carray_init)` +int csqlite_sqlite3_cancel_auto_extension_carray(void); diff --git a/Sources/extensions/carray/include/module.modulemap b/Sources/extensions/carray/include/module.modulemap new file mode 100644 index 0000000..d3611dc --- /dev/null +++ b/Sources/extensions/carray/include/module.modulemap @@ -0,0 +1,5 @@ +module CSQLiteCArrayExtension { + header "carray.h" + header "csqlite_carray_extension.h" + export * +} diff --git a/Sources/extensions/decimal/csqlite_decimal_extension.c b/Sources/extensions/decimal/csqlite_decimal_extension.c new file mode 100644 index 0000000..018e8be --- /dev/null +++ b/Sources/extensions/decimal/csqlite_decimal_extension.c @@ -0,0 +1,28 @@ +/* + ** 2025-05-30 + ** + ** The author disclaims copyright to this source code. In place of + ** a legal notice, here is a blessing: + ** + ** May you do good and not evil. + ** May you find forgiveness for yourself and forgive others. + ** May you share freely, never taking more than you give. + ** + ****************************************************************************** + ** + ** Functions to manage automatic database extension registration from Swift. + */ + +#include "csqlite_decimal_extension.h" +#include "sqlite3.h" + +void sqlite3_decimal_init(void); +int csqlite_sqlite3_auto_extension_decimal() +{ + return sqlite3_auto_extension(sqlite3_decimal_init); +} + +int csqlite_sqlite3_cancel_auto_extension_decimal() +{ + return sqlite3_cancel_auto_extension(sqlite3_decimal_init); +} diff --git a/Sources/CSQLite/decimal.c b/Sources/extensions/decimal/decimal.c similarity index 100% rename from Sources/CSQLite/decimal.c rename to Sources/extensions/decimal/decimal.c diff --git a/Sources/extensions/decimal/include/csqlite_decimal_extension.h b/Sources/extensions/decimal/include/csqlite_decimal_extension.h new file mode 100644 index 0000000..05a1f1f --- /dev/null +++ b/Sources/extensions/decimal/include/csqlite_decimal_extension.h @@ -0,0 +1,22 @@ +/* + ** 2025-05-30 + ** + ** The author disclaims copyright to this source code. In place of + ** a legal notice, here is a blessing: + ** + ** May you do good and not evil. + ** May you find forgiveness for yourself and forgive others. + ** May you share freely, never taking more than you give. + ** + ****************************************************************************** + ** + ** Functions to manage automatic database extension registration from Swift. + */ + +// MARK: - Database extensions +// See https://sqlite.org/loadext.html + +/// Equivalent to `sqlite3_auto_extension(sqlite3_decimal_init)` +int csqlite_sqlite3_auto_extension_decimal(void); +/// Equivalent to `sqlite3_cancel_auto_extension(sqlite3_decimal_init)` +int csqlite_sqlite3_cancel_auto_extension_decimal(void); diff --git a/Sources/extensions/decimal/include/module.modulemap b/Sources/extensions/decimal/include/module.modulemap new file mode 100644 index 0000000..663c837 --- /dev/null +++ b/Sources/extensions/decimal/include/module.modulemap @@ -0,0 +1,4 @@ +module CSQLiteDecimalExtension { + header "csqlite_decimal_extension.h" + export * +} diff --git a/Sources/extensions/ieee754/csqlite_ieee754_extension.c b/Sources/extensions/ieee754/csqlite_ieee754_extension.c new file mode 100644 index 0000000..1ac1076 --- /dev/null +++ b/Sources/extensions/ieee754/csqlite_ieee754_extension.c @@ -0,0 +1,28 @@ +/* + ** 2025-05-30 + ** + ** The author disclaims copyright to this source code. In place of + ** a legal notice, here is a blessing: + ** + ** May you do good and not evil. + ** May you find forgiveness for yourself and forgive others. + ** May you share freely, never taking more than you give. + ** + ****************************************************************************** + ** + ** Functions to manage automatic database extension registration from Swift. + */ + +#include "csqlite_ieee754_extension.h" +#include "sqlite3.h" + +void sqlite3_ieee_init(void); +int csqlite_sqlite3_auto_extension_ieee754() +{ + return sqlite3_auto_extension(sqlite3_ieee_init); +} + +int csqlite_sqlite3_cancel_auto_extension_ieee754() +{ + return sqlite3_cancel_auto_extension(sqlite3_ieee_init); +} diff --git a/Sources/CSQLite/ieee754.c b/Sources/extensions/ieee754/ieee754.c similarity index 100% rename from Sources/CSQLite/ieee754.c rename to Sources/extensions/ieee754/ieee754.c diff --git a/Sources/extensions/ieee754/include/csqlite_ieee754_extension.h b/Sources/extensions/ieee754/include/csqlite_ieee754_extension.h new file mode 100644 index 0000000..50417d5 --- /dev/null +++ b/Sources/extensions/ieee754/include/csqlite_ieee754_extension.h @@ -0,0 +1,22 @@ +/* + ** 2025-05-30 + ** + ** The author disclaims copyright to this source code. In place of + ** a legal notice, here is a blessing: + ** + ** May you do good and not evil. + ** May you find forgiveness for yourself and forgive others. + ** May you share freely, never taking more than you give. + ** + ****************************************************************************** + ** + ** Functions to manage automatic database extension registration from Swift. + */ + +// MARK: - Database extensions +// See https://sqlite.org/loadext.html + +/// Equivalent to `sqlite3_auto_extension(sqlite3_ieee_init)` +int csqlite_sqlite3_auto_extension_ieee754(void); +/// Equivalent to `sqlite3_cancel_auto_extension(sqlite3_ieee_init)` +int csqlite_sqlite3_cancel_auto_extension_ieee754(void); diff --git a/Sources/extensions/ieee754/include/module.modulemap b/Sources/extensions/ieee754/include/module.modulemap new file mode 100644 index 0000000..a2390e9 --- /dev/null +++ b/Sources/extensions/ieee754/include/module.modulemap @@ -0,0 +1,4 @@ +module CSQLiteIEEE754Extension { + header "csqlite_ieee754_extension.h" + export * +} diff --git a/Sources/extensions/percentile/csqlite_percentile_extension.c b/Sources/extensions/percentile/csqlite_percentile_extension.c new file mode 100644 index 0000000..1af1bf8 --- /dev/null +++ b/Sources/extensions/percentile/csqlite_percentile_extension.c @@ -0,0 +1,28 @@ +/* + ** 2025-05-30 + ** + ** The author disclaims copyright to this source code. In place of + ** a legal notice, here is a blessing: + ** + ** May you do good and not evil. + ** May you find forgiveness for yourself and forgive others. + ** May you share freely, never taking more than you give. + ** + ****************************************************************************** + ** + ** Functions to manage automatic database extension registration from Swift. + */ + +#include "csqlite_percentile_extension.h" +#include "sqlite3.h" + +void sqlite3_percentile_init(void); +int csqlite_sqlite3_auto_extension_percentile() +{ + return sqlite3_auto_extension(sqlite3_percentile_init); +} + +int csqlite_sqlite3_cancel_auto_extension_percentile() +{ + return sqlite3_cancel_auto_extension(sqlite3_percentile_init); +} diff --git a/Sources/extensions/percentile/include/csqlite_percentile_extension.h b/Sources/extensions/percentile/include/csqlite_percentile_extension.h new file mode 100644 index 0000000..d379b61 --- /dev/null +++ b/Sources/extensions/percentile/include/csqlite_percentile_extension.h @@ -0,0 +1,22 @@ +/* + ** 2025-05-30 + ** + ** The author disclaims copyright to this source code. In place of + ** a legal notice, here is a blessing: + ** + ** May you do good and not evil. + ** May you find forgiveness for yourself and forgive others. + ** May you share freely, never taking more than you give. + ** + ****************************************************************************** + ** + ** Functions to manage automatic database extension registration from Swift. + */ + +// MARK: - Database extensions +// See https://sqlite.org/loadext.html + +/// Equivalent to `sqlite3_auto_extension(sqlite3_percentile_init)` +int csqlite_sqlite3_auto_extension_percentile(void); +/// Equivalent to `sqlite3_cancel_auto_extension(sqlite3_percentile_init)` +int csqlite_sqlite3_cancel_auto_extension_percentile(void); diff --git a/Sources/extensions/percentile/include/module.modulemap b/Sources/extensions/percentile/include/module.modulemap new file mode 100644 index 0000000..682c716 --- /dev/null +++ b/Sources/extensions/percentile/include/module.modulemap @@ -0,0 +1,4 @@ +module CSQLitePercentileExtension { + header "csqlite_percentile_extension.h" + export * +} diff --git a/Sources/CSQLite/percentile.c b/Sources/extensions/percentile/percentile.c similarity index 100% rename from Sources/CSQLite/percentile.c rename to Sources/extensions/percentile/percentile.c diff --git a/Sources/extensions/series/csqlite_series_extension.c b/Sources/extensions/series/csqlite_series_extension.c new file mode 100644 index 0000000..e59a71a --- /dev/null +++ b/Sources/extensions/series/csqlite_series_extension.c @@ -0,0 +1,28 @@ +/* + ** 2025-05-30 + ** + ** The author disclaims copyright to this source code. In place of + ** a legal notice, here is a blessing: + ** + ** May you do good and not evil. + ** May you find forgiveness for yourself and forgive others. + ** May you share freely, never taking more than you give. + ** + ****************************************************************************** + ** + ** Functions to manage automatic database extension registration from Swift. + */ + +#include "csqlite_series_extension.h" +#include "sqlite3.h" + +void sqlite3_series_init(void); +int csqlite_sqlite3_auto_extension_series() +{ + return sqlite3_auto_extension(sqlite3_series_init); +} + +int csqlite_sqlite3_cancel_auto_extension_series() +{ + return sqlite3_cancel_auto_extension(sqlite3_series_init); +} diff --git a/Sources/extensions/series/include/csqlite_series_extension.h b/Sources/extensions/series/include/csqlite_series_extension.h new file mode 100644 index 0000000..0619aa0 --- /dev/null +++ b/Sources/extensions/series/include/csqlite_series_extension.h @@ -0,0 +1,22 @@ +/* + ** 2025-05-30 + ** + ** The author disclaims copyright to this source code. In place of + ** a legal notice, here is a blessing: + ** + ** May you do good and not evil. + ** May you find forgiveness for yourself and forgive others. + ** May you share freely, never taking more than you give. + ** + ****************************************************************************** + ** + ** Functions to manage automatic database extension registration from Swift. + */ + +// MARK: - Database extensions +// See https://sqlite.org/loadext.html + +/// Equivalent to `sqlite3_auto_extension(sqlite3_series_init)` +int csqlite_sqlite3_auto_extension_series(void); +/// Equivalent to `sqlite3_cancel_auto_extension(sqlite3_series_init)` +int csqlite_sqlite3_cancel_auto_extension_series(void); diff --git a/Sources/extensions/series/include/module.modulemap b/Sources/extensions/series/include/module.modulemap new file mode 100644 index 0000000..5789092 --- /dev/null +++ b/Sources/extensions/series/include/module.modulemap @@ -0,0 +1,4 @@ +module CSQLiteSeriesExtension { + header "csqlite_series_extension.h" + export * +} diff --git a/Sources/CSQLite/series.c b/Sources/extensions/series/series.c similarity index 100% rename from Sources/CSQLite/series.c rename to Sources/extensions/series/series.c diff --git a/Sources/extensions/sha3/csqlite_sha3_extension.c b/Sources/extensions/sha3/csqlite_sha3_extension.c new file mode 100644 index 0000000..e3ed958 --- /dev/null +++ b/Sources/extensions/sha3/csqlite_sha3_extension.c @@ -0,0 +1,28 @@ +/* + ** 2025-05-30 + ** + ** The author disclaims copyright to this source code. In place of + ** a legal notice, here is a blessing: + ** + ** May you do good and not evil. + ** May you find forgiveness for yourself and forgive others. + ** May you share freely, never taking more than you give. + ** + ****************************************************************************** + ** + ** Functions to manage automatic database extension registration from Swift. + */ + +#include "csqlite_sha3_extension.h" +#include "sqlite3.h" + +void sqlite3_shathree_init(void); +int csqlite_sqlite3_auto_extension_sha3() +{ + return sqlite3_auto_extension(sqlite3_shathree_init); +} + +int csqlite_sqlite3_cancel_auto_extension_sha3() +{ + return sqlite3_cancel_auto_extension(sqlite3_shathree_init); +} diff --git a/Sources/extensions/sha3/include/csqlite_sha3_extension.h b/Sources/extensions/sha3/include/csqlite_sha3_extension.h new file mode 100644 index 0000000..19b5ec6 --- /dev/null +++ b/Sources/extensions/sha3/include/csqlite_sha3_extension.h @@ -0,0 +1,22 @@ +/* + ** 2025-05-30 + ** + ** The author disclaims copyright to this source code. In place of + ** a legal notice, here is a blessing: + ** + ** May you do good and not evil. + ** May you find forgiveness for yourself and forgive others. + ** May you share freely, never taking more than you give. + ** + ****************************************************************************** + ** + ** Functions to manage automatic database extension registration from Swift. + */ + +// MARK: - Database extensions +// See https://sqlite.org/loadext.html + +/// Equivalent to `sqlite3_auto_extension(sqlite3_shathree_init)` +int csqlite_sqlite3_auto_extension_sha3(void); +/// Equivalent to `sqlite3_cancel_auto_extension(sqlite3_shathree_init)` +int csqlite_sqlite3_cancel_auto_extension_sha3(void); diff --git a/Sources/extensions/sha3/include/module.modulemap b/Sources/extensions/sha3/include/module.modulemap new file mode 100644 index 0000000..497ec49 --- /dev/null +++ b/Sources/extensions/sha3/include/module.modulemap @@ -0,0 +1,4 @@ +module CSQLiteSHA3Extension { + header "csqlite_sha3_extension.h" + export * +} diff --git a/Sources/CSQLite/shathree.c b/Sources/extensions/sha3/shathree.c similarity index 100% rename from Sources/CSQLite/shathree.c rename to Sources/extensions/sha3/shathree.c diff --git a/Sources/extensions/uuid/csqlite_uuid_extension.c b/Sources/extensions/uuid/csqlite_uuid_extension.c new file mode 100644 index 0000000..0b1c39b --- /dev/null +++ b/Sources/extensions/uuid/csqlite_uuid_extension.c @@ -0,0 +1,28 @@ +/* + ** 2025-05-30 + ** + ** The author disclaims copyright to this source code. In place of + ** a legal notice, here is a blessing: + ** + ** May you do good and not evil. + ** May you find forgiveness for yourself and forgive others. + ** May you share freely, never taking more than you give. + ** + ****************************************************************************** + ** + ** Functions to manage automatic database extension registration from Swift. + */ + +#include "csqlite_uuid_extension.h" +#include "sqlite3.h" + +void sqlite3_uuid_init(void); +int csqlite_sqlite3_auto_extension_uuid() +{ + return sqlite3_auto_extension(sqlite3_uuid_init); +} + +int csqlite_sqlite3_cancel_auto_extension_uuid() +{ + return sqlite3_cancel_auto_extension(sqlite3_uuid_init); +} diff --git a/Sources/extensions/uuid/include/csqlite_uuid_extension.h b/Sources/extensions/uuid/include/csqlite_uuid_extension.h new file mode 100644 index 0000000..e218831 --- /dev/null +++ b/Sources/extensions/uuid/include/csqlite_uuid_extension.h @@ -0,0 +1,22 @@ +/* + ** 2025-05-30 + ** + ** The author disclaims copyright to this source code. In place of + ** a legal notice, here is a blessing: + ** + ** May you do good and not evil. + ** May you find forgiveness for yourself and forgive others. + ** May you share freely, never taking more than you give. + ** + ****************************************************************************** + ** + ** Functions to manage automatic database extension registration from Swift. + */ + +// MARK: - Database extensions +// See https://sqlite.org/loadext.html + +/// Equivalent to `sqlite3_auto_extension(sqlite3_uuid_init)` +int csqlite_sqlite3_auto_extension_uuid(void); +/// Equivalent to `sqlite3_cancel_auto_extension(sqlite3_uuid_init)` +int csqlite_sqlite3_cancel_auto_extension_uuid(void); diff --git a/Sources/extensions/uuid/include/module.modulemap b/Sources/extensions/uuid/include/module.modulemap new file mode 100644 index 0000000..f73c296 --- /dev/null +++ b/Sources/extensions/uuid/include/module.modulemap @@ -0,0 +1,4 @@ +module CSQLiteUUIDExtension { + header "csqlite_uuid_extension.h" + export * +} diff --git a/Sources/CSQLite/uuid.c b/Sources/extensions/uuid/uuid.c similarity index 100% rename from Sources/CSQLite/uuid.c rename to Sources/extensions/uuid/uuid.c diff --git a/Tests/CSQLiteTests/CSQLiteExtensionTests.swift b/Tests/CSQLiteExtensionsTests/CSQLiteExtensionsTests.swift similarity index 91% rename from Tests/CSQLiteTests/CSQLiteExtensionTests.swift rename to Tests/CSQLiteExtensionsTests/CSQLiteExtensionsTests.swift index f58bdbf..481c6f3 100644 --- a/Tests/CSQLiteTests/CSQLiteExtensionTests.swift +++ b/Tests/CSQLiteExtensionsTests/CSQLiteExtensionsTests.swift @@ -1,5 +1,5 @@ /* - ** 2021-06-08 + ** 2024-05-24 ** ** The author disclaims copyright to this source code. In place of ** a legal notice, here is a blessing: @@ -10,11 +10,12 @@ ** ****************************************************************************** ** - ** Basic tests of CSQLite statically-linked extension functionality. + ** Basic tests of CSQLite statically linked extension functionality. */ import XCTest -@testable import CSQLite +import CSQLite +@testable import CSQLiteExtensions final class CSQLiteExtensionTests: XCTestCase { #if swift(<6.1) || OMIT_AUTOINIT @@ -25,6 +26,7 @@ final class CSQLiteExtensionTests: XCTestCase { } #endif +#if swift(<6.1) || CSQLITE_ENABLE_CARRAY_EXTENSION func testCarray() { XCTAssertEqual(csqlite_sqlite3_auto_extension_carray(), SQLITE_OK) @@ -50,7 +52,9 @@ final class CSQLiteExtensionTests: XCTestCase { XCTAssertEqual(sqlite3_finalize(stmt), SQLITE_OK) XCTAssertEqual(sqlite3_close(db), SQLITE_OK) } +#endif +#if swift(<6.1) || CSQLITE_ENABLE_DECIMAL_EXTENSION func testDecimal() { XCTAssertEqual(csqlite_sqlite3_auto_extension_decimal(), SQLITE_OK) @@ -66,7 +70,9 @@ final class CSQLiteExtensionTests: XCTestCase { XCTAssertEqual(sqlite3_finalize(stmt), SQLITE_OK) XCTAssertEqual(sqlite3_close(db), SQLITE_OK) } +#endif +#if swift(<6.1) || CSQLITE_ENABLE_IEEE754_EXTENSION func testIEEE() { XCTAssertEqual(csqlite_sqlite3_auto_extension_ieee754(), SQLITE_OK) @@ -82,7 +88,9 @@ final class CSQLiteExtensionTests: XCTestCase { XCTAssertEqual(sqlite3_finalize(stmt), SQLITE_OK) XCTAssertEqual(sqlite3_close(db), SQLITE_OK) } +#endif +#if swift(<6.1) || CSQLITE_ENABLE_PERCENTILE_EXTENSION func testPercentile() { XCTAssertEqual(csqlite_sqlite3_auto_extension_percentile(), SQLITE_OK) @@ -97,7 +105,9 @@ final class CSQLiteExtensionTests: XCTestCase { XCTAssertEqual(sqlite3_finalize(stmt), SQLITE_OK) XCTAssertEqual(sqlite3_close(db), SQLITE_OK) } +#endif +#if swift(<6.1) || CSQLITE_ENABLE_SERIES_EXTENSION func testSeries() { XCTAssertEqual(csqlite_sqlite3_auto_extension_series(), SQLITE_OK) @@ -116,7 +126,9 @@ final class CSQLiteExtensionTests: XCTestCase { XCTAssertEqual(sqlite3_finalize(stmt), SQLITE_OK) XCTAssertEqual(sqlite3_close(db), SQLITE_OK) } +#endif +#if swift(<6.1) || CSQLITE_ENABLE_SHA3_EXTENSION func testSHA3() { XCTAssertEqual(csqlite_sqlite3_auto_extension_sha3(), SQLITE_OK) @@ -132,7 +144,9 @@ final class CSQLiteExtensionTests: XCTestCase { XCTAssertEqual(sqlite3_finalize(stmt), SQLITE_OK) XCTAssertEqual(sqlite3_close(db), SQLITE_OK) } +#endif +#if swift(<6.1) || CSQLITE_ENABLE_UUID_EXTENSION func testUUID() { XCTAssertEqual(csqlite_sqlite3_auto_extension_uuid(), SQLITE_OK) @@ -156,4 +170,5 @@ final class CSQLiteExtensionTests: XCTestCase { XCTAssertEqual(sqlite3_finalize(stmt), SQLITE_OK) XCTAssertEqual(sqlite3_close(db), SQLITE_OK) } +#endif }