initial commit
This commit is contained in:
+156
-7
@@ -15,6 +15,7 @@ cPictureLibrary::cPictureLibrary(QObject *parent) : QObject(parent)
|
||||
|
||||
bool cPictureLibrary::openDatabase()
|
||||
{
|
||||
QSqlQuery query;
|
||||
QSettings settings;
|
||||
QString szDB = settings.value("database/path").toString();
|
||||
|
||||
@@ -32,8 +33,6 @@ bool cPictureLibrary::openDatabase()
|
||||
createDatabase();
|
||||
else
|
||||
{
|
||||
QSqlQuery query;
|
||||
|
||||
query.prepare("SELECT version FROM config;");
|
||||
if(!query.exec())
|
||||
{
|
||||
@@ -43,14 +42,45 @@ bool cPictureLibrary::openDatabase()
|
||||
}
|
||||
|
||||
query.next();
|
||||
if(query.value("version").toInt() < 2)
|
||||
if(query.value("version").toInt() < 4)
|
||||
updateDatabase(query.value("version").toInt());
|
||||
query.finish();
|
||||
}
|
||||
|
||||
if(!query.exec("SELECT rootPath FROM config;"))
|
||||
{
|
||||
myDebug << query.lastError().text();
|
||||
return(false);
|
||||
}
|
||||
|
||||
if(!query.next())
|
||||
{
|
||||
myDebug << query.lastError().text();
|
||||
return(false);
|
||||
}
|
||||
|
||||
m_szRootPath = query.value("rootPath").toString();
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
QString cPictureLibrary::rootPath()
|
||||
{
|
||||
return(m_szRootPath);
|
||||
}
|
||||
|
||||
bool cPictureLibrary::isValid()
|
||||
{
|
||||
if(m_db.isOpen() && m_db.isValid())
|
||||
return(true);
|
||||
return(false);
|
||||
}
|
||||
|
||||
QSqlDatabase cPictureLibrary::database()
|
||||
{
|
||||
return(m_db);
|
||||
}
|
||||
|
||||
bool cPictureLibrary::createTable(const QString& szSQL)
|
||||
{
|
||||
QSqlQuery query;
|
||||
@@ -71,12 +101,40 @@ bool cPictureLibrary::createDatabase()
|
||||
QSqlQuery query;
|
||||
|
||||
if(!createTable("CREATE TABLE config ( "
|
||||
" version INTEGER"
|
||||
" version INTEGER, "
|
||||
" rootPath TEXT"
|
||||
"); "))
|
||||
return(false);
|
||||
|
||||
if(!createTable("CREATE TABLE picture ( "
|
||||
" id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE, "
|
||||
" fileName TEXT, "
|
||||
" filePath TEXT, "
|
||||
" imageWidth INTEGER, "
|
||||
" imageHeight INTEGER, "
|
||||
" cameraMake TEXT, "
|
||||
" cameraModel TEXT, "
|
||||
" dateTime DATETIME, "
|
||||
" fNumber TEXT, "
|
||||
" iso INTEGER, "
|
||||
" flashID INTEGER, "
|
||||
" focalLength DOUBLE, "
|
||||
" lensMake TEXT, "
|
||||
" lensModel TEXT, "
|
||||
" exposureTime TEXT, "
|
||||
" exposureBias INTEGER, "
|
||||
" exifVersion TEXT, "
|
||||
" dateTimeOriginal DATETIME, "
|
||||
" dateTimeDigitized DATETIME, "
|
||||
" whiteBalance INTEGER, "
|
||||
" focalLength35 DOUBLE, "
|
||||
" gps TEXT, "
|
||||
" thumbnail BLOB"
|
||||
"); "))
|
||||
return(false);
|
||||
|
||||
query.prepare("INSERT INTO config (version) VALUES (:version);");
|
||||
query.bindValue(":version", 1);
|
||||
query.bindValue(":version", 4);
|
||||
if(!query.exec())
|
||||
{
|
||||
myDebug << query.lastError().text();
|
||||
@@ -88,8 +146,8 @@ bool cPictureLibrary::createDatabase()
|
||||
|
||||
bool cPictureLibrary::updateDatabase(qint32 version)
|
||||
{
|
||||
if(version < 2)
|
||||
updateDatabase2(version);
|
||||
if(version < 4)
|
||||
updateDatabase4(version);
|
||||
|
||||
return(true);
|
||||
}
|
||||
@@ -112,3 +170,94 @@ bool cPictureLibrary::updateDatabase2(qint32 /*version*/)
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool cPictureLibrary::updateDatabase3(qint32 version)
|
||||
{
|
||||
if(version < 2)
|
||||
updateDatabase2(version);
|
||||
|
||||
QSqlQuery query;
|
||||
|
||||
if(!createTable("CREATE TABLE picture ( "
|
||||
" id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE, "
|
||||
" fileName TEXT, "
|
||||
" imageWidth INTEGER, "
|
||||
" imageHeight INTEGER, "
|
||||
" cameraMake TEXT, "
|
||||
" cameraModel TEXT, "
|
||||
" dateTime DATETIME, "
|
||||
" fNumber TEXT, "
|
||||
" iso INTEGER, "
|
||||
" flashID INTEGER, "
|
||||
" focalLength DOUBLE, "
|
||||
" lensMake TEXT, "
|
||||
" lensModel TEXT, "
|
||||
" exposureTime TEXT, "
|
||||
" exposureBias INTEGER, "
|
||||
" exifVersion TEXT, "
|
||||
" dateTimeOriginal DATETIME, "
|
||||
" dateTimeDigitized DATETIME, "
|
||||
" whiteBalance INTEGER, "
|
||||
" focalLength35 DOUBLE, "
|
||||
" gps TEXT, "
|
||||
" thumbnail BLOB"
|
||||
"); "))
|
||||
return(false);
|
||||
|
||||
if(!query.exec("UPDATE config SET version=3;"))
|
||||
{
|
||||
myDebug << query.lastError().text();
|
||||
return(false);
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool cPictureLibrary::updateDatabase4(qint32 version)
|
||||
{
|
||||
if(version < 3)
|
||||
updateDatabase3(version);
|
||||
|
||||
QSqlQuery query;
|
||||
|
||||
QString rootPath;
|
||||
|
||||
if(!query.exec("SELECT rootPath FROM config;"))
|
||||
{
|
||||
myDebug << query.lastError().text();
|
||||
return(false);
|
||||
}
|
||||
if(!query.next())
|
||||
{
|
||||
myDebug << query.lastError().text();
|
||||
return(false);
|
||||
}
|
||||
rootPath = query.value("rootPath").toString();
|
||||
|
||||
if(!query.exec("ALTER TABLE picture ADD filePath TEXT;"))
|
||||
{
|
||||
myDebug << query.lastError().text();
|
||||
return(false);
|
||||
}
|
||||
|
||||
query.prepare(" UPDATE picture"
|
||||
" SET fileName = REPLACE(fileName, RTRIM(fileName, REPLACE(fileName, '\', '')), ''),"
|
||||
" filePath = SUBSTR(SUBSTR(fileName, LENGTH(:rootPath1)+2, LENGTH(SUBSTR(fileName, LENGTH(:rootPath2)+2))-LENGTH(REPLACE(fileName, RTRIM(fileName, REPLACE(fileName, '\', '')), ''))), 1, LENGTH(SUBSTR(fileName, LENGTH(:rootPath3)+2, LENGTH(SUBSTR(fileName, LENGTH(:rootPath4)+2))-LENGTH(REPLACE(fileName, RTRIM(fileName, REPLACE(fileName, '\', '')), ''))))-1);");
|
||||
query.bindValue(":rootPath1", rootPath);
|
||||
query.bindValue(":rootPath2", rootPath);
|
||||
query.bindValue(":rootPath3", rootPath);
|
||||
query.bindValue(":rootPath4", rootPath);
|
||||
if(!query.exec())
|
||||
{
|
||||
myDebug << query.lastError().text();
|
||||
return(false);
|
||||
}
|
||||
|
||||
if(!query.exec("UPDATE config SET version=4;"))
|
||||
{
|
||||
myDebug << query.lastError().text();
|
||||
return(false);
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user