Re: dynamic queries
Tomasz Rakowski <mourawi-/[email protected]> Mon, 20 Nov 2006 17:10:59 -0800 (PST)
| Newsgroups | gmane.text.xml.o-xml |
|---|---|
| Message-ID | <[email protected]> |
--===============1404846079==
Content-Type: multipart/alternative; boundary="0-839901240-1164071459=:99160"
Content-Transfer-Encoding: 7bit
--0-839901240-1164071459=:99160
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
Hi,
I think that I didn't clearly expressed my problem.
Here is another small example :
I would like to create general purpose function which will take two param=
eters:
SQL Query and name of the column. Function should execute given query a=
nd from
ResultSet it should return data from given column name.
QUERY: "SELECT lastname,birth,sex FROM person WHERE id=3D23" and second p=
arametr
'lastname'
How to do this ?=20
Normally in db:execute statement I would use{$lastname} but in this case
'lastname' is stored in some variable (function parameter) and I don't it=
during
compilation time ....
Tomasz Rakowski
<mars@...> writes:
>=20
> Hi Tomasz,
>=20
> I think this was maybe answered in response to your other mail, let me =
know if
you still have problems with this.
>=20
> Another approach might be to treat the problem as two sets of data; one=
being
the database result, the other
> the dynamic information necessary to execute the query. You can then me=
rge the
two into whatever form you require.
>=20
> You could also use o:XML types to represent the datastructures, then se=
t the
dynamic values programmatically.
> For example, if you define a type DataEntity with a suitable constructo=
r and
setter functions, then:
> <o:variable name=3D"entities">
> <db:execute sql=3D"...">
> <o:eval select=3D"DataEntity($firstname, $lastname, $birthyear)=
"/>
> <!-- creates one DataEntity for each row in result set -->
> </db:execute>
> </o:variable>
> <o:do select=3D"$entities.SetSomeAttribute('firstname')"/>
> <!-- sets some attribute on _all_ DataEntity objects in $entities -->
>=20
> Now if you want to produce an XML result set from the DataEntity object=
, you
can overload the nodes()
> function to do so. Eg
> <o:type name=3D"DataEntity">
> ...
> <o:function name=3D"nodes">
> <o:do>
> <entity><o:eval select=3D"$SomeAttribute"/></entity>
> </o:do>
> </o:function>
> </o:type>
>=20
> hope this makes sense -
> there's lots more you could do with o:XML types, let me know if you wan=
t any
more specific info!
>=20
> /m
>=20
> On 12 Nov 2006, at 17:50, Tomasz Rakowski wrote:
>=20
> Hi,
>=20
> I'm having problems with dynamic queries I create on the fly in oml.
> I really would be gratefull for any help.
>=20
=20
---------------------------------
Sponsored Link
$420,000 Mortgage for $1,399/month - Think You Pay Too Much For Your Mo=
rtgage? Find Out!
--0-839901240-1164071459=:99160
Content-Type: text/html; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
Hi,<br><br>I think that I didn't clearly expressed my problem.<br><br>Her=
e is another small example :<br><br>I would like to create general purpos=
e function which will take two parameters:<br> SQL Query and name o=
f the column. Function should execute given query and from<br>ResultSet i=
t should return data from given column name.<br><br>QUERY: "SELECT lastna=
me,birth,sex FROM person WHERE id=3D23" and second parametr<br>'lastname'=
<br><br>How to do this ? <br>Normally in db:execute statement I would use=
{$lastname} but in this case<br>'lastname' is stored in some variable (fu=
nction parameter) and I don't it during<br>compilation time ....<br><br><=
br>Tomasz Rakowski<br><br><br><br> <mars@...> writes:<br><br>&=
gt; <br>> Hi Tomasz,<br>> <br>> I think this was maybe answered =
in response to your other mail, let me know if<br>you still have problems=
with this.<br>> <br>> Another approach might be to treat the probl=
em as two sets of data; one being<br>the
database result, the other<br>> the dynamic information necessary to =
execute the query. You can then merge the<br>two into whatever form you r=
equire.<br>> <br>> You could also use o:XML types to represent the =
datastructures, then set the<br>dynamic values programmatically.<br>> =
For example, if you define a type DataEntity with a suitable constructor =
and<br>setter functions, then:<br>> <o:variable name=3D"entities"&g=
t;<br>> <db:execute sql=3D"..."><br>>=
<o:eval select=3D"Dat=
aEntity($firstname, $lastname, $birthyear)"/><br>>  =
; <!-- creates one DataEntity for each r=
ow in result set --><br>> </db:execute&g=
t;<br>> </o:variable><br>> <o:do select=3D"$entities.SetSo=
meAttribute('firstname')"/><br>> <!-- sets some attribute on _al=
l_ DataEntity objects in $entities
--><br>> <br>> Now if you want to produce an XML result set fro=
m the DataEntity object, you<br>can overload the nodes()<br>> function=
to do so. Eg<br>> <o:type name=3D"DataEntity"><br>> ..=
.<br>> <o:function name=3D"nodes"><br>> &nbs=
p; <o:do><br>> &n=
bsp; <entity><o:eval select=3D"$SomeAttribute"/></entity&g=
t;<br>> </o:do><br>> </o:fun=
ction><br>> </o:type><br>> <br>> hope this makes sense =
-<br>> there's lots more you could do with o:XML types, let me know if=
you want any<br>more specific info!<br>> <br>> /m<br>> <br>>=
On 12 Nov 2006, at 17:50, Tomasz Rakowski wrote:<br>> <br>> Hi,<br=
>> <br>> I'm having problems with dynamic queries I create on the f=
ly in oml.<br>> I really would be gratefull for any help.<br>> <br>=
<br><p> 
<font color=3D"666666"><font size=3D"2"><hr size=3D1>Sponsored Link</font=
></font><br><br>$420,000 Mortgage for $1,399/month - =20
<a href=3D"http://www.lowermybills.com/lre/index.jsp?sourceid=3Dlmb-9135-=
16417&moid=3D4116">Think You Pay Too Much For Your Mortgage? Find Out!</a=
>
--0-839901240-1164071459=:99160--
--===============1404846079==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
o-xml mailing list
o-xml-zRfLyl9bSvv/[email protected]
http://lists.pingdynasty.com/mailman/listinfo/o-xml
--===============1404846079==--