garten
view environment.c @ 10:13c6828bd4a5
switched from mysql to sqlite; (+ some cleanups)
author | meillo@marmaro.de |
---|---|
date | Wed, 23 Jul 2008 11:40:45 +0200 |
parents | |
children | 176ee28e7464 |
line source
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <mysql.h>
5 #include "db.h"
6 #include "game.h"
11 void set_environment() {
12 int groundwater, slugs, earthworms;
14 /* get weather and last environments to calculate the next one *
15 sprintf(query, "select time from simulation where name = '%s' ", gamename);
16 db_query(query);
17 result = mysql_store_result(conn);
18 if (mysql_num_rows(result)) {
19 row = mysql_fetch_row(result);
20 time = atoi(row[0]);
21 }
22 mysql_free_result(result);
23 */
25 groundwater = 20;
26 slugs = 5;
27 earthworms = 10;
30 /* set weather */
31 sprintf(query, " insert into environment \
32 (tick, game_id, groundwater, slugs, earthworms) \
33 values ('%d', '%d', '%d', '%d', '%d') ",
34 gametime, gameid, groundwater, slugs, earthworms);
35 db_query(query);
36 if (mysql_affected_rows(conn) > 0) {
37 printf("environment successful inserted\n");
38 } else {
39 printf("E: environment insertion failed\n");
40 }
42 }
45 int main(int argc, char* argv[]) {
46 printf(" --> environment\n");
48 /* init */
49 if (argc != 2) {
50 printf("usage: %s <game>\n", argv[0]);
51 exit(1);
52 }
53 gamename = argv[1];
55 db_connect();
56 check_game();
58 set_environment();
61 db_close();
63 printf(" --< environment\n");
64 return 0;
65 }