Home » Community » Newbie corner » Sqlite3 database
Sqlite3 database [message #40081] |
Fri, 07 June 2013 11:59  |
idkfa46
Messages: 155 Registered: December 2011
|
Experienced Member |
|
|
Hi all,
I'm trying to move schemas file and database file in a different directory.
bool nodb = false;
Sqlite3Session db;
db.LogErrors(true);
#ifdef flagDEBUG
db.SetTrace();
nodb = true;
#endif
FileIn fi("setting.db3");
if(fi.IsError() || fi.GetSize() <= 0)
nodb = true;
fi.Close();
if(!db.Open(ConfigFile("setting.db3")))
{
Exclamation(t_("Can't create or open database file"));
return;
}
SQL = db;
if(nodb)
{
SqlSchema sch(SQLITE3);
StdStatementExecutor se(db);
All_Tables(sch);
Progress p;
p.SetText(t_("Creating database"));
{
if(sch.ScriptChanged(SqlSchema::UPGRADE))
{
Sqlite3PerformScript(sch.Upgrade(), se, p);
}
if(sch.ScriptChanged(SqlSchema::ATTRIBUTES))
{
Sqlite3PerformScript(sch.Attributes(), se, p);
}
if(sch.ScriptChanged(SqlSchema::CONFIG))
{
Sqlite3PerformScript(sch.ConfigDrop(), se, p);
Sqlite3PerformScript(sch.Config(), se, p);
}
sch.SaveNormal();
}
}
Atm the are located in the .exe directory. With a sch.SaveNormal(ConfigPath) I'm able to move schemas but not the setting.db3 .
any suggestion?
Regards,
Matteo
|
|
|
Re: Sqlite3 database [message #40082 is a reply to message #40081] |
Fri, 07 June 2013 21:32  |
|
Hi Matteo,
Maybe I missed something in your question, but if you just need to move files somewhere else, why not use the functions from Core that do just that. Simple call one of those before you call db.Open():bool FileCopy(const char *oldpath, const char *newpath);
bool FileMove(const char *oldpath, const char *newpath);
Also, I see your code checks if the file exists by reading it all in memory. That is not very efficient There are functions for this too:int64 GetFileLength(const char *path);
bool FileExists(const char *path);
bool DirectoryExists(const char *path);
Have a look in Core/Path.h or in the relevant documentation 
If I misunderstood the problem, please try to specify what exactly is the problem...
Best regards,
Honza
[Updated on: Fri, 07 June 2013 21:33] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Sat Apr 26 15:08:21 CEST 2025
Total time taken to generate the page: 0.00654 seconds
|