Skip to content
accelerando

Monthly Archives: January 2007

On writing binary data from within Oracle Forms 6i

29-Jan-07

There is this nice project of ours from 2002…. developed with Oracle Forms 6i and database PL/SQL Procedures. This project runs fine with an estimated 6gig database. Plain old client server model.

We have some XML / XSLT based HTML reports that are processed – thanks to Oracle 9i – directly in the database with packages dbms_xmlgen and xmlparser. Data is collected in a mere handful of so called “object views”, that are denormalized, hierarchical views on data.

After receiving the assignment to generate pdf it was no big problem at all to write some java classes around iText and dom4j to generate new reports.
I decided agains xsl-fo as i found no inexpensive tools for easily designing adequate stylesheets. For the worse, xsl-fo lacks several important features, i.e. collapsing borders. My customers would have laughed at best if i had presented the prototype…

So i have this java classes – all in the database for sure, no need for java on the client side -, i have added code to my package and i thought it would be easy to write the resulting blob with Forms 6i to the client…

Bah! There is no such easy thing in Forms. I remembered havin’ problems reading a clob, as the whole bunch of dbms_lob functionality doesn’t work in forms… So my workaround for creating text files from clobs was on the database side:

PROCEDURE  read_export(
  p_export_id  IN     NUMBER,
  p_menge      IN OUT BINARY_INTEGER,
  p_offset     IN     BINARY_INTEGER,
  p_buffer     IN OUT VARCHAR2
) IS
 clInhalt  CLOB;
 BEGIN
  BEGIN
    SELECT processed_export
      INTO clInhalt
      FROM xmlt_exporte
     WHERE export_id = p_export_id;
    DBMS_LOB.READ(clInhalt, p_menge, p_offset, p_buffer);
  EXCEPTION
    WHEN NO_DATA_FOUND THEN
      p_menge:= 0;
  END;
EXCEPTION
  WHEN OTHERS THEN
    p_menge := 0;
END;

and in a forms on client side:

fhDateiOut := text_io.fopen(vcPath || vcFile, 'W');   	  	   	
LOOP			
  pck_xml.read_export(p_export_id, i, offset, vcBuffer);
  EXIT WHEN i = 0;
  offset := offset + i;
  text_io.put(fhDateiOut, vcBuffer);
END LOOP;					   
text_io.fclose(fhDateiOut);

(text_io is a forms standard package).

This works quite well.. So i thought, well, d2kwutil has some functions to write binary files, so i copy the database procedure, use dbms_lob.read with blob and raw and i’m done…
Yeah, i was done. Well fucked off.

I have no idea in which way dbms_lob.read converts blob data to raw, but it’s everything but the original. So after banging my head against the wall, finding things like “use software developed in this century” in forums, i wrote the following java code:

final BASE64Encoder enc = new BASE64Encoder();
 
final CLOB rv = CLOB.createTemporary(tmp.getJavaSqlConnection(), true, CLOB.DURATION_SESSION);
 
int bufSize = 1024*1024*1;
 
final BufferedInputStream in = new BufferedInputStream(tmp.getBinaryStream(), bufSize * 2);        
final BufferedOutputStream out = new BufferedOutputStream(rv.setAsciiStream(0L), bufSize);
 
enc.encode(in, out);
out.flush();
out.close();

which runs in the database, takes a blob as parameter and base64 encodes it to a clob. This clob is written to my export table and read by forms in the above way. Then i have a little base64.exe along with my forms that is called from within forms that decodes the file….

So much trouble just for writing binary data from server to client… it’s a twoliner with c or java.

Universal Binaries mit GCC

19-Jan-07

Nützlich, wenn man ohne XCode unterwegs ist und “nur mal schnell” was kompilieren möchte:

Universal Binaries

Ruby on Rails Auto complete

11-Jan-07
# view
Just a little test:
<%= text_field_with_auto_complete :contact, :name %>
 
# controller
auto_complete_for :contact, :name

Zwei(!) Zeilen im Zweifelsfall. Unglaublich. Jaw dropper.

Wer mehr dazu wissen möchte:

Das ganze basiert Clientseitig übrigens auf script.aculo.us

Ruby On Rails native MySQL Bindings Vs. RMagick

02-Jan-07

I’m writing this post in english in hope that more people find it useful…

Some times ago i really had bad problems installing the MySQL Gem 2.7 with Ruby 1.8.2 or 1.8.5 in conjunction with Rails 1.1.6 on Mac OS X 10.4

Compilation failed with:

Building native extensions. This could take a while…
mysql.c: In function ‘Init_mysql’:
mysql.c:2015: error: ‘ulong’ undeclared (first use in this function)
mysql.c:2015: error: (Each undeclared identifier is reported only once
mysql.c:2015: error: for each function it appears in.)
mysql.c:2015: error: parse error before numeric constant
mysql.c:2018: error: parse error before numeric constant
make: *** [mysql.o] Error 1
mysql.c: In function ‘Init_mysql’:
mysql.c:2015: error: ‘ulong’ undeclared (first use in this function)
mysql.c:2015: error: (Each undeclared identifier is reported only once
mysql.c:2015: error: for each function it appears in.)
mysql.c:2015: error: parse error before numeric constant
mysql.c:2018: error: parse error before numeric constant
make: *** [mysql.o] Error 1
ruby extconf.rb install mysql — –with-mysql-dir=/usr/local/mysql
checking for mysql_query() in -lmysqlclient… no
checking for main() in -lm… yes
checking for mysql_query() in -lmysqlclient… no
checking for main() in -lz… yes
checking for mysql_query() in -lmysqlclient… yes
checking for mysql_ssl_set()yes
checking for mysql.h… yes
creating Makefile

The gem would then install with Successfully installed mysql-2.7. Creepy!!! But that damn thing just didn’t work.

After quite some googling i found this one:

Running Rails on OS X with MySQL 5.0.24

It’s all about puting a little

#ifndef ulong 
#define ulong unsigned long
#endif

somewhere in “/usr/include/stdlib.h”.

This tipp is still necessary for MySQL 5.0.24+. Thanks again mate!!

But here the trouble starts….

I put the define in a nice little conditional just in case but bah… It would come down to hunt me…

For my project DailyFratze.de i also need RMagick. Again, the gem (1.14.1, 1.14.0 and 1.13) failed to compile but didn’t tell (on runtime it said “require “RMagick” LoadError: No such file to load — RMagick.so” … ) and installation from source did fail as well with:

setup.rb:655:in `command': system("make") failed (RuntimeError)
from setup.rb:664:in `make'
from setup.rb:1258:in `setup_dir_ext'
from setup.rb:1532:in `__send__'
from setup.rb:1532:in `traverse'
from setup.rb:1530:in `dive_into'
from setup.rb:1530:in `traverse'
from setup.rb:1534:in `traverse'
from setup.rb:1533:in `each'
... 8 levels...
from setup.rb:826:in `__send__'
from setup.rb:826:in `invoke'
from setup.rb:772:in `invoke'
from setup.rb:1578
make: *** [all] Error 1

Damn! After banging my head against the walls, reinstalling ImageMagick and all it’s depencies either direct from source, via i-installer and finally as mentioned here i took a break, visited some porn sites and stuff like that and though, hmm… stdlib.h….

I removed the little define and bam! It’s that easy, RMagick compiles just fine…

From the forums i found i guess other people with the same error message may have the same problem as i had…

I really wish installing a ruby on rails environment would be a less pain in the ass…. somewhere near as easy as developing with rails.

Close
E-mail It