Mercurial > 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 wrap: on
line diff
--- a/environment.c Wed Jul 23 11:40:45 2008 +0200 +++ b/environment.c Wed Jul 23 11:41:38 2008 +0200 @@ -1,6 +1,5 @@ #include <stdio.h> #include <stdlib.h> -#include <mysql.h> #include "db.h" #include "game.h" @@ -12,7 +11,7 @@ int groundwater, slugs, earthworms; /* get weather and last environments to calculate the next one * - sprintf(query, "select time from simulation where name = '%s' ", gamename); + sprintf(query, "select time from simulation"); db_query(query); result = mysql_store_result(conn); if (mysql_num_rows(result)) { @@ -29,14 +28,14 @@ /* set weather */ sprintf(query, " insert into environment \ - (tick, game_id, groundwater, slugs, earthworms) \ - values ('%d', '%d', '%d', '%d', '%d') ", - gametime, gameid, groundwater, slugs, earthworms); + (tick, groundwater, slugs, earthworms) \ + values ('%d', '%d', '%d', '%d') ", + gametime, groundwater, slugs, earthworms); db_query(query); - if (mysql_affected_rows(conn) > 0) { + if (sqlite3_step(stmt) == SQLITE_DONE) { printf("environment successful inserted\n"); } else { - printf("E: environment insertion failed\n"); + printf("error: environment insertion failed: %s\n", sqlite3_errmsg(db)); } } @@ -47,13 +46,13 @@ /* init */ if (argc != 2) { - printf("usage: %s <game>\n", argv[0]); + printf("usage: %s <database>\n", argv[0]); exit(1); } - gamename = argv[1]; + database = argv[1]; db_connect(); - check_game(); + read_time(); set_environment();