Some refactoring. (0.37.21)
This commit is contained in:
parent
3e64bfb8f9
commit
033bf53889
11 changed files with 10 additions and 10 deletions
49
src/external/sqlite.c
vendored
Normal file
49
src/external/sqlite.c
vendored
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* This file is part of the Fun programming language.
|
||||
* https://fun-lang.xyz/
|
||||
*
|
||||
* Copyright 2025 Johannes Findeisen <you@hanez.org>
|
||||
* Licensed under the terms of the Apache-2.0 license.
|
||||
* https://opensource.org/license/apache-2-0
|
||||
*
|
||||
* Added: 2025-12-11 (2025-12-11 migrated from src/vm/sqlite/common.c)
|
||||
*/
|
||||
|
||||
/**
|
||||
* SQLite handle registry and helpers
|
||||
*/
|
||||
#ifdef FUN_WITH_SQLITE
|
||||
#include <sqlite3.h>
|
||||
|
||||
typedef struct SqlHandle {
|
||||
int id;
|
||||
sqlite3 *db;
|
||||
struct SqlHandle *next;
|
||||
} SqlHandle;
|
||||
|
||||
static SqlHandle *g_sql_handles = NULL;
|
||||
static int g_sql_next_id = 1;
|
||||
|
||||
static SqlHandle* sql_reg_add(sqlite3 *db) {
|
||||
SqlHandle *h = (SqlHandle*)calloc(1, sizeof(SqlHandle));
|
||||
if (!h) return NULL;
|
||||
h->id = g_sql_next_id++;
|
||||
h->db = db;
|
||||
h->next = g_sql_handles;
|
||||
g_sql_handles = h;
|
||||
return h;
|
||||
}
|
||||
|
||||
static SqlHandle* sql_reg_get(int id) {
|
||||
for (SqlHandle *p = g_sql_handles; p; p = p->next) if (p->id == id) return p;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void sql_reg_del(int id) {
|
||||
SqlHandle **pp = &g_sql_handles;
|
||||
while (*pp) {
|
||||
if ((*pp)->id == id) { SqlHandle *d = *pp; *pp = d->next; free(d); return; }
|
||||
pp = &(*pp)->next;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue