Connecting Tech Pros Worldwide Help | Site Map

OracleConnection not returning correct number of rows

Member
 
Join Date: Aug 2007
Posts: 39
#1: Sep 15 '09
I have an query I run against an Oracle Connection.
I have these objects, an event table and a table to map my objects to my events.
My select statement selects the most recent event for each object and if it meets certain requirements then the object's id is returned.

something like
Expand|Select|Wrap|Line Numbers
  1. select o.id from
  2. objects o, events e, objecteventmap oem,
  3. (select max(date), o.id from events e, objects o, objecteventmap oem 
  4. where e.id = oem.eventid and o.id = oem.objectid) ss
  5. where
  6. o.id = oem.objectid and
  7. e.id = oem.eventid and
  8. o.id = ss.id and
  9. e.date = ss.date and
  10. <more where clause stuff>
  11.  
The problem is when I run the query in Oracle SQL Developer I get 42 rows (the correct result set) and when I create an OracleCommand object and put that in as my query in my C# I get 30 rows (a reduced result set).

Help!

Edit:
Ok so I broke apart my query to get a better look at the data. In .net for some reason my Max date is getting the wrong date for some events. I am getting the ides of march instead of the correct date for a bunch of them. The weird thing is I do not have March 15th entered in my data anywhere....
Plater's Avatar
Moderator
 
Join Date: Apr 2007
Location: New England
Posts: 7,148
#2: Sep 15 '09

re: OracleConnection not returning correct number of rows


Have you checked to see if more then one table is being returned?
Edit: Oh it was date trouble. Are you making sure your date formats come out correctly?
Member
 
Join Date: Aug 2007
Posts: 39
#3: Sep 15 '09

re: OracleConnection not returning correct number of rows


I had a look into the ungrouped data. In SQL Developer I'm getting 193 rows in .Net I'm getting 239 rows :(
Could this be a driver issue? It is like my join is all messed up.
Member
 
Join Date: Aug 2007
Posts: 39
#4: Sep 15 '09

re: OracleConnection not returning correct number of rows


Ok, the select * on my mapping table gives different row counts .Net than when in SQl Developer.

Could this be a garbage collection issue?
Plater's Avatar
Moderator
 
Join Date: Apr 2007
Location: New England
Posts: 7,148
#5: Sep 15 '09

re: OracleConnection not returning correct number of rows


Have you tried making the SQL code into stored procedure? (Oracle has those right? I never got to in-depth with oracle)
Member
 
Join Date: Aug 2007
Posts: 39
#6: Sep 15 '09

re: OracleConnection not returning correct number of rows


Ok, I think perhaps it might be a commit type issue.
Member
 
Join Date: Aug 2007
Posts: 39
#7: Sep 15 '09

re: OracleConnection not returning correct number of rows


My co-worker says it is a pain in the butt to get a result set returned from an oracle sp.
Member
 
Join Date: Aug 2007
Posts: 39
#8: Sep 15 '09

re: OracleConnection not returning correct number of rows


Ok I think I solved it... it just took 2 days...
I don't think my deletes were being committed to the DB. At some point I started getting the correct rows in .Net. I think this happened because I was not putting my OracleCommand object within a transaction... I hope.
Anyways to prevent this use this from happening again I am doing this.
Expand|Select|Wrap|Line Numbers
  1.         OracleCommand com = GetCommand(myCommand);
  2.             com.Connection.Open();
  3.             OracleTransaction ot = com.Connection.BeginTransaction();
  4.             com.Transaction = ot;
  5.             try
  6.             {
  7.                 com.Prepare();
  8.                 com.ExecuteNonQuery();
  9.                 com.Transaction.Commit();
  10.             }
  11.             catch
  12.             {
  13.             }
  14.             finally
  15.             {
  16.                 com.Connection.Close();
  17.             }
Reply