[Zope] ZSQL question

Bryan C. Andregg bryan.andregg@duke.edu
Wed, 27 Mar 2002 16:49:18 -0500


--VEG93Z8xfWyRDB6c
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Wed, Mar 27, 2002 at 01:30:23PM -0800, Colin Fox mailed:
> Hi, all.
>=20
> I have a ZSQL insert function that requires an optional parameter.=20
>=20
> The variables are coming from an HTML form, and one of the variables is
> a checkbox. Apparently, if the checkbox is unchecked, the variable
> doesn't appear.
>=20
> As a small example, let's say there were two strings and a checkbox,
> labelled str1, str2 and cb. I need this:
>=20
> insert into mytable(col1, col2, col3) values (str1, str2, cb)
>=20
> as well as
>=20
> insert into mytable(col1, col2) values (str1, str2)
>=20
> if cb is None.
>=20
> I can't find any examples of optional insert variables, just optional
> join parameters.

You could do something like this

  <dtml-if "REQUEST.has_attr(cb)">
    <dtml-call dbInsert(str1 =3D REQUEST[str1],
                        str2 =3D REQUEST[str2],
			cb =3D REQUEST[cb] )">
  <dtml-else>
    <dtml-call dbInsert(str1 =3D REQUEST[str1],
                        str2 =3D REQUEST[str2],
			cb =3D '' )">
  </dtml-if>

--=20
Bryan C. Andregg		Duke University Medical Center
 Programmer			Dept. of Anesthesiology
 e <bryan.andregg@duke.edu>
 p +1 919 684 6201

--VEG93Z8xfWyRDB6c
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE8oj5ej9pElyS/cakRAkZIAJ4x86plbZUXkOY2W6Gegb0oW7TQgwCeNu97
Ph+NrDtXAYM0uOMEK4a92Yo=
=i7ft
-----END PGP SIGNATURE-----

--VEG93Z8xfWyRDB6c--