PC Review


Reply
Thread Tools Rate Thread

Bug with Jet OLEDB provider and DECIMAL subquery?

 
 
Jamie Collins
Guest
Posts: n/a
 
      18th Oct 2006
Consider this test table with a DECIMAL data column:

CurrentProject.Connection.Execute _
"CREATE TABLE Test (" & _
"key_col INTEGER NOT NULL UNIQUE," & _
" data_col DECIMAL(19, 4) NOT NULL);"

CurrentProject.Connection.Execute _
"INSERT INTO Test VALUES (1, 1);"
CurrentProject.Connection.Execute _
"INSERT INTO Test VALUES (2, 2);"
CurrentProject.Connection.Execute _
"INSERT INTO Test VALUES (3, 3);"

Consider this SQL to return a repeating column total on every row of
the resultset (although the resultset is limited to one row by the
search condition):

sSQL = _
"SELECT T1.key_col, T1.data_col," & _
" (SELECT SUM(T2.data_col)" & _
" FROM Test AS T2) AS total_data_col" & _
" FROM Test AS T1 WHERE T1.key_col = 1;"

First, DAO provides the correct result for total_data_col:

? CurrentDb.OpenRecordset(sSQL)(2)
6

Now for the wrong answers from ADO:

? CurrentProject.Connection.Execute(sSQL)(2)

Well, the first thing to note is that most of the time I get an error,
"Invalid procedure call or argument." but a small proportion of the
time I get the value

114850184919423154316574819

Hmm, a little overestimated, methinks <g>.

OK, using another method to get the field's value:

? CurrentProject.Connection.Execute(sSQL).GetRows()(2, 0)
1

Oh, dear. This is the value in the field but it is incorrect. I'm not
quite sure what is going on here but it seems the result of the
subquery is being replaced by the value of T1.data_col.
If the data type is changed (CURRENCY. FLOAT, etc) the behaviour is
correct. If the SUM keyword is changed to COUNT the behaviour is
correct.

The above works fine in a Access2007 query object's SQL view while in
ANSI-92 mode but the same (wrong) behaviour against CurrentProject. I
think therefore the source of the bug is the Jet 4.0 OLEDB provider but
again I'm merely guessing.

Workarounds are simple enough e.g.

sSQL = _
"SELECT T1.key_col, T1.data_col, DT1.total_data_col" & _
" FROM Test AS T1, (SELECT SUM(T2.data_col)" & _
" AS total_data_col FROM Test AS T2) AS DT1" & _
" WHERE T1.key_col = 1;"

Jamie.

--

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
OLEDB Provider Paul Ilacqua Microsoft Dot NET Compact Framework 2 17th Jan 2005 08:16 PM
DB2 IBM OleDB Provider Parking Meters Microsoft ADO .NET 12 17th Jan 2005 09:07 AM
DB2 IBM OleDB Provider Parking Meters Microsoft C# .NET 12 17th Jan 2005 09:07 AM
DB2 IBM OleDB Provider Parking Meters Microsoft Dot NET 12 17th Jan 2005 09:07 AM
OLEDB Provider Eror Zachary Burns Microsoft ADO .NET 1 16th Sep 2004 11:58 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:09 AM.