comparison clock.c @ 12:8db6497d6065

merged everything to only one program
author meillo@marmaro.de
date Wed, 23 Jul 2008 15:19:45 +0200
parents 176ee28e7464
children 5e6c9260913a
comparison
equal deleted inserted replaced
11:176ee28e7464 12:8db6497d6065
1 #include <stdio.h> 1 #include <stdio.h>
2 #include <stdlib.h> 2 #include <stdlib.h>
3 3
4 #include "db.h" 4 #include "db.h"
5 #include "game.h" 5 #include "game.h"
6
6 7
7 8
8 9
9 void inc_time() { 10 void inc_time() {
10 /* get current time */ 11 /* get current time */
11 sprintf(query, "select time from game;"); 12 sprintf(query, "select time from game;");
12 db_query(query); 13 db_query(query);
13 if (sqlite3_step(stmt) == SQLITE_ROW) { 14 if (sqlite3_step(stmt) == SQLITE_ROW) {
14 gametime = sqlite3_column_int(stmt, 0); 15 gametime = sqlite3_column_int(stmt, 0);
15 printf("gametime: %d\n", gametime);
16 } else { 16 } else {
17 fprintf(stderr, "error: %s\n", sqlite3_errmsg(db)); 17 fprintf(stderr, "error: %s\n", sqlite3_errmsg(db));
18 } 18 }
19 sqlite3_finalize(stmt); 19 sqlite3_finalize(stmt);
20 20
21 /* increment time */ 21 /* increment time */
22 sprintf(query, " update game set time = '%d';", ++gametime); 22 sprintf(query, " update game set time = '%d';", ++gametime);
23 db_query(query); 23 if (!db_update(query)) {
24 if (sqlite3_step(stmt) == SQLITE_DONE) {
25 printf("time update successful\n");
26 printf("virtual time: %d\n", gametime);
27 } else {
28 printf("error: time update failed: %s\n", sqlite3_errmsg(db)); 24 printf("error: time update failed: %s\n", sqlite3_errmsg(db));
29 } 25 }
30 sqlite3_finalize(stmt); 26 sqlite3_finalize(stmt);
31 } 27 }
32 28
33 29
34 int main(int argc, char* argv[]) { 30 void worldclock(void) {
35 printf(" --> clock\n");
36
37 /* init */
38 if (argc != 2) {
39 printf("usage: %s <game>\n", argv[0]);
40 exit(1);
41 }
42 database = argv[1];
43
44 db_connect();
45 read_time();
46
47 inc_time(); 31 inc_time();
48 32 printf("gametime: %d\n", gametime);
49 /*
50 while ((row = mysql_fetch_row(result)) != NULL) {
51 for (i = 0; i < mysql_num_fields(result); i++) {
52 printf("%10s ", row[i]);
53 }
54 printf("\n");
55 }
56 */
57
58
59
60
61 db_close();
62
63 printf(" --< clock\n");
64 return 0;
65 } 33 }