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