#include "pureimagecache.h" qlonglong PureImageCache::ConnCounter=0; PureImageCache::PureImageCache() { gtilecache=QDir::currentPath()+QDir::separator()+"mapscache"+QDir::separator(); } void PureImageCache::setGtileCache(const QString &value) { gtilecache=value; } QString PureImageCache::GtileCache() { return gtilecache; } bool PureImageCache::CreateEmptyDB(const QString &file) { qDebug()<<"Create database at:"< add; if(!QFileInfo(destFile).exists()) { qDebug()<<"Try to create EmptyDB"; ret=CreateEmptyDB(destFile); } if(!ret) return false; QSqlDatabase ca = QSqlDatabase::addDatabase("QSQLITE","ca"); ca.setDatabaseName(sourceFile); if(ca.open()) { QSqlDatabase cb = QSqlDatabase::addDatabase("QSQLITE","cb"); cb.setDatabaseName(destFile); if(cb.open()) { QSqlQuery queryb(cb); queryb.exec(QString("ATTACH DATABASE \"%1\" AS Source").arg(sourceFile)); QSqlQuery querya(ca); querya.exec("SELECT id, X, Y, Zoom, Type FROM Tiles"); while(querya.next()) { long id=querya.value(0).toLongLong(); queryb.exec(QString("SELECT id FROM Tiles WHERE X=%1 AND Y=%2 AND Zoom=%3 AND Type=%4;").arg(querya.value(1).toLongLong()).arg(querya.value(2).toLongLong()).arg(querya.value(3).toLongLong()).arg(querya.value(4).toLongLong())); if(!queryb.next()) { add.append(id); } } long f; foreach(f,add) { queryb.exec(QString("INSERT INTO Tiles(X, Y, Zoom, Type) SELECT X, Y, Zoom, Type FROM Source.Tiles WHERE id=%1").arg(f)); queryb.exec(QString("INSERT INTO TilesData(id, Tile) Values((SELECT last_insert_rowid()), (SELECT Tile FROM Source.TilesData WHERE id=%1))").arg(f)); } add.clear(); ca.close(); cb.close(); } else return false; } else return false; return true; }