Mercurial > ~darius > hgwebdir.cgi > wh1080
comparison db.c @ 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 | e0b32014ed14 |
comparison
equal
deleted
inserted
replaced
3:dc5ff2a1ed81 | 4:f561c7f130a0 |
---|---|
115 debug = 1; | 115 debug = 1; |
116 else if (! strcmp (argv [arg], "-n")) /* turn off DB updates */ | 116 else if (! strcmp (argv [arg], "-n")) /* turn off DB updates */ |
117 update = 0; | 117 update = 0; |
118 else if (! strcmp (argv [arg], "-v")) /* verbose */ | 118 else if (! strcmp (argv [arg], "-v")) /* verbose */ |
119 verbose = 1; | 119 verbose = 1; |
120 else if (! strcmp (argv [arg], "-vv")) /* more verbose */ | |
121 verbose = 2; | |
120 else if (! strcmp (argv [arg], "-1")) /* run once and exit */ | 122 else if (! strcmp (argv [arg], "-1")) /* run once and exit */ |
121 once = 1; | 123 once = 1; |
122 else | 124 else |
123 { | 125 { |
124 if (! config.station_id) | 126 if (! config.station_id) |
137 return -1; | 139 return -1; |
138 } | 140 } |
139 } | 141 } |
140 } | 142 } |
141 | 143 |
142 /* Set default values for config stuff above. */ | 144 /* Set default values for config stuff above. */ |
143 if (! config.station_id) | 145 if (! config.station_id) |
144 config.station_id = "mystation"; | 146 config.station_id = "mystation"; |
145 if (! config.db_host) | 147 if (! config.db_host) |
146 config.db_host = "localhost"; | 148 config.db_host = "localhost"; |
147 if (! config.db_user) | 149 if (! config.db_user) |
159 if (! config.db_passwd) | 161 if (! config.db_passwd) |
160 config.db_passwd = ""; | 162 config.db_passwd = ""; |
161 if (! config.db) | 163 if (! config.db) |
162 config.db = "weather"; | 164 config.db = "weather"; |
163 | 165 |
164 #if 0 | 166 /* No updates required so don't bother with DB stuff */ |
167 if (!update) { | |
168 config.poll_interval = 5; | |
169 return 0; | |
170 } | |
171 | |
165 if (! mysql_init (mysql)) | 172 if (! mysql_init (mysql)) |
166 { | 173 { |
167 fprintf (stderr, "Can't initialize MySQL\n"); | 174 fprintf (stderr, "Can't initialize MySQL\n"); |
168 exit (1); | 175 exit (1); |
169 } | 176 } |
172 { | 179 { |
173 fprintf (stderr, "Can't initialize MySQL: insufficient memory\n"); | 180 fprintf (stderr, "Can't initialize MySQL: insufficient memory\n"); |
174 exit (1); | 181 exit (1); |
175 } | 182 } |
176 if (! mysql_real_connect (mysql, /* DB state */ | 183 if (! mysql_real_connect (mysql, /* DB state */ |
177 config.db_host, /* database host */ | 184 config.db_host, /* database host */ |
178 config.db_user, | 185 config.db_user, |
179 config.db_passwd, | 186 config.db_passwd, |
180 config.db, | 187 config.db, |
181 0, | 188 0, |
182 NULL, | 189 NULL, |
183 0 )) | 190 0 )) |
184 { | 191 { |
185 fprintf (stderr, | 192 fprintf (stderr, |
186 "Can't connect to databaase: %s (%d)\n", | 193 "Can't connect to databaase: %s (%d)\n", |
187 mysql_error (mysql), | 194 mysql_error (mysql), |
188 mysql_errno (mysql) ); | 195 mysql_errno (mysql) ); |
189 exit (1); | 196 exit (1); |
190 } | 197 } |
191 | 198 |
192 /* | 199 /* |
193 * Read the rest of the config from specified database. | 200 * Read the rest of the config from specified database. |
194 */ | 201 */ |
195 | 202 |
196 sprintf (mysql_querytext, | 203 sprintf (mysql_querytext, |
197 "SELECT version,\n" | 204 "SELECT version,\n" |
198 " latitude,\n" | 205 " latitude,\n" |
199 " longitude,\n" | 206 " longitude,\n" |
200 " elevation,\n" | 207 " elevation,\n" |
201 " pressure_error,\n" | 208 " pressure_error,\n" |
202 " poll_interval,\n" | 209 " poll_interval,\n" |
203 " address,\n" | 210 " address,\n" |
204 " wunderground_station_id,\n" | 211 " wunderground_station_id,\n" |
205 " wunderground_passwd,\n" | 212 " wunderground_passwd,\n" |
206 " wunderground_report_interval,\n" | 213 " wunderground_report_interval,\n" |
207 " weatheforyou_station_id,\n" | 214 " weatheforyou_station_id,\n" |
208 " weatheforyou_passwd,\n" | 215 " weatheforyou_passwd,\n" |
209 " weatherforyou_report_interval,\n" | 216 " weatherforyou_report_interval,\n" |
210 " website_generation_interval,\n" | 217 " website_generation_interval,\n" |
211 " db_table,\n" | 218 " db_table,\n" |
212 " php_header,\n" | 219 " php_header,\n" |
213 " comparefile\n" | 220 " comparefile\n" |
214 "FROM config\n" | 221 "FROM config\n" |
215 "WHERE station_id = \"%s\";\n", | 222 "WHERE station_id = \"%s\";\n", |
216 config.station_id ); | 223 config.station_id ); |
217 if (doquery (mysql_querytext)) /* failure */ | 224 if (doquery (mysql_querytext)) /* failure */ |
218 exit (1); | 225 exit (1); |
219 | 226 |
220 if (! (mysql_row = mysql_fetch_row (mysql_result))) /* got something */ | 227 if (! (mysql_row = mysql_fetch_row (mysql_result))) /* got something */ |
221 { | 228 { |
243 config.weatherforyou_report_interval = atoi (mysql_row [col++]); /* how many seconds between reports to Weather for you */ | 250 config.weatherforyou_report_interval = atoi (mysql_row [col++]); /* how many seconds between reports to Weather for you */ |
244 config.website_generation_interval = atoi (mysql_row [col++]); /* how many seconds between generating PHP header file */ | 251 config.website_generation_interval = atoi (mysql_row [col++]); /* how many seconds between generating PHP header file */ |
245 config.db_table = mycopy (mysql_row [col++]); /* table */ | 252 config.db_table = mycopy (mysql_row [col++]); /* table */ |
246 config.php_header = mycopy (mysql_row [col++]); /* php header file with weather data */ | 253 config.php_header = mycopy (mysql_row [col++]); /* php header file with weather data */ |
247 config.comparefile = mycopy (mysql_row [col++]); /* file to compare local weather stations */ | 254 config.comparefile = mycopy (mysql_row [col++]); /* file to compare local weather stations */ |
248 #endif | 255 |
249 return 0; /* success */ | 256 return 0; /* success */ |
250 } | 257 } |
251 | 258 |