2013-04-26 88 views
0

我想首先创建数据文件夹中的临时quizz.db,然后创建它里面的表,然后创建的资产文件夹中的文件quizz.db它复制到文件夹资产。通过调试代码,它显示该文件夹已创建。但我无法在资产文件夹中找到它。下面是代码,无法建立资产文件夹中的.db文件

#include <bb/cascades/Application> 
#include <bb/cascades/QmlDocument> 
#include <bb/cascades/AbstractPane> 
#include <bb/data/SqlDataAccess> 

using namespace bb::cascades; 
using namespace bb::data; 

SQLTest::SQLTest(bb::cascades::Application *app): QObject(app) 
{ 
const QString fileName = QString("quizz.db"); 
QString dataFolder = QDir::homePath(); 
QString newFileName = dataFolder + "/" + fileName; 
QTemporaryFile file(newFileName); 

// Open the file that was created 
if (file.open()) 
{ 
    // Create an SqlDataAccess object 
    SqlDataAccess sda(newFileName); 

    // Create a table called Employee in the database file 
    sda.execute("CREATE TABLE Employee(firstName VARCHAR(50),lastName VARCHAR(50), salary INT);"); 

    // Insert employee records into the table 
    sda.execute("INSERT INTO Employee (firstName, lastName, salary) VALUES (\"Mike\", \"Chepesky\", 42000);"); 
    sda.execute("INSERT INTO Employee (firstName, lastName, salary) VALUES (\"Westlee\", \"Barichak\", 55000);"); 
    sda.execute("INSERT INTO Employee (firstName, lastName, salary) VALUES (\"Ian\", \"Dundas\", 47000);"); 
    if(sda.hasError()) 
    { 

    } 
    else 
     copyFileToAssetsFolder("quizz.db"); 
} 
} 

void SQLTest::copyFileToAssetsFolder(const QString fileName) 
{ 
QString appFolder(QDir::homePath()); 
appFolder.chop(4); 
QString originalFileName = appFolder + "app/native/assets/" + fileName; 
QFile newFile(originalFileName); 
// If I enable this `if` condition the code satisfies it and removes the quizz.db file and then it satisfies the next `if` condition and successfully copies the quizz.db file from `data` folder to `assets` folder. 
/*if(newFile.exists()) 
    QDir().remove(originalFileName);*/ 
// this `if` condition is not satisfied. Which should mean the quizz.db file has been created on assets folder. 
if (!newFile.exists()) 
{ 
    // If the file is not already in the assets folder, we copy it from the 
    // data folder (read and write) to the assets folder (read only). 
    QString dataFolder = QDir::homePath(); 
    QString newFileName = dataFolder + "/" + fileName; 
    QFile originalFile(newFileName); 

    if (originalFile.exists()) 
    { 
     // Create sub folders if any creates the SQL folder for a file path like e.g. sql/quotesdb 
     QFileInfo fileInfo(originalFileName); 
     QDir().mkpath (fileInfo.dir().path()); 

     if(!originalFile.copy(originalFileName)) { 
      qDebug() << "Failed to copy file to path: " << originalFileName; 
     } 
    } else { 
     qDebug() << "Failed to copy file data base file does not exists."; 
    } 
} 

// mSourceInDataFolder = newFileName; 
} 

如果我能copyFileToAssetsFolder功能评论if条件它删除已经创建的资产文件夹(IM无法找到它)quizz.db文件,并进入下一if条件和副本里面在data文件夹中创建quizz.db以资产fodler。但无论如何,我无法在资产文件夹中找到quizz.db。我很快需要帮助。谢谢。

回答

0

看来它不可能修改here提到现在我创建的数据文件夹我的数据库文件,因为它是可写的资产文件夹。在资产

+1

.BAR的文件通常包含文件夹“资产”,我希望它从应用程序的家目录链接到存档,因为你不能修改。 BAR(这意味着,您可以更改已签名的应用程序...),您将无法更改资产目录或其内容。那么,你自己找到了你的解决方案,我只是想解释这个问题的可能原因。 – Schlangi 2013-04-27 14:35:27

相关问题