]> git.proxmox.com Git - ceph.git/blob - ceph/src/include/libcephsqlite.h
0fd1b5fd5604fd4dcf86e1312fd4dc6801c2c0f2
[ceph.git] / ceph / src / include / libcephsqlite.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 /*
5 * Ceph - scalable distributed file system
6 *
7 * Copyright (C) 2021 Red Hat, Inc.
8 *
9 * This is free software; you can redistribute it and/or modify it under the
10 * terms of the GNU Lesser General Public License version 2.1, as published by
11 * the Free Software Foundation. See file COPYING.
12 *
13 */
14
15 #ifndef LIBCEPHSQLITE_H
16 #define LIBCEPHSQLITE_H
17
18 /* This loadable extension does not generally require using this header. It is
19 * here to allow controlling which version of the library is linked in. See
20 * also sqlite3_cephsqlite_init below. Additionally, you may specify which
21 * CephContext to use rather than the library instantiating its own and using
22 * whatever the default credential is.
23 */
24
25 #include <sqlite3.h>
26
27 #ifdef _WIN32
28 # define LIBCEPHSQLITE_API __declspec(dllexport)
29 #else
30 # define LIBCEPHSQLITE_API extern "C"
31 #endif
32
33 /* This is the SQLite entry point when loaded as a dynamic library. You also
34 * need to ensure SQLite calls this method when using libcephsqlite as a static
35 * library or a dynamic library linked at compile time. For the latter case,
36 * you can do this by:
37 *
38 * sqlite3_auto_extension((void (*)())sqlite3_cephsqlite_init);
39 * sqlite3* db = nullptr;
40 * int rc = sqlite3_open_v2(":memory:", &db, SQLITE_OPEN_READWRITE, nullptr);
41 * if (rc == SQLITE_DONE) {
42 * sqlite3_close(db);
43 * } else {
44 * // failure
45 * }
46 *
47 * The throwaway database created (name == "") is a memory database opened so
48 * that SQLite runs the libcephsqlite initialization routine to register the
49 * VFS. AFter that's done, the VFS is available for a future database open with
50 * the VFS set to "ceph":
51 *
52 * sqlite3_open_v2("foo:bar/baz.db", &db, SQLITE_OPEN_READWRITE, "ceph");
53 *
54 * You MUST do this before calling any other libcephsqlite routine so that
55 * sqlite3 can pass its API routines to the libcephsqlite extension.
56 */
57
58 LIBCEPHSQLITE_API int sqlite3_cephsqlite_init(sqlite3* db, char** err, const sqlite3_api_routines* api);
59
60 /* If you prefer to have libcephsqlite use a CephContext managed by your
61 * application, use this routine to set that. libcephsqlite can only have one
62 * context globally.
63 */
64
65 LIBCEPHSQLITE_API int cephsqlite_setcct(class CephContext* cct, char** ident);
66
67 #endif