Mercurial > garten
annotate 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 |
rev | line source |
---|---|
7
b1e309dc0b98
added growth module (quite static and limited implementation)
meillo@marmaro.de
parents:
diff
changeset
|
1 #include <stdio.h> |
b1e309dc0b98
added growth module (quite static and limited implementation)
meillo@marmaro.de
parents:
diff
changeset
|
2 #include <stdlib.h> |
b1e309dc0b98
added growth module (quite static and limited implementation)
meillo@marmaro.de
parents:
diff
changeset
|
3 |
b1e309dc0b98
added growth module (quite static and limited implementation)
meillo@marmaro.de
parents:
diff
changeset
|
4 #include "db.h" |
b1e309dc0b98
added growth module (quite static and limited implementation)
meillo@marmaro.de
parents:
diff
changeset
|
5 #include "game.h" |
b1e309dc0b98
added growth module (quite static and limited implementation)
meillo@marmaro.de
parents:
diff
changeset
|
6 |
b1e309dc0b98
added growth module (quite static and limited implementation)
meillo@marmaro.de
parents:
diff
changeset
|
7 |
b1e309dc0b98
added growth module (quite static and limited implementation)
meillo@marmaro.de
parents:
diff
changeset
|
8 |
b1e309dc0b98
added growth module (quite static and limited implementation)
meillo@marmaro.de
parents:
diff
changeset
|
9 |
b1e309dc0b98
added growth module (quite static and limited implementation)
meillo@marmaro.de
parents:
diff
changeset
|
10 void grow_plants() { |
b1e309dc0b98
added growth module (quite static and limited implementation)
meillo@marmaro.de
parents:
diff
changeset
|
11 int i; |
b1e309dc0b98
added growth module (quite static and limited implementation)
meillo@marmaro.de
parents:
diff
changeset
|
12 unsigned char r[6]; |
b1e309dc0b98
added growth module (quite static and limited implementation)
meillo@marmaro.de
parents:
diff
changeset
|
13 |
b1e309dc0b98
added growth module (quite static and limited implementation)
meillo@marmaro.de
parents:
diff
changeset
|
14 /* get weather and last environments to calculate the next one */ |
b1e309dc0b98
added growth module (quite static and limited implementation)
meillo@marmaro.de
parents:
diff
changeset
|
15 sprintf(query, "select\ |
b1e309dc0b98
added growth module (quite static and limited implementation)
meillo@marmaro.de
parents:
diff
changeset
|
16 f.id, f.size, f.age, p.size, p.growspeed, p.age\ |
b1e309dc0b98
added growth module (quite static and limited implementation)
meillo@marmaro.de
parents:
diff
changeset
|
17 from field f\ |
11
176ee28e7464
switched from mysql to sqlite; (+ some cleanups)
meillo@marmaro.de
parents:
7
diff
changeset
|
18 join plant p on f.plant_id = p.id "); |
7
b1e309dc0b98
added growth module (quite static and limited implementation)
meillo@marmaro.de
parents:
diff
changeset
|
19 db_query(query); |
11
176ee28e7464
switched from mysql to sqlite; (+ some cleanups)
meillo@marmaro.de
parents:
7
diff
changeset
|
20 /* printf("number of plants to process: %d\n", (int)mysql_num_rows(result)); */ |
176ee28e7464
switched from mysql to sqlite; (+ some cleanups)
meillo@marmaro.de
parents:
7
diff
changeset
|
21 while (sqlite3_step(stmt) == SQLITE_ROW) { |
7
b1e309dc0b98
added growth module (quite static and limited implementation)
meillo@marmaro.de
parents:
diff
changeset
|
22 for (i = 0; i < 6; i++) { |
11
176ee28e7464
switched from mysql to sqlite; (+ some cleanups)
meillo@marmaro.de
parents:
7
diff
changeset
|
23 r[i] = (char) sqlite3_column_int(stmt, i); |
7
b1e309dc0b98
added growth module (quite static and limited implementation)
meillo@marmaro.de
parents:
diff
changeset
|
24 } |
b1e309dc0b98
added growth module (quite static and limited implementation)
meillo@marmaro.de
parents:
diff
changeset
|
25 |
b1e309dc0b98
added growth module (quite static and limited implementation)
meillo@marmaro.de
parents:
diff
changeset
|
26 sprintf(query, "update field set \ |
b1e309dc0b98
added growth module (quite static and limited implementation)
meillo@marmaro.de
parents:
diff
changeset
|
27 size = '%d', age = '%d' \ |
b1e309dc0b98
added growth module (quite static and limited implementation)
meillo@marmaro.de
parents:
diff
changeset
|
28 where id = '%d' ", |
b1e309dc0b98
added growth module (quite static and limited implementation)
meillo@marmaro.de
parents:
diff
changeset
|
29 (r[1] + 1), r[2]+1, r[0]); |
b1e309dc0b98
added growth module (quite static and limited implementation)
meillo@marmaro.de
parents:
diff
changeset
|
30 db_query(query); |
11
176ee28e7464
switched from mysql to sqlite; (+ some cleanups)
meillo@marmaro.de
parents:
7
diff
changeset
|
31 ; |
7
b1e309dc0b98
added growth module (quite static and limited implementation)
meillo@marmaro.de
parents:
diff
changeset
|
32 |
11
176ee28e7464
switched from mysql to sqlite; (+ some cleanups)
meillo@marmaro.de
parents:
7
diff
changeset
|
33 if (sqlite3_step(stmt) == SQLITE_DONE) { |
7
b1e309dc0b98
added growth module (quite static and limited implementation)
meillo@marmaro.de
parents:
diff
changeset
|
34 printf("update successful ++ %s\n", query); |
b1e309dc0b98
added growth module (quite static and limited implementation)
meillo@marmaro.de
parents:
diff
changeset
|
35 } else { |
11
176ee28e7464
switched from mysql to sqlite; (+ some cleanups)
meillo@marmaro.de
parents:
7
diff
changeset
|
36 printf("E: update failed ++ %s\n", sqlite3_errmsg(db)); |
7
b1e309dc0b98
added growth module (quite static and limited implementation)
meillo@marmaro.de
parents:
diff
changeset
|
37 } |
b1e309dc0b98
added growth module (quite static and limited implementation)
meillo@marmaro.de
parents:
diff
changeset
|
38 |
b1e309dc0b98
added growth module (quite static and limited implementation)
meillo@marmaro.de
parents:
diff
changeset
|
39 } |
11
176ee28e7464
switched from mysql to sqlite; (+ some cleanups)
meillo@marmaro.de
parents:
7
diff
changeset
|
40 sqlite3_finalize(stmt); |
7
b1e309dc0b98
added growth module (quite static and limited implementation)
meillo@marmaro.de
parents:
diff
changeset
|
41 |
b1e309dc0b98
added growth module (quite static and limited implementation)
meillo@marmaro.de
parents:
diff
changeset
|
42 |
b1e309dc0b98
added growth module (quite static and limited implementation)
meillo@marmaro.de
parents:
diff
changeset
|
43 |
b1e309dc0b98
added growth module (quite static and limited implementation)
meillo@marmaro.de
parents:
diff
changeset
|
44 |
b1e309dc0b98
added growth module (quite static and limited implementation)
meillo@marmaro.de
parents:
diff
changeset
|
45 } |
b1e309dc0b98
added growth module (quite static and limited implementation)
meillo@marmaro.de
parents:
diff
changeset
|
46 |
b1e309dc0b98
added growth module (quite static and limited implementation)
meillo@marmaro.de
parents:
diff
changeset
|
47 |
b1e309dc0b98
added growth module (quite static and limited implementation)
meillo@marmaro.de
parents:
diff
changeset
|
48 int main(int argc, char* argv[]) { |
b1e309dc0b98
added growth module (quite static and limited implementation)
meillo@marmaro.de
parents:
diff
changeset
|
49 printf(" --> %s\n", argv[0]); |
b1e309dc0b98
added growth module (quite static and limited implementation)
meillo@marmaro.de
parents:
diff
changeset
|
50 |
b1e309dc0b98
added growth module (quite static and limited implementation)
meillo@marmaro.de
parents:
diff
changeset
|
51 /* init */ |
b1e309dc0b98
added growth module (quite static and limited implementation)
meillo@marmaro.de
parents:
diff
changeset
|
52 if (argc != 2) { |
11
176ee28e7464
switched from mysql to sqlite; (+ some cleanups)
meillo@marmaro.de
parents:
7
diff
changeset
|
53 printf("usage: %s <database>\n", argv[0]); |
7
b1e309dc0b98
added growth module (quite static and limited implementation)
meillo@marmaro.de
parents:
diff
changeset
|
54 exit(1); |
b1e309dc0b98
added growth module (quite static and limited implementation)
meillo@marmaro.de
parents:
diff
changeset
|
55 } |
11
176ee28e7464
switched from mysql to sqlite; (+ some cleanups)
meillo@marmaro.de
parents:
7
diff
changeset
|
56 database = argv[1]; |
7
b1e309dc0b98
added growth module (quite static and limited implementation)
meillo@marmaro.de
parents:
diff
changeset
|
57 |
b1e309dc0b98
added growth module (quite static and limited implementation)
meillo@marmaro.de
parents:
diff
changeset
|
58 db_connect(); |
11
176ee28e7464
switched from mysql to sqlite; (+ some cleanups)
meillo@marmaro.de
parents:
7
diff
changeset
|
59 read_time(); |
7
b1e309dc0b98
added growth module (quite static and limited implementation)
meillo@marmaro.de
parents:
diff
changeset
|
60 |
b1e309dc0b98
added growth module (quite static and limited implementation)
meillo@marmaro.de
parents:
diff
changeset
|
61 grow_plants(); |
b1e309dc0b98
added growth module (quite static and limited implementation)
meillo@marmaro.de
parents:
diff
changeset
|
62 |
b1e309dc0b98
added growth module (quite static and limited implementation)
meillo@marmaro.de
parents:
diff
changeset
|
63 |
b1e309dc0b98
added growth module (quite static and limited implementation)
meillo@marmaro.de
parents:
diff
changeset
|
64 db_close(); |
b1e309dc0b98
added growth module (quite static and limited implementation)
meillo@marmaro.de
parents:
diff
changeset
|
65 |
b1e309dc0b98
added growth module (quite static and limited implementation)
meillo@marmaro.de
parents:
diff
changeset
|
66 printf(" --< %s\n", argv[0]); |
b1e309dc0b98
added growth module (quite static and limited implementation)
meillo@marmaro.de
parents:
diff
changeset
|
67 return 0; |
b1e309dc0b98
added growth module (quite static and limited implementation)
meillo@marmaro.de
parents:
diff
changeset
|
68 } |