chiark / gitweb /
1e710dc0075082cfc821d997f5f86c01bc85144f
[ypp-sc-tools.db-test.git] / yarrg / rscommon.h
1 #ifndef RSCOMMON_H
2 #define RSCOMMON_H
3
4 #include <sqlite3.h>
5
6 #define DEBUG_FLAG_LIST                         \
7    DF(sql)                                      \
8    DF(sql2)                                     \
9    DF(value)                                    \
10    DF(lp)
11
12 #define debug stdout
13 #define DEBUG_DEV "/dev/stdout"
14
15 #include "common.h"
16
17
18 #define SQL_MUST( call ) ({                                              \
19     /* `call' is an expression returning result, using  const char *sqe; \
20      * chk1 and chk2 are blocks using sqe and  int sqr; */               \
21     const char *sql_must_call_string= #call;                             \
22     int sqr;                                                             \
23     if (DEBUGP(sql2)) fprintf(stderr,"SQL %s", sql_must_call_string);    \
24     sqr= (call);                                                         \
25     if (DEBUGP(sql2)) fprintf(stderr," = %d\n", sqr);                    \
26     if (sqr) sql_fatal("(unknown)", sqr, sql_must_call_string);          \
27   })                                                                     \
28
29 void sql_fatal(const char *stmt_what, int sqr, const char *act_what) NORET;
30
31 #define SQL_STEP(ssh) (sql_step_wrap((ssh), #ssh, __FILE__, __LINE__))
32 int sql_step_wrap(sqlite3_stmt *ssh, const char *ssh_string,
33                   const char *file, int line);
34
35 int sql_single_int(const char *stmt);
36
37 #define SQL_PREPARE(ss,stmt) ((ss)= sql_prepare((stmt),#ss))
38 sqlite3_stmt *sql_prepare(const char *stmt, const char *what);
39
40 #define SQL_BIND(ss,index,value) (sql_bind((ss),(index),(value),#ss,#value))
41 void sql_bind(sqlite3_stmt *ss, int index, int value,
42               const char *ss_what, const char *val_what);
43
44 #define MAX_ROUTELEN 20
45
46 extern sqlite3 *db;
47
48 void setup_sql(void);
49 double value_route(int nislands, const int *islands);
50 void setup_value(void);
51 void setup_search(void);
52 void search(int start_isle);
53
54 extern double max_mass, max_volu, max_capi;
55 extern double distance_loss_factor_per_league;
56 extern int max_dist;
57
58 #define LOSS_FACTOR_PER_DELAY_SLOT (1-1e-8)
59
60 extern int islandtablesz;
61
62
63 #endif /*RSCOMMON_H*/