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);
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 ();
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)))
break;
}
if (j < 0)
{
parent = katze_array_new (KATZE_TYPE_ARRAY);
katze_item_set_added (KATZE_ITEM (parent), day);
strftime (token, sizeof (token), "%x",
localtime ((time_t *)&date));
strftime (token, sizeof (token), "%x", localtime ((time_t *)&date));
katze_item_set_name (KATZE_ITEM (parent), token);
katze_array_add_item (array, parent);
}
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;
}
@ -675,15 +642,10 @@ midori_history_initialize (KatzeArray* array,
error))
return NULL;
if (!db_exec_callback (db,
"PRAGMA table_info(history)",
midori_history_test_day_column,
&has_day, error))
if (!db_exec (db, "SELECT day FROM history LIMIT 1", error))
return NULL;
if (!has_day)
{
if (!db_exec (db,
if (!has_day && !db_exec (db,
"BEGIN TRANSACTION;"
"CREATE TEMPORARY TABLE backup (uri text, title text, date integer);"
"INSERT INTO backup SELECT uri,title,date FROM history;"
@ -697,7 +659,6 @@ midori_history_initialize (KatzeArray* array,
"COMMIT;",
error))
return NULL;
}
if (!db_exec_callback (db,
"SELECT uri, title, date, day FROM history "
@ -2030,11 +1991,10 @@ main (int argc,
g_error_free (error);
}
#endif
#if HAVE_SQLITE
katze_assign (config_file, build_config_filename ("history.db"));
#endif
history = katze_array_new (KATZE_TYPE_ARRAY);
#if HAVE_SQLITE
katze_assign (config_file, build_config_filename ("history.db"));
error = NULL;
if ((db = midori_history_initialize (history, config_file, &error)) == NULL)
{