garten

view environment.c @ 20:17b2bcc42d72

added check for empty result; minor stuff
author meillo@marmaro.de
date Sun, 27 Jul 2008 21:34:54 +0200
parents 5e6c9260913a
children
line source
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include "db.h"
6 int set_environment() {
7 int groundwater, slugs, earthworms;
9 /* get weather and last environments to calculate the next one *
10 sprintf(query, "select time from simulation");
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 */
20 groundwater = 20;
21 slugs = 5;
22 earthworms = 10;
24 /* set weather */
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 );
34 if (!db_update(query)) {
35 db_error("environment insertion");
36 return 0;
37 }
38 return 1;
39 }
42 int environment(void) {
43 return set_environment();
44 }