Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » Newbie corner » Sqlite3 database
Sqlite3 database [message #40081] Fri, 07 June 2013 11:59 Go to next message
idkfa46 is currently offline  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 Go to previous message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

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 Wink 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 Wink

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

Previous Topic: Linking error again
Next Topic: Program loses hover focus
Goto Forum:
  


Current Time: Tue Apr 23 18:45:58 CEST 2024

Total time taken to generate the page: 1.03335 seconds