garten
diff 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 |
line diff
1.1 --- a/environment.c Wed Jul 23 11:40:45 2008 +0200 1.2 +++ b/environment.c Wed Jul 23 11:41:38 2008 +0200 1.3 @@ -1,6 +1,5 @@ 1.4 #include <stdio.h> 1.5 #include <stdlib.h> 1.6 -#include <mysql.h> 1.7 1.8 #include "db.h" 1.9 #include "game.h" 1.10 @@ -12,7 +11,7 @@ 1.11 int groundwater, slugs, earthworms; 1.12 1.13 /* get weather and last environments to calculate the next one * 1.14 - sprintf(query, "select time from simulation where name = '%s' ", gamename); 1.15 + sprintf(query, "select time from simulation"); 1.16 db_query(query); 1.17 result = mysql_store_result(conn); 1.18 if (mysql_num_rows(result)) { 1.19 @@ -29,14 +28,14 @@ 1.20 1.21 /* set weather */ 1.22 sprintf(query, " insert into environment \ 1.23 - (tick, game_id, groundwater, slugs, earthworms) \ 1.24 - values ('%d', '%d', '%d', '%d', '%d') ", 1.25 - gametime, gameid, groundwater, slugs, earthworms); 1.26 + (tick, groundwater, slugs, earthworms) \ 1.27 + values ('%d', '%d', '%d', '%d') ", 1.28 + gametime, groundwater, slugs, earthworms); 1.29 db_query(query); 1.30 - if (mysql_affected_rows(conn) > 0) { 1.31 + if (sqlite3_step(stmt) == SQLITE_DONE) { 1.32 printf("environment successful inserted\n"); 1.33 } else { 1.34 - printf("E: environment insertion failed\n"); 1.35 + printf("error: environment insertion failed: %s\n", sqlite3_errmsg(db)); 1.36 } 1.37 1.38 } 1.39 @@ -47,13 +46,13 @@ 1.40 1.41 /* init */ 1.42 if (argc != 2) { 1.43 - printf("usage: %s <game>\n", argv[0]); 1.44 + printf("usage: %s <database>\n", argv[0]); 1.45 exit(1); 1.46 } 1.47 - gamename = argv[1]; 1.48 + database = argv[1]; 1.49 1.50 db_connect(); 1.51 - check_game(); 1.52 + read_time(); 1.53 1.54 set_environment(); 1.55