IWETHEY v. 0.3.0 | TODO
1,095 registered users | 0 active users | 2 LpH | Statistics
Login | Create New User
IWETHEY Banner

Welcome to IWETHEY!

New Objects, REFs, and Oracle collections
We're trying to develop a way to hold a set of base type objects in a collection in PL/SQL. The basic idea is a collection of buffer objects, where the objects could be single string objects or other complex subtypes of a buffer object. However, from the looks of it if you declare a collection of a particular base type and put a subtyped object in, the object turns into a base type object. Whoops.

One might try to use REFs... however, REFs can't be used without an object table or view, so they're useless for in-memory transient stuff.

Any ideas?
Regards,

-scott anderson

"Welcome to Rivendell, Mr. Anderson..."
New Will TREAT not work?
Slightly modified from the [link|http://www.angelfire.com/tx4/cus/shapes/plsql.html|Shapes junk]:

rect := TREAT(scribble(1) AS rectangle);
rect.setHeight(50);
rect.draw();

Or is the problem that you can't retrieve what subtype was stored in the collection?
Expand Edited by ChrisR Aug. 21, 2003, 02:20:17 PM EDT
New Interesting...
Oracle documentation says that TREAT is not supported in PL/SQL...
Regards,

-scott anderson

"Welcome to Rivendell, Mr. Anderson..."
New Just playing around
It does seem idiosyncratic. In the first place, you have to use assignment - casting doesn't work in-line. Means that the following won't compile:

TREAT(scribble(1) AS rectangle).setHeight(60);

Guess you could work around that by just using assignment. Also, a simple assignment copies the object as a clone. Any modifications are not applied to the original object. Means that if you drew the original base object, it remains unmodified after the setHeight instruction:

scribble(1).draw();

Still fumbling my way around PL/SQL, but would it require a REF of some sorts to make the scribble(1) and rect vars point to the same memory location?
New The problem with REFs:
They're only usable on table objects, not transitory objects.

Copying the object as a clone isn't really a solution, since that's fairly wasteful. The idea is to use the original.

Also, if you save a bunch of rectangles in a collection (varray of shape_t), and then do a treat to get a rectangle back, does it have the attributes of the original rectangle, or only those of the shape_t plus new default rectangle attributes?
Regards,

-scott anderson

"Welcome to Rivendell, Mr. Anderson..."
New Quickly exhausting my sum total of PL/SQL knowledge :-)
Also, if you save a bunch of rectangles in a collection (varray of shape_t), and then do a treat to get a rectangle back, does it have the attributes of the original rectangle, or only those of the shape_t plus new default rectangle attributes?
From my limited tests, it does appear that the attributes from the collection are correctly maintained (although copy would seem to be the more appropriate term).

Copying the object as a clone isn't really a solution, since that's fairly wasteful. The idea is to use the original.
Can't help you there. A downcast operator that clones really isn't a downcast operator is it? :-)

Speaking of cast, what about the CAST function. Appears to convert one type of collection to another. But I can't figure how to use it.
New Re: Quickly exhausting my sum total of PL/SQL knowledge :-)
Only works on collections and built-ins.

And in the case of a collection, CAST apparently needs to be used on a query.
Regards,

-scott anderson

"Welcome to Rivendell, Mr. Anderson..."
New Some other thoughts on TREAT
I see that TREAT was not implemented in Oracle until release 2 of 9i - which is probably why the docs you have say it's not supported.

Playing a bit more, I see that functions which return values can be used with the dot notation:

i := TREAT(scribble(1) AS rectangle).getHeight(); -- this works

TREAT(scribble(1) AS rectangle).setHeight(50); -- this doesn't compile

I can't tell whether the function call does a copy, though I don't see why it would be different than what I had on the previous posts.
New I'll pass that on
And as soon as I get 9.2 up on my box I'll start playing with it as well.
Regards,

-scott anderson

"Welcome to Rivendell, Mr. Anderson..."
New can you not bang out to .dat files in the OS?
Unless and probably misunderstanding what you need
temp data descripts of an object

store useless perhaps knowledge in /tmp/foo
if called suck /tmp/foo into memory and populate object

floating config files.
thanx,
bill
who still uses bc in scripts for math
America, Love it or give it back
questions, help? [link|mailto:pappas@catholic.org|email pappas at catholic.org]
New In-memory, transient.
In other words, we're trying to do OO programming in PL/SQL, and we're being defeated by arbitrary restrictions that require the use of tables in conjunction with objects.
Regards,

-scott anderson

"Welcome to Rivendell, Mr. Anderson..."
     Objects, REFs, and Oracle collections - (admin) - (10)
         Will TREAT not work? - (ChrisR) - (7)
             Interesting... - (admin) - (6)
                 Just playing around - (ChrisR) - (3)
                     The problem with REFs: - (admin) - (2)
                         Quickly exhausting my sum total of PL/SQL knowledge :-) - (ChrisR) - (1)
                             Re: Quickly exhausting my sum total of PL/SQL knowledge :-) - (admin)
                 Some other thoughts on TREAT - (ChrisR) - (1)
                     I'll pass that on - (admin)
         can you not bang out to .dat files in the OS? - (boxley) - (1)
             In-memory, transient. - (admin)

A hearty “Shalom amigos!” comes to mind.
67 ms