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 » Multiple fields primary key
Re: Multiple fields primary key [message #5340 is a reply to message #5338] Thu, 14 September 2006 11:48 Go to previous messageGo to previous message
unodgs is currently offline  unodgs
Messages: 1366
Registered: November 2005
Location: Poland
Ultimate Contributor

I didn't write it but I meant OleDB...
Anyway I found that in Oracle schema (as well as in Sqlite3) there is DOUBLE_PRIMARY_KEY macro.
I copied it to OleDBSchema.h and mofied my sch file to look like this:

TABLE_(PERSON)
	INT_ (ID)
	INT_ (VER) DUAL_PRIMARY_KEY(ID, VER)
	STRING_ (NAME, 40)
END_TABLE


I removed all previously generated sql files (and table from db too) and run the test app. Now sql files have inside:

S_SQL-OleDb.sql
--------------------------

create table PERSON (
    ID                   integer,
    VER                  integer, primary key (ID, VER),
    NAME                 varchar(40)
);

U_SQL-OleDb.sql
--------------------------

create table PERSON (
    ID                   integer
);

alter table PERSON add  VER                  integer;
alter table PERSON alter column     VER                  integer, primary key (ID, VER);
alter table PERSON add  NAME                 varchar(40);
alter table PERSON alter column     NAME                 varchar(40);

SD_SQL-OleDb.sql
--------------------------
drop table PERSON;



Other genereated files were empty.

Syntax of S_Sql-OleDb.sql is correct for ms sql server 2005. Unfortunately it seems like upp always executes upgrade script which does not create primary key from two fields.

Code I use to perform schema changes:

	Cout() << "Performing schema changes...\n";
	SqlSchema sch(MSSQL);
	StdStatementExecutor se(db);
	All_Tables(sch);
	if(sch.ScriptChanged(SqlSchema::UPGRADE))
	{
		Cout() << "Upgrading...\n";
		OleDBPerformScript(sch.Upgrade(), se);
	}
	if(sch.ScriptChanged(SqlSchema::ATTRIBUTES)) 
	{
		Cout() << "Attributes...\n";
		OleDBPerformScript(sch.Attributes(), se);
	}
	if(sch.ScriptChanged(SqlSchema::CONFIG)) 
	{
		Cout() << "Configuration...\n";
		OleDBPerformScript(sch.ConfigDrop(), se);
		OleDBPerformScript(sch.Config(), se);
	}
	sch.SaveNormal();


 
Read Message
Read Message
Read Message
Previous Topic: select(*)
Next Topic: my_sql's charset in linux
Goto Forum:
  


Current Time: Sun Jun 02 06:15:17 CEST 2024

Total time taken to generate the page: 0.01454 seconds