garten

view growth.c @ 11:176ee28e7464

switched from mysql to sqlite; (+ some cleanups)
author meillo@marmaro.de
date Wed, 23 Jul 2008 11:41:38 +0200
parents b1e309dc0b98
children 8db6497d6065
line source
1 #include <stdio.h>
2 #include <stdlib.h>
4 #include "db.h"
5 #include "game.h"
10 void grow_plants() {
11 int i;
12 unsigned char r[6];
14 /* get weather and last environments to calculate the next one */
15 sprintf(query, "select\
16 f.id, f.size, f.age, p.size, p.growspeed, p.age\
17 from field f\
18 join plant p on f.plant_id = p.id ");
19 db_query(query);
20 /* printf("number of plants to process: %d\n", (int)mysql_num_rows(result)); */
21 while (sqlite3_step(stmt) == SQLITE_ROW) {
22 for (i = 0; i < 6; i++) {
23 r[i] = (char) sqlite3_column_int(stmt, i);
24 }
26 sprintf(query, "update field set \
27 size = '%d', age = '%d' \
28 where id = '%d' ",
29 (r[1] + 1), r[2]+1, r[0]);
30 db_query(query);
31 ;
33 if (sqlite3_step(stmt) == SQLITE_DONE) {
34 printf("update successful ++ %s\n", query);
35 } else {
36 printf("E: update failed ++ %s\n", sqlite3_errmsg(db));
37 }
39 }
40 sqlite3_finalize(stmt);
45 }
48 int main(int argc, char* argv[]) {
49 printf(" --> %s\n", argv[0]);
51 /* init */
52 if (argc != 2) {
53 printf("usage: %s <database>\n", argv[0]);
54 exit(1);
55 }
56 database = argv[1];
58 db_connect();
59 read_time();
61 grow_plants();
64 db_close();
66 printf(" --< %s\n", argv[0]);
67 return 0;
68 }