Forum OpenACS Development: Response to FIX ME PLSQL problem

Collapse
Posted by Don Baccus on
Check the routine bboard_message__remove_thread in packages/bboard/sql/postgresql/bboard-packages.sql for an example.

You just remove the cursor entirely.  Get rid of it.  Shoot it dead.  Bury it six feet under.

for foo in select something blah blah blah ...

Actually there's a stylistic problem in that example, as the child val
is declared as a RECORD, while it could easily be declared as acs_object%ROWTYPE.  I think the latter form is more efficient as the compiler can compute the attribute (column) offset at compile time while in the record case I believe it has to look up the offsets at runtime (since the RECORD can be assigned a row from any table).

So for looping through a table "foo" you might declare a variable:

one_foo foo%ROWTYPE;

then loop through like this:

for one_foo in select * from foo

loop

  (do something with one_foo.column etc etc)

end;

I see why Luke used "record" above - he only grabs a couple of columns
from each row, rather than the whole row, so that's cool.  Cuts down the number of bytes that need to be extracted and passed out, which may balance the dynamic lookup of the columns within the loop.