~ubuntu-branches/ubuntu/natty/digikam/natty

« back to all changes in this revision

Viewing changes to libs/database/upgradedb_sqlite2tosqlite3.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2010-12-21 23:19:11 UTC
  • mfrom: (1.2.33 upstream) (3.1.7 experimental)
  • Revision ID: james.westby@ubuntu.com-20101221231911-z9jip7s5aht1jqn9
Tags: 2:1.7.0-1ubuntu1
* Merge from Debian Experimental. Remaining Ubuntu changes:
  - Export .pot name and copy to plugins in debian/rules
  - Version build-depends on kipi-plugins-dev to ensure build is against the
    same version on all archs
* Drop debian/patches/kubuntu_01_linker.diff, incoporated upstream
* Remove patches directory and unused patches

Show diffs side-by-side

added added

removed removed

Lines of Context:
66
66
    QString icon;
67
67
};
68
68
 
69
 
qlonglong findOrAddImage(DatabaseBackend *backend, int dirid, const QString& name,
 
69
qlonglong findOrAddImage(DatabaseBackend* backend, int dirid, const QString& name,
70
70
                         const QString& caption)
71
71
{
72
72
    QList<QVariant> values;
73
73
 
74
74
    backend->execSql(QString("SELECT id FROM Images WHERE dirid=? AND name=?"),
75
 
                              dirid, name, &values);
 
75
                     dirid, name, &values);
76
76
 
77
77
    if (!values.isEmpty())
78
78
    {
81
81
 
82
82
    QVariant id;
83
83
    backend->execSql(QString("INSERT INTO Images (dirid, name, caption) \n "
84
 
                                      "VALUES(?, ?, ?);"),
85
 
                              dirid, name, caption, 0, &id);
 
84
                             "VALUES(?, ?, ?);"),
 
85
                     dirid, name, caption, 0, &id);
86
86
 
87
87
    return id.toInt();
88
88
}
89
89
 
90
90
 
91
 
bool upgradeDB_Sqlite2ToSqlite3(AlbumDB *albumDB, DatabaseBackend *backend, const QString& sql2DBPath)
 
91
bool upgradeDB_Sqlite2ToSqlite3(AlbumDB* albumDB, DatabaseBackend* backend, const QString& sql2DBPath)
92
92
{
93
93
    QString libraryPath = QDir::cleanPath(sql2DBPath);
94
94
 
112
112
    //DatabaseAccess access;
113
113
 
114
114
    if (albumDB->getSetting("UpgradedFromSqlite2") == "yes")
 
115
    {
115
116
        return true;
 
117
    }
116
118
 
117
119
    QString dbPath = libraryPath + "/digikam3.db";
118
120
 
134
136
 
135
137
    AlbumDB_Sqlite2 db2;
136
138
    db2.setDBPath( dbPath );
 
139
 
137
140
    if (!db2.isValid())
138
141
    {
139
142
        kDebug() << "Failed to initialize Old Album Database";
163
166
    AlbumMap albumMap;
164
167
 
165
168
    backend->beginTransaction();
 
169
 
166
170
    for (QStringList::const_iterator it=values.constBegin(); it!=values.constEnd();)
167
171
    {
168
172
        _Album album;
187
191
        boundValues << album.id << album.url << album.date << album.caption << album.collection;
188
192
 
189
193
        backend->execSql(QString("INSERT INTO Albums (id, url, date, caption, collection) "
190
 
                                          "VALUES(?, ?, ?, ?, ?);"),
191
 
                                  boundValues);
 
194
                                 "VALUES(?, ?, ?, ?, ?);"),
 
195
                         boundValues);
192
196
    }
 
197
 
193
198
    backend->commitTransaction();
194
199
 
195
200
    // update tags -------------------------------------------------
202
207
    TagList tagList;
203
208
 
204
209
    backend->beginTransaction();
 
210
 
205
211
    for (QStringList::const_iterator it=values.constBegin(); it!=values.constEnd();)
