Compare commits

..
21 Commits
Author SHA1 Message Date
retoor b6ac734183 fix: suppress unused parameter warnings and remove dead code in cli and main
SORM tests / Compile (push) Successful in 6s
SORM build / build (push) Successful in 19s
2024-12-08 19:27:05 +00:00
retoor 985b469af4 chore: remove debug console.log statements from user authentication flow 2024-12-08 18:59:58 +00:00
retoor 60f98fdec7 chore: strip debug print statements and dead csv cleanup code from sormc and sormq 2024-12-08 18:58:50 +00:00
retoor 5565dd7e81 feat: add rlib.h header with 8.4k lines of core utility macros, type definitions, and MIT license boilerplate 2024-12-02 13:21:44 +00:00
retoor e28a87af74 fix: replace broken curl download with local cp for rlib.h in build workflow 2024-12-02 13:21:11 +00:00
retoor dbe70775d5 chore: add rlib.h download step before build in build.yaml workflow 2024-12-02 13:18:12 +00:00
retoor fc73c4221b feat: add rlib.h dependency and update includes to local path for runtime library support 2024-11-28 22:28:33 +00:00
retoor 0dfeef5d9d chore: fix trailing quote typo in build workflow echo command 2024-11-22 15:31:46 +00:00
retoor 228163c92d chore: fix apt-get command syntax in build workflow by removing extraneous 'get' 2024-11-22 15:30:38 +00:00
retoor 9f2941859d chore: replace named steps with echo placeholders in CI build workflow 2024-11-22 15:30:01 +00:00
retoor faa3749681 chore: add gitea ci workflow with build steps for sorm project 2024-11-22 15:27:37 +00:00
retoor d473276fd8 chore: remove trailing whitespace and reorder includes in cli.h, main.c, sorm.h, sorm.py, str.h 2024-11-22 14:51:47 +00:00
retoor 625e78ba79 docs: clarify C standard compatibility and fix punctuation in README dependencies section 2024-11-22 13:57:47 +00:00
retoor f54e36bdd8 docs: add building requirements and thread safety sections to readme
The README now includes a new "Building" section with build command and dependency list, and moves the "Thread safety" section after "Design choices" for better logical flow. The caution about missing rlib.h has been removed.
2024-11-22 13:56:40 +00:00
retoor f3a3dfef9e docs: add caution note about missing rlib.h dependency and future plans 2024-11-22 13:51:55 +00:00
retoor 01415a8fe9 feat: add Gitea workflow for automated SORM tests on push events
- Created .gitea/workflows/test.yaml with a Compile job running on ubuntu-latest
- Configured workflow to trigger on push events with echo steps for event, branch, and repository info
- Added checkout action and file listing step using gitea workspace variable
2024-11-22 13:45:03 +00:00
retoor b9e687ebdb chore: fix grammar and phrasing errors in README documentation files 2024-11-22 13:45:03 +00:00
retoor 1da30958d1 docs: fix formatting of code literals and casing in README examples 2024-11-22 13:45:03 +00:00
retoor f81ad80fa6 docs: add language identifier to C code blocks in README examples 2024-11-22 13:45:03 +00:00
retoor e58479ccd1 docs: add comprehensive project overview, setup instructions, and C/Python API examples to README
The README now includes a full project description explaining the SORM (SQL ORM) philosophy, thread safety considerations, design choices favoring native types for cross-language compatibility, and detailed C API examples covering connection, table creation, and query execution. Also adds Python support documentation with variadic function calling patterns through ctypes.
2024-11-22 13:45:03 +00:00
retoor 0f0657496b feat: add initial project scaffold with clang-format, gitignore, Makefile, core C headers, main entry, Python bindings, and dynamic library build 2024-11-22 13:45:03 +00:00
7 changed files with 30 additions and 54 deletions
+1 -1
View File
@@ -15,7 +15,7 @@ jobs:
- name: List files in the repository
run: |
ls ${{ gitea.workspace }}
- run: curl -OJ https://retoor.molodetz.nl/api/packages/retoor/generic/rlib.h/1.0.0/rlib.h /usr/include/rlib.h
- run: cp rlib.h /usr/include/
- run: echo "Build project (misses rlib.h)"
- run: make build
- run: echo "This job's status is ${{ job.status }}."
+5 -4
View File
@@ -1,9 +1,10 @@
all: build run
build:
gcc main.c -lsqlite3 -lreadline -o sorm
gcc -shared -o sorm.so -fPIC main.c -lsqlite3 -lreadline
gcc main.c -Wextra -Wall -lsqlite3 -lreadline -o sorm
gcc -shared -o sorm.so -fPIC main.c -lsqlite3 -lreadline
run:
./sorm
./sorm
+6 -6
View File
@@ -14,6 +14,8 @@
const char *history_filename = ".sorm_history";
int _sorm_readline_accept_line(int count, int key) {
(void)count;
(void)key;
if (strchr(rl_line_buffer, ';')) {
rl_done = 1;
@@ -42,6 +44,8 @@ char *_sorm_autocompletion_generator(const char *text, int state) {
}
char **_sorm_autocomplete(const char *text, int start, int end) {
(void)start;
(void)end;
rl_attempted_completion_over = 1;
return rl_completion_matches(text, _sorm_autocompletion_generator);
}
@@ -84,7 +88,7 @@ int sorm_cli_history_dump(const char *filename) {
}
input[file_size] = '\0';
for (line_start = line_end = 0; line_end < file_size; line_end++) {
for (line_start = line_end = 0; (size_t)line_end < file_size; line_end++) {
if (input[line_end] == '\n') {
input[line_end] = '\0';
@@ -94,7 +98,7 @@ int sorm_cli_history_dump(const char *filename) {
}
}
if (line_start < file_size)
if ((size_t)line_start < file_size)
printf("%s\n", input + line_start);
free(input);
@@ -139,9 +143,6 @@ bool sormrepl_handle_command(char *command) {
return false;
}
void sormrepl(int sorm) {
sorm_t *db = sormg(sorm);
char sql[4097];
sorm_cli_init(history_filename);
char *query;
while ((query = sorm_cli_readline("sql> "))) {
@@ -150,7 +151,6 @@ void sormrepl(int sorm) {
sorm_ptr res = sormq(sorm, query);
if (res) {
if (sormqt(query) == SORM_SELECT) {
int length = sormlv(res);
sormfmtd(res);
free(res);
} else if (sormqt(query) == SORM_DELETE) {
+6 -9
View File
@@ -4,16 +4,13 @@
int main() {
int db = sormc("db.sqlite3");
// sormq(db,"DROP TABLE IF EXISTS pony;");
printf("%d\n", db);
sormq(db, "CREATE TABLE IF NOT EXISTS pony (id INTEGER PRIMARY KEY AUTOINCREMENT,name,age);", NULL);
sorm_pk iid = sormq(db, "INSERT INTO pony (id,name,age) VALUES (NULL,%s,%d);", "Teenii", 19);
iid = sormq(db, "INSERT INTO pony (id,name,age) VALUES (NULL,%s,%d);", "Amber", 20);
iid = sormq(db, "INSERT INTO pony (id,name,age) VALUES (NULL,%s,%d);", "Feuerherz", 20);
iid = sormq(db, "INSERT INTO pony (id,name,age) VALUES (NULL,%s,%d);", "Retoor", 34);
sorm_str csv = sormq(db, "SELECT * FROM pony WHERE id in (?i,?i,?i)", 1, 2, 3);
sorm_str csv2 = sormq(db, "SELECT * FROM pony WHERE id = %d and age = %d ", 1, 33);
sorm_str csv3 = sormq(db, "SELECT * FROM pony LIMIT 2");
sormq(db, "INSERT INTO pony (id,name,age) VALUES (NULL,%s,%d);", "Teenii", 19);
sormq(db, "INSERT INTO pony (id,name,age) VALUES (NULL,%s,%d);", "Amber", 20);
sormq(db, "INSERT INTO pony (id,name,age) VALUES (NULL,%s,%d);", "Feuerherz", 20);
sormq(db, "INSERT INTO pony (id,name,age) VALUES (NULL,%s,%d);", "Retoor", 34);
sorm_str csv2 = (sorm_str)sormq(db, "SELECT * FROM pony WHERE id = %d and age = %d ", 1, 33);
sorm_str csv3 = (sorm_str)sormq(db, "SELECT * FROM pony LIMIT 2");
// free(csv3);
// free(csv2);
if (csv2)
BIN
View File
Binary file not shown.
+12 -34
View File
@@ -51,7 +51,6 @@ void sormd(int db);
char *sormpt(char *sql, int number);
unsigned int sormcq(char *sql, char *out);
unsigned int sormpc(char *sql);
sqlite3_stmt *sormb(sorm_t *db, char *sql, ...);
sorm_ptr sormq(int db, char *sql, ...);
char *sorm_csvc(int db, sqlite3_stmt *stmt);
char *sorm_csvd(int db, sqlite3_stmt *stmt);
@@ -73,18 +72,14 @@ int sorm_instance_count = 0;
int sormc(char *path) {
// sorm connect
printf("HIERR\n");
sorm_instance_count++;
sorm_instance_count++;
sorm_instances = realloc(sorm_instances, sorm_instance_count * sizeof(sorm_t *) + sorm_instance_count * sizeof(sorm_t));
printf("HIERR\n");
sorm_t *db = &sorm_instances[sorm_instance_count - 1];
sorm_t *db = (sorm_t *)&sorm_instances[sorm_instance_count - 1];
printf("HIERR\n");
db->conn = NULL;
printf("HIERR\n");
db->csv = NULL;
db->current_column = 0;
db->current_row = 0;
@@ -99,10 +94,9 @@ int sormc(char *path) {
fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db->conn));
return 0;
}
printf("DONE!\n");
return sorm_instance_count;
}
sorm_t *sormg(int ptr) { return &sorm_instances[ptr - 1]; }
sorm_t *sormg(int ptr) { return (sorm_t *)&sorm_instances[ptr - 1]; }
char *sormgcsv(int ptr) {
/* sorm get csv*/
@@ -213,9 +207,10 @@ Execute 3.35s, Format: 36.77s
Memory usage: 537 GB, 96.026 allocated, 96.024 freed, 2 in use.
*/
char *sorm_csvc(int db, sqlite3_stmt *stmt) {
(void)db;
sormstr_t *str = sormstrn(512);
unsigned int column_count = sqlite3_column_count(stmt);
for (int i = 0; i < column_count; i++) {
for (uint i = 0; i < column_count; i++) {
const char *column_name = sqlite3_column_name(stmt, i);
sormstra(str, column_name);
sormstra(str, "(");
@@ -230,7 +225,7 @@ char *sorm_csvc(int db, sqlite3_stmt *stmt) {
return sormstrc(str);
}
char *sorm_csvd(int sorm, sqlite3_stmt *stmt) {
sorm_t *db = sormg(sorm);
(void)sorm;
int rc = SQLITE_ROW;
int column_count = sqlite3_column_count(stmt);
/*
@@ -257,7 +252,7 @@ char *sorm_csvd(int sorm, sqlite3_stmt *stmt) {
sprintf(temp, "%f", sqlite3_column_double(stmt, field_index));
sormstra(str, temp);
} else if (sqlite3_column_type(stmt, field_index) == SQLITE3_TEXT) {
const char *temp = sqlite3_column_text(stmt, field_index);
const char *temp = ( char *)sqlite3_column_text(stmt, field_index);
sormstra(str, temp);
} else {
// exit(1);
@@ -276,7 +271,6 @@ char *sorm_csvd(int sorm, sqlite3_stmt *stmt) {
}
char *sorm_csv(int sorm, sqlite3_stmt *stmt) {
sorm_t *db = sormg(sorm);
sorm_row_count = 0;
char *column_names = sorm_csvc(sorm, stmt);
char *data = sorm_csvd(sorm, stmt);
@@ -291,31 +285,16 @@ char *sorm_csv(int sorm, sqlite3_stmt *stmt) {
return result;
}
sqlite3_stmt *sormb(sorm_t *db, char *sql, ...) {
// Bind parameters to statement and return amount of parameters
int rc = 0;
sqlite3_stmt *stmt;
va_list args;
va_start(args, sql);
unsigned int number = 0;
char *clean_query = (char *)malloc(strlen(sql) + 1);
unsigned int parameter_count = sormcq(sql, clean_query);
free(clean_query);
return stmt;
}
char *sormm(sorm_t *db) {
(void)db;
/* sormmemory */
return rmalloc_stats();
}
sorm_ptr sormq(int sorm, char *sql, ...) {
sorm_t *db = sormg(sorm);
if (db->csv) {
// free(db->csv);
// db->csv = NULL;
}
_sorm_query_start = nsecs();
db->time_query_start = nsecs();
va_list args;
@@ -323,17 +302,16 @@ sorm_ptr sormq(int sorm, char *sql, ...) {
sqlite3_stmt *stmt;
sorm_ptr result = NULL;
char *clean_query = malloc(strlen(sql) + 1);
unsigned int parameter_count = sormcq(sql, clean_query);
uint parameter_count = sormcq(sql, clean_query);
int rc = sqlite3_prepare_v2(db->conn, clean_query, -1, &stmt, 0);
if (rc != SQLITE_OK) {
fprintf(stderr, "%s\n", sqlite3_errmsg(db->conn));
}
free(clean_query);
int number = 0;
for (int i = 0; i < parameter_count; i++) {
for (uint i = 0; i < parameter_count; i++) {
number++;
char *column_type = sormpt(sql, number);
int arg_index = number - 1;
if (!strcmp(column_type, "int") || !strcmp(column_type, "integer") || !strcmp(column_type, "number")) {
rc = sqlite3_bind_int(stmt, number, va_arg(args, int));
} else if (!strcmp(column_type, "int64")) {
@@ -347,7 +325,7 @@ sorm_ptr sormq(int sorm, char *sql, ...) {
rc = sqlite3_bind_blob(stmt, number, data, size, SQLITE_STATIC);
} else if (!strcmp(column_type, "text") || !strcmp(column_type, "str") || !strcmp(column_type, "string")) {
unsigned char *data = va_arg(args, unsigned char *);
rc = sqlite3_bind_text(stmt, number, data, -1, SQLITE_STATIC);
rc = sqlite3_bind_text(stmt, number, (char *)data, -1, SQLITE_STATIC);
}
if (rc != SQLITE_OK) {
fprintf(stderr, "Failed to bind parameters: %s\n", sqlite3_errmsg(db->conn));
@@ -406,7 +384,7 @@ int sormlv(char *csv) {
while (*csv) {
char *found = strstr(csv, ";");
if (found) {
if (found - csv > longest)
if (found - csv > (long int)longest)
longest = found - csv;
csv = csv + (found - csv) + 1;
} else {
@@ -497,7 +475,7 @@ char *sormfmt(char *csv) {
sormstr_t *str = sormstrn(longest + 2);
while (*csv && (field = sormcsvn(csv))) {
sormstra(str, field);
for (int i = 0; i < longest - strlen(field); i++)
for (size_t i = 0; i < longest - strlen(field); i++)
sormstra(str, " ");
csv += strlen(field);
BIN
View File
Binary file not shown.