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 » Defining composite primary key
Defining composite primary key [message #45080] Fri, 28 August 2015 16:47 Go to next message
Giorgio is currently offline  Giorgio
Messages: 218
Registered: August 2015
Experienced Member
Hi there,
in the database I am managing, several tables have composite primary key. I tried to describe those keys in the .sch file adding the PRIMARY KEY keyword to each field the key is composed by, but it did not work. I searched the forum and found only this http://www.ultimatepp.org/forums/index.php?t=msg&goto=53 38& thread. Maybe the issue has been already addressed in other threads, as it is a common situation in db. Could anyone point me to a solution?
Regards,
Giorgio
Re: Defining composite primary key [message #45081 is a reply to message #45080] Fri, 28 August 2015 20:29 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

Giorgio wrote on Fri, 28 August 2015 16:47
Hi there,
in the database I am managing, several tables have composite primary key. I tried to describe those keys in the .sch file adding the PRIMARY KEY keyword to each field the key is composed by, but it did not work. I searched the forum and found only this http://www.ultimatepp.org/forums/index.php?t=msg&goto=53 38& thread. Maybe the issue has been already addressed in other threads, as it is a common situation in db. Could anyone point me to a solution?
Regards,
Giorgio


Hi Giorgio,

As you probably noticed in the linked thread, there is also DUAL_PRIMARY_KEY(k1, k2). For postgres, there is even PRIMARY_KEY_LIST(name, keys). Not sure why it is not implemented for other backends.

If you need more then two columns in your composite key (and you're not using postgres), then you can introduce your own macro. It is relatively easy just look at how your backend implements DUAL_PRIMARY_KEY. E.g. For MySql, look at MySql/MySqlSchema.h:
#define DUAL_PRIMARY_KEY(k1, k2)   INLINE_ATTRIBUTE(", primary key (" #k1 ", " #k2 ")")

So you can just define similary for four columns (must be defined before including sch_schema.h, sch_header.h or sch_source.h):
#define QUADRUPLE_PRIMARY_KEY(k1, k2, k3, k4)   INLINE_ATTRIBUTE(", primary key (" #k1 ", " #k2 ", " #k3 ", " #k4 ")")

I haven't tested this right now, but I have made similar augmentations for my code in the past and it worked just fine Smile If you hit any problem, just post what code you got so far and where you got stuck.

Best regards,
Honza
Re: Defining composite primary key [message #45101 is a reply to message #45081] Tue, 01 September 2015 08:10 Go to previous message
Giorgio is currently offline  Giorgio
Messages: 218
Registered: August 2015
Experienced Member
I did not notice that the answer was already there Embarassed , thanks!
Previous Topic: Where is the debug window «memory» in TheIDE?
Next Topic: Action on exit from an EditString field
Goto Forum:
  


Current Time: Fri Mar 29 02:58:30 CET 2024

Total time taken to generate the page: 0.01338 seconds