[EXDI]Can outputbinding be used with variables for collection?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
J G
Reply | Threaded
Open this post in threaded view
|

[EXDI]Can outputbinding be used with variables for collection?

J G
Hi,

Say I have a Quote object which has dateNo, open, high, low, close instance
variables and each holds an OrderedCollection of data.

Now I've prepared a database with rows of data such as:
date--open--high--low--close
0001--11.1--11.2--10.9-11.1
0002--11.5--11.5--11.0-11.2
0003--11.3--11.9--10.8-10.9

And when I read them from database to aQuote, I want the open variable holds
#(11.1 11.5 11.3) and close holds #(11.1 11.2 10.9), etc.

The question is, when I read from table quotes with:

  session prepare: 'SELECT open, close FROM quotes';
  bindOutputNamed: Quote new;
  execute.
  aQuote:= session answer.
  aQuote next.

Then I would get a atom object with only one single data for each variable.
Now how can I:

1. get rows of data as a collection into instance variables?
2. specify the rows to read into an object from db?

Thanks!

yours,

jimg


Reply | Threaded
Open this post in threaded view
|

Re: [EXDI]Can outputbinding be used with variables for collection?

Joachim Geidel
jimg wrote:
> Then I would get a atom object with only one single data for each variable.
> Now how can I:
>
> 1. get rows of data as a collection into instance variables?
> 2. specify the rows to read into an object from db?

The answer stream of a session iterates over the rows of the query's
result table, which are Arrays containing whatever you defined in the
SELECT statement. Output binding is just a convenience for the case
where the results directly correspond to the instance variables of an
object, but it does not support more complex mappings.

If you don't want to program the mapping yourself, you should use an
object-relational mapping tool, e.g. the Object Lens or Glorp. These
tools allow you to specify how rows from a table / from a query result
are mapped to objects, including the mapping of Collections.

HTH,
Joachim