This are my notes in the fields of computer science and technology. Everything is written with ABSOLUTE NO WARRANTY of fitness for any purpose. Of course, feel free to comment anything.

Sunday, August 17, 2008

ActiveScaffold and LOB sorting in Oracle

If you are using ActiveScaffold and an Oracle DB, you will notice that you can't natively sort on LOB columns. If you click on the table header for a LOB column, you will get an error message. A way to fix this is to sort using the substr function and pass it to config.columns[].sort_by :sql.

To make it simpler, I solved the matter including in ActiveScaffold::DataStructures::Column a
method:
def sort_as_lob(lenght = 50, offset = 1)
sort_by :sql => "dbms_lob.substr(#{name},"+
"#{lenght},"+
"#{offset})"
end
which I use on LOBs column declaring in the active scaffold config block:
active_scaffold do |config|
config.columns[:my_lob].sort_as_lob
end

About Me

My photo
Hamburg, Hamburg, Germany
Former molecular biologist and web developer (Rails) and currently research scientist in bioinformatics.