garten
view clock.c @ 1:3ff1fbe4693d
moved gamecheck and some vars out
author | meillo@marmaro.de |
---|---|
date | Wed, 14 May 2008 21:07:33 +0200 |
parents | |
children | 8369454d4ec9 |
line source
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <mysql.h>
5 #include "db.h"
7 char query[512];
10 int check_game(char* gamename) {
11 int rows;
13 sprintf(query, "select id from simulation where name = '%s' ", gamename);
14 db_query(query);
15 result = mysql_store_result(conn);
16 rows = mysql_num_rows(result);
17 mysql_free_result(result);
18 return rows;
19 }
22 void inc_time(char* gamename) {
23 int time = 0;
25 /* get current time */
26 sprintf(query, "select time from simulation where name = '%s' ", gamename);
27 db_query(query);
28 result = mysql_store_result(conn);
29 if (mysql_num_rows(result)) {
30 row = mysql_fetch_row(result);
31 time = atoi(row[0]);
32 }
33 mysql_free_result(result);
36 /* increment time */
37 sprintf(query, " update simulation set time = '%d' where name = '%s' ", ++time, gamename);
38 db_query(query);
39 if (mysql_affected_rows(conn) > 0) {
40 printf("time update successful\n");
41 printf("simulation time: %d\n", time);
42 } else {
43 printf("E: time update failed\n");
44 }
46 }
49 int main(int argc, char* argv[]) {
50 int i;
51 char* gamename;
53 /* init */
54 if (argc != 2) {
55 printf("usage: %s <game>\n", argv[0]);
56 exit(1);
57 }
58 gamename = argv[1];
60 printf("gamename: %s\n", gamename);
62 db_connect();
64 if (check_game(gamename) != 1) {
65 printf("game '%s' does not exist\n", gamename);
66 exit(1);
67 }
69 inc_time(gamename);
71 /*
72 while ((row = mysql_fetch_row(result)) != NULL) {
73 for (i = 0; i < mysql_num_fields(result); i++) {
74 printf("%10s ", row[i]);
75 }
76 printf("\n");
77 }
78 */
83 db_close();
85 printf("the garten program\n");
86 return 0;
87 }