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
How to share a schema .sch with multiple header and source files [message #52193] Wed, 07 August 2019 14:54 Go to next message
MonkeyH is currently offline  MonkeyH
Messages: 3
Registered: August 2019
Junior Member
Hello,
I'm new to U++ and I'm making a generic desktop application wich read and write data to an sqlite database.

Planning for multiple functionalities, I guess the structure of this application could be like this:
Main Application (main window definition and methods) 
    | 
    |   Db schema definition   
    |  
    +------> functionality class 1 (some data manipulation and user interface)
    |
  (...)
    |
    +------> functionality class N (some data manipulation and user interface)

How I can share the database schema with all the header and source files, avoiding multiple definitions and link errors?

Thanks.
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: 13975
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
Previous Topic: BOOL in SQLite
Next Topic: formatting time to pass to sqlite
Goto Forum:
  


Current Time: Fri Mar 29 00:27:07 CET 2024

Total time taken to generate the page: 0.00958 seconds