1

I've been struggling to get DbMetal to process my SQLite database. I finally isolated the problem. It won't allow a table to have two foreign key references to the same column.

For example, a SQLite database with these two tables will fail:

CREATE TABLE Person
(
    Id INTEGER PRIMARY KEY,
    Name TEXT NOT NULL
);

CREATE TABLE Match
(
    Id INTEGER PRIMARY KEY,
    WinnerPersonId INTEGER NOT NULL REFERENCES Person(Id),
    LoserPersonId INTEGER NOT NULL REFERENCES Person(Id)
);

I get this error:

DbMetal: Sequence contains more than one matching element

If I get rid of the second foreign key reference, no error occurs.

So, this works:

CREATE TABLE Match
(
    Id INTEGER PRIMARY KEY,
    WinnerPersonId INTEGER NOT NULL REFERENCES Person(Id),
    LoserPersonId INTEGER NOT NULL
);

But I really need both "person" columns to reference the Person table.

I submitted a bug report for this, but I could use a workaround in the meantime. Any ideas?

devuxer
  • 41,681
  • 47
  • 180
  • 292

1 Answers1

3

I just had the same problem and created a patch. I've also posted it at your bug report. For others, you can find the patch here: http://pastebin.com/VhNptMqp.

FrozenCow
  • 320
  • 2
  • 6
  • Great, FrozenCow, thanks! Is there any way I can get my hands on a compiled .exe or do I have to download the source and paste in? – devuxer May 05 '10 at 21:50
  • I ended up downloading the source and putting in your fixes. Worked like a charm. Thanks again for you help. – devuxer May 08 '10 at 01:25
  • Ah, sorry, didn't get notified about your comments. Good to hear it all worked out. – FrozenCow May 23 '10 at 10:35