ibatis-user-cs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "roberto" <robe...@theaegis.org>
Subject RE: Some info on referencing a parameter more than once...
Date Tue, 01 Feb 2005 23:06:36 GMT
Gilles,

I just tried this <statement> test with a parameterClass but haven't fully
debugged it (Kit is probably on the right track).  

Here's a modified NUnit Statement test:

/// <summary>
/// Test Get Account Via Inline Parameters
/// </summary>
[Test] 
public void TestExecuteQueryForObjectViaInlineParameters()
{
	Account account = new Account();
	account.Id = 1;
	account.FirstName = "Joe";
	account.LastName = "Dalton";

	Account testAccount =
sqlMap.QueryForObject("GetAccountViaInlineParameters", account) as Account;
			
	AssertAccount1(testAccount);
}

This <statement> passes with the above test:

<select id="GetAccountViaInlineParameters"
		parameterClass="Account" 
		resultMap="account-result">
	select
		Account_ID,
		Account_FirstName,
		Account_LastName,
		Account_Email
	from Accounts
	where Account_ID = #Id# and 
		Account_FirstName = #FirstName# and 
		Account_LastName = #LastName# and 
		Account_ID = #Id#
</select>

However, it does not pass with this <statement>, and I see that the value of
the Account.Id is being used as the value of @FirstName and the value of
Account.FirstName is being used as the value of @LastName:

<select id="GetAccountViaInlineParameters"
		parameterClass="Account" 
		resultMap="account-result">
	select
		Account_ID,
		Account_FirstName,
		Account_LastName,
		Account_Email
	from Accounts
	where Account_ID = #Id# and 
		Account_ID = #Id# and 
		Account_FirstName = #FirstName# and 
		Account_LastName = #LastName# and 
		Account_ID = #Id#
</select>

Roberto

> -----Original Message-----
> From: Gilles Bayon [mailto:ibatis.net@gmail.com]
> Sent: Tuesday, February 01, 2005 5:43 PM
> To: ibatis-user-cs@incubator.apache.org
> Subject: Re: Some info on referencing a parameter more than once...
> 
> If you use a parameterMap, you must only declare a parameter once as
> you will do in ADO.NET.
> For the parmeterClass usage, open a JIRA ticket, I will see it.
> 
> -Gilles
> 
> On Tue, 1 Feb 2005 14:48:56 -0600, Kit Cragin
> <kit.cragin@entervalent.com> wrote:
> > I've found that if you reference a property in a parameterClass or an
> entry
> > in a parameterMap more than once, strange behavior results.
> >
> > For example (where ... = some legal SQL fragment):
> >
> > <select id="whatever" parameterClass="SomeClass">
> >  ... #SomeIntProperty# ... #SomeOtherIntProperty# ... #SomeIntProperty#
> ...
> > </select>
> >
> > could produce some sort of SQL error (types of errors I've gotten are
> > different) or even an error within iBATIS itself before the SQL is sent
> to
> > the database. I *think* the reason is that iBATIS is pulling information
> > from the parameterClass or parameterMap by index after mapping the
> > parameters to SqlParameters.
> >
> > The workaround is to do something like this:
> >
> > <select id="whatever" parameterClass="SomeClass">
> >  declare @SP int
> >  select @SP = #SomeIntProperty#
> >  ... @SP ... #SomeOtherIntProperty# ... @SP ...
> > </select>
> >
> > Hope this saves someone some time. Can anyone confirm this issue? If so,
> I
> > can enter into Jira.
> >
> > - Kit
> >
> >



Mime
View raw message