Circle.sql 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. drop database mydb;
  2. create database mydb;
  3. -- create the circle UDT
  4. create opaque type circle (internallength = 24, alignment = 8);
  5. create function circle_input(lvarchar) returns circle
  6. external name '$INFORMIXDIR/extend/krakatoa/examples/circle.dll'
  7. language c;
  8. create function circle_output(circle) returns lvarchar
  9. external name '$INFORMIXDIR/extend/krakatoa/examples/circle.dll'
  10. language c;
  11. create implicit cast (lvarchar as circle with circle_input);
  12. create explicit cast (circle as lvarchar with circle_output);
  13. -- create the circle UDT table
  14. create table mytable (c circle);
  15. insert into mytable values("1 1 1");
  16. insert into mytable values("2 2 2");
  17. insert into mytable values("3 3 3");
  18. select * From mytable;
  19. -- install the Java class Circle (customize the URL for your installation)
  20. execute procedure install_jar(
  21. "file:$INFORMIXDIR/extend/krakatoa/examples/Circle.jar", "circle_jar", 0);
  22. -- register the Java class that maps to the circle UDT
  23. execute procedure setUDTExtName("circle", "Circle");
  24. -- register the Java UDR
  25. create function area(circle) returns float
  26. external name 'circle_jar:Circle.area(Circle)'
  27. language java;
  28. -- test the Java UDR
  29. select c, area(c) from mytable;