OT: Oracle Data Provider ODP.NET and GetInt32

OT: Oracle Data Provider ODP.NET and GetInt32

Old forum URL: forums.lhotka.net/forums/t/5794.aspx


Wbmstrmjb posted on Wednesday, November 12, 2008

Anyone else using the Oracle Data Provider (Oracle.DataAccess.Client) instead of System.Data.OracleClient?  GetInt32 doesn't work for ints because Oracle always returns numbers at decimals.  I can change the calls to (int)dr.GetDecimal but was wondering if anyone had a better workaround.

Thanks,

Mike

DancesWithBamboo replied on Wednesday, November 12, 2008

You do have to typecast it to an int.  I made a version of the SafeRowReader/SafeDataReader that was Oracle friendly.  Inside of the GetInt32 overload I did my typecast from decimal.

Jack replied on Saturday, November 15, 2008

Any interest in sharing any of that code? I'm starting to run into a few of these things.

thanks

jack

JoeFallon1 replied on Monday, November 17, 2008

You just subclass SafeDataReader and override the method you want to modify and use your own implementation. Then in your code instead of using "New SafeDataReader" you use "New MySafeDataReader" (or whatever you decide to call it.)

Here is how I handled Booleans for Oracle:

Imports Csla
Imports Csla.Data
Imports System.Web.Configuration

Namespace BO

'My Base class for modifications to Csla.Data.SafeDataReader
'Add support to SafeDataReader class to support Oracle reading Booleans.

<Serializable()> _
Public Class MySafeDataReader
Inherits SafeDataReader

#Region " Class Variable Declarations "

Private
mDBType As String = WebConfigurationManager.AppSettings("DBType")

Public
Sub New(ByVal dataReader As IDataReader)
  MyBase.New(dataReader)
End Sub

#End
Region

#Region " Properties and Methods "

Public Overrides Function GetBoolean(ByVal i As Integer) As Boolean
  If mDBType = "SQL Server" Then
   
If DataReader.IsDBNull(i) Then
     
Return False
    
Else
     
Return DataReader.GetBoolean(i)
   
End If
  ElseIf mDBType = "Oracle" Then
   
If DataReader.IsDBNull(i) Then
     
Return False
   
Else
     
If CStr(DataReader(i)) = "1" Then
       
Return True
     
Else
       
Return False
     
End If
    End If
  End If
End Function

#End Region

End Class

End
Namespace

Joe

Jack replied on Monday, November 17, 2008

Thank you.  Anything less I have to code the better.

Jack replied on Monday, November 17, 2008

Joe,

Just out of curiosity what are you doing with decimal vs. int32?  My earlier version of my application used int32 all over the place for my ID keys and I did the (int) conversion on reading them in.  Now with CSLA and using CodeSmith all my keys are coming back as decimal. 

Would you suggest I re-code the templates to use int32 in lieu of decimal except when directly doing Oracle data access?

Thanks

jack

JoeFallon1 replied on Monday, November 17, 2008

I no longer have to support Oracle. Plus I never used the Oracle provider - I used the Microsoft version. But now you should be able to make a decision as to which way to go and then use the code sample to get you there.

Joe

 

Copyright (c) Marimer LLC