Browse Source

get random assignment support

pull/3/head
anon 10 months ago
parent
commit
5bb4216d7e
3 changed files with 26 additions and 0 deletions
  1. +8
    -0
      include/stmt.h
  2. +15
    -0
      src/api.c
  3. +3
    -0
      src/irc.c

+ 8
- 0
include/stmt.h View File

@@ -34,3 +34,11 @@ static const char get_nth_id_stmt_template[] =
"LIMIT 1 "
"OFFSET ?;"
;

static sqlite3_stmt* new_assignment_stmt;
static const char new_assignment_stmt_template[] =
"INSERT INTO assignment "
"(who, project)"
" VALUES "
"(?, ?);"
;

+ 15
- 0
src/api.c View File

@@ -1,4 +1,5 @@
#include <stdio.h>
#include <stdlib.h>

#include <sqlite3.h>

@@ -164,3 +165,17 @@ get_nth_id(const int i){
r = sqlite3_column_int(get_nth_id_stmt, 0);
return r;
}

DECL void
new_assignment(const char * const who, const int project){
DBERR(sqlite3_bind_text(new_assignment_stmt, 1, who, -1, SQLITE_STATIC));
DBERR(sqlite3_bind_int(new_assignment_stmt, 2, project));
DBERR(sqlite3_step(new_assignment_stmt));
}

DECL void
random_assign(const char * const who){
int i = rand() % get_project_count();
i = get_nth_id(i);
new_assignment(who, i);
}

+ 3
- 0
src/irc.c View File

@@ -22,6 +22,8 @@
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>

#include "irc.h"
#include "parse.h"
@@ -120,6 +122,7 @@ event_channel(irc_session_t * session,
int
init(void)
{
srand(time(NULL));
if(api_init())
{ ERR(DB_ERROR, "Error initializing database."); }
memset(&callbacks, 0, sizeof(callbacks));