Fun 0.41.5
The programming language that makes you have fun!
Loading...
Searching...
No Matches
exec.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
10/**
11 * @file exec.c
12 * @brief Implements the OP_SQLITE_EXEC opcode (conditional build).
13 *
14 * Executes a SQL statement against an open SQLite handle when
15 * FUN_WITH_SQLITE is enabled. Returns the SQLite result code.
16 *
17 * OP_SQLITE_EXEC: (handle:int, sql:string) -> int rc (0=OK)
18 */
19
21#ifdef FUN_WITH_SQLITE
22 Value vsql = pop_value(vm);
24 int hid = (int)vh.i;
25 char *sql = value_to_string_alloc(&vsql);
29 if (!h || !h->db || !sql) {
30 if (sql) free(sql);
31 push_value(vm, make_int(SQLITE_MISUSE));
32 break;
33 }
34 char *errmsg = NULL;
35 int rc = sqlite3_exec(h->db, sql, NULL, NULL, &errmsg);
36 if (errmsg) sqlite3_free(errmsg);
37 free(sql);
39#else
40 Value v1 = pop_value(vm);
41 free_value(v1);
42 Value v2 = pop_value(vm);
43 free_value(v2);
44 push_value(vm, make_int(-1));
45#endif
46 break;
47}
@ OP_SQLITE_EXEC
Definition bytecode.h:180
int hid
Definition disconnect.c:33
CURLcode rc
Definition download.c:71
CURL * h
Definition download.c:59
free_value(vh)
char * errmsg
Definition exec.c:34
char * sql
Definition exec.c:25
Value vh
Definition get_bool.c:38
free(vals)
static SqlHandle * sql_reg_get(int id)
Look up a registered SQLite handle by id.
Definition sqlite.c:70
Node in a singly-linked list of registered SQLite handles.
Definition sqlite.c:29
Tagged union representing a Fun value.
Definition value.h:68
char * value_to_string_alloc(const Value *v)
Allocate a printable C string for a Value.
Definition value.c:641
Value make_int(int64_t v)
Construct a Value representing a 64-bit integer.
Definition value.c:51
static Value pop_value(VM *vm)
Pop a Value from the VM operand stack.
Definition vm.c:580
static void push_value(VM *vm, Value v)
Push a Value onto the VM operand stack.
Definition vm.c:564