Beispiel #1
0
static void populateList(list l, sqlite3_stmt* statement) {
    char* title;
    char* description;
    struct tm start;
    struct tm end;

    int title_length = strlen((char*)sqlite3_column_text(statement, 0)) + 1;
    int descr_length = strlen((char*)sqlite3_column_text(statement, 1)) + 1;

    title       = (char*)malloc(title_length*sizeof(char));
    description = (char*)malloc(descr_length*sizeof(char));

    strptime((char*)sqlite3_column_text(statement, 2), "%a %b %d %H:%M:%S %Y%n", &start);
    strptime((char*)sqlite3_column_text(statement, 3), "%a %b %d %H:%M:%S %Y%n", &end);

    strcpy(title,(char*)sqlite3_column_text(statement, 0));
    strcpy(description, (char*)sqlite3_column_text(statement, 1));

    Task t          = (Task)malloc(sizeof(struct task));
    t->title        = title;
    t->description  = description;
    t->startDay     = start;
    t->dueDay       = end;

    l_push(l, t);
}
Beispiel #2
0
list getBetweenDate(struct tm start, struct tm end, struct error* err) {
    err->error = NO_ERROR;

    if(!db) {
        if(!initializeConnection(NULL)) {
            exit(1);
        }
    }

    sqlite3_stmt* statement;
    const char* sql = "select * from tasks";
    const char* unused;

    
    int rc = sqlite3_prepare(db, sql, -1, &statement, &unused);
    if(rc != SQLITE_OK) {
        err->error = DATABASE_SELECT;
        err->description = sqlite3_errmsg(db);
        return NULL;
    }

    list l = l_new();
    while(sqlite3_step(statement) == SQLITE_ROW) {
        struct tm s;
        struct tm e;

        
        strptime((char*)sqlite3_column_text(statement, 2), "%a %b %d %H:%M:%S %Y%n", &s);
        strptime((char*)sqlite3_column_text(statement, 3), "%a %b %d %H:%M:%S %Y%n", &e);

        if(date_compare(start, s) > 0 || date_compare(end, e) < 0) {
            continue ;
        }

        char* title;
        char* description;
        
        int title_length = strlen((char*)sqlite3_column_text(statement, 0)) + 1;
        int descr_length = strlen((char*)sqlite3_column_text(statement, 1)) + 1;

        title       = (char*)malloc(title_length*sizeof(char));
        description = (char*)malloc(descr_length*sizeof(char));

        strcpy(title,(char*)sqlite3_column_text(statement, 0));
        strcpy(description, (char*)sqlite3_column_text(statement, 1));
    
        Task t          = (Task)malloc(sizeof(struct task));
        t->title        = title;
        t->description  = description;
        t->startDay     = s;
        t->dueDay       = e;
        l_push(l, t);
    } 

    sqlite3_finalize(statement);
    return l;

}
Beispiel #3
0
void l_push_level(register Lexer *lp, register char const *str)
{
    if (*str)
        l_push(lp, str, l_media_construct_memory);
}