Do no extra type checking when querying the history database

This commit is contained in:
Christian Dywan 2010-01-13 00:10:32 +01:00
parent 4e561eeef3
commit 789485a086

View file

@ -591,13 +591,6 @@ midori_history_add_items (void* data,
g_return_val_if_fail (argc % ncols == 0, 1); g_return_val_if_fail (argc % ncols == 0, 1);
for (i = 0; i < (argc - ncols) + 1; i++) for (i = 0; i < (argc - ncols) + 1; i++)
{
if (argv[i])
{
if (colname[i] && !g_ascii_strcasecmp (colname[i], "uri") &&
colname[i + 1] && !g_ascii_strcasecmp (colname[i + 1], "title") &&
colname[i + 2] && !g_ascii_strcasecmp (colname[i + 2], "date") &&
colname[i + 3] && !g_ascii_strcasecmp (colname[i + 3], "day"))
{ {
item = katze_item_new (); item = katze_item_new ();
katze_item_set_uri (item, argv[i]); katze_item_set_uri (item, argv[i]);
@ -613,44 +606,18 @@ midori_history_add_items (void* data,
if (day == katze_item_get_added (KATZE_ITEM (parent))) if (day == katze_item_get_added (KATZE_ITEM (parent)))
break; break;
} }
if (j < 0) if (j < 0)
{ {
parent = katze_array_new (KATZE_TYPE_ARRAY); parent = katze_array_new (KATZE_TYPE_ARRAY);
katze_item_set_added (KATZE_ITEM (parent), day); katze_item_set_added (KATZE_ITEM (parent), day);
strftime (token, sizeof (token), "%x", strftime (token, sizeof (token), "%x", localtime ((time_t *)&date));
localtime ((time_t *)&date));
katze_item_set_name (KATZE_ITEM (parent), token); katze_item_set_name (KATZE_ITEM (parent), token);
katze_array_add_item (array, parent); katze_array_add_item (array, parent);
} }
katze_array_add_item (parent, item); katze_array_add_item (parent, item);
} }
}
}
return 0;
}
static int
midori_history_test_day_column (void* data,
int argc,
char** argv,
char** colname)
{
gint i;
gboolean* has_day;
has_day = (gboolean*)data;
for (i = 0; i < argc; i++)
{
if (argv[i] &&
!g_ascii_strcasecmp (colname[i], "name") &&
!g_ascii_strcasecmp (argv[i], "day"))
{
*has_day = TRUE;
break;
}
}
return 0; return 0;
} }
@ -675,15 +642,10 @@ midori_history_initialize (KatzeArray* array,
error)) error))
return NULL; return NULL;
if (!db_exec_callback (db, if (!db_exec (db, "SELECT day FROM history LIMIT 1", error))
"PRAGMA table_info(history)",
midori_history_test_day_column,
&has_day, error))
return NULL; return NULL;
if (!has_day) if (!has_day && !db_exec (db,
{
if (!db_exec (db,
"BEGIN TRANSACTION;" "BEGIN TRANSACTION;"
"CREATE TEMPORARY TABLE backup (uri text, title text, date integer);" "CREATE TEMPORARY TABLE backup (uri text, title text, date integer);"
"INSERT INTO backup SELECT uri,title,date FROM history;" "INSERT INTO backup SELECT uri,title,date FROM history;"
@ -697,7 +659,6 @@ midori_history_initialize (KatzeArray* array,
"COMMIT;", "COMMIT;",
error)) error))
return NULL; return NULL;
}
if (!db_exec_callback (db, if (!db_exec_callback (db,
"SELECT uri, title, date, day FROM history " "SELECT uri, title, date, day FROM history "
@ -2030,11 +1991,10 @@ main (int argc,
g_error_free (error); g_error_free (error);
} }
#endif #endif
#if HAVE_SQLITE
katze_assign (config_file, build_config_filename ("history.db"));
#endif
history = katze_array_new (KATZE_TYPE_ARRAY); history = katze_array_new (KATZE_TYPE_ARRAY);
#if HAVE_SQLITE #if HAVE_SQLITE
katze_assign (config_file, build_config_filename ("history.db"));
error = NULL; error = NULL;
if ((db = midori_history_initialize (history, config_file, &error)) == NULL) if ((db = midori_history_initialize (history, config_file, &error)) == NULL)
{ {