comparison clock.c @ 17:5e6c9260913a

lots of cleanups and small fixes
author meillo@marmaro.de
date Wed, 23 Jul 2008 17:14:38 +0200
parents 8db6497d6065
children 5937504619f2
comparison
equal deleted inserted replaced
16:3c104b5f5158 17:5e6c9260913a
1 #include <stdio.h> 1 #include <stdio.h>
2 #include <stdlib.h> 2 #include <stdlib.h>
3
4 #include "db.h" 3 #include "db.h"
5 #include "game.h" 4 #include "game.h"
6
7
8 5
9 6
10 void inc_time() { 7 void inc_time() {
11 /* get current time */ 8 /* get current time */
12 sprintf(query, "select time from game;"); 9 sprintf(query, "select time from game;");
13 db_query(query); 10 stmt = db_query(query);
14 if (sqlite3_step(stmt) == SQLITE_ROW) { 11 if (sqlite3_step(stmt) == SQLITE_ROW) {
15 gametime = sqlite3_column_int(stmt, 0); 12 gametime = sqlite3_column_int(stmt, 0);
16 } else { 13 } else {
17 fprintf(stderr, "error: %s\n", sqlite3_errmsg(db)); 14 db_error("get current time");
18 } 15 }
19 sqlite3_finalize(stmt); 16 sqlite3_finalize(stmt);
20 17
21 /* increment time */ 18 /* increment time */
22 sprintf(query, " update game set time = '%d';", ++gametime); 19 sprintf(query,
20 "update game"
21 "set time = '%d';"
22 , ++gametime
23 );
23 if (!db_update(query)) { 24 if (!db_update(query)) {
24 printf("error: time update failed: %s\n", sqlite3_errmsg(db)); 25 db_error("time update");
25 } 26 }
26 sqlite3_finalize(stmt);
27 } 27 }
28 28
29 29
30 void worldclock(void) { 30 void worldclock(void) {
31 inc_time(); 31 inc_time();