diff options
author | John Turner <jturner.usa@gmail.com> | 2025-09-14 00:16:10 -0400 |
---|---|---|
committer | John Turner <jturner.usa@gmail.com> | 2025-09-14 00:16:10 -0400 |
commit | 13e0821fd783a1d5083d825af53cf20e8dcbfd76 (patch) | |
tree | 1ea363b0f13b3e87d177100e6ae6b9f30a2de1b8 /subprojects/boost-sqlite/doc/reference/collation.adoc | |
parent | aa55cb93036a89c64c08e08f4e1de4fa1fd5a775 (diff) | |
parent | efcea3a80da7c4479d5fe168435ecc9fd06bdc72 (diff) | |
download | sqlite-kv-bench-13e0821fd783a1d5083d825af53cf20e8dcbfd76.tar.gz |
Merge commit 'efcea3a80da7c4479d5fe168435ecc9fd06bdc72' as 'subprojects/boost-sqlite'
Diffstat (limited to 'subprojects/boost-sqlite/doc/reference/collation.adoc')
-rw-r--r-- | subprojects/boost-sqlite/doc/reference/collation.adoc | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/subprojects/boost-sqlite/doc/reference/collation.adoc b/subprojects/boost-sqlite/doc/reference/collation.adoc new file mode 100644 index 0000000..6578f59 --- /dev/null +++ b/subprojects/boost-sqlite/doc/reference/collation.adoc @@ -0,0 +1,45 @@ +== `sqlite/collation.hpp` +[#collation] + +A https://www.sqlite.org/datatype3.html#collation[collation] is a comparison operator between two string-like values, +that allows ordering with a custom algorithm. + +.Definition +[source,cpp] +---- + +// Create a collation +template<typename Func> +void create_collation(connection & conn, cstring_ref name, Func && func); +template<typename Func> +void create_collation(connection & conn, cstring_ref name, Func && func, system::error_code &ec); + +// Delete an existing collation. +void delete_collation(connection & conn, cstring_ref name, system::error_code & ec); +void delete_collation(connection & conn, cstring_ref name); +---- + + conn:: A connection to the database in which to install the collation. + name:: The name of the collation. + func:: The function + +The function must be callable with two `string_view` and return an int, indicating the comparison results. + +.Example +[source,cpp] +---- +// a case insensitive string omparison, e.g. from boost.urls +int ci_compare(string_view s0, string_view s1) noexcept; + +extern sqlite::connection conn; + +// Register the collation +sqlite::create_collation(conn, "iequal", &ci_compare); + +// use the collation to get by name, case insensitively +conn.query("select first_name, last_name from people where first_name = 'Klemens' collate iequal;"); + +// order by names case insensitively +conn.query("select * from people order by last_name collate iequal asc;"); +---- + |