chiark / gitweb /
Debug improved
[ypp-sc-tools.main.git] / yarrg / rsvalue.c
1 /**/
2
3 #include "rscommon.h"
4
5 DEBUG_DEFINE_SOME_DEBUGF(sql,sql_dprintf);
6
7 typedef struct {
8   int commodid, src_price, src_qty, dst_price, dst_qty;
9 } Trade;
10
11 typedef struct {
12   int ntrades;
13   Trade *trades;
14 } IslandPair;
15
16 static void ipair_gettrades(int si, int di) {
17   char *stmt= masprintf
18     ("SELECT\n"
19      " sell.commodid            commodid,\n"
20      " sell.price               src_price,\n"
21      " sum(sell.qty)            src_qty,\n"
22      " buy.price                dst_price,\n"
23      " sum(buy.qty)             dst_qty\n"
24      " FROM sell JOIN buy\n"
25      "   ON sell.commodid = buy.commodid\n"
26      "  AND buy.price > sell.price\n"
27      " WHERE sell.islandid=%d\n"
28      "   AND buy.islandid=%d\n"
29      " GROUP BY sell.commodid, sell.price, buy.price\n",
30      si, di);
31   
32   sql_dprintf("SQL\n[\n%s\n]\n", stmt);
33
34   free(stmt);
35 }
36
37 void value_route(int nislands, const int *islands) {
38   int s,d;
39   
40   for (s=0; s<nislands; s++) {
41     for (d=s; d<nislands; d++) {
42       ipair_gettrades(islands[s], islands[d]);
43     }
44   }
45
46   //char *tail;
47   //struct sqlite_vm *sth;
48   //r= sqlite_compile(db, stmt, &tail, &sth, 
49 }