[Mono-list] Automatic Binding of Variables to Parameters in ADO.NET

Daniel Morgan danmorg@sc.rr.com
Mon, 27 Jan 2003 08:33:12 -0500


This is a multi-part message in MIME format.

------=_NextPart_000_0006_01C2C5DE.BA800980
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: 7bit

RE: [Mono-list] Automatic Binding of Variables to Parameters in ADO.NETMaybe
that's what we need then - for someone to start working on the xsd.exe tool
for creating type-safe DataSets.

What would be involved in creating this tool?

Any takers?

-----Original Message-----
From: Piers Haken [mailto:piersh@friskit.com]
Sent: Monday, January 27, 2003 8:46 AM
To: Daniel Morgan; Mono-List
Subject: RE: [Mono-list] Automatic Binding of Variables to Parameters in
ADO.NET


  Microsoft ships a tool called xsd.exe that generates type-safe DataSets
that do basically this. You give it an XML Schma for your table and it
generates a source file for a class that drives from DataSet but which has
typesafe accessors and events. It might be a little heavy-handed for what
you want, though.

  Piers.

  > -----Original Message-----
  > From: Daniel Morgan [mailto:danmorg@sc.rr.com]
  > Sent: Monday, January 27, 2003 4:52 AM
  > To: Mono-List
  > Subject: [Mono-list] Automatic Binding of Variables to
  > Parameters in ADO.NET
  >
  >
  > Hello,
  >
  > How could I automatically bind variables as paramters in SQL,
  > execute the SQL, and get the results automatically.  Would
  > this involve creating new attributes to handle this.  I know
  > Glade# uses attributes to bind variables.
  >
  > Let's say we have a database table SOMETABLE with the following data:
  >
  > ANUM AMONEYVALUE ADATETIME           ABOOLEAN AVALUE
  > ==== =========== =================== ======== ======
  > 5    152.32      2002-12-31 12:34:56 False    9
  > 6    36.45       2001-01-23 05:12:23 True     8
  >
  > Here is a struct that will contain the returned values.
  >
  > public struct MyStruct
  > {
  >   int someNumber;
  >   double someMonetaryValue;
  >   DateTime someDataTime;
  >   bool someBoolean;
  > }
  >
  > Here is the sample code that demonstrates what I am asking.
  >
  > [SomeMagicMethodParameterDataBind("someValue"]
  > public MyStruct GetData (IDbConnection dbcon, int someValue)
  > {
  >       [SomeMagicDataBind("mystruct"]
  >       MyStruct mystruct;
  >
  >       string sql =
  >          "SELECT aNum, aMoneyValue, " +
  >          "       aDateTime, aBoolean " +
  >          "FROM sometable " +
  >          "WHERE :someValue " +
  >          "INTO mystruct.someNumber, mystruct.someMonetaryValue, " +
  >          "     mystruct.someDateTime, mystruct.someBoolean";
  >
  >      SomeMagicalClass magic = new SomeMagicalClass(dbcon, sql);
  >      magic.ExecuteSQL();
  >
  >      return mystruct;
  > }
  >
  > If I call GetData() with someValue set to 9, I should get a
  > MyStruct struct that has the following resuls:
  >
  > MyStrcut mystruct = GetData(dbcon, 9);
  >
  > // expected results
  > mystruct.someNumber = 5
  > mystruct.someMonetaryValue = 152.32
  > mystruct.someDateTime = "2002-12-31 12:34:56"
  > mystruct.someBoolean = false
  >
  > This is what I am interested in having.  Now, how do I get
  > this?  I'm sure I would need to use reflection heavily and
  > attributes. There would be parsing of SQL for parameters,
  > create parameters based on the parameters in the SQL, update
  > the parameters with information from variables currently in
  > scope that match the name of the parameter, set the value of
  > any input or input/output parameters from the variable that
  > have been bounded earlier, execute the SQL, set the values of
  > any return, output, or input/output variables based on the
  > results in the parameters.
  >
  > Any ideas?
  >
  > If you ever used RAD programming languages like Delphi,
  > Centura/Gupta SQL Windows, PowerBuilder, or Visual Basic, you
  > would understand how powerful this can be for database applications.
  >
  > Thanks Daniel
  >
  > _______________________________________________
  > Mono-list maillist  -  Mono-list@lists.ximian.com
  > http://lists.ximian.com/mailman/listinfo/mono-list
  >


------=_NextPart_000_0006_01C2C5DE.BA800980
Content-Type: text/html;
	charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>RE: [Mono-list] Automatic Binding of Variables to =
Parameters in ADO.NET</TITLE>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Dus-ascii">
<META content=3D"MSHTML 6.00.2722.900" name=3DGENERATOR></HEAD>
<BODY>
<DIV><SPAN class=3D385273113-27012003><FONT face=3DArial color=3D#0000ff =
size=3D2>Maybe=20
that's what we need then - for someone to start working on the xsd.exe =
tool for=20
creating type-safe DataSets.</FONT></SPAN></DIV>
<DIV><SPAN class=3D385273113-27012003><FONT face=3DArial color=3D#0000ff =

size=3D2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=3D385273113-27012003><FONT face=3DArial color=3D#0000ff =
size=3D2>What=20
would be involved in creating this tool?</FONT></SPAN></DIV>
<DIV><SPAN class=3D385273113-27012003><FONT face=3DArial color=3D#0000ff =

size=3D2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=3D385273113-27012003><FONT face=3DArial color=3D#0000ff =
size=3D2>Any=20
takers?</FONT></SPAN></DIV>
<DIV><SPAN class=3D385273113-27012003><FONT face=3DArial color=3D#0000ff =

size=3D2></FONT></SPAN>&nbsp;</DIV>
<DIV><FONT face=3DTahoma size=3D2>-----Original =
Message-----<BR><B>From:</B> Piers=20
Haken [mailto:piersh@friskit.com]<BR><B>Sent:</B> Monday, January 27, =
2003 8:46=20
AM<BR><B>To:</B> Daniel Morgan; Mono-List<BR><B>Subject:</B> RE: =
[Mono-list]=20
Automatic Binding of Variables to Parameters in =
ADO.NET<BR><BR></FONT></DIV>
<BLOCKQUOTE dir=3Dltr style=3D"MARGIN-RIGHT: 0px"><!-- Converted from =
text/plain format -->
  <P><FONT size=3D2>Microsoft ships a tool called xsd.exe that generates =
type-safe=20
  DataSets that do basically this. You give it an XML Schma for your =
table and=20
  it generates a source file for a class that drives from DataSet but =
which has=20
  typesafe accessors and events. It might be a little heavy-handed for =
what you=20
  want, though.</FONT></P>
  <P><FONT size=3D2>Piers.</FONT> </P>
  <P><FONT size=3D2>&gt; -----Original Message-----</FONT> <BR><FONT =
size=3D2>&gt;=20
  From: Daniel Morgan [<A=20
  href=3D"mailto:danmorg@sc.rr.com">mailto:danmorg@sc.rr.com</A>] =
</FONT><BR><FONT=20
  size=3D2>&gt; Sent: Monday, January 27, 2003 4:52 AM</FONT> <BR><FONT=20
  size=3D2>&gt; To: Mono-List</FONT> <BR><FONT size=3D2>&gt; Subject: =
[Mono-list]=20
  Automatic Binding of Variables to </FONT><BR><FONT size=3D2>&gt; =
Parameters in=20
  ADO.NET</FONT> <BR><FONT size=3D2>&gt; </FONT><BR><FONT size=3D2>&gt;=20
  </FONT><BR><FONT size=3D2>&gt; Hello,</FONT> <BR><FONT size=3D2>&gt;=20
  </FONT><BR><FONT size=3D2>&gt; How could I automatically bind =
variables as=20
  paramters in SQL, </FONT><BR><FONT size=3D2>&gt; execute the SQL, and =
get the=20
  results automatically.&nbsp; Would </FONT><BR><FONT size=3D2>&gt; this =
involve=20
  creating new attributes to handle this.&nbsp; I know </FONT><BR><FONT=20
  size=3D2>&gt; Glade# uses attributes to bind variables.</FONT> =
<BR><FONT=20
  size=3D2>&gt; </FONT><BR><FONT size=3D2>&gt; Let's say we have a =
database table=20
  SOMETABLE with the following data:</FONT> <BR><FONT size=3D2>&gt;=20
  </FONT><BR><FONT size=3D2>&gt; ANUM AMONEYVALUE=20
  ADATETIME&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
ABOOLEAN=20
  AVALUE</FONT> <BR><FONT size=3D2>&gt; =3D=3D=3D=3D =
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=20
  =3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D</FONT> <BR><FONT =
size=3D2>&gt; 5&nbsp;&nbsp;&nbsp;=20
  152.32&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2002-12-31 12:34:56=20
  False&nbsp;&nbsp;&nbsp; 9</FONT> <BR><FONT size=3D2>&gt; =
6&nbsp;&nbsp;&nbsp;=20
  36.45&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2001-01-23 05:12:23=20
  True&nbsp;&nbsp;&nbsp;&nbsp; 8</FONT> <BR><FONT size=3D2>&gt; =
</FONT><BR><FONT=20
  size=3D2>&gt; Here is a struct that will contain the returned =
values.</FONT>=20
  <BR><FONT size=3D2>&gt; </FONT><BR><FONT size=3D2>&gt; public struct=20
  MyStruct</FONT> <BR><FONT size=3D2>&gt; {</FONT> <BR><FONT=20
  size=3D2>&gt;&nbsp;&nbsp; int someNumber;</FONT> <BR><FONT=20
  size=3D2>&gt;&nbsp;&nbsp; double someMonetaryValue;</FONT> <BR><FONT=20
  size=3D2>&gt;&nbsp;&nbsp; DateTime someDataTime;</FONT> <BR><FONT=20
  size=3D2>&gt;&nbsp;&nbsp; bool someBoolean;</FONT> <BR><FONT =
size=3D2>&gt;=20
  }</FONT> <BR><FONT size=3D2>&gt; </FONT><BR><FONT size=3D2>&gt; Here =
is the sample=20
  code that demonstrates what I am asking.</FONT> <BR><FONT =
size=3D2>&gt;=20
  </FONT><BR><FONT size=3D2>&gt;=20
  [SomeMagicMethodParameterDataBind("someValue"]</FONT> <BR><FONT =
size=3D2>&gt;=20
  public MyStruct GetData (IDbConnection dbcon, int someValue)</FONT> =
<BR><FONT=20
  size=3D2>&gt; {</FONT> <BR><FONT =
size=3D2>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
  [SomeMagicDataBind("mystruct"]</FONT> <BR><FONT size=3D2>&gt;=20
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MyStruct mystruct;</FONT> <BR><FONT =
size=3D2>&gt;=20
  </FONT><BR><FONT size=3D2>&gt; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string =
sql=20
  =3D</FONT> <BR><FONT=20
  size=3D2>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
"SELECT=20
  aNum, aMoneyValue, " +</FONT> <BR><FONT=20
  size=3D2>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
  "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; aDateTime, aBoolean " +</FONT> =
<BR><FONT=20
  size=3D2>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
"FROM=20
  sometable " +</FONT> <BR><FONT=20
  size=3D2>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
"WHERE=20
  :someValue " +</FONT> <BR><FONT=20
  size=3D2>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
"INTO=20
  mystruct.someNumber, mystruct.someMonetaryValue, " +</FONT> <BR><FONT=20
  size=3D2>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
  "&nbsp;&nbsp;&nbsp;&nbsp; mystruct.someDateTime, =
mystruct.someBoolean";</FONT>=20
  <BR><FONT size=3D2>&gt; </FONT><BR><FONT=20
  size=3D2>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SomeMagicalClass magic =3D =
new=20
  SomeMagicalClass(dbcon, sql);</FONT> <BR><FONT=20
  size=3D2>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; magic.ExecuteSQL();</FONT> =
<BR><FONT=20
  size=3D2>&gt; </FONT><BR><FONT =
size=3D2>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return=20
  mystruct;</FONT> <BR><FONT size=3D2>&gt; }</FONT> <BR><FONT =
size=3D2>&gt;=20
  </FONT><BR><FONT size=3D2>&gt; If I call GetData() with someValue set =
to 9, I=20
  should get a </FONT><BR><FONT size=3D2>&gt; MyStruct struct that has =
the=20
  following resuls:</FONT> <BR><FONT size=3D2>&gt; </FONT><BR><FONT =
size=3D2>&gt;=20
  MyStrcut mystruct =3D GetData(dbcon, 9);</FONT> <BR><FONT =
size=3D2>&gt;=20
  </FONT><BR><FONT size=3D2>&gt; // expected results</FONT> <BR><FONT =
size=3D2>&gt;=20
  mystruct.someNumber =3D 5</FONT> <BR><FONT size=3D2>&gt;=20
  mystruct.someMonetaryValue =3D 152.32</FONT> <BR><FONT size=3D2>&gt;=20
  mystruct.someDateTime =3D "2002-12-31 12:34:56" </FONT><BR><FONT =
size=3D2>&gt;=20
  mystruct.someBoolean =3D false</FONT> <BR><FONT size=3D2>&gt; =
</FONT><BR><FONT=20
  size=3D2>&gt; This is what I am interested in having.&nbsp; Now, how =
do I get=20
  </FONT><BR><FONT size=3D2>&gt; this?&nbsp; I'm sure I would need to =
use=20
  reflection heavily and </FONT><BR><FONT size=3D2>&gt; attributes. =
There would be=20
  parsing of SQL for parameters, </FONT><BR><FONT size=3D2>&gt; create =
parameters=20
  based on the parameters in the SQL, update </FONT><BR><FONT =
size=3D2>&gt; the=20
  parameters with information from variables currently in =
</FONT><BR><FONT=20
  size=3D2>&gt; scope that match the name of the parameter, set the =
value of=20
  </FONT><BR><FONT size=3D2>&gt; any input or input/output parameters =
from the=20
  variable that </FONT><BR><FONT size=3D2>&gt; have been bounded =
earlier, execute=20
  the SQL, set the values of </FONT><BR><FONT size=3D2>&gt; any return, =
output, or=20
  input/output variables based on the </FONT><BR><FONT size=3D2>&gt; =
results in=20
  the parameters.</FONT> <BR><FONT size=3D2>&gt; </FONT><BR><FONT =
size=3D2>&gt; Any=20
  ideas?</FONT> <BR><FONT size=3D2>&gt; </FONT><BR><FONT size=3D2>&gt; =
If you ever=20
  used RAD programming languages like Delphi, </FONT><BR><FONT =
size=3D2>&gt;=20
  Centura/Gupta SQL Windows, PowerBuilder, or Visual Basic, you =
</FONT><BR><FONT=20
  size=3D2>&gt; would understand how powerful this can be for database=20
  applications.</FONT> <BR><FONT size=3D2>&gt; </FONT><BR><FONT =
size=3D2>&gt; Thanks=20
  Daniel</FONT> <BR><FONT size=3D2>&gt; </FONT><BR><FONT size=3D2>&gt;=20
  _______________________________________________</FONT> <BR><FONT =
size=3D2>&gt;=20
  Mono-list maillist&nbsp; -&nbsp; Mono-list@lists.ximian.com =
</FONT><BR><FONT=20
  size=3D2>&gt; <A=20
  =
href=3D"http://lists.ximian.com/mailman/listinfo/mono-list">http://lists.=
ximian.com/mailman/listinfo/mono-list</A></FONT>=20
  <BR><FONT size=3D2>&gt; </FONT></P></BLOCKQUOTE></BODY></HTML>

------=_NextPart_000_0006_01C2C5DE.BA800980--