Permalink
Browse files

Merge pull request #138 from AkosLukacs/master

Bug in Oracle paging SQL generation if there is no explicit ordering
  • Loading branch information...
2 parents 914e22f + 7e1166b commit b6813a819b05bd29f90ba58259204aebb42addec @mythz mythz committed Jan 22, 2013
Showing with 385 additions and 17 deletions.
  1. 0 src/{ServiceStack.OrmLite.Oracle.Tests → OracleTests}/TestClassWriter/AssemblyInfo.cs
  2. 0 src/{ServiceStack.OrmLite.Oracle.Tests → OracleTests}/TestClassWriter/Main.cs
  3. 0 src/{ServiceStack.OrmLite.Oracle.Tests → OracleTests}/TestClassWriter/TestClassWriter.csproj
  4. 0 src/{ServiceStack.OrmLite.Oracle.Tests → OracleTests}/TestExpression02/AssemblyInfo.cs
  5. 0 src/{ServiceStack.OrmLite.Oracle.Tests → OracleTests}/TestExpression02/Main.cs
  6. 0 src/{ServiceStack.OrmLite.Oracle.Tests → OracleTests}/TestExpression02/TestExpression02.csproj
  7. 0 src/{ServiceStack.OrmLite.Oracle.Tests → OracleTests}/TestExpressions/AssemblyInfo.cs
  8. 0 src/{ServiceStack.OrmLite.Oracle.Tests → OracleTests}/TestExpressions/Main.cs
  9. 0 src/{ServiceStack.OrmLite.Oracle.Tests → OracleTests}/TestExpressions/TestExpressions.csproj
  10. 0 src/{ServiceStack.OrmLite.Oracle.Tests → OracleTests}/TestLiteOracle00/AssemblyInfo.cs
  11. 0 src/{ServiceStack.OrmLite.Oracle.Tests → OracleTests}/TestLiteOracle00/Main.cs
  12. 0 src/{ServiceStack.OrmLite.Oracle.Tests → OracleTests}/TestLiteOracle00/TestLiteOracle00.csproj
  13. 0 src/{ServiceStack.OrmLite.Oracle.Tests → OracleTests}/TestLiteOracle04/AssemblyInfo.cs
  14. 0 src/{ServiceStack.OrmLite.Oracle.Tests → OracleTests}/TestLiteOracle04/Company.cs
  15. 0 src/{ServiceStack.OrmLite.Oracle.Tests → OracleTests}/TestLiteOracle04/DbMethodsIn.cs
  16. 0 src/{ServiceStack.OrmLite.Oracle.Tests → OracleTests}/TestLiteOracle04/Main.cs
  17. 0 src/{ServiceStack.OrmLite.Oracle.Tests → OracleTests}/TestLiteOracle04/TestLiteOracle04.csproj
  18. 0 src/{ServiceStack.OrmLite.Oracle.Tests → OracleTests}/TestSimpleOracle01/AssemblyInfo.cs
  19. 0 src/{ServiceStack.OrmLite.Oracle.Tests → OracleTests}/TestSimpleOracle01/Main.cs
  20. 0 src/{ServiceStack.OrmLite.Oracle.Tests → OracleTests}/TestSimpleOracle01/TestLiteOracle01.csproj
  21. 0 src/{ServiceStack.OrmLite.Oracle.Tests → OracleTests}/TestSimpleOracle02/AssemblyInfo.cs
  22. 0 src/{ServiceStack.OrmLite.Oracle.Tests → OracleTests}/TestSimpleOracle02/Company.cs
  23. 0 src/{ServiceStack.OrmLite.Oracle.Tests → OracleTests}/TestSimpleOracle02/Main.cs
  24. 0 src/{ServiceStack.OrmLite.Oracle.Tests → OracleTests}/TestSimpleOracle02/TestLiteOracle02.csproj
  25. 0 src/{ServiceStack.OrmLite.Oracle.Tests → OracleTests}/TestSimpleOracle03/AssemblyInfo.cs
  26. 0 src/{ServiceStack.OrmLite.Oracle.Tests → OracleTests}/TestSimpleOracle03/Main.cs
  27. 0 src/{ServiceStack.OrmLite.Oracle.Tests → OracleTests}/TestSimpleOracle03/TestSimpleOracle03.csproj
  28. 0 src/{ServiceStack.OrmLite.Oracle.Tests → OracleTests}/TestSimpleOracleProcedures/AssemblyInfo.cs
  29. 0 src/{ServiceStack.OrmLite.Oracle.Tests → OracleTests}/TestSimpleOracleProcedures/Main.cs
  30. 0 ....OrmLite.Oracle.Tests → OracleTests}/TestSimpleOracleProcedures/TestSimpleOracleProcedures.csproj
  31. +125 −0 src/ServiceStack.OrmLite.Oracle.Tests/OracleSyntaxTests.cs
  32. +27 −0 src/ServiceStack.OrmLite.Oracle.Tests/OracleTestBase.cs
  33. +36 −0 src/ServiceStack.OrmLite.Oracle.Tests/Properties/AssemblyInfo.cs
  34. +82 −0 src/ServiceStack.OrmLite.Oracle.Tests/ServiceStack.OrmLite.Oracle.Tests.csproj
  35. +8 −0 src/ServiceStack.OrmLite.Oracle.Tests/app.config
  36. +0 −12 src/ServiceStack.OrmLite.Oracle/OracleOrmLiteDialectProvider.cs
  37. +1 −0 src/ServiceStack.OrmLite.SqlServerTests/ServiceStack.OrmLite.SqlServerTests.csproj
  38. +74 −0 src/ServiceStack.OrmLite.SqlServerTests/UnicodeTests.cs
  39. +32 −5 src/ServiceStack.OrmLite.sln
