reldb 0.1.0
Recreational SQLite
Loading...
Searching...
No Matches
main.c
Go to the documentation of this file.
1
5
6#include "compiler.h"
7#include "inputbuffer.h"
8#include "vm.h"
9
10#include <macros.h>
11#include <stdbool.h>
12#include <stdio.h>
13#include <stdlib.h>
14#include <string.h>
15#include <types.h>
16
18
19INTERNAL inline void
21{
22 printf("db > ");
23}
24
25int
26main(void)
27{
29 if (inbuf == NULL) {
30 exit(EXIT_FAILURE);
31 }
32
33 while (true) {
35 read_input(inbuf);
36
37 /* Handle Meta-Commands */
38 if ('.' == inbuf->buffer[0]) {
39 switch (do_meta_cmd(inbuf)) {
40 case (META_CMD_SUCCESS):
41 continue;
42 case (META_COMMAND_UNRECOGNISED_CMD):
43 r = fprintf(stderr, "Unrecognised command '%s'\n", inbuf->buffer);
44 continue;
45 }
46 }
47
48 /* Compile SQL Statement */
49 Statement stmt;
50 switch (prepare_statement(inbuf, &stmt)) {
51 case (PREPARE_SUCCESS):
52 break;
53 case (PREPARE_UNRECOGNIZED_STATEMENT):
54 r =
55 fprintf(stderr,
56 "Unrecognised keyword at start of '%s'\n",
57 inbuf->buffer);
58 continue;
59 }
60
61 /* Execute SQL Statement */
62 execute_statement(&stmt);
63 }
64
65 return 0;
66}
SQL text parsing and meta-command routing.
MetaCmdRes do_meta_cmd(InputBuffer *inbuf)
Parses and executes non-SQL meta-commands (commands starting with '.').
Definition compiler.c:11
PrepareRes prepare_statement(InputBuffer *inbuf, Statement *stmt)
The "Compiler": parses raw string input into an executable Statement.
Definition compiler.c:22
uint8_t u8
Definition types.h:29
#define INTERNAL
Definition macros.h:143
Defines the InputBuffer structure and related I/O functions.
InputBuffer * new_input_buffer(void)
Allocates and initializes a new InputBuffer.
Definition inputbuffer.c:9
void read_input(InputBuffer *input_buffer)
Reads a line of input from standard input into the buffer.
Definition inputbuffer.c:56
Context detection, utilities, and compiler abstractions.
static u8 r
Definition main.c:17
static void print_prompt(void)
Definition main.c:20
A structure to hold dynamically allocated string input data.
Definition inputbuffer.h:24
char * buffer
Definition inputbuffer.h:27
A parsed SQL statement ready for execution by the VM.
Definition statement.h:31
Core type definitions and fixed-width aliases.
Virtual Machine for executing compiled SQL statements.
void execute_statement(Statement *stmt)
The "Virtual Machine": executes a compiled Statement.
Definition vm.c:10