Wrong realization of method?

Can anybody help me?

I’v got the function (method) that was written before me. I have to use
this method. I think that I can’t understand several primitive things,
but I (may be) don’t know about these things.

Questions:
When this function can (may) returns nil?
I’v got incidents when I know that this function must returns me a
record from Oracle. But I receive return value = nil. Why? Reasons?

The text of ruby method is below…

find cm_batch_id by given invoice number, shipments_status_id,

batches_status_id

#Example:
#CmShipment.find_cm_batch_id_by_invoice_and_status_id(@lneIInvoice.text,
#CM_SHIPMEMTS_STATUSID_ERR_SHIPMENT,CM_SHIPMEMTS_STATUSID_INITIAL)
def
self.find_cm_batch_id_by_invoice_and_status_id(invoice,shipments_status_id,batches_status_id)
begin
sql_statement = <<-END_OF_SQL
SELECT cm_batch_id
FROM CM_SHIPMENTS sp
WHERE i_invoice=#{invoice}
AND status_id=#{shipments_status_id}
AND EXISTS (SELECT 1 FROM CM_BATCHES bh
WHERE sp.cm_batch_id = bh.id
AND bh.status_id=#{batches_status_id})
END_OF_SQL
return CmShipment.find_by_sql(sql_statement)
rescue
return nil
end
end

P.S. Execuse me my bad English :slight_smile: I’m from Russia :slight_smile:

Subject: Wrong realization of method?
Date: ven 25 ott 13 08:06:35 +0200

Quoting Eugene Greenwood ([email protected]):

I’v got the function (method) that was written before me. I have to use
this method. I think that I can’t understand several primitive things,
but I (may be) don’t know about these things.

Questions:
When this function can (may) returns nil?
I’v got incidents when I know that this function must returns me a
record from Oracle. But I receive return value = nil. Why? Reasons?

Well, can’t you see where the ‘return nil’ statement is? The method
returns nil when rescue is executed. This means that the find_by_sql
method has raised an exception.

If you want to know what exactly is going wrong, add a printout before
returning nil.

Carlo

Carlo E. Prelz wrote in post #1125576:

Subject: Wrong realization of method?
Date: ven 25 ott 13 08:06:35 +0200

Quoting Eugene Greenwood ([email protected]):

I’v got the function (method) that was written before me. I have to use
this method. I think that I can’t understand several primitive things,
but I (may be) don’t know about these things.

Questions:
When this function can (may) returns nil?
I’v got incidents when I know that this function must returns me a
record from Oracle. But I receive return value = nil. Why? Reasons?

Well, can’t you see where the ‘return nil’ statement is? The method
returns nil when rescue is executed. This means that the find_by_sql
method has raised an exception.

If you want to know what exactly is going wrong, add a printout before
returning nil.

Carlo, thanks very much for your attention and your reply!

Usually I make such things using “puts” in place of “printout”
for debug purposes. “Puts”, after rescue, say me that parameter
sql_statement is what I need… And I make the same sql-request from
console… and I’v got a record from console.

May be it’s bug from ActiveRecord?

On Fri, Oct 25, 2013 at 2:06 PM, Eugene Greenwood
[email protected]wrote:

Carlo, thanks very much for your attention and your reply!

Usually I make such things using “puts” in place of “printout”
for debug purposes. “Puts”, after rescue, say me that parameter
sql_statement is what I need… And I make the same sql-request from
console… and I’v got a record from console.

So u ran the same SQL statement from the console and got the required
out
put? Can you do one thing,
can you remove the begin, and rescue, so that we can know the actually
error that is returned. From that
error we will get a clearer picture if the error is from active record
or
not.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs