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

Adding Skip to chained command throws exception. #301

Closed
hmobius opened this issue Aug 6, 2013 · 1 comment
Closed

Adding Skip to chained command throws exception. #301

hmobius opened this issue Aug 6, 2013 · 1 comment

Comments

@hmobius
Copy link

hmobius commented Aug 6, 2013

I'm trying to do a pretty robust query and Simple.Data is giving me an error. I have an SQL table called "Album" with the following structure:

AlbumId (PK) bigint
GenreId (FK) bigint
ArtistId (FK) bigint
Title varchar(128)
Price decimal(18, 2)
AlbumnArtUrl varchar(128)

I need to generate a query where I group by 2 fields and since Simple.Data doesn't have a "GroupBy" function, I'm adding an aggregate to my select query to force a "GroupBy" on the remaining fields in this way:

Future<int> c;

db.Albumn.All()
.Select(db.Albumn.Price, db.Albumn.AlbumnArtUrl, view.Price.Count())
.Where(db.Albumn.ArtistId != null && db.Albumn.ArtistId > 0 && db.Albumn.ArtistId < 100)
.OrderBy(db.Albumn.Price)
.WithTotalCount(out c)
.Skip(startIndex)
.Take(pageSize)

And I get the following error:

Simple.Data.Ado.AdoAdapterException was unhandled by user code
  HResult=-2146233088
  Message=Incorrect syntax near the keyword 'AND'.
  Source=Simple.Data.Ado
  CommandText=select COUNT(*) from [dbo].[Album] WHERE (([dbo].[Album].[ArtistId] IS NOT NULL AND [dbo].[Album].[ArtistId] > @p1_c0) AND [dbo].[Album].[ArtistId] < @p2_c0); WITH __Data AS (SELECT [dbo].[Album].[AlbumId], ROW_NUMBER() OVER(ORDER BY [dbo].[Album].[Price]) AS [_#_]
from [dbo].[Album] WHERE (([dbo].[Album].[ArtistId] IS NOT NULL AND [dbo].[Album].[ArtistId] > @p1_c1) AND [dbo].[Album].[ArtistId] < @p2_c1) GROUP BY [dbo].[Album].[Price],[dbo].[Album].[AlbumArtUrl])
SELECT [dbo].[Album].[Price],[dbo].[Album].[AlbumArtUrl],Count([dbo].[Album].[Price]) FROM __Data JOIN [dbo].[Album] ON [dbo].[Album].[AlbumId] = __Data.[AlbumId] WHERE (([dbo].[Album].[ArtistId] IS NOT NULL AND [dbo].[Album].[ArtistId] > @p1_c1) AND [dbo].[Album].[ArtistId] < @p2_c1) GROUP BY [dbo].[Album].[Price],[dbo].[Album].[AlbumArtUrl] AND [_#_] BETWEEN 3 AND 10
  StackTrace:
       at Simple.Data.Ado.DbCommandExtensions.TryExecuteReader(IDbCommand command)
       at Simple.Data.Ado.DataReaderMultipleEnumerator.ExecuteReader()
       at Simple.Data.Ado.DataReaderMultipleEnumerator.MoveNext()
       at Simple.Data.Ado.AdoAdapterQueryRunner.<RunQueries>d__b.MoveNext()
       at Simple.Data.Ado.AdoAdapterQueryRunner.RunQueryWithCount(SimpleQuery query, IEnumerable`1& unhandledClauses)
       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.TryConvert(ConvertBinder binder, Object& result)
       at CallSite.Target(Closure , CallSite , Object )
       at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0)
       at Ibfx.DataAccess.DataView`1.JoinFetchAll(Int32 startIndex, Int32 pageSize, Int32& count) in d:\Code\Dev\Src\Core\Ibfx.DataAccess\DataView.cs:line 747
       at Ibfx.DataAccess.DataView`1.DynamicFetchAll(Int32 startIndex, Int32 pageSize, Int32& count) in d:\Code\Dev\Src\Core\Ibfx.DataAccess\DataView.cs:line 805
       at Ibfx.DataAccess.TSS.Tests.AccountTest.TestCrazyEverything() in d:\Code\Dev\Src\Tests\Unit\Ibfx.DataAccess.TSS.Tests\AccountTest.cs:line 487
  InnerException: 

Skip seems to be the culprit. If I remove Skip, this query works.

@richardhopton
Copy link
Collaborator

I don't have the infrastructure to test this - hence it's in a branch and pull request. By all means grab the branch and check it works for you.

richardhopton added a commit that referenced this issue Aug 12, 2013
richardhopton added a commit that referenced this issue Aug 15, 2013
richardhopton added a commit that referenced this issue Aug 15, 2013
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