praeclarum / sqlite-net

Simple, powerful, cross-platform SQLite client and ORM for .NET
MIT License
4.05k stars 1.42k forks source link

Joins are not supported #193

Open vkattamudi opened 11 years ago

vkattamudi commented 11 years ago

Hi All,

We are trying to use joins but not working because it is mentioned as "Joins are not supported" in below code. Please help us on this because we need to implement joins.

        private SQLiteCommand GenerateCommand (string selectionList)
        {
            if (_joinInner != null && _joinOuter != null) {
                throw new NotSupportedException ("Joins are not supported.");
            }
            else {
                var cmdText = "select " + selectionList + " from \"" + Table.TableName + "\"";
                var args = new List<object> ();
                if (_where != null) {
                    var w = CompileExpr (_where, args);
                    cmdText += " where " + w.CommandText;
                }
                if ((_orderBys != null) && (_orderBys.Count > 0)) {
                    var t = string.Join (", ", _orderBys.Select (o => "\"" + o.ColumnName + "\"" + (o.Ascending ? "" : " desc")).ToArray ());
                    cmdText += " order by " + t;
                }
                if (_limit.HasValue) {
                    cmdText += " limit " + _limit.Value;
                }
                if (_offset.HasValue) {
                    if (!_limit.HasValue) {
                        cmdText += " limit -1 ";
                    }
                    cmdText += " offset " + _offset.Value;
                }
                return Connection.CreateCommand (cmdText, args.ToArray ());
            }
        }

Thanks, Veerabhadra Kattamudi

ice128man commented 11 years ago

I vote for this feature. Perhaps someone knows how to add support for joins. I believe it involves a lot of changes to the architecture.

The only work around I know of is to build the entire sql query string yourself.

Geramy commented 7 years ago

Does anyone know what it might take to implement this? I am looking at implementing this because most my application runs off of Linq and having the degradation of no SQLite Join Features sucks bad. Also can be slightly annoying so if you have any help or pointers please let me know.

praeclarum commented 7 years ago

I've looked into it from time to time and agree it would be nice to have.

Geramy commented 7 years ago

I have created the ability to do joins. Also I have optimized the library to use Lambda Functions for new object instances because its faster then Reflection by a whole lot. How do I go about submitting my changes is there a sub branch I can use? https://vagifabilov.wordpress.com/2010/04/02/dont-use-activator-createinstance-or-constructorinfo-invoke-use-compiled-lambda-expressions/

praeclarum commented 7 years ago

Great! However I do want to first look into SQLiteNetExtensions to see if they did it too.

You can contribute by forking the project, creating a branch, and then pushing your code to that branch. You can then open a pull request to get it reviewed.

Please do not include the lambda work. That sounds great but it should be a separate pull request. I need to make sure it doesn't hurt performance on iOS (compiling lambdas on iOS can be costly since there is no JIT).