Hello
I have problem when using count with ordered list from firebird
database.
I found similar problem with SQL Server (http://www.mail-archive.com/
[email protected]/msg00928.html) and transfer the changes to
firebird files.
The patch file is:


Index: src/DbLinq.Firebird/DbLinq.Firebird.csproj
===================================================================
--- src/DbLinq.Firebird/DbLinq.Firebird.csproj  (revision 1234)
+++ src/DbLinq.Firebird/DbLinq.Firebird.csproj  (working copy)
@@ -49,6 +49,7 @@
   </ItemGroup>
   <ItemGroup>
     <Compile Include="FirebirdDataContext.cs" />
+       <Compile Include="FirebirdExpressionTranslator.cs" />
     <Compile Include="FirebirdSchemaLoader.Columns.cs" />
     <Compile Include="FirebirdSchemaLoader.Constraints.cs" />
     <Compile Include="FirebirdSchemaLoader.cs" />
Index: src/DbLinq.Firebird/FirebirdSqlProvider.cs
===================================================================
--- src/DbLinq.Firebird/FirebirdSqlProvider.cs  (revision 1234)
+++ src/DbLinq.Firebird/FirebirdSqlProvider.cs  (working copy)
@@ -25,14 +25,20 @@
 #endregion

 using System;
+using System.Diagnostics;
 using System.Collections.Generic;
+using System.Linq.Expressions;
 using System.Linq;
 using System.Text;

 using DbLinq.Data.Linq.Sql;
 using DbLinq.Util;
 using DbLinq.Vendor.Implementation;
+using DbLinq.Data.Linq.Sugar;
+using DbLinq.Data.Linq.Sugar.Implementation;
+using DbLinq.Data.Linq.Sugar.Expressions;

+
 namespace DbLinq.Firebird
 {
 #if !MONO_STRICT
@@ -40,8 +46,13 @@
 #endif
     class FirebirdSqlProvider : SqlProvider
     {
-        public override string GetParameterName(string nameBase)
+        public override ExpressionTranslator GetTranslator()
         {
+            return new FirebirdExpressionTranslator();
+        }
+
+               public override string GetParameterName(string nameBase)
+        {
             return "@" + nameBase;
         }

@@ -94,6 +105,17 @@
             return select.Replace("SELECT", stmt, true);
         }

+        public override SqlStatement GetLiteralLimit(SqlStatement
select, SqlStatement limit, SqlStatement offset, SqlStatement
offsetAndLimit)
+        {
+            string stmt = (limit.Count == 2
+                ? string.Format("SELECT FIRST {0}, LAST {1} SKIP
{2}", limit[0].Sql, limit[1].Sql, offset)
+                : string.Format("SELECT FIRST {0} SKIP {1}", limit
[0].Sql, offset));
+           //string stmt = string.Format("SELECT FIRST {0} SKIP {1}",
limit, offset);
+
+            return select.Replace("SELECT", stmt, true);
+        }
+
+
         public override SqlStatement GetInsertIds(SqlStatement table,
IList<SqlStatement> autoPKColumn, IList<SqlStatement> inputPKColumns,
IList<SqlStatement> inputPKValues, IList<SqlStatement> outputColumns,
IList<SqlStatement> outputParameters, IList<SqlStatement>
outputExpressions)
         {
             // no parameters? no need to get them back
Index: src/DbLinq/System.Data.Linq.csproj
===================================================================
--- src/DbLinq/System.Data.Linq.csproj  (revision 1234)
+++ src/DbLinq/System.Data.Linq.csproj  (working copy)
@@ -96,6 +96,9 @@
     <Compile Include="..\DbLinq.SqlServer
\SqlServerExpressionTranslator.cs">
       <Link>Vendors\DbLinq.SqlServer
\SqlServerExpressionTranslator.cs</Link>
     </Compile>
+    <Compile Include="..\DbLinq.Firebird
\FirebirdExpressionTranslator.cs">
+      <Link>Vendors\DbLinq.Firebird\FirebirdExpressionTranslator.cs</
Link>
+    </Compile>
     <Compile Include="Data\Linq\ChangeAction.cs" />
     <Compile Include="Data\Linq\ChangeSet.cs" />
     <Compile Include="Data\Linq\Database\IDatabaseContext.cs" />




and the content of FirebirdExpressionTranslator.cs is



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

//#if MONO_STRICT
//using System.Data.Linq.Sugar.Expressions;
//#else
using DbLinq.Data.Linq.Sugar.Expressions;
//#endif

namespace DbLinq.Firebird
{
    class FirebirdExpressionTranslator : ExpressionTranslator
    {
        public override SelectExpression OuterExpression
(SelectExpression e)
        {
            // Check for (from f in foo orderby f.Field select f).Count
() trees
            // SQL Server doesn't support 'ORDER BY' for 'SELECT COUNT
(*)'.
            if (e.Operands.Select(o => o as SpecialExpression)
                    .Where(o => o != null)
                    .Where(s => s.SpecialNodeType ==
SpecialExpressionType.Count)
                    .Any())
            {
                e.OrderBy.Clear();
            }
            return e;
        }
    }
}

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"DbLinq" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/dblinq?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to