garten

diff clock.c @ 11:176ee28e7464

switched from mysql to sqlite; (+ some cleanups)
author meillo@marmaro.de
date Wed, 23 Jul 2008 11:41:38 +0200
parents 8369454d4ec9
children 8db6497d6065
line diff
     1.1 --- a/clock.c	Wed Jul 23 11:40:45 2008 +0200
     1.2 +++ b/clock.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 @@ -8,28 +7,27 @@
    1.11  
    1.12  
    1.13  void inc_time() {
    1.14 -
    1.15  	/* get current time */
    1.16 -	sprintf(query, "select time from game where name = '%s' ", gamename);
    1.17 +	sprintf(query, "select time from game;");
    1.18  	db_query(query);
    1.19 -	result = mysql_store_result(conn);
    1.20 -	if (mysql_num_rows(result)) {
    1.21 -		row = mysql_fetch_row(result);
    1.22 -		gametime = atoi(row[0]);
    1.23 +	if (sqlite3_step(stmt) == SQLITE_ROW) {
    1.24 +		gametime = sqlite3_column_int(stmt, 0);
    1.25 +		printf("gametime: %d\n", gametime);
    1.26 +	} else {
    1.27 +		fprintf(stderr, "error: %s\n", sqlite3_errmsg(db));
    1.28  	}
    1.29 -	mysql_free_result(result);
    1.30 -
    1.31 +	sqlite3_finalize(stmt);
    1.32  
    1.33  	/* increment time */
    1.34 -	sprintf(query, " update game set time = '%d' where name = '%s' ", ++gametime, gamename);
    1.35 +	sprintf(query, " update game set time = '%d';", ++gametime);
    1.36  	db_query(query);
    1.37 -	if (mysql_affected_rows(conn) > 0) {
    1.38 +	if (sqlite3_step(stmt) == SQLITE_DONE) {
    1.39  		printf("time update successful\n");
    1.40  		printf("virtual time: %d\n", gametime);
    1.41  	} else {
    1.42 -		printf("E: time update failed\n");
    1.43 +		printf("error: time update failed: %s\n", sqlite3_errmsg(db));
    1.44  	}
    1.45 -
    1.46 +	sqlite3_finalize(stmt);
    1.47  }
    1.48  
    1.49  
    1.50 @@ -41,10 +39,10 @@
    1.51  		printf("usage: %s <game>\n", argv[0]);
    1.52  		exit(1);
    1.53  	}
    1.54 -	gamename = argv[1];
    1.55 +	database = argv[1];
    1.56  
    1.57  	db_connect();
    1.58 -	check_game();
    1.59 +	read_time();
    1.60  
    1.61  	inc_time();
    1.62