Compare commits

..

4 Commits

Author SHA1 Message Date
52b70c3df1 Added dodo.schema and modified Makefile to include db creation 2024-08-20 21:49:45 -07:00
3a86a83f54 Added Makefile 2024-08-19 21:59:34 -07:00
134037bfde Added test.c 2024-08-01 13:12:41 -07:00
c8a2907d6b Added static lib for sqlite3
Compiled with gcc -c sqlite3.c and ar rcs libsqlite3.a sqlite3.o
2024-08-01 13:12:11 -07:00
11 changed files with 573426 additions and 0 deletions

31095
sqlite3/shell.c Normal file

File diff suppressed because it is too large Load Diff

257673
sqlite3/sqlite3.c Normal file

File diff suppressed because it is too large Load Diff

13425
sqlite3/sqlite3.h Normal file

File diff suppressed because it is too large Load Diff

25
src/Makefile Normal file
View File

@ -0,0 +1,25 @@
.POSIX:
SRC = dodo.c sqlite3.c x_string.c
OBJ = $(SRC:.c=.o)
CONFIG_PATH = $$HOME/.config/dodo
all: dodo
$(OBJ):
dodo: $(OBJ)
$(CC) -o $@ $(OBJ)
install: dodo
mkdir -p $(CONFIG_PATH)
sqlite3 $(CONFIG_PATH)/dodo.db < dodo.schema
uninstall:
rm -rf $(CONFIG_PATH)
clean:
rm -f dodo $(OBJ)
.PHONY: all clean install uninstall

4
src/config.h Normal file
View File

@ -0,0 +1,4 @@
#ifndef DB_PATH
#define DB_PATH "db.db"
#endif

36
src/dodo.c Normal file
View File

@ -0,0 +1,36 @@
#include <stdio.h>
#include <stdlib.h>
#include "sqlite3.h"
#include "x_string.h"
#define HOME_DIR "HOME"
#define DB_DIR "/current_projects/dodo/db/"
#define FILENAME "db.db"
int initdb(sqlite3 *db, char* filename){
int rc = 0;
rc = sqlite3_open(filename, &db);
if ( rc != 0 ){
fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
sqlite3_close(db);
return(rc);
}
return(rc);
}
int main( int argc, char **argv ){
sqlite3 *db;
char* home_dir = getenv(HOME_DIR);
char* filename = x_strconcat(home_dir, DB_DIR);
filename = x_strconcat(filename, FILENAME);
initdb(db, filename);
puts(filename);
return 0;
}

19
src/dodo.schema Normal file
View File

@ -0,0 +1,19 @@
CREATE TABLE tasks(
task_id INTEGER PRIMARY KEY,
title TEXT NOT NULL,
status TEXT NOT NULL DEFAULT 'backlog',
due_date DATE,
creation_date DATE DEFAULT (date('now'))
);
CREATE TABLE entries(
entry_id INTEGER PRIMARY KEY,
task_id INTEGER NOT NULL REFERENCES tasks(task_id),
body TEXT NOT NULL,
creation_date DATETIME DEFAULT (datetime('now', 'localtime'))
);
INSERT INTO tasks (title) VALUES ('test1'), ('test2'), ('test3');
INSERT INTO entries (task_id, body) VALUES (1, 'this is an entry for test1'), (2, 'this is an entry for test2'), (3, 'this is an entry for test3');
CREATE VIEW all_info AS SELECT * FROM entries JOIN tasks ON entries.task_id = tasks.task_id;

257673
src/sqlite3.c Normal file

File diff suppressed because it is too large Load Diff

13425
src/sqlite3.h Normal file

File diff suppressed because it is too large Load Diff

43
src/x_string.c Normal file
View File

@ -0,0 +1,43 @@
#include <stdio.h>
#include <stdlib.h>
int x_strlen(char* str){
char* ptr = str;
while(*ptr != '\0'){
ptr++;
}
return ptr - str;
}
void x_strcpy(char* dest, char* src, const int size_dest){
char* dest_ptr = dest;
char* src_ptr = src;
int i = 0;
while(*src_ptr != '\0'){
if (i >= size_dest){
fprintf(stderr, "Error: x_strcpy\nSource string exeeds destination memory\n");
exit(1);
}
*dest_ptr = *src_ptr;
dest_ptr++;
src_ptr++;
i++;
}
}
char* x_strconcat(char* str1, char* str2){
char* new_string;
int len1 = x_strlen(str1);
int len2 = x_strlen(str2);
int new_length = len1 + len2;
new_string = malloc( sizeof(*new_string) * new_length );
x_strcpy(new_string, str1, new_length);
x_strcpy(&new_string[len1], str2, new_length - len1);
return new_string;
}

8
src/x_string.h Normal file
View File

@ -0,0 +1,8 @@
#ifndef X_STRING_H
#define X_STRING_H
int x_strlen(char*);
void x_strcpy(char*, char*, const int);
char* x_strconcat(char*, char*);
#endif