# HG changeset patch # User Daniel O'Connor # Date 1265851031 -37800 # Node ID f561c7f130a069bdc1c6517bf0af29b9b7cbe2f7 # Parent dc5ff2a1ed81a316fe4060ca7c3b72db14f6d5f1 Make -n not do any DB stuff so we don't need to #if the MySQL stuff out. diff -r dc5ff2a1ed81 -r f561c7f130a0 db.c --- a/db.c Wed Feb 10 11:33:27 2010 +1030 +++ b/db.c Thu Feb 11 11:47:11 2010 +1030 @@ -117,6 +117,8 @@ update = 0; else if (! strcmp (argv [arg], "-v")) /* verbose */ verbose = 1; + else if (! strcmp (argv [arg], "-vv")) /* more verbose */ + verbose = 2; else if (! strcmp (argv [arg], "-1")) /* run once and exit */ once = 1; else @@ -139,7 +141,7 @@ } } - /* Set default values for config stuff above. */ + /* Set default values for config stuff above. */ if (! config.station_id) config.station_id = "mystation"; if (! config.db_host) @@ -161,7 +163,12 @@ if (! config.db) config.db = "weather"; -#if 0 + /* No updates required so don't bother with DB stuff */ + if (!update) { + config.poll_interval = 5; + return 0; + } + if (! mysql_init (mysql)) { fprintf (stderr, "Can't initialize MySQL\n"); @@ -174,18 +181,18 @@ exit (1); } if (! mysql_real_connect (mysql, /* DB state */ - config.db_host, /* database host */ - config.db_user, - config.db_passwd, - config.db, - 0, - NULL, - 0 )) + config.db_host, /* database host */ + config.db_user, + config.db_passwd, + config.db, + 0, + NULL, + 0 )) { fprintf (stderr, - "Can't connect to databaase: %s (%d)\n", - mysql_error (mysql), - mysql_errno (mysql) ); + "Can't connect to databaase: %s (%d)\n", + mysql_error (mysql), + mysql_errno (mysql) ); exit (1); } @@ -194,26 +201,26 @@ */ sprintf (mysql_querytext, - "SELECT version,\n" - " latitude,\n" - " longitude,\n" - " elevation,\n" - " pressure_error,\n" - " poll_interval,\n" - " address,\n" - " wunderground_station_id,\n" - " wunderground_passwd,\n" - " wunderground_report_interval,\n" - " weatheforyou_station_id,\n" - " weatheforyou_passwd,\n" - " weatherforyou_report_interval,\n" - " website_generation_interval,\n" - " db_table,\n" - " php_header,\n" - " comparefile\n" - "FROM config\n" - "WHERE station_id = \"%s\";\n", - config.station_id ); + "SELECT version,\n" + " latitude,\n" + " longitude,\n" + " elevation,\n" + " pressure_error,\n" + " poll_interval,\n" + " address,\n" + " wunderground_station_id,\n" + " wunderground_passwd,\n" + " wunderground_report_interval,\n" + " weatheforyou_station_id,\n" + " weatheforyou_passwd,\n" + " weatherforyou_report_interval,\n" + " website_generation_interval,\n" + " db_table,\n" + " php_header,\n" + " comparefile\n" + "FROM config\n" + "WHERE station_id = \"%s\";\n", + config.station_id ); if (doquery (mysql_querytext)) /* failure */ exit (1); @@ -245,7 +252,7 @@ config.db_table = mycopy (mysql_row [col++]); /* table */ config.php_header = mycopy (mysql_row [col++]); /* php header file with weather data */ config.comparefile = mycopy (mysql_row [col++]); /* file to compare local weather stations */ -#endif + return 0; /* success */ }