Mercurial > garten
annotate 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 |
rev | line source |
---|---|
0 | 1 #include <stdio.h> |
2 #include <stdlib.h> | |
3 | |
4 #include "db.h" | |
2 | 5 #include "game.h" |
0 | 6 |
7 | |
8 | |
2 | 9 void inc_time() { |
0 | 10 /* get current time */ |
11
176ee28e7464
switched from mysql to sqlite; (+ some cleanups)
meillo@marmaro.de
parents:
2
diff
changeset
|
11 sprintf(query, "select time from game;"); |
0 | 12 db_query(query); |
11
176ee28e7464
switched from mysql to sqlite; (+ some cleanups)
meillo@marmaro.de
parents:
2
diff
changeset
|
13 if (sqlite3_step(stmt) == SQLITE_ROW) { |
176ee28e7464
switched from mysql to sqlite; (+ some cleanups)
meillo@marmaro.de
parents:
2
diff
changeset
|
14 gametime = sqlite3_column_int(stmt, 0); |
176ee28e7464
switched from mysql to sqlite; (+ some cleanups)
meillo@marmaro.de
parents:
2
diff
changeset
|
15 printf("gametime: %d\n", gametime); |
176ee28e7464
switched from mysql to sqlite; (+ some cleanups)
meillo@marmaro.de
parents:
2
diff
changeset
|
16 } else { |
176ee28e7464
switched from mysql to sqlite; (+ some cleanups)
meillo@marmaro.de
parents:
2
diff
changeset
|
17 fprintf(stderr, "error: %s\n", sqlite3_errmsg(db)); |
0 | 18 } |
11
176ee28e7464
switched from mysql to sqlite; (+ some cleanups)
meillo@marmaro.de
parents:
2
diff
changeset
|
19 sqlite3_finalize(stmt); |
0 | 20 |
21 /* increment time */ | |
11
176ee28e7464
switched from mysql to sqlite; (+ some cleanups)
meillo@marmaro.de
parents:
2
diff
changeset
|
22 sprintf(query, " update game set time = '%d';", ++gametime); |
0 | 23 db_query(query); |
11
176ee28e7464
switched from mysql to sqlite; (+ some cleanups)
meillo@marmaro.de
parents:
2
diff
changeset
|
24 if (sqlite3_step(stmt) == SQLITE_DONE) { |
0 | 25 printf("time update successful\n"); |
2 | 26 printf("virtual time: %d\n", gametime); |
0 | 27 } else { |
11
176ee28e7464
switched from mysql to sqlite; (+ some cleanups)
meillo@marmaro.de
parents:
2
diff
changeset
|
28 printf("error: time update failed: %s\n", sqlite3_errmsg(db)); |
0 | 29 } |
11
176ee28e7464
switched from mysql to sqlite; (+ some cleanups)
meillo@marmaro.de
parents:
2
diff
changeset
|
30 sqlite3_finalize(stmt); |
0 | 31 } |
32 | |
33 | |
34 int main(int argc, char* argv[]) { | |
2 | 35 printf(" --> clock\n"); |
0 | 36 |
37 /* init */ | |
38 if (argc != 2) { | |
39 printf("usage: %s <game>\n", argv[0]); | |
40 exit(1); | |
41 } | |
11
176ee28e7464
switched from mysql to sqlite; (+ some cleanups)
meillo@marmaro.de
parents:
2
diff
changeset
|
42 database = argv[1]; |
0 | 43 |
44 db_connect(); | |
11
176ee28e7464
switched from mysql to sqlite; (+ some cleanups)
meillo@marmaro.de
parents:
2
diff
changeset
|
45 read_time(); |
0 | 46 |
2 | 47 inc_time(); |
0 | 48 |
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 | |
2 | 63 printf(" --< clock\n"); |
0 | 64 return 0; |
65 } |