Summary: | SQL code generator generates "circular reference" foreign keys | ||
---|---|---|---|
Product: | [Applications] umbrello | Reporter: | Maciej J . Woloszyk <matofesi> |
Component: | general | Assignee: | Umbrello Development Group <umbrello-devel> |
Status: | RESOLVED FIXED | ||
Severity: | normal | CC: | holster |
Priority: | NOR | ||
Version: | 1.2 | ||
Target Milestone: | --- | ||
Platform: | unspecified | ||
OS: | Linux | ||
Latest Commit: | Version Fixed In: | ||
Sentry Crash Report: | |||
Attachments: | Patch to allow tables to have self-references |
Description
Maciej J . Woloszyk
2004-03-12 13:04:24 UTC
I've applied the patch, thanks for your contribution. *** Bug 76877 has been marked as a duplicate of this bug. *** - foreign key constraint fixed - comma adding fixed for different scopes Ah, I added the wrong comment a minute ago. This bug was already mostly fixed. I just removed the commented foreign key constraint, because it is nonsense and makes the code easier to read. Created attachment 18621 [details]
Patch to allow tables to have self-references
Sometimes, you need something like this:
create table t1 (
id int primary key,
parent int references t1(id)
);
The proposed patch allows it.
Also, Umbrello sometimes tries to create (in the export file) the empty foreign
keys with no table name and fields. These declarations come as a result of
deleting associations and not accessible through the Umbrello interface.
However, they are presented in the XMI file. This patch offers a primitive
workaround for this problem, too, by ignoring such associations during export.
Forgot to tell: Umbrello version I'm reporting about is a part of KDE 3.5.5. In attachment id=18621, Alexey Parshin wrote: + if ( a->getRoleName(Uml::B) != "" && a->getRoleName(Uml::B) != "") { Hmm, twice the same expression? Please check. SVN commit 606555 by okellogg:
Apply attachment 18621 [details] by Alexey Parshin with slight modification.
Thanks Alexey for contributing.
CCBUG:77377
M +12 -8 sqlwriter.cpp
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/codegenerators/sqlwriter.cpp #606554:606555
@@ -86,14 +86,18 @@
UMLAssociationList aggregations = c->getAggregations();
if( forceSections() || !aggregations.isEmpty() ) {
for(UMLAssociation* a = aggregations.first(); a; a = aggregations.next()) {
- if( a->getObject(Uml::A)->getID() != c->getID() ) {
-
- sql << m_indentation << "," << m_endl << m_indentation
- << "CONSTRAINT " << a->getName() << " FOREIGN KEY ("
- << a->getRoleName(Uml::B) << ") REFERENCES "
- << a->getObject(Uml::A)->getName()
- << " (" << a->getRoleName(Uml::A) << ")";
- }
+ UMLObject *objA = a->getObject(Uml::A);
+ UMLObject *objB = a->getObject(Uml::B);
+ if (objA->getID() == c->getID() && objB->getID() != c->getID())
+ continue;
+ QString roleNameA = a->getRoleName(Uml::A);
+ QString roleNameB = a->getRoleName(Uml::B);
+ if (roleNameA.isEmpty() || roleNameB.isEmpty())
+ continue;
+ sql << m_indentation << "," << m_endl;
+ sql << m_indentation << "CONSTRAINT " << a->getName()
+ << " FOREIGN KEY (" << roleNameB << ") REFERENCES "
+ << objA->getName() << " (" << roleNameA << ")";
}
}
|