1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
/*
* Copyright (C) 2001, 2002, 2003, 2004 Philip Blundell <philb@gnu.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*/
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/stat.h>
#include <ctype.h>
#include <time.h>
#include <gpe/pim-categories.h>
#include <gpe/errorbox.h>
#include <sqlite.h>
struct map
{
int old, new;
};
GSList *mapping;
void
migrate_one_category (sqlite *db, int id, gchar *string)
{
struct map *map;
int new_id;
char *err;
if (sqlite_exec_printf (db, "update contacts set value='MIGRATED-%d' where tag='CATEGORY' and value='%d'",
NULL, NULL, &err, id, id) != SQLITE_OK)
{
gpe_error_box (err);
free (err);
}
if (gpe_pim_category_new (string, &new_id))
{
fprintf (stderr, "old %d, new %d\n", id, new_id);
map = g_malloc0 (sizeof (*map));
map->old = id;
map->new = new_id;
mapping = g_slist_prepend (mapping, map);
}
}
void
migrate_old_categories (sqlite *db)
{
gint r, c;
gchar **list;
if (sqlite_get_table (db, "select id,description from contacts_category", &list, &r, &c, NULL) == SQLITE_OK)
{
int i;
GSList *iter;
for (i = 1; i < r; i++)
{
gchar **data = &list[i * c];
int id = atoi (data[0]);
if (id)
migrate_one_category (db, id, data[1]);
}
for (iter = mapping; iter; iter = iter->next)
{
struct map *map = iter->data;
sqlite_exec_printf (db, "update contacts set value='%d' where tag='CATEGORY' and value='MIGRATED-%d'",
NULL, NULL, NULL, map->new, map->old);
g_free (map);
}
sqlite_exec_printf (db, "drop table contacts_category", NULL, NULL, NULL);
sqlite_free_table (list);
}
}
|