/* Collection of code snippets by Arne Vajhøj */
/* (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#include "sqlite3.h"

#include "address.h"

int main()
{
    sqlite3 *con;
    sqlite3_stmt *sel;
    char *sqlstr = "SELECT id,name,address FROM address";
    int stat;
    int count;
    struct address res[1000];
    int i;
    stat = sqlite3_open("address.db", &con);
    stat = sqlite3_prepare(con, sqlstr, strlen(sqlstr), &sel, NULL);
    count = 0;
    while(sqlite3_step(sel) == SQLITE_ROW)
    {
        count++;
        res[count-1].id = sqlite3_column_int(sel, 0);
        strcpy(res[count-1].name, (char *)sqlite3_column_text(sel, 1));
        strcpy(res[count-1].address, (char *)sqlite3_column_text(sel, 2));
    }
    sqlite3_finalize(sel);
    sqlite3_close(con);
    for(i = 0; i < count; i++)
    {
        printf("%d|%s|%s\n", res[i].id, res[i].name, res[i].address);
    }
    return 0;
}
