+
+void setup_value(void) {
+ sqlite3_stmt *sst;
+
+ SQL_MUST( sqlite3_prepare(db, "SELECT max(islandid) FROM islands",
+ -1,&sst,0) );
+ assert( SQL_STEP(sst) );
+ nislands= sqlite3_column_int(sst,0);
+ nislands++;
+ sqlite3_finalize(sst);
+ debugf("VALUE nislands=%d\n",nislands);
+
+ SQL_MUST( sqlite3_prepare(db,
+ "SELECT\n"
+ " sell.commodid commodid,\n"
+ " sell.price src_price,\n"
+ " sum(sell.qty) src_qty,\n"
+ " buy.price dst_price,\n"
+ " sum(buy.qty) dst_qty\n"
+ " FROM sell JOIN buy\n"
+ " ON sell.commodid = buy.commodid\n"
+ " AND buy.price > sell.price\n"
+ " WHERE sell.islandid=?\n"
+ " AND buy.islandid=?\n"
+ " GROUP BY sell.commodid, sell.price, buy.price",
+ -1, &ss_ipair, 0) );
+
+ ipairs= mcalloc(sizeof(*ipairs) * nislands);
+}