Fun 0.41.5
The programming language that makes You have fun
Loading...
Searching...
No Matches
sqlite.c
Go to the documentation of this file.
1/*
2 * This file is part of the Fun programming language.
3 * https://fun-lang.xyz/
4 *
5 * Copyright 2025 Johannes Findeisen <you@hanez.org>
6 * Licensed under the terms of the Apache-2.0 license.
7 * https://opensource.org/license/apache-2-0
8 */
9
23#ifdef FUN_WITH_SQLITE
24#include <sqlite3.h>
25
29typedef struct SqlHandle {
30 int id;
31 sqlite3 *db;
32 struct SqlHandle *next;
33} SqlHandle;
34
36static SqlHandle *g_sql_handles = NULL;
38static int g_sql_next_id = 1;
39
54static SqlHandle *sql_reg_add(sqlite3 *db) {
55 SqlHandle *h = (SqlHandle *)calloc(1, sizeof(SqlHandle));
56 if (!h) return NULL;
57 h->id = g_sql_next_id++;
58 h->db = db;
59 h->next = g_sql_handles;
60 g_sql_handles = h;
61 return h;
62}
63
70static SqlHandle *sql_reg_get(int id) {
71 for (SqlHandle *p = g_sql_handles; p; p = p->next)
72 if (p->id == id) return p;
73 return NULL;
74}
75
85static void sql_reg_del(int id) {
86 SqlHandle **pp = &g_sql_handles;
87 while (*pp) {
88 if ((*pp)->id == id) {
89 SqlHandle *d = *pp;
90 *pp = d->next;
91 free(d);
92 return;
93 }
94 pp = &(*pp)->next;
95 }
96}
97#endif
double db
Definition fmax.c:27
free(vals)
const char * p
Definition read_file.c:37