@@ -0,0 +1,125 @@
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.Linq;
+using System.Text;
+using NUnit.Framework;
+using System.Data;
+using ServiceStack.DataAnnotations;
+
+namespace ServiceStack.OrmLite.Oracle.Tests
+{
+ [TestFixture]
+ public class OracleSyntaxTests : OracleTestBase
+ {
+ [Test]
+ public void can_generate_correct_paging_if_first_column_must_be_quoted()
+ {
+ using(var db = ConnectionString.OpenDbConnection()) {
+ db.CreateTable<FirstColMustBeQuoted>(true);
+
+ var noRows = db.Select<FirstColMustBeQuoted>(ev => ev.Limit(100));
+
+ Assert.AreEqual(0, noRows.Count());
+
+ for(int i = 0; i < 150; i++) {
+ db.Insert<FirstColMustBeQuoted>(new FirstColMustBeQuoted { COMMENT = "row #" + i });
+ }
+
+ var hundredRows = db.Select<FirstColMustBeQuoted>(ev => ev.Limit(100));
+ Assert.AreEqual(100, hundredRows.Count());
+ }
+ }
+
+ [Test]
+ public void can_generate_correct_paging_if_first_column_dont_have_to_be_quoted()
+ {
+ using(var db = ConnectionString.OpenDbConnection()) {
+ db.CreateTable<FirstColNoQuotes>(true);
+
+ var noRows = db.Select<FirstColNoQuotes>(ev => ev.Limit(100));
+
+ Assert.AreEqual(0, noRows.Count());
+
+ for(int i = 0; i < 150; i++) {
+ db.Insert<FirstColNoQuotes>(new FirstColNoQuotes { COMMENT = "row #" + i });
+ }
+
+ var hundredRows = db.Select<FirstColNoQuotes>(ev => ev.Limit(100));
+ Assert.AreEqual(100, hundredRows.Count());
+ }
+ }
+
+ [Test]
+ public void can_generate_correct_paging_if_TABLE_NAME_must_be_quoted_and_first_column_have_to_be_quoted()
+ {
+ using(var db = ConnectionString.OpenDbConnection()) {
+ db.CreateTable<COMMENT_first>(true);
+
+ var noRows = db.Select<COMMENT_first>(ev => ev.Limit(100));
+
+ Assert.AreEqual(0, noRows.Count());
+
+ for(int i = 0; i < 150; i++) {
+ db.Insert(new COMMENT_first { COMMENT = "COMMENT row #" + i });
+ }
+
+ var hundredRows = db.Select<COMMENT_first>(ev => ev.Limit(100));
+ Assert.AreEqual(100, hundredRows.Count());
+ }
+ }
+
+ [Test]
+ public void can_generate_correct_paging_if_TABLE_NAME_must_be_quoted_and_first_column_dont_have_to_be_quoted()
+ {
+ using(var db = ConnectionString.OpenDbConnection()) {
+ db.CreateTable<COMMENT_other>(true);
+
+ var noRows = db.Select<COMMENT_other>(ev => ev.Limit(100));
+
+ Assert.AreEqual(0, noRows.Count());
+
+ for(int i = 0; i < 150; i++) {
+ db.Insert(new COMMENT_other { COMMENT = "COMMENT row #" + i });
+ }
+
+ var hundredRows = db.Select<COMMENT_other>(ev => ev.Limit(100));
+ Assert.AreEqual(100, hundredRows.Count());
+ }
+ }
+
+ [Alias("COMMENT")]
+ private class COMMENT_first
+ {
+ public string COMMENT { get; set; }
+
+ [AutoIncrement, PrimaryKey]
+ public int Id { get; set; }
+ }
+
+ [Alias("COMMENT")]
+ private class COMMENT_other
+ {
+ [AutoIncrement, PrimaryKey]
+ public int Id { get; set; }
+
+ public string COMMENT { get; set; }
+ }
+
+ private class FirstColMustBeQuoted
+ {
+ public string COMMENT { get; set; }
+
+ [AutoIncrement, PrimaryKey]
+ public int Id { get; set; }
+ }
+
+ private class FirstColNoQuotes//Oracle: max 30 characters...
+ {
+ [AutoIncrement, PrimaryKey]
+ public int Id { get; set; }
+
+ public string COMMENT { get; set; }
+ }
+ }
+}
@@ -0,0 +1,27 @@
+using System;
+using System.Configuration;
+using System.IO;
+using NUnit.Framework;
+using ServiceStack.Common.Utils;
+using ServiceStack.Logging;
+using ServiceStack.Logging.Support.Logging;
+using ServiceStack.OrmLite.Oracle;
+
+
+namespace ServiceStack.OrmLite.Oracle.Tests
+{
+ public class OracleTestBase
+ {
+ protected virtual string ConnectionString { get; set; }
+
+ [TestFixtureSetUp]
+ public void TestFixtureSetUp()
+ {
+ LogManager.LogFactory = new ConsoleLogFactory();
+
+ OrmLiteConfig.DialectProvider = OracleOrmLiteDialectProvider.Instance;
+ OrmLiteConfig.ClearCache();
+ ConnectionString = ConfigurationManager.ConnectionStrings["testDb"].ConnectionString;
+ }
+ }
+}
@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("ServiceStack.OrmLite.Oracle.Tests")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("ServiceStack.OrmLite.Oracle.Tests")]
+[assembly: AssemblyCopyright("Copyright © 2013")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("98a76291-26c2-4012-aeef-ab688752d30b")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
@@ -0,0 +1,82 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProductVersion>8.0.30703</ProductVersion>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{DE5CA3EB-010D-492A-A0B7-501D7941FA51}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>ServiceStack.OrmLite.Oracle.Tests</RootNamespace>
+ <AssemblyName>ServiceStack.OrmLite.Oracle.Tests</AssemblyName>
+ <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="nunit.framework, Version=2.6.2.12296, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\lib\tests\nunit.framework.dll</HintPath>
+ </Reference>
+ <Reference Include="ServiceStack.Common">
+ <HintPath>..\..\lib\ServiceStack.Common.dll</HintPath>
+ </Reference>
+ <Reference Include="ServiceStack.Interfaces">
+ <HintPath>..\..\lib\ServiceStack.Interfaces.dll</HintPath>
+ </Reference>
+ <Reference Include="System" />
+ <Reference Include="System.configuration" />
+ <Reference Include="System.Core" />
+ <Reference Include="System.Xml.Linq" />
+ <Reference Include="System.Data.DataSetExtensions" />
+ <Reference Include="System.Data" />
+ <Reference Include="System.Xml" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="OracleSyntaxTests.cs" />
+ <Compile Include="OracleTestBase.cs">
+ <SubType>Code</SubType>
+ </Compile>
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\ServiceStack.OrmLite.Oracle\ServiceStack.OrmLite.Oracle.csproj">
+ <Project>{517B64BA-D7A6-4A15-8719-821B38147C61}</Project>
+ <Name>ServiceStack.OrmLite.Oracle</Name>
+ </ProjectReference>
+ <ProjectReference Include="..\ServiceStack.OrmLite\ServiceStack.OrmLite.csproj">
+ <Project>{96179AC6-F6F1-40C3-9FDD-4F6582F54C5C}</Project>
+ <Name>ServiceStack.OrmLite</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="app.config">
+ <SubType>Designer</SubType>
+ </None>
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project>
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<configuration>
+ <configSections>
+ </configSections>
+ <connectionStrings>
+ <add name="testDb" connectionString="Data Source=localhost:1521/XE;User ID=servicestack_test;Password=servicestack_test;Unicode=True"/>
+ </connectionStrings>
+</configuration>
@@ -697,18 +697,6 @@ private string Quote(string name)
: name;
}
- public override string GetColumnNames(ModelDefinition modelDef)
- {
- if (QuoteNames) return modelDef.GetColumnNames();
- var sqlColumns = new StringBuilder();
- modelDef.FieldDefinitions.ForEach(x =>
- sqlColumns.AppendFormat("{0} {1}",
- sqlColumns.Length > 0 ? "," : "",
- GetQuotedColumnName(x.FieldName)));
-
- return sqlColumns.ToString();
- }
-
public override string GetQuotedName(string fieldName)
{
return Quote(fieldName);
@@ -73,6 +73,7 @@
<Compile Include="OrmLiteTestBase.cs" />
<Compile Include="SqlServerExpressionVisitorQueryTest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="UnicodeTests.cs" />
<Compile Include="UpdateTests.cs" />
<Compile Include="UseCase\SimpleUseCase.cs" />
<Compile Include="UseCase\TestEntity.cs" />
@@ -0,0 +1,74 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using NUnit.Framework;
+using ServiceStack.DataAnnotations;
+
+namespace ServiceStack.OrmLite.SqlServerTests
+{
+ /// <summary>
+ /// test for issue #69
+ /// </summary>
+ class UnicodeTests : OrmLiteTestBase
+ {
+ [Test]
+ public void can_insert_and_retrieve_unicode_values()
+ {
+ OrmLiteConfig.DialectProvider.UseUnicode = true;
+
+ var testData = new[]{
+ "árvíztűrő tükörfúrógép",
+ "ÁRVÍZTŰRŐ TÜKÖRFÚRÓGÉP", //these are the Hungarian "special" characters, they work fine out of the box
+ "♪♪♫" //this one comes back as 'ddd'
+ };
+
+ using(var con = ConnectionString.OpenDbConnection()) {
+ con.ExecuteSql(table_re_creation_script);
+
+ foreach(var item in testData) { con.Insert(new Unicode_poco { Text = item }); }
+
+ var fromDb = con.Select<Unicode_poco>().Select(x => x.Text).ToArray();
+
+ CollectionAssert.AreEquivalent(testData, fromDb);
+ }
+ }
+
+
+ /* *
+--if you run this in SSMS, it produces 'ddd'
+INSERT INTO [Unicode_poco] ([Text]) VALUES ('hai ♪♪♫')
+
+--if you run this in SSMS, it works fine
+INSERT INTO [Unicode_poco] ([Text]) VALUES (N'hai ♪♪♫')
+
+select * from Unicode_poco
+ * */
+
+
+ private class Unicode_poco
+ {
+ [PrimaryKey, AutoIncrement]
+ public int Id { get; set; }
+
+ public string Text { get; set; }
+ }
+
+ /// <summary>
+ /// because OrmLite does not create nvarchar columns
+ /// </summary>
+ private string table_re_creation_script = @"
+IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Unicode_poco]') AND type in (N'U'))
+DROP TABLE [dbo].[Unicode_poco];
+
+
+CREATE TABLE [dbo].[Unicode_poco](
+ [Id] [int] IDENTITY(1,1) NOT NULL,
+ [Text] [nvarchar](4000) NULL,
+ CONSTRAINT [PK_Unicode_poco] PRIMARY KEY CLUSTERED
+(
+ [Id] ASC
+)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
+) ON [PRIMARY]";
+ }
+}
Oops, something went wrong.

0 comments on commit b6813a8

Please sign in to comment.