changeset 4:f561c7f130a0

Make -n not do any DB stuff so we don't need to #if the MySQL stuff out.
author Daniel O'Connor <darius@dons.net.au>
date Thu, 11 Feb 2010 11:47:11 +1030
parents dc5ff2a1ed81
children b22a888eb975
files db.c
diffstat 1 files changed, 40 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- 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 */
 }