Column order problem

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for SQLite
Post Reply
dilbert
Posts: 68
Joined: Tue 28 Apr 2009 10:11

Column order problem

Post by dilbert » Wed 20 Jun 2012 13:33

There is still problem with column order. (Using version 4.0.17)

This query:

Code: Select all

from esv in DB.ExamSubjectVirtuals
join esvx in DB.ExamSubjectVirtualXes on esv.Id equals esvx.Id_subject_virtual
from eqc in DB.ExamQuestionCounts.Where(c => esvx.Id_subject == c.Id_area).DefaultIfEmpty()
where esv.Id_exam == idExam
orderby esv.Code
select new { esv.Id, eqc.Qs_count, esvx.Id_subject };

Is translated into:

Code: Select all

SELECT t1.Id AS Id, t2.Id_subject AS Id_subject, t3.Qs_count AS Qs_count
FROM exam_subject_virtual t1
INNER JOIN exam_subject_virtual_x t2 ON t1.Id = t2.Id_subject_virtual
LEFT OUTER JOIN exam_question_count t3 ON (t2.Id_subject = t3.Id_area)
WHERE t1.Id_exam = :p1
ORDER BY t1.Code

It executes properly. However in the result set, there are switched values from two last columns (Qs_count and Id_Subject).

MariiaI
Devart Team
Posts: 1472
Joined: Mon 13 Feb 2012 08:17

Re: Column order problem

Post by MariiaI » Fri 22 Jun 2012 12:19

We couldn't reproduce this issue. Please send us the model you are working with or give us the definitions of the tables 'ExamSubjectVirtuals', 'ExamSubjectVirtualXes' and 'ExamQuestionCounts'.
You may also try rewriting your query like below (we have rearranged the columns of the select block in the same order as in the join) and notify us about the results:

Code: Select all

from esv in DB.ExamSubjectVirtuals
join esvx in DB.ExamSubjectVirtualXes on esv.Id equals esvx.Id_subject_virtual
from eqc in DB.ExamQuestionCounts.Where(c => esvx.Id_subject == c.Id_area).DefaultIfEmpty()
where esv.Id_exam == idExam
orderby esv.Code
select new { esv.Id, esvx.Id_subject, eqc.Qs_count};

dilbert
Posts: 68
Joined: Tue 28 Apr 2009 10:11

Re: Column order problem

Post by dilbert » Tue 26 Jun 2012 15:47

After trying to create simple project for demonstration I realized it's a little more complicated. It's probably again concerned with compiled query cache. However, after disabling it problem still persists.
I use latest SQLite dotConnect 4.0.25.

Finally, I sent you project to simulate it.
I describe it here too. Tested with following database schema:

Code: Select all

CREATE TABLE [order] (
  [id_order] INT NOT NULL, 
  CONSTRAINT [sqlite_autoindex_order_1] PRIMARY KEY ([id_order]));

CREATE TABLE [order_item] (
  [id_order] INT NOT NULL, 
  [amount] int NOT NULL, 
  CONSTRAINT [sqlite_autoindex_order_item_1] PRIMARY KEY ([id_order]));

INSERT INTO [order](id_order) VALUES(1);
INSERT INTO [order_item](id_order, amount) VALUES(1, 6);
Then I called this code:

Code: Select all

01 public void GetAmount(int idOrder, int? minAmount)
02 {
03   using (DBContext db = new DBContext())
04   {
05     var query = from o in db.Orders
06        from i in db.OrderItems.Where(i => i.IdOrder == i.IdOrder).DefaultIfEmpty()
07        where o.IdOrder == idOrder
08        select new { i.Amount, o.IdOrder };
09    
10     if (minAmount.HasValue)
11       query = query.Where(q => q.Amount > minAmount);
12    
13     foreach (var i in query)
14       Console.Write("Id order: " + i.IdOrder + "\t Amount: " + i.Amount);  
15 }
16  
17 GetAmount(1, 1);  
18 GetAmount(1, null);

The result should be the same for both calling of method GetAmount (Lines 17 and 18). However it is:

Id_order: 1 Amount: 6
Id_order: 6 Amount: 1


If the method is called only once the result is always correct. But in the example above, in second calling lines 13 and 14 are omitted which constructs different sql query with different order of columns.
It causes that values are switched.

Image

MariiaI
Devart Team
Posts: 1472
Joined: Mon 13 Feb 2012 08:17

Re: Column order problem

Post by MariiaI » Wed 27 Jun 2012 10:47

Thank you for the sample project. We have reproduced this behaviour. We will investigate it and inform you about the results as soon as possible.

MariiaI
Devart Team
Posts: 1472
Joined: Mon 13 Feb 2012 08:17

Re: Column order problem

Post by MariiaI » Mon 02 Jul 2012 10:00

The bug, related to the switched columns, has been fixed. The problem was in the materialization functions cache. This fix will be available in the next build of dotConnect for SQLite, which we plan to release next week.
Also, we will consider the possibility of disabling the materialization cache and will inform you about the results as soon as possible.

MariiaI
Devart Team
Posts: 1472
Joined: Mon 13 Feb 2012 08:17

Re: Column order problem

Post by MariiaI » Thu 19 Jul 2012 07:04

New build of dotConnect for SQLite 4.1.40 is available for download now!
It can be downloaded from http://www.devart.com/dotconnect/sqlite/download.html (trial version) or from Registered Users' Area (for users with active subscription only).
For more information, please refer to http://forums.devart.com/viewtopic.php?f=29&t=24526

Post Reply