Permalink
Browse files

Merge pull request #6 from Vidarls/master

Updated to work with Simple.Data 0.16.0.0
  • Loading branch information...
2 parents f488585 + 1db0906 commit f3f997b2c86053c4ee74de81e831919a397c8226 @NotMyself committed Apr 19, 2012
@@ -31,13 +31,11 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
- <Reference Include="Simple.Data, Version=0.12.2.2, Culture=neutral, processorArchitecture=MSIL">
- <SpecificVersion>False</SpecificVersion>
- <HintPath>..\..\packages\Simple.Data.Core.0.12.2.2\lib\net40\Simple.Data.dll</HintPath>
+ <Reference Include="Simple.Data">
+ <HintPath>..\..\packages\Simple.Data.Core.0.16.0.0\lib\net40\Simple.Data.dll</HintPath>
</Reference>
- <Reference Include="Simple.Data.Ado, Version=0.12.2.2, Culture=neutral, processorArchitecture=MSIL">
- <SpecificVersion>False</SpecificVersion>
- <HintPath>..\..\packages\Simple.Data.Ado.0.12.2.2\lib\net40\Simple.Data.Ado.dll</HintPath>
+ <Reference Include="Simple.Data.Ado">
+ <HintPath>..\..\packages\Simple.Data.Ado.0.16.0.0\lib\net40\Simple.Data.Ado.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.Composition" />
@@ -12,16 +12,28 @@ public class SqliteQueryPager : IQueryPager
{
private static readonly Regex ColumnExtract = new Regex(@"SELECT\s*(.*)\s*(FROM.*)", RegexOptions.Multiline | RegexOptions.IgnoreCase);
+ public IEnumerable<string> ApplyLimit(string sql, int take)
+ {
+ sql = AddMissingOrderBy(sql);
+ yield return string.Format("{0} LIMIT {1}", sql, take);
+ }
+
public IEnumerable<string> ApplyPaging(string sql, int skip, int take)
{
+ sql = AddMissingOrderBy(sql);
+
+ yield return string.Format("{0} LIMIT {1},{2}", sql, skip, take);
+ }
+
+ private string AddMissingOrderBy(string sql)
+ {
if (sql.IndexOf("order by", StringComparison.InvariantCultureIgnoreCase) < 0)
{
var match = ColumnExtract.Match(sql);
var columns = match.Groups[1].Value.Trim();
sql += " ORDER BY " + columns.Split(',').First().Trim();
}
-
- yield return string.Format("{0} LIMIT {1},{2}", sql, skip, take);
+ return sql;
}
}
}
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
- <package id="Simple.Data.Ado" version="0.12.2.2" />
- <package id="Simple.Data.Core" version="0.12.2.2" />
+ <package id="Simple.Data.Ado" version="0.16.0.0" />
+ <package id="Simple.Data.Core" version="0.16.0.0" />
<package id="System.Data.SQLite" version="1.0.79.0" />
</packages>
@@ -36,5 +36,30 @@ public void ShouldApplyPagingUsingOrderByFirstColumnIfNotAlreadyOrdered()
Assert.AreEqual(expected, modified);
}
+ [Test]
+ public void ShouldApplyLimitWithoutOffsetUsingOrderBy()
+ {
+ const string sql = "select a,b,c from d where a = 1 order by c";
+ const string expected =
+ "select a,b,c from d where a = 1 order by c limit 10";
+
+ var modified = new SqliteQueryPager().ApplyLimit(sql, 10).Single();
+ modified = Normalize.Replace(modified, " ").ToLowerInvariant();
+ Assert.AreEqual(expected,modified);
+ }
+
+ [Test]
+ public void ShouldApplyLimitUsingOrderByFirstColumnIfNotAlreadyOrdered()
+ {
+ const string sql = "select a,b,c from d where a = 1";
+ const string expected =
+ "select a,b,c from d where a = 1 order by a limit 10";
+
+ var modified = new SqliteQueryPager().ApplyLimit(sql, 10).Single();
+ modified = Normalize.Replace(modified, " ").ToLowerInvariant();
+
+ Assert.AreEqual(expected, modified);
+ }
+
}
}
@@ -42,17 +42,14 @@
<Reference Include="pnunit.framework">
<HintPath>..\..\packages\NUnit.2.5.10.11092\lib\pnunit.framework.dll</HintPath>
</Reference>
- <Reference Include="Simple.Data, Version=0.12.2.2, Culture=neutral, processorArchitecture=MSIL">
- <SpecificVersion>False</SpecificVersion>
- <HintPath>..\..\packages\Simple.Data.Core.0.12.2.2\lib\net40\Simple.Data.dll</HintPath>
+ <Reference Include="Simple.Data">
+ <HintPath>..\..\packages\Simple.Data.Core.0.16.0.0\lib\net40\Simple.Data.dll</HintPath>
</Reference>
- <Reference Include="Simple.Data.Ado, Version=0.12.2.2, Culture=neutral, processorArchitecture=MSIL">
- <SpecificVersion>False</SpecificVersion>
- <HintPath>..\..\packages\Simple.Data.Ado.0.12.2.2\lib\net40\Simple.Data.Ado.dll</HintPath>
+ <Reference Include="Simple.Data.Ado">
+ <HintPath>..\..\packages\Simple.Data.Ado.0.16.0.0\lib\net40\Simple.Data.Ado.dll</HintPath>
</Reference>
- <Reference Include="Simple.Data.Mocking, Version=0.12.2.2, Culture=neutral, processorArchitecture=MSIL">
- <SpecificVersion>False</SpecificVersion>
- <HintPath>..\..\packages\Simple.Data.Mocking.0.12.2.2\lib\net40\Simple.Data.Mocking.dll</HintPath>
+ <Reference Include="Simple.Data.Mocking">
+ <HintPath>..\..\packages\Simple.Data.Mocking.0.16.0.0\lib\net40\Simple.Data.Mocking.dll</HintPath>
</Reference>
<Reference Include="Simple.Data.TestHelper, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Simple.Data.TestHelper\Simple.Data.TestHelper.dll</HintPath>
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NUnit" version="2.5.10.11092" />
- <package id="Simple.Data.Ado" version="0.12.2.2" />
- <package id="Simple.Data.Core" version="0.12.2.2" />
- <package id="Simple.Data.Mocking" version="0.12.2.2" />
+ <package id="Simple.Data.Ado" version="0.16.0.0" />
+ <package id="Simple.Data.Core" version="0.16.0.0" />
+ <package id="Simple.Data.Mocking" version="0.16.0.0" />
<package id="System.Data.SQLite" version="1.0.79.0" />
</packages>

0 comments on commit f3f997b

Please sign in to comment.