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>&nbsp; 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>&nbsp;&lt;mars@...&gt; writes:<br><br>&=
gt; <br>&gt; Hi Tomasz,<br>&gt; <br>&gt; I think this was maybe answered =
in response to your other mail, let me know if<br>you still have problems=
 with this.<br>&gt; <br>&gt; Another approach might be to treat the probl=
em as two sets of data; one being<br>the
 database result, the other<br>&gt; the dynamic information necessary to =
execute the query. You can then merge the<br>two into whatever form you r=
equire.<br>&gt; <br>&gt; You could also use o:XML types to represent the =
datastructures, then set the<br>dynamic values programmatically.<br>&gt; =
For example, if you define a type DataEntity with a suitable constructor =
and<br>setter functions, then:<br>&gt; &lt;o:variable name=3D"entities"&g=
t;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &lt;db:execute sql=3D"..."&gt;<br>&gt;=
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;o:eval select=3D"Dat=
aEntity($firstname, $lastname, $birthyear)"/&gt;<br>&gt;&nbsp;&nbsp;&nbsp=
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;!-- creates one DataEntity for each r=
ow in result set --&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/db:execute&g=
t;<br>&gt; &lt;/o:variable&gt;<br>&gt; &lt;o:do select=3D"$entities.SetSo=
meAttribute('firstname')"/&gt;<br>&gt; &lt;!-- sets some attribute on _al=
l_ DataEntity objects in $entities
 --&gt;<br>&gt; <br>&gt; Now if you want to produce an XML result set fro=
m the DataEntity object, you<br>can overload the nodes()<br>&gt; function=
 to do so. Eg<br>&gt; &lt;o:type name=3D"DataEntity"&gt;<br>&gt;&nbsp; ..=
.<br>&gt;&nbsp; &lt;o:function name=3D"nodes"&gt;<br>&gt;&nbsp;&nbsp;&nbs=
p;&nbsp; &lt;o:do&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp; &lt;entity&gt;&lt;o:eval select=3D"$SomeAttribute"/&gt;&lt;/entity&g=
t;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/o:do&gt;<br>&gt;&nbsp; &lt;/o:fun=
ction&gt;<br>&gt; &lt;/o:type&gt;<br>&gt; <br>&gt; hope this makes sense =
-<br>&gt; there's lots more you could do with o:XML types, let me know if=
 you want any<br>more specific info!<br>&gt; <br>&gt; /m<br>&gt; <br>&gt;=
 On 12 Nov 2006, at 17:50, Tomasz Rakowski wrote:<br>&gt; <br>&gt; Hi,<br=
>&gt; <br>&gt; I'm having problems with dynamic queries I create on the f=
ly in oml.<br>&gt; I really would be gratefull for any help.<br>&gt; <br>=
<br><p>&#32;

<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==--