Mercurial > garten
annotate environment.c @ 20:17b2bcc42d72 default tip
added check for empty result; minor stuff
author | meillo@marmaro.de |
---|---|
date | Sun, 27 Jul 2008 21:34:54 +0200 |
parents | 5937504619f2 |
children |
rev | line source |
---|---|
6 | 1 #include <stdio.h> |
2 #include <stdlib.h> | |
3 #include "db.h" | |
4 | |
5 | |
18
5937504619f2
rename game.h -> modules.h; added some error handling; and more
meillo@marmaro.de
parents:
17
diff
changeset
|
6 int set_environment() { |
6 | 7 int groundwater, slugs, earthworms; |
8 | |
9 /* 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
|
10 sprintf(query, "select time from simulation"); |
6 | 11 db_query(query); |
12 result = mysql_store_result(conn); | |
13 if (mysql_num_rows(result)) { | |
14 row = mysql_fetch_row(result); | |
15 time = atoi(row[0]); | |
16 } | |
17 mysql_free_result(result); | |
18 */ | |
19 | |
20 groundwater = 20; | |
21 slugs = 5; | |
22 earthworms = 10; | |
23 | |
24 /* set weather */ | |
17 | 25 sprintf(query, |
26 "insert into environment " | |
27 "(tick, groundwater, slugs, earthworms) " | |
28 "values ('%d', '%d', '%d', '%d') " | |
29 , gametime | |
30 , groundwater | |
31 , slugs | |
32 , earthworms | |
33 ); | |
12 | 34 if (!db_update(query)) { |
17 | 35 db_error("environment insertion"); |
18
5937504619f2
rename game.h -> modules.h; added some error handling; and more
meillo@marmaro.de
parents:
17
diff
changeset
|
36 return 0; |
6 | 37 } |
18
5937504619f2
rename game.h -> modules.h; added some error handling; and more
meillo@marmaro.de
parents:
17
diff
changeset
|
38 return 1; |
6 | 39 } |
40 | |
41 | |
18
5937504619f2
rename game.h -> modules.h; added some error handling; and more
meillo@marmaro.de
parents:
17
diff
changeset
|
42 int environment(void) { |
5937504619f2
rename game.h -> modules.h; added some error handling; and more
meillo@marmaro.de
parents:
17
diff
changeset
|
43 return set_environment(); |
6 | 44 } |