C++ Can';t在资产文件夹中创建.db文件
我试图在assets文件夹中创建一个quizz.db文件,首先在data文件夹中创建一个临时的C++ Can';t在资产文件夹中创建.db文件,c++,sql,blackberry-10,C++,Sql,Blackberry 10,我试图在assets文件夹中创建一个quizz.db文件,首先在data文件夹中创建一个临时的quizz.db,然后在其中创建表,然后将其复制到assets文件夹。通过调试代码,显示文件夹已创建。但我在资产文件夹中找不到它。这是密码 #include <bb/cascades/Application> #include <bb/cascades/QmlDocument> #include <bb/cascades/AbstractPane> #include
quizz.db
,然后在其中创建表,然后将其复制到assets文件夹。通过调试代码,显示文件夹已创建。但我在资产文件夹中找不到它。这是密码
#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;
}
#包括
#包括
#包括
#包括
使用名称空间bb::cascades;
使用名称空间bb::data;
SQLTest::SQLTest(bb::cascades::Application*app):QObject(app)
{
const QString fileName=QString(“quizz.db”);
QString dataFolder=QDir::homePath();
QString newFileName=dataFolder+“/”+文件名;
QTemporaryFile文件(newFileName);
//打开创建的文件
if(file.open())
{
//创建SqlDataAccess对象
SqlDataAccess sda(新文件名);
//在数据库文件中创建名为Employee的表
execute(“创建表Employee(firstName VARCHAR(50),lastName VARCHAR(50),salary INT);”;
//将员工记录插入表中
sda.execute(“插入员工(名字、姓氏、薪水)值(\“Mike\”、\“Chepesky\”、42000);”;
sda.execute(“插入员工(名字、姓氏、薪水)值(\'Westlee\'、\'Barichak\'、55000);”;
sda.execute(“插入员工(名字、姓氏、薪水)值(\'Ian\'、\'Dundas\'、47000);”;
if(sda.hasError())
{
}
其他的
CopyFileToAssetFolder(“quizz.db”);
}
}
void SQLTest::copyFileToAssetFolder(const QString文件名)
{
QString appFolder(QDir::homePath());
加盖公章(4);
QString originalFileName=appFolder+“app/native/assets/”+文件名;
QFile newFile(原始文件名);
//如果启用此'If'条件,代码将满足该条件并删除quizz.db文件,然后它满足下一个'If'条件并成功地将quizz.db文件从'data'文件夹复制到'assets'文件夹。
/*if(newFile.exists())
QDir().remove(原始文件名)*/
//此“if”条件不满足。这意味着quizz.db文件已在资产文件夹中创建。
如果(!newFile.exists())
{
//如果该文件不在资产文件夹中,我们将从
//数据文件夹(读写)到资产文件夹(只读)。
QString dataFolder=QDir::homePath();
QString newFileName=dataFolder+“/”+文件名;
QFile originalFile(新文件名);
if(originalFile.exists())
{
//创建子文件夹(如果有)为文件路径创建SQL文件夹,如SQL/quotesdb
QFileInfo文件信息(原始文件名);
QDir().mkpath(fileInfo.dir().path());
如果(!originalFile.copy(originalFileName)){
qDebug()似乎无法修改中提到的资产文件夹,现在我正在数据文件夹中创建我的db文件,因为它是可写的。似乎无法修改中提到的资产文件夹,现在我正在数据文件夹中创建我的db文件,因为它是可写的。资产中的文件无法修改。资产中的文件无法修改如果.BAR文件通常包含一个文件夹“assets”,我希望它能从app home dir链接到归档文件,并且由于您不能修改.BAR(这意味着,您可以更改已签名的应用程序…)您将无法更改资产目录或其内容。好吧,您自己找到了解决方案,我只是想解释此问题的可能原因。通常,.BAR文件包含一个文件夹“资产”,我希望它从app home dir链接到存档,并且由于您无法修改.BAR(这意味着,您可以更改已签名的应用程序…)您将无法更改assets dir或其内容。好的,您自己找到了解决方案,我只是想解释此问题的可能原因。