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 » How to share a schema .sch with multiple header and source files
Re: How to share a schema .sch with multiple header and source files [message #52211 is a reply to message #52193] Fri, 09 August 2019 10:56 Go to previous message
mirek is currently offline  mirek
Messages: 14267
Registered: November 2005
Ultimate Member
Actually, SQL_Sqlite3 example has it already right:

This goes to header:

#define SCHEMADIALECT <plugin/sqlite3/Sqlite3Schema.h>
#define MODEL <SQL_Sqlite3/simple.sch>
#include "Sql/sch_header.h"


(hint, hint, see "_header" Smile

This goes to some C++ file:

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

#include <Sql/sch_source.h>


Now above provides two things. "_schema" part creates script generation routines that create sql scripts to actually create the schema in the database. Usually we are using script with "alter table add column" commands so that incremental changes can be added to database (we just ignore "thing already exists" errors when performing that script). In the example, this coresponds to

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


(SaveNormal saves scripts files to the disk, so that they can be used e.g. for the production machine).

Not that this is usually excluded in release (#ifdef _DEBUG) version of application... (but not necessary).

"_source" part creates code to support S_TABLE structures (e.g. mapping between column names and C++ variables) and is always needed.

Mirek
 
Read Message
Read Message
Previous Topic: BOOL in SQLite
Next Topic: formatting time to pass to sqlite
Goto Forum:
  


Current Time: Sun Aug 24 16:44:45 CEST 2025

Total time taken to generate the page: 0.04857 seconds