Correctness of the "In" clause implementation

19 views
Skip to first unread message

Raman Yukhnevich

unread,
Nov 9, 2015, 8:20:10 AM11/9/15
to Simple.Data
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.<CreateParameterComplex>d__10.MoveNext()
   at Simple.Data.Ado.CommandBuilder.SetParameters(IDbParameterFactory parameterFactory, IDbCommand command, IEnumerable`1 parameters)
   at Simple.Data.Ado.CommandBuilder.CreateCommand(IDbParameterFactory parameterFactory, ICommandBuilder[] commandBuilders, IDbConnection connection, AdoOptions options)
   at Simple.Data.Ado.AdoAdapterQueryRunner.RunQuery(SimpleQuery query, IEnumerable`1& unhandledClauses)
   at Simple.Data.Ado.AdoAdapter.RunQuery(SimpleQuery query, IEnumerable`1& unhandledClauses)
   at Simple.Data.DatabaseRunner.RunQuery(SimpleQuery query, IEnumerable`1& unhandledClauses)
   at Simple.Data.SimpleQuery.Run()
   at Simple.Data.SimpleQuery.Cast[T]()
   at Simple.Data.SimpleQuery.ToList[T]()
   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.
May be I'm doing something wrong?

Raman Yukhnevich

unread,
Nov 9, 2015, 2:15:24 PM11/9/15
to Simple.Data
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()
Reply all
Reply to author
Forward
0 new messages