Mercurial > garten
annotate environment.c @ 11:176ee28e7464
switched from mysql to sqlite; (+ some cleanups)
author | meillo@marmaro.de |
---|---|
date | Wed, 23 Jul 2008 11:41:38 +0200 |
parents | e3679f888813 |
children | 8db6497d6065 |
rev | line source |
---|---|
6 | 1 #include <stdio.h> |
2 #include <stdlib.h> | |
3 | |
4 #include "db.h" | |
5 #include "game.h" | |
6 | |
7 | |
8 | |
9 | |
10 void set_environment() { | |
11 int groundwater, slugs, earthworms; | |
12 | |
13 /* get weather and last environments to calculate the next one * | |
11
176ee28e7464
switched from mysql to sqlite; (+ some cleanups)
meillo@marmaro.de
parents:
6
diff
changeset
|
14 sprintf(query, "select time from simulation"); |
6 | 15 db_query(query); |
16 result = mysql_store_result(conn); | |
17 if (mysql_num_rows(result)) { | |
18 row = mysql_fetch_row(result); | |
19 time = atoi(row[0]); | |
20 } | |
21 mysql_free_result(result); | |
22 */ | |
23 | |
24 groundwater = 20; | |
25 slugs = 5; | |
26 earthworms = 10; | |
27 | |
28 | |
29 /* set weather */ | |
30 sprintf(query, " insert into environment \ | |
11
176ee28e7464
switched from mysql to sqlite; (+ some cleanups)
meillo@marmaro.de
parents:
6
diff
changeset
|
31 (tick, groundwater, slugs, earthworms) \ |
176ee28e7464
switched from mysql to sqlite; (+ some cleanups)
meillo@marmaro.de
parents:
6
diff
changeset
|
32 values ('%d', '%d', '%d', '%d') ", |
176ee28e7464
switched from mysql to sqlite; (+ some cleanups)
meillo@marmaro.de
parents:
6
diff
changeset
|
33 gametime, groundwater, slugs, earthworms); |
6 | 34 db_query(query); |
11
176ee28e7464
switched from mysql to sqlite; (+ some cleanups)
meillo@marmaro.de
parents:
6
diff
changeset
|
35 if (sqlite3_step(stmt) == SQLITE_DONE) { |
6 | 36 printf("environment successful inserted\n"); |
37 } else { | |
11
176ee28e7464
switched from mysql to sqlite; (+ some cleanups)
meillo@marmaro.de
parents:
6
diff
changeset
|
38 printf("error: environment insertion failed: %s\n", sqlite3_errmsg(db)); |
6 | 39 } |
40 | |
41 } | |
42 | |
43 | |
44 int main(int argc, char* argv[]) { | |
45 printf(" --> environment\n"); | |
46 | |
47 /* init */ | |
48 if (argc != 2) { | |
11
176ee28e7464
switched from mysql to sqlite; (+ some cleanups)
meillo@marmaro.de
parents:
6
diff
changeset
|
49 printf("usage: %s <database>\n", argv[0]); |
6 | 50 exit(1); |
51 } | |
11
176ee28e7464
switched from mysql to sqlite; (+ some cleanups)
meillo@marmaro.de
parents:
6
diff
changeset
|
52 database = argv[1]; |
6 | 53 |
54 db_connect(); | |
11
176ee28e7464
switched from mysql to sqlite; (+ some cleanups)
meillo@marmaro.de
parents:
6
diff
changeset
|
55 read_time(); |
6 | 56 |
57 set_environment(); | |
58 | |
59 | |
60 db_close(); | |
61 | |
62 printf(" --< environment\n"); | |
63 return 0; | |
64 } |