[dblinq] Bug in DbLinq 0.20.1 with Oracle ODP.NET

27 views
Skip to first unread message

Pietro

unread,
Apr 26, 2010, 6:05:27 AM4/26/10
to DbLinq
Hello,
i've found a bug on the last release of DBLinq when i try to update an
entity using Oracle and ODP.NET.

ODP.NET have a problem with OracleCommand and its parameters, the
command don't find parameters by ID but only by Name, so when we try
to update a field on a table and dblinq generate the sql command with
the parameters the ExecuteNonQuery don't through and don't update
nothing.

I've find a solution by setting up a property of OracleCommand that
specify to find parameters ByName.
I've create a static class like this:
public static class DBCommandExtender
{
private const string DBOracleType =
"oracle.dataaccess.client.oracleconnection";

public static void SetDefaultProperties(IDbCommand command)
{
if (command == null)
return;

if (IsDBType(command.Connection, DBOracleType))
SetOracleProperties(command);
}

private static bool IsDBType(IDbConnection connection, string
dbtype)
{
return
connection.GetType().FullName.ToLower().Equals(dbtype);
}

private static void SetOracleProperties(IDbCommand command)
{
System.Reflection.PropertyInfo pBindByName =
command.GetType().GetProperty("BindByName");
if (pBindByName != null)
pBindByName.SetValue(command, true, null);
}
}

and in file
DbLinq.Data.Linq.Database.Implementation.DatabaseContext.cs at line
119 after:
IDbCommand command = Connection.CreateCommand();
've added this line:
DBCommandExtender.SetDefaultProperties(command);

So ODP.NET find the right parameter during the ExecuteNonQuery
method.

I don't know if it's the best way to solve the bug but it's work fine
for me.

--
You received this message because you are subscribed to the Google Groups "DbLinq" group.
To post to this group, send email to dbl...@googlegroups.com.
To unsubscribe from this group, send email to dblinq+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/dblinq?hl=en.

Anders

unread,
Apr 26, 2010, 8:20:20 AM4/26/10
to DbLinq
On Apr 26, 12:05 pm, Pietro <p.giar...@gmail.com> wrote:
> i've found a bug on the last release of DBLinq when i try to update an
> entity using Oracle and ODP.NET.
>
> ODP.NET have a problem with OracleCommand and its parameters, the
> command don't find parameters by ID but only by Name, so when we try
> to update a field on a table and dblinq generate the sql command with
> the parameters the ExecuteNonQuery don't through and don't update
> nothing.

Thanks for reporting this. To make sure, we are talking about the same
thing: Does this test case illustrate the problem or do you have
another test case?

using (var context = new ReadTest().CreateDB()) {
var c = context.Categories.First();
c.CategoryName += "!";
context.SubmitChanges();
}

When run from Program3Ora.cs in DbLinq.Oracle_test_odp, it attempts to
execute two queries, but fails during the second with the error
"ORA-01722: invalid number" (probably because "Beverages!" isn't a
number):

SELECT LimitedTable___.*, rownum Limit___ FROM (
SELECT "CategoryID", "CategoryName", "Description", "Picture"
FROM "NORTHWIND"."Categories"
) LimitedTable___ WHERE rownum <= 1

UPDATE "NORTHWIND"."Categories" SET "CategoryName" = :CategoryName
WHERE "CategoryID" = :CategoryID
-- :CategoryID: Input Decimal (Size = 0; Prec = 0; Scale = 0) [1]
-- :CategoryName: Input String (Size = 0; Prec = 0; Scale = 0)
[Beverages!]

Adding your change (simplified a bit) seem to solve the problem:

Index: DatabaseContext.cs
===================================================================
--- DatabaseContext.cs (revision 1408)
+++ DatabaseContext.cs (working copy)
@@ -117,6 +117,12 @@
public IDbCommand CreateCommand()
{
IDbCommand command = Connection.CreateCommand();
+ if (command.GetType().FullName ==
"Oracle.DataAccess.Client.OracleCommand")
+ {
+ var p = command.GetType().GetProperty("BindByName");
+ if (p != null)
+ p.SetValue(command, true, null);
+ }
if (command.Transaction == null)
command.Transaction = CurrentTransaction;
return command;

--
Anders

Pietro

unread,
May 6, 2010, 5:18:27 AM5/6/10
to DbLinq
Yes, this test case illustrate the problem.
Thank you!
Pietro
Reply all
Reply to author
Forward
0 new messages