Skip to content
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

Incorrect "In" clause implementation. #378

Open
ramankarman opened this issue Nov 17, 2015 · 1 comment
Open

Incorrect "In" clause implementation. #378

ramankarman opened this issue Nov 17, 2015 · 1 comment

Comments

@ramankarman
Copy link

I found that if subquery for select parameters for In clause returns empty set, Simple.Data throws ArgumentOutOfRangeException with message "startIndex cannot be larger than length of string.
Parameter name: startIndex" and stack trace " at System.String.Substring(Int32 startIndex, Int32 length)
at Simple.Data.Ado.CommandBuilder.d__10.MoveNext()
at Simple.Data.Ado.CommandBuilder.SetParameters(IDbParameterFactory parameterFactory, IDbCommand command, IEnumerable1 parameters) at Simple.Data.Ado.CommandBuilder.CreateCommand(IDbParameterFactory parameterFactory, ICommandBuilder[] commandBuilders, IDbConnection connection, AdoOptions options) at Simple.Data.Ado.AdoAdapterQueryRunner.RunQuery(SimpleQuery query, IEnumerable1& unhandledClauses)
at Simple.Data.Ado.AdoAdapter.RunQuery(SimpleQuery query, IEnumerable1& unhandledClauses) at Simple.Data.DatabaseRunner.RunQuery(SimpleQuery query, IEnumerable1& unhandledClauses)
at Simple.Data.SimpleQuery.Run()
at Simple.Data.SimpleQuery.CastT
at Simple.Data.SimpleQuery.ToListT
at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet ](CallSite site, T0 arg0)
at ....".
Is it correct implementations of the In clause?

For example, there are two tables tblA(a_id, a_name) and tblB(b_id, b_name, b_a_id) where b_a_id is FK to the tblA(a_id field) and I want to select all a_name values for tblB objects which have b_name containig "a" sign.
The sql query is "SELECT a_name FROM tblA WHERE a_id IN(SELECT b_a_id FROM tblB WHERE b_name LIKE '%a%')".
Using Simple.Data, query is DB.tblA.FindAll(DB.tblA.a_id == DB.tblB.FindAll(DB.tblB.b_name.Like("%a%").ToScalarList()).ToScalarList().
If I execute "native" query, sql server returns empty query result, if I execute simple.data query, Simple.Data throws exception instead of returning empty list.

Ie problem is the query result inside "in" clause. If result of the query inside "In" clause is empty set, Simple.Data query throws exception at runtime. This exception is thrown even if I pass empty array to "In" clause to Simple.Data query:
DB.tblA.FindAll(DB.tblA.a_id == new int[]{}).ToScalarList()

@BenMagyar
Copy link

Simple.Data does not do nested queries, you would be better off just joining the two tables.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants