Files
first-repo/sqlite_ex.h

48 lines
1.4 KiB
C

#define _GNU_SOURCE 1
#include <sqlite3.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#define SELECT_MEASUREMENTS "select * from measurements order by date;"
#define SELECT_COUNT_MEAS "select count(*) from measurements;"
#define SELECT_ALL_TABLES "select * from sqlite_schema where type = 'table';"
#define SELECT_TWNTH_DAY "select * from twnth_day;"
#define SELECT_CURRENT_COSTS "select * from costs where id = ?;"
#define INSERT_MEASUREMENT "insert into measurements (gas, water, electricity, costs) values (?, ?, ?, 1);"
#define CALCULATION_FORMAT "%s: %d - %d = %f * %f = %f\n"
#define STR_SIZE 11
typedef struct tm Datetime;
typedef struct {
Datetime *datetime;
/* NOTE: probably should change to union type?
* (to hold both double and int representation, to count the integer cost)
*/
double gas;
double water;
double electricity;
int cost_id;
} meas;
typedef struct {
double gas_c;
double water_c;
double electricity_c;
double housing_c;
} Cost;
int print_tables(void *, int, char **, char **);
void print_measurements();
void free_measurements();
int dates_same(Datetime *, Datetime *);
double communal_difference(meas *, meas *);
int parse_measurements(void *, int, char **, char **);
int count_measurements(void *, int, char **, char **);
int select_twnth_day(void *, int, char **, char **);
void sqlite_list_tables(sqlite3 *db);
void sqlite_exec_query(char *query, void *callback);