Wednesday, April 27, 2005
Writeup for the Oracle Changes
It’s been requested of me that i do a writeup of what i did to the Enterprise Library for the changes for Oracle.
The first thing i fixed was a problem with the package name and prefix combo when using oracle. The way I fixed this was to make a small change to the code in OracleDatabase.cs file. In the PreparePackageSchema method i changed an if statement to read:
if ((oraPackage.Prefix == allPrefix) || (commandText.StartsWith(oraPackage.Prefix)))
Originally, it read:
if ((oraPackage.Prefix == allPrefix) || (commandText.StartsWith(prefix)))
My addition allows it to compare the prefix value that is in the oraPackage correctly. So now, if you set the prefix to * then the Name value of the pair will always be appended with a . after it to the command. You could also specify that all commands with a prefix of mysp_ are found in the MyPackage system, so it would write out MyPackage.mysp_SomeSP
The second thing i fixed was the problem with Reference Out Cursors and Oracle. Microsoft had hard coded that reference cursors, if one was not specified, were to be named cur_OUT. The problem with that is that THEY NEVER LET YOU SPECIFIY A DIFFERENT CURSOR. To solve this, I modified the DBCommandWrapper.cs file. I added an abstract method:
public abstract void AddCursorOutParameter(string CursorName);
Now, when you add a method like this to the Abstract class, you have to define it in all of it’s child classes that inherited it. So this meant i had to add the AddCursorOutParameter to both SqlCommandWrapper.cs and OracleCommandWrapper.cs. The implementation of each is below.
/// <summary>
/// <para>Does nothing in SQL Server. Cursors are not used. Only here for compliance with DBCommandWrapper</para>
/// </summary>
/// <param name="CursorName"><para>The name of the cursor</para></param>
public override void AddCursorOutParameter(string CursorName)
{
// Do Nothing
}
Oracle:
/// <summary>
/// <para>When overridden in a derived class, adds a new instance of an <see cref="IDataParameter"/> object to the command set as <see cref="ParameterDirection"/> value of Output and
/// Type of Cursor.</para>
/// <para>Created by Rob Edwards REdwards@quilogy.com</para>
/// </summary>
/// <param name="CursorName"><para>The name of the Reference Cursor</para></param>
public override void AddCursorOutParameter(string CursorName)
{
this.AddParameter(CursorName, OracleType.Cursor, 0, ParameterDirection.Output, true, 0, 0, String.Empty, DataRowVersion.Default, Convert.DBNull);
}
As you can see, not a lot of code in either. Sql’s code is a do nothing method. You don’t need to specify cursors to Sql Server like you do to Oracle, but something had to be there. Oracle’s implementation only called the AddParameter method and specified a type of OracleType.Cursor. Had the EntLib had a DbType.Cursor to begin with, it wouldn’t have been needed, but i thought it would be alot easier to just add a new method than try and do something different with a new DbType.
Hope this helped and stay tuned for more stuff!
Tuesday, April 19, 2005
Fixes to the Enterprise Library for Oracle.
I’ve solved some of the issues with Oracle when using the Enterprise Library. I’ve published the patch to the gotdotnet users samples and will update the URL below when i know the exact link. I hope to submit the changes to Microsoft and that they will be added to the Enterprise Library.
Stay tuned for future information about Oracle, Enterprise Library and other coding ideas.
Edit: My contribution was accepted by GotDotNet. I’ve updated the link above to the location of the zip file.