Skip to content
Snippets Groups Projects
Commit 13cc6fb8 authored by Hugo Hörnquist's avatar Hugo Hörnquist
Browse files

Add sqlite extension for generating uuid's.

parent 1e842f6c
No related branches found
No related tags found
No related merge requests found
Makefile 0 → 100644
libs = sqlite3 uuid
CFLAGS = -Wall -pedantic -std=c2x -fPIC \
-ggdb \
$(shell pkg-config --cflags $(libs))
LDLIBS = $(shell pkg-config --libs $(libs))
C_FILES = sqlite-uuid.c
O_FILES = $(C_FILES:%.c=%.o)
sqlite-uuid.so: $(O_FILES)
$(CC) -shared -o $@ $^ $(LDLIBS)
#include <sqlite3ext.h>
SQLITE_EXTENSION_INIT1
#include <uuid.h>
static void sqlite_uuid(sqlite3_context *context, int argc, sqlite3_value **argv) {
uuid_t uuid;
uuid_generate_random(uuid);
char str[37];
uuid_unparse(uuid, &str[0]);
sqlite3_result_text(context, str, 37, SQLITE_TRANSIENT);
uuid_clear(uuid);
}
#ifdef _WIN32
__declspec(dllexport)
#endif
int sqlite3_extension_init (
sqlite3 *db,
char **pzErrMsg,
const sqlite3_api_routines *pApi
) {
int rc = SQLITE_OK;
SQLITE_EXTENSION_INIT2(pApi);
(void) pzErrMsg;
rc = sqlite3_create_function(db, "uuid", 0,
SQLITE_UTF8|SQLITE_INNOCUOUS,
0, sqlite_uuid, 0, 0);
return rc;
}
.load sqlite-uuid
SELECT uuid();
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment