robertohuertasm / SQLite4Unity3d

SQLite made easy for Unity3d
MIT License
1.29k stars 266 forks source link

Avoid using intermediate vars instead object properties in Expressions ( for Where(), Get()) #6

Closed cardinalby closed 9 years ago

cardinalby commented 9 years ago

TableQuery.Where and Get methods takes Expression, analyze it and build SQL “where” sentence. Some kind of expressions works on Android but don’t work on iOS. Let’s use classical example with Employee and Department tables (http://www.oracle.com/ocom/groups/public/@otn/documents/digitalasset/513145.jpg). We have 2 corresponded classes with needed attributes. Code:

var dep = connection.Table<Department>().Where(d => d.Name == “blabla”).First();
int count = connection.Table<Employee>().Where(e => e.Department_ID == dep.Department_ID).Count();

This code will work on Android, but wil not on iOS due to problems with AOT compilation in CompileExpr method. To fix it on iOS you can:

var dep = connection.Table().Where(d => d.Name == “blabla”).First();
int depId = dep.Department_ID;
int count = connection.Table().Where(e => e.Department_ID == depId).Count();

It works! And there are question: can we avoid using intermediate var for compability with AOT compilation on iOS?

May be upgrade to latest SQLiteNet version would solve the problem?

robertohuertasm commented 9 years ago

Hi @cardinalby, I'm extending the SQLConnection class with some methods that avoid the use of Interfaces so it will be up to you to use whatever you want. Just a question about what you pose here. This solution works even with interface use? Or only without the interfaces?

robertohuertasm commented 9 years ago

I can't reproduce the error with my iPad following your first example. It works for me... I'll try to make it crash with a more complicated query. Do you get error with such a query?

cardinalby commented 9 years ago

I am waiting for IDisposable (commented in https://github.com/codecoding/SQLite4Unity3d/issues/5) fix, then will test on the latest version and prepare the reproducible example.

cardinalby commented 9 years ago

I can't reproduce it too on last version :). May be it was due to interface usage, which was fixed.

robertohuertasm commented 9 years ago

I'm glad but I have to say that I couldn't reproduce it even with the interfaces. In fact I tested it before removing the interfaces just to see if I could learn something. Anyway, I'll close this issue and if you somehow manage to reproduce the behaviour don't hesitate to tell me. I will reopen it again and see how we deal with it.