Mercurial > garten
comparison 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 |
comparison
equal
deleted
inserted
replaced
10:13c6828bd4a5 | 11:176ee28e7464 |
---|---|
1 #include <stdio.h> | 1 #include <stdio.h> |
2 #include <stdlib.h> | 2 #include <stdlib.h> |
3 #include <mysql.h> | |
4 | 3 |
5 #include "db.h" | 4 #include "db.h" |
6 #include "game.h" | 5 #include "game.h" |
7 | 6 |
8 | 7 |
10 | 9 |
11 void set_environment() { | 10 void set_environment() { |
12 int groundwater, slugs, earthworms; | 11 int groundwater, slugs, earthworms; |
13 | 12 |
14 /* get weather and last environments to calculate the next one * | 13 /* get weather and last environments to calculate the next one * |
15 sprintf(query, "select time from simulation where name = '%s' ", gamename); | 14 sprintf(query, "select time from simulation"); |
16 db_query(query); | 15 db_query(query); |
17 result = mysql_store_result(conn); | 16 result = mysql_store_result(conn); |
18 if (mysql_num_rows(result)) { | 17 if (mysql_num_rows(result)) { |
19 row = mysql_fetch_row(result); | 18 row = mysql_fetch_row(result); |
20 time = atoi(row[0]); | 19 time = atoi(row[0]); |
27 earthworms = 10; | 26 earthworms = 10; |
28 | 27 |
29 | 28 |
30 /* set weather */ | 29 /* set weather */ |
31 sprintf(query, " insert into environment \ | 30 sprintf(query, " insert into environment \ |
32 (tick, game_id, groundwater, slugs, earthworms) \ | 31 (tick, groundwater, slugs, earthworms) \ |
33 values ('%d', '%d', '%d', '%d', '%d') ", | 32 values ('%d', '%d', '%d', '%d') ", |
34 gametime, gameid, groundwater, slugs, earthworms); | 33 gametime, groundwater, slugs, earthworms); |
35 db_query(query); | 34 db_query(query); |
36 if (mysql_affected_rows(conn) > 0) { | 35 if (sqlite3_step(stmt) == SQLITE_DONE) { |
37 printf("environment successful inserted\n"); | 36 printf("environment successful inserted\n"); |
38 } else { | 37 } else { |
39 printf("E: environment insertion failed\n"); | 38 printf("error: environment insertion failed: %s\n", sqlite3_errmsg(db)); |
40 } | 39 } |
41 | 40 |
42 } | 41 } |
43 | 42 |
44 | 43 |
45 int main(int argc, char* argv[]) { | 44 int main(int argc, char* argv[]) { |
46 printf(" --> environment\n"); | 45 printf(" --> environment\n"); |
47 | 46 |
48 /* init */ | 47 /* init */ |
49 if (argc != 2) { | 48 if (argc != 2) { |
50 printf("usage: %s <game>\n", argv[0]); | 49 printf("usage: %s <database>\n", argv[0]); |
51 exit(1); | 50 exit(1); |
52 } | 51 } |
53 gamename = argv[1]; | 52 database = argv[1]; |
54 | 53 |
55 db_connect(); | 54 db_connect(); |
56 check_game(); | 55 read_time(); |
57 | 56 |
58 set_environment(); | 57 set_environment(); |
59 | 58 |
60 | 59 |
61 db_close(); | 60 db_close(); |