partial raw implementation

This commit is contained in:
anon 2023-08-03 11:08:26 +02:00
parent 201e1167f9
commit 418ea56174
3 changed files with 71 additions and 9 deletions

View File

@ -2,9 +2,10 @@
SRC := api.c irc.c main.c parse.c unity.c
HDR := api.h error.h irc.h irccolors.h parse.h stmt.h
DEBUG := 1
probotic: $(SRC) $(HDR)
./build.sh
DEBUG=$(DEBUG) ./build.sh
# do nothing but update them...
$(SRC) $(HDR):

View File

@ -20,6 +20,13 @@
} \
} while (0)
#define DBUSERERR(line) do { \
const int e = line; \
if(e != SQLITE_OK && e != SQLITE_ROW && e != SQLITE_DONE) { \
r = sqlite3_errmsg(connection); \
} \
} while(0)
static sqlite3 * connection = NULL;
DECL int
@ -52,11 +59,56 @@ remind(char * who)
char * title;
char * desc;
DBERR(sqlite3_bind_text(remind_stmt, 1, who, -1, SQLITE_STATIC));
DBERR(sqlite3_step(remind_stmt));
title = (char *) sqlite3_column_text(remind_stmt, 0);
title = strdup(title);
desc = (char *) sqlite3_column_text(remind_stmt, 1);
desc = strdup(desc);
asprintf(&r, IRC_COLOR_RED "%s: " IRC_COLOR_YELLOW "%s", title, desc);
const int i = sqlite3_step(remind_stmt);
DBERR(i);
if (i == SQLITE_ROW)
{
title = (char *) sqlite3_column_text(remind_stmt, 0);
title = strdup(title);
desc = (char *) sqlite3_column_text(remind_stmt, 1);
desc = strdup(desc);
asprintf(&r, IRC_COLOR_RED "%s: " IRC_COLOR_YELLOW "%s", title, desc);
}
else
{
r = strdup("No current assignment.");
}
return r;
}
DECL int
rtos(void* data,
int argc,
char** argv,
char** colname
){
(void) colname;
char *const *const r = (char**)data;
for(int i = 0; i < argc; i++){
strcat(*r, "|");
if(argv[i]){
strcat(*r, argv[i]);
}
else
{
strcat(*r, "NULL");
}
}
strcat(*r, "|");
return 0;
}
DECL char *
raw(char * sql)
{
char* errmsg;
char* r = (char*)malloc(10000);
DBUSERERR(sqlite3_exec(connection, sql, rtos, &r, &errmsg));
if (errmsg){
free(r);
r = errmsg;
} else { strcat(r, "\00"); }
return r;
}

View File

@ -49,6 +49,7 @@ DECL void
parse_command(char * cmd)
{
size_t i = 0;
char* msgswp = NULL;
/* size_t len = strlen(cmd); */
while (cmd[i] &&
cmd[i] != ' ')
@ -57,7 +58,10 @@ parse_command(char * cmd)
{
/* no arguments */
if (strcmp(cmd, "remind") == 0)
{ ircmsg("%s: No current assignment", current_username); }
{
msgswp = remind(current_username);
ircmsg("%s: %s", current_username, msgswp);
}
else if (strcmp(cmd, "next") == 0)
{ ircmsg("%s: No future assignments", current_username); }
else if (strcmp(cmd, "dump") == 0)
@ -71,11 +75,16 @@ parse_command(char * cmd)
char * arg = cmd + i + 1;
cmd[i] = '\0';
if (strcmp(cmd, "raw") == 0)
{ ircmsg("%s: Executing SQL `%s'", arg); }
{
ircmsg("%s: Executing SQL `%s'.", current_username, arg);
msgswp = raw(arg);
ircmsg(msgswp);
}
else if (strcmp(cmd, "submit") == 0)
{ ircmsg("%s: Submitting project link '%s' to <random janny>",
current_username, arg); }
}
free(msgswp);
}
DECL int