SQLite.Net-PCL icon indicating copy to clipboard operation
SQLite.Net-PCL copied to clipboard

Support for composite primary keys

Open igrali opened this issue 9 years ago • 19 comments

Code changes to enable composite primary keys.

It was mentioned here. https://github.com/oysteinkrog/SQLite.Net-PCL/issues/72

I think it would be really good to have this supported. I was only able to run tests under Generic, Win32 and WindowsPhone8, others wouldn't build for some reason, I'll have to investigate.

Let me know what you think!

EDIT: I see AppVeyor build failed for some reason, but I don't think it's because of my code.

igrali avatar Apr 04 '15 01:04 igrali

Would it be better to keep the current methods for if there is only one column of primary key. Also why have you only changed the delete methods to accept multiple primary keys a and missed out the get methods?

Shiney avatar Apr 06 '15 10:04 Shiney

I'll gladly fix if I missed anything, could you point to exact methods?

Delete was the only one with changed signature as there is an overload which allows deleting based on the primary key. But maybe it would be worthwhile to keep the old one too, so if someone is using only single attribute keys they can keep using the old Delete call, without creating a dictionary every time.

Creating the table should behave the same if there's a single attribute key, allowing for autoincrement to be set.

Maybe I also should have left the name "PK" instead of changing it to "PKs" as technically there's always only one primary key (even if it spans over multiple columns).

igrali avatar Apr 06 '15 12:04 igrali

There are two "Find" methods that you would need to change also a "Get" method all on SQLiteConnection

Shiney avatar Apr 06 '15 13:04 Shiney

Good point. I changed those 2 methods, and also Delete method to take object again as parameter to not break any calls with only a single column primary key.

igrali avatar Apr 06 '15 15:04 igrali

Also TableMapping is at the moment part of the publicAPI, so it may not be a good idea to remove a property like you have, maybe it would be better to provide both properties and have PK throw an exception if there is a composite primary key so that current users of the library can still use the Property if they are not using composite primary keys.

Shiney avatar Apr 06 '15 16:04 Shiney

You mean, have both PK and PKs? Hmm.

igrali avatar Apr 06 '15 16:04 igrali

Yeah that would probably be better than breaking the code of people who are using the library.

Shiney avatar Apr 06 '15 17:04 Shiney

Yeah, both options are kind of bad, but breaking change is probably worse. :) I'll do it that way then.

igrali avatar Apr 06 '15 20:04 igrali

I pushed the changes we discussed.

igrali avatar Apr 11 '15 16:04 igrali

This sounds nice, I'll review/merge when I've got the current prerelease/beta out the door.

oysteinkrog avatar Apr 18 '15 11:04 oysteinkrog

Any news on this?

ghost avatar May 21 '15 17:05 ghost

I'm sorry but I don't have any time to spend on this project at the moment.

oysteinkrog avatar May 21 '15 17:05 oysteinkrog

Any word on this? Just ran into a situation where Composite Keys would be really nice to have :)

pkl728 avatar Jul 22 '15 13:07 pkl728

It's already done here with latests paracleum updates: https://github.com/softlion/SQLite.Net-PCL All test passed. + new tests for multiple keys and partial keys (select and delete). This is my own implementation started 20 months ago and used in multiple commercial apps.

It breaks the Delete(primary key), as it conflicts with the Delete<T>(object) and with Delete(primary keys[]).

softlion avatar Aug 21 '15 16:08 softlion

Can we get an update? Would love to have this.

softlion, do you have your nuget for your fork? I couldn't find it.

MisterJimson avatar Dec 11 '15 18:12 MisterJimson

Yes i have a private nuget server on internet. PM me your email and i grant you access.

softlion avatar Dec 11 '15 21:12 softlion

Is this supported now?

wierzba3 avatar Jan 06 '17 02:01 wierzba3

Any news with this?? When it's going to be released?

gsaldana avatar Jan 18 '17 18:01 gsaldana

Any news with this?? Is working in Xamarin Ios?

filyjunior avatar Apr 06 '17 14:04 filyjunior