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 » U++ Library support » U++ SQL » sql script question
sql script question [message #34921] Sat, 17 December 2011 10:26 Go to next message
forlano is currently offline  forlano
Messages: 1189
Registered: March 2006
Location: Italy
Senior Contributor
Hello,

I have run the SQL_sqlite3 reference package and found that in debug mode it works (simple.db not empty) and fails in Optimal mode (simple.db empty).
This should be related to the following script that run only in debug mode and are responsible of the tables creation

#ifdef _DEBUG
SqlSchema sch(SQLITE3);
StdStatementExecutor se(sqlite3);
All_Tables(sch);
if(sch.ScriptChanged(SqlSchema::UPGRADE))
Sqlite3PerformScript(sch.Upgrade(),se);
if(sch.ScriptChanged(SqlSchema::ATTRIBUTES)) {
Sqlite3PerformScript(sch.Attributes(),se);
}
if(sch.ScriptChanged(SqlSchema::CONFIG)) {
Sqlite3PerformScript(sch.ConfigDrop(),se);
Sqlite3PerformScript(sch.Config(),se);
}
sch.SaveNormal();
#endif

I guess that at least one time the script should be run.
My app needs to work with different dbs although only one at once. So I need to close the current db and open or create a new one.
In case of a new one, if I have understood, I run the previous script, but if the db has been already created I can skip the previous scripts. Am I right?

The method sqlite3.Open() open or create the db. At this level is there a way to understand if I need to run the scripts?
Perhaps it is easier to simply check if the file *.db exists to determine if the scripts need to be run.

Thanks,
Luigi
Re: sql script question [message #34924 is a reply to message #34921] Sat, 17 December 2011 11:08 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13984
Registered: November 2005
Ultimate Member
forlano wrote on Sat, 17 December 2011 04:26

Hello,

I have run the SQL_sqlite3 reference package and found that in debug mode it works (simple.db not empty) and fails in Optimal mode (simple.db empty).
This should be related to the following script that run only in debug mode and are responsible of the tables creation

#ifdef _DEBUG
SqlSchema sch(SQLITE3);
StdStatementExecutor se(sqlite3);
All_Tables(sch);
if(sch.ScriptChanged(SqlSchema::UPGRADE))
Sqlite3PerformScript(sch.Upgrade(),se);
if(sch.ScriptChanged(SqlSchema::ATTRIBUTES)) {
Sqlite3PerformScript(sch.Attributes(),se);
}
if(sch.ScriptChanged(SqlSchema::CONFIG)) {
Sqlite3PerformScript(sch.ConfigDrop(),se);
Sqlite3PerformScript(sch.Config(),se);
}
sch.SaveNormal();
#endif

I guess that at least one time the script should be run.
My app needs to work with different dbs although only one at once. So I need to close the current db and open or create a new one.
In case of a new one, if I have understood, I run the previous script, but if the db has been already created I can skip the previous scripts. Am I right?

The method sqlite3.Open() open or create the db. At this level is there a way to understand if I need to run the scripts?
Perhaps it is easier to simply check if the file *.db exists to determine if the scripts need to be run.

Thanks,
Luigi


Yes. The actual reason why it is #ifdef _DEBUG is that usually you do not want to create database schema in production.

So you either create the schema by running debug version against production database (if you have control about production and you are sure you are doing the right thing), or alternatively you might provide db creation scripts for production (e.g. bundle them in debian package). That is why there is that "SaveNormal" line, it saves all scripts for further processing.

But that is just the most common solution. Nothing prevents you to create the schema in release mode.

Mirek
Re: sql script question [message #34930 is a reply to message #34924] Sat, 17 December 2011 19:44 Go to previous messageGo to next message
forlano is currently offline  forlano
Messages: 1189
Registered: March 2006
Location: Italy
Senior Contributor
mirek wrote on Sat, 17 December 2011 11:08


But that is just the most common solution. Nothing prevents you to create the schema in release mode.

Mirek


Thanks. One more question please.
I commented #ifdef and #endif and compiled in "optimal mode".
The compiler answered with

error C3861: 'All_Tables': identifier not found

Why in debug mode it does not complain about 'All_Table'? Perhaps some include is not set properly in that reference case but I can't fix it.

Thanks again,
Luigi

[Updated on: Sat, 17 December 2011 19:45]

Report message to a moderator

Re: sql script question [message #34931 is a reply to message #34930] Sat, 17 December 2011 20:41 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13984
Registered: November 2005
Ultimate Member
Have you comment #ifdef around schema include too?

This one:

#ifdef _DEBUG
#include <Sql/sch_schema.h>
#endif


Mirek
Re: sql script question [message #34932 is a reply to message #34931] Sat, 17 December 2011 20:51 Go to previous message
forlano is currently offline  forlano
Messages: 1189
Registered: March 2006
Location: Italy
Senior Contributor
mirek wrote on Sat, 17 December 2011 20:41

Have you comment #ifdef around schema include too?

This one:

#ifdef _DEBUG
#include <Sql/sch_schema.h>
#endif


Mirek


Of course no Embarassed I was blind.
Now it works, sorry.

Luigi
Previous Topic: BUG with "Run to cursor (in debug)"
Next Topic: CLOB data handling
Goto Forum:
  


Current Time: Thu Jun 13 20:14:19 CEST 2024

Total time taken to generate the page: 0.01524 seconds