--- myinsane.orig 2012-01-11 15:40:49.764000023 +0100 +++ myinsane.c 2012-01-11 16:49:49.218000025 +0100 @@ -107,17 +107,15 @@ char query[1024]; unsigned long ts = 0; struct tm t1, t2; - snprintf(query, sizeof(query), "SELECT UNIX_TIMESTAMP(`%s`), `%s` FROM `%s` WHERE `%s` IS NOT NULL AND `%s` <> '0000-00-00 00:00:00'", column, column, table, column, column); + snprintf(query, sizeof(query), "SELECT UNIX_TIMESTAMP(`%s`), `%s` FROM `%s` WHERE `%s` IS NOT NULL AND `%s` <> '0000-00-00 00:00:00' AND (`%s` < FROM_UNIXTIME(%d) OR `%s` > FROM_UNIXTIME(%d))", column, column, table, column, column, column, (int)ts_lower_limit, column, (int)ts_upper_limit); if(0 == mysql_query(connection, query)){ result = mysql_store_result(connection); while(NULL!=(row = mysql_fetch_row(result))){ ts = strtoul(row[0], NULL, 10); - if((ts < ts_lower_limit) || (ts > ts_upper_limit)){ - localtime_r(&ts_lower_limit, &t1); - localtime_r(&ts_upper_limit, &t2); - fprintf(stderr,"Error: Table: `%s`, field `%s`: Value '%s' is out of allowed range ('%04u-%02u-%02u %02u-%02u-%02u'..'%04u-%02u-%02u %02u-%02u-%02u')\n", table, column, row[1], t1.tm_year + 1900, t1.tm_mon + 1, t1.tm_mday, t1.tm_hour, t1.tm_min, t1.tm_sec, t2.tm_year + 1900, t2.tm_mon + 1, t2.tm_mday, t2.tm_hour, t2.tm_min, t2.tm_sec); - exit(EXIT_FAILURE); - } + localtime_r(&ts_lower_limit, &t1); + localtime_r(&ts_upper_limit, &t2); + fprintf(stderr,"Error: Table: `%s`, field `%s`: Value '%s' is out of allowed range ('%04u-%02u-%02u %02u-%02u-%02u'..'%04u-%02u-%02u %02u-%02u-%02u')\n", table, column, row[1], t1.tm_year + 1900, t1.tm_mon + 1, t1.tm_mday, t1.tm_hour, t1.tm_min, t1.tm_sec, t2.tm_year + 1900, t2.tm_mon + 1, t2.tm_mday, t2.tm_hour, t2.tm_min, t2.tm_sec); + exit(EXIT_FAILURE); } } else{ fprintf(stderr,"Error: %s\n", mysql_error(connection)); @@ -177,7 +175,7 @@ MYSQL_RES *result; MYSQL_ROW row; - while ((c = getopt(argc, argv, "h:P:u:p:d:t:?c:asiW")) != -1){ + while ((c = getopt(argc, argv, "h:P:u:p:d:t:?c:r:asiW")) != -1){ switch (c) { case 'h': strncpy(host, optarg, sizeof(host)); break; case 'P': port = strtol(optarg, (char **)NULL, 10); break; @@ -192,6 +190,7 @@ case 'a': check_auto_inc = 1; break; case 's': check_date = 1; break; case 'i': check_id = 1; break; + case 'r': count_div = strtoull(optarg, NULL, 10); break; case 'W': warnings = 0; break; case '?': default: usage(argv[0]);