garten

annotate growth.c @ 11:176ee28e7464

switched from mysql to sqlite; (+ some cleanups)
author meillo@marmaro.de
date Wed, 23 Jul 2008 11:41:38 +0200
parents b1e309dc0b98
children 8db6497d6065
rev   line source
meillo@7 1 #include <stdio.h>
meillo@7 2 #include <stdlib.h>
meillo@7 3
meillo@7 4 #include "db.h"
meillo@7 5 #include "game.h"
meillo@7 6
meillo@7 7
meillo@7 8
meillo@7 9
meillo@7 10 void grow_plants() {
meillo@7 11 int i;
meillo@7 12 unsigned char r[6];
meillo@7 13
meillo@7 14 /* get weather and last environments to calculate the next one */
meillo@7 15 sprintf(query, "select\
meillo@7 16 f.id, f.size, f.age, p.size, p.growspeed, p.age\
meillo@7 17 from field f\
meillo@11 18 join plant p on f.plant_id = p.id ");
meillo@7 19 db_query(query);
meillo@11 20 /* printf("number of plants to process: %d\n", (int)mysql_num_rows(result)); */
meillo@11 21 while (sqlite3_step(stmt) == SQLITE_ROW) {
meillo@7 22 for (i = 0; i < 6; i++) {
meillo@11 23 r[i] = (char) sqlite3_column_int(stmt, i);
meillo@7 24 }
meillo@7 25
meillo@7 26 sprintf(query, "update field set \
meillo@7 27 size = '%d', age = '%d' \
meillo@7 28 where id = '%d' ",
meillo@7 29 (r[1] + 1), r[2]+1, r[0]);
meillo@7 30 db_query(query);
meillo@11 31 ;
meillo@7 32
meillo@11 33 if (sqlite3_step(stmt) == SQLITE_DONE) {
meillo@7 34 printf("update successful ++ %s\n", query);
meillo@7 35 } else {
meillo@11 36 printf("E: update failed ++ %s\n", sqlite3_errmsg(db));
meillo@7 37 }
meillo@7 38
meillo@7 39 }
meillo@11 40 sqlite3_finalize(stmt);
meillo@7 41
meillo@7 42
meillo@7 43
meillo@7 44
meillo@7 45 }
meillo@7 46
meillo@7 47
meillo@7 48 int main(int argc, char* argv[]) {
meillo@7 49 printf(" --> %s\n", argv[0]);
meillo@7 50
meillo@7 51 /* init */
meillo@7 52 if (argc != 2) {
meillo@11 53 printf("usage: %s <database>\n", argv[0]);
meillo@7 54 exit(1);
meillo@7 55 }
meillo@11 56 database = argv[1];
meillo@7 57
meillo@7 58 db_connect();
meillo@11 59 read_time();
meillo@7 60
meillo@7 61 grow_plants();
meillo@7 62
meillo@7 63
meillo@7 64 db_close();
meillo@7 65
meillo@7 66 printf(" --< %s\n", argv[0]);
meillo@7 67 return 0;
meillo@7 68 }