-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
SQLite.SQLiteException: duplicate column name id in v1.3.3 #549
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I'm getting similar errors when jumping from 1.3.1 to 1.3.3:
This seems to happen for |
I've added an
|
This can be solved in a trivial way by changing parts of the TableMapping function in line 1888, from foreach (var p in props)
{
var ignore = p.CustomAttributes.Any(x => x.AttributeType == typeof(IgnoreAttribute));
if (p.CanWrite && !ignore)
{
cols.Add(new Column(p, createFlags));
}
} to foreach (var p in props)
{
var ignore = p.CustomAttributes.Any(x => x.AttributeType == typeof(IgnoreAttribute));
var actualDefinition = p.GetGetMethod(false);
var baseDefinition = actualDefinition.GetBaseDefinition();
bool isOverridden = actualDefinition != baseDefinition;
if (p.CanWrite && !ignore && !isOverridden)
{
cols.Add(new Column(p, createFlags));
}
} Source is Stackoverflow: https://stackoverflow.com/a/4505303/3414957 However, I'm not aware of any side effects this may cause, but it's sufficient for my use case. Might want to do the same check for GetSetMethod, though. Oh, and 1.0.10 is the oldest version I can from NuGet and even this version is broken already. Can't confirm dernippels statement 'This works fine up to v1.3.2 but in v1.3.3 it causes an SQLite.SQLiteException', but I'm not using the async library. |
Please Fix this quick. I can even create a new table, the whole thing just crash after the table is created. If i run it the second time without the createtable method the table exists.
|
After spending some hours doing trail and error, process of elimination, I think I have manage to get this working. Go to VS Menu -> Project -> Appname Properties -> Android Options -> Linker - Skip linking assemblies SQLite-net;SQLitePCLRaw.batteries_v2;SQLitePCLRaw.core Go to VS Menu Build -> Clean Solution. Build and Deploy. |
Hi, |
I ran into the duplicate column issue as well and after stepping thru code, realized that the TableMapping function has a "bug".
will throw an exception stating Id column is duplicate. The Table mapping function walks thru the inheritance chain collecting the public properties to determine the SQL to be generated. The workaround that worked for me is to add [Ignore] attribute to the base class like so
Hope this helps. |
Also seeing this issue. While IDispose's solution would work just fine, my base class is defined in a separate project which is shared with other projects and so I do not want to have to take a dependency on SQLite for that separate project. I also tried using Looking at PropertyInfo.IsDefined's inherit parameter and this 1.3.3 commit, I am wondering if this is caused by using One potential fix may be to use Attribute.IsDefined which does take inherited properties into account. Also I can confirm that 1.3.2 does not have this problem. |
Ahh this is very fascinating. Sorry for the bugs - we didn't have a test for this case. Writing the test now and hope to have a fix soon. |
This has been fixed by 05e71dc I will get a release out today! |
@praeclarum |
@praeclarum I have the same problem, some solution right away? 08-21 15:01:45.774 I/MonoDroid( 4006): UNHANDLED EXCEPTION: 08-21 15:01:46.688 D/Mono ( 4006): [0x9b77f930] worker unparking, timeout? no interrupted? no |
@izefler Downgrade to 1.3.2. |
@hvaughan3 |
Hi, I tried out v1.4.118 on a fresh Xamarin.Forms App (using Prism Template-Pack and .netstandard2.0 libs) today. Luckily the sqlite-net is .Net Standard compatible since v1.3.0 so I was able to use v1.3.2 successfully again. |
I had this issue on a Xamarin.Forms project, though it's with a .Net target, not a .Net Standard project. 1.4.118 worked fine on Android, but this issue appeared on the iOS build. Per https://forums.xamarin.com/discussion/65328/sqlite-duplicate-column-name-exception-on-device-but-not-on-simulator, adding --linkskip=SQLite-net to the iOS build resolved the problem for me. |
Any updates on when this will be fixed? |
@praeclarum For the same code in iOS and UWP it works. |
@WillAutioItrax That is not the same error others in this thread are talking about so it may be a different issue. Having said that, are you making sure to delete the app after changing library versions? Otherwise the old DB schema will remain intact. 1.3.2 works fine for me. |
@hvaughan3 Thanks for the response. I am getting two types of exceptions. The "Cannot create a table with zero columns" one and also "duplicate column name: MyId" (which is what brought me here I expect they are related as they appeard at the same time). |
@WillAutioItrax, try adding SQLiteNetStandard to ignored assemblies list in Android Linker options. This did the trick for me. |
@alexshakurin Thanks for the suggestion. I tried it but no change. What did work, was comparing my current Droid.csproj with an older one for a project where things behaved. After making the current one look like the old one, I think what did it for me was to do a clean and then delete the bin and obj directories. I did that for both .core and .Droid |
This issue shouldn't be closed because of the number of other issues referring to this one which hasn't been solved (merely worked around) |
Why is this issue closed? The problem still exists. The only way for me is to set linking to Sdk Assemblies only, but my app size grows bigger. Could you please reopen it? Or should we open a new issue? |
Please check that the problem is still present, I'm updating the thread in Xamarin Forms Forum here: |
Hi, Inheritance of the models is working very well, and because the key is named "Id" I haven't need to set any Attributes anymore. However I have one case in that I have to insert around 5700 new entries at once. This was pretty fast in sqlite-net-pcl using a transaction (I guess it was under a second), now it needs around 11 seconds. You may be able to tune this (at least you can use direct SQL in EF Core, if you want). I haven't tried this further because this operation is only done once after installing the app. I could not publish my current project. If you want further information or need some help moving to EF Core just contact me. Christopher |
Just adding a note this, upgrading to latest 1.5.166-beta seems to solve this for Android at least. |
Hi,
I'm using connection.CreateTableAsync() with a SQLiteAsyncConnection to create tables.
I've a base-type for all of my tables:
In some cases I need a [AutoIncrement] Attribute for Id, so I'm using inheritance like:
This works fine up to v1.3.2 but in v1.3.3 it causes an
SQLite.SQLiteException: duplicate column name id
I'm using current Visual Studio 2017 with a Xamarin.Forms App and test against Android (Target Framework Android 7.1) and UWP (Target version: Creators Update). The exception happens on both platforms.
Removing the overriding Properties doe also work, but the tables are created without AutoIncrement for sure. So I think the problem must be in using such a construct.
Thanks for helping.
The text was updated successfully, but these errors were encountered: