How to map a stored package function in iBatis? - ibatis

I am presently using
<parameterMap class="map" id="param1">
<parameter property="result" jdbcType="BOOLEAN" javaType="boolean" mode="OUT"/>
<parameter property="arg1" jdbcType="VARCHAR" mode="IN"/>
<parameter property="resultCode" jdbcType="INTEGER" javaType="int" mode="OUT"/>
</parameterMap>
<procedure id="contAvail" parameterMap="param1">
<![CDATA[
{ ? = call pkg.func(?,?)}
]]>
</procedure>
what is missing ?

You have two parameters in your CALL but a parameterMap with three parameters. You have one result but no resultMap.
Not sure if the CDATA hurts anything, but it shouldn't be needed.
See the online help for details. Also check out this and this.

It turns out there is nothing wrong with the code above. It works if we change the return data type from boolean to anything else. It seems boolean is not supported properly.
Also as Jim rightfully suggested, CDATA is not imp. It works with or without it.

An important thing to note is that ibatis returns the result in the input parameter map itself even for function call. In this case param1 will hold the result of the function call (and null is returned in the java method queryForObject()..)

Related

Odoo - Cannot loop through model records

I want to call a method every time my module gets installed or updated. Inside that method I want to loop through model records, but I'm only getting different errors.
This documentation looks pretty straightforward: https://www.odoo.com/documentation/9.0/reference/orm.html
But it doesn't work for me. I'm getting this error:
ParseError: "'account.tax' object has no attribute '_ids'" while parsing
This is how I call the method:
<openerp>
<data>
<function model="account.tax" name="_my_method" />
</data>
</openerp>
I took this from the first answer here: https://www.odoo.com/forum/help-1/question/how-can-i-execute-a-sql-statement-on-module-update-and-installation-6131
My model:
class my_account_tax(models.Model):
_name = 'account.tax'
_inherit = 'account.tax'
def _my_method(self, cr, uid, ids=None, context=None):
self.do_operation()
def do_operation(self):
print self
for record in self:
print record
It is basically a copy-paste from the docs. I only added method parameters cr, uid,.. If I take them away (and just leave 'self'), the error is a little different:
ParseError: "_my_method() takes exactly 1 argument (3 given)"
But also does not tell much.
use new api
#api.multi #if you use the new api you don't have to list all parameter in the function
def _my_method(self):
but you can keep it like that and do a pool on your model than loop throw the result that you get don't use self
if you use the new api use : self.env['model_name'].search([domain])

SSRS expression for empty parameter value returns #Error

I have a parameter in report that I recently changed it to accept NULL values. It was a required parameter before but now it is not required. Header in the report has below expression to read data from the parameter value. Ever since I modified the parameter to accept NULLvalues, it is erroring out. It shows #Error in the header. I have tried modifying the expression to display result even if the parameter is 'NULL', but nothing has worked so far. I am pretty much stuck here. Here is the expression I am using in SSRS:
=IIF(Code.MultipleValues(Parameters!ProductID.Value(0))="True"
,IIF(IsNothing(First(Fields!ProductName.Value, "ProductHeader")),""
,First(Fields!ProductName.Value, "ProductHeader")).ToString
,IIF(Len(Parameters!ProductID.Value(0)) > 0
,IIF(First(Fields!ProductName.Value, "ProductHeader") is nothing,""
,First(Fields!ProductName.Value, "ProductHeader")),"All Products Selected"))
I believe the error has to do with the VB custom code that is in the report. I am not too familar with the code so I am having trouble troubleshooting it.
VB code:
Public Function MultipleValues(ByVal str As String) As String
If str.Contains(",")
Return "True"
Else
Return "False"
End If
End Function
Any suggestion on how to handle #Error in SSRS? thanks
Replace
Code.MultipleValues(Parameters!ProductID.Value(0))="True"
with
IndexOf(Parameters!ProductID.Value(0).ToString(),",") >= 0
Instead of a function, can you just put the IsNothing check in front of the parameter ?
=IIF(Code.MultipleValues(IsNothing(Parameters!ProductID.Value(0),""))="True"

bug with IEntity.toString()?

There seem to be a bug with calling .toString() on an entity created by createQueryEntity. If you use it in a query. It will have some garbage string "tring" in it.
IEntity queryEntity = (IEntity) GenerateQuery.createQueryEntity(Vendor.class);
queryEntity.toString();
Calendar start = Calendar.getInstance();
start.add(Calendar.YEAR, -1);
Vendor vendor = (Vendor) queryEntity ;
return select($(vendor))
.where($(vendor.getMetaData().getLastUpdatedTime()).gte(start))
.where($(vendor.isActive()).eq(false))
.skip(1).take(1000)
.generate();
This would result to something like "select tring.tring.* from ..." Has anyone else seen this?
Finally figured it out. Apparently you can't call any methods on the queryEntity returned by createQueryEntity BEFORE calling select(). That means toString() or ((Vendor) queryEntity).isActive() shouldn't be called before select ($(vendor)).
The solution is to store the results of select($(vendor)) first before calling these methods.
Be careful when debugging because adding a watch expression will call toString() too.

Error with ibatis sql iterate

I'm using ibatis + DWR , but when i pass a map to ibatis i will get an error as below:
Cause: com.ibatis.sqlmap.client.SqlMapException: ParameterObject or
property was not a Collection, Array or Iterator.
here is my sql:
<update id="updateDarenFlagByUserTagIDs" parameterClass="java.util.Map">
update system_usertag
set isdaren = 1
where uid = #uid#
<isNotEmpty prepend=" AND " property="utidlist">
and utid in
<iterate open="(" close=")" conjunction="," property="utidlist">
#utidlist[]#
</iterate>
</isNotEmpty>
</update>
and here in the DWR part, i passed a map as below:
{'uid':uid, 'utidlist':utidlist}
Any ideas on this error?
I have answered the exact same question in the following post https://stackoverflow.com/questions/18997883/malformed-url-exception-in-ibatis/19025819#19025819 do make reference to it. The solution to your problem is very simple, ensure that the argument nested in your iterate tag <iterate></iterate> which in your case is "utidlist" is indeed a list/collection and nothing but a list. The cause of this error is that your iterable property "utidlist" isn't a list. If you can get it to be a list and not a flat value you'll just be fine.
Just in case you can still get it to work you may also want to paste a full stack of your logs so that you can see what is going wrong.

why does gql query result cause exception when calling get()

I am attempting to retrieve an entry from my datastore with this:
query = UserData.gql("WHERE mDeviceId = :1", id)
Utils.log("my Object:" + str(query))
entry = query.get()
It just so happens that the variable 'id' doesn't even exist (typo), so I know how to fix this, but I don't understand why the result I get won't let me call get() on it. When I do, I get the error:
Exception: Unsupported type for property : <type 'builtin_function_or_method'>
Normally I just check if entry == None to see if I get no results. Does anyone know why this occurs and if I should be doing my checks for None differently, in case I have such typos in the future?
A variable named id is not defined in your code, so it passes the builtin function id, and QL complains that it's getting a function when it expected a value (integer?).
Check to make sure you're assigning id a value before you use it.
Even better, don't shadow builtins with your own variables-- it'll cause confusing errors like this. :-)

Resources