206
212
    {
207
213
        _Tag tag;
218
224
        tagList.append(tag);
219
225
 
220
226
        backend->execSql(QString("INSERT INTO Tags (id, pid, name) "
221
 
                                          "VALUES(?, ?, ?);"),
222
 
                                  tag.id, tag.pid, tag.name);
 
227
                                 "VALUES(?, ?, ?);"),
 
228
                         tag.id, tag.pid, tag.name);
223
229
    }
 
230
 
224
231
    backend->commitTransaction();
225
232
 
226
233
    // update images -------------------------------------------------
230
237
                &values);
231
238
 
232
239
    backend->beginTransaction();
 
240
 
233
241
    for (QStringList::const_iterator it=values.constBegin(); it!=values.constEnd();)
234
242
    {
235
243
        int dirid   = (*it).toInt();
241
249
 
242
250
        findOrAddImage(backend, dirid, name, caption);
243
251
    }
 
252
 
244
253
    backend->commitTransaction();
245
254
 
246
255
    // update imagetags -----------------------------------------------
249
258
    db2.execSql("SELECT dirid, name, tagid FROM ImageTags;",
250
259
                &values);
251
260
    backend->beginTransaction();
 
261
 
252
262
    for (QStringList::const_iterator it=values.constBegin(); it!=values.constEnd();)
253
263
    {
254
264
        int dirid = (*it).toInt();
263
273
        qlonglong imageid = findOrAddImage(backend, dirid, name, QString());
264
274
 
265
275
        backend->execSql(QString("INSERT INTO ImageTags VALUES(?, ?)"),
266
 
                                  imageid, tagid);
 
276
                         imageid, tagid);
267
277
    }
 
278
 
268
279
    backend->commitTransaction();
269
280
 
270
281
    // update album icons -------------------------------------------------
271
282
 
272
283
    backend->beginTransaction();
 
284
 
273
285
    for (AlbumList::const_iterator it = albumList.constBegin(); it != albumList.constEnd();
274
286
         ++it)
275
287
    {
276
288
        _Album album = *it;
277
289
 
278
290
        if (album.icon.isEmpty())
 
291
        {
279
292
            continue;
 
293
        }
280
294
 
281
295
        qlonglong imageid = findOrAddImage(backend, album.id, album.icon, QString());
282
296
 
283
297
        backend->execSql(QString("UPDATE Albums SET icon=? WHERE id=?"),
284
 
                                  imageid, album.id);
 
298
                         imageid, album.id);
285
299
    }
 
300
 
286
301
    backend->commitTransaction();
287
302
 
288
303
    // -- update tag icons ---------------------------------------------------
289
304
 
290
305
    backend->beginTransaction();
 
306
 
291
307
    for (TagList::const_iterator it = tagList.constBegin(); it != tagList.constEnd(); ++it)
292
308
    {
293
309
        _Tag tag = *it;
294
310
 
295
311
        if (tag.icon.isEmpty())
 
312
        {
296
313
            continue;
 
314
        }
297
315
 
298
316
        QFileInfo fi(tag.icon);
 
317
 
299
318
        if (fi.isRelative())
300
319
        {
301
320
            backend->execSql(QString("UPDATE Tags SET iconkde=? WHERE id=?"),
302
 
                                      tag.icon, tag.id);
 
321
                             tag.icon, tag.id);
303
322
            continue;
304
323
        }
305
324
 
310
329
        QString name = fi.fileName();
311
330
 
312
331
        AlbumMap::iterator it1 = albumMap.find(url);
 
332
 
313
333
        if (it1 == albumMap.end())
314
334
        {
315
335
            kDebug() << "Could not find album with url: " << url;
322
342
        qlonglong imageid = findOrAddImage(backend, dirid, name, QString());;
323
343
 
324
344
        backend->execSql(QString("UPDATE Tags SET icon=? WHERE id=?"),
325
 
                                  imageid, tag.id);
 
345
                         imageid, tag.id);
326
346
 
327
347
    }
 
348
 
328
349
    backend->commitTransaction();
329
350
 
330
351
    // -- Remove invalid entries ----------------------------------------