How to insert "empty" or "default" values when SQL is first prepared and then executed
How to insert "empty" or "default" values when SQL is first prepared and then executed
am 26.09.2006 21:51:35 von PPeng
------_=_NextPart_001_01C6E1A5.2CB4F066
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
In my project I first prepare an INSERT statement 'INSERT INTO table
(col1, col2, col3, ...) VALUES (?, ?, ?, ...)' once, then insert
multiple records using 'execute(@values)'. The problem is that not all
values of all columns are available. So I should either leave them empty
or set them as default values. I try to use 'NULL' or 'DEFAULT' for
those unavailable values in '@values', but it didn't work. I know I
probably can set '0' for numerical columns and 'space' for varchar
columns. But is there a simpler way so I don't need to worry about data
types?
=20
Thanks,
Pai
------_=_NextPart_001_01C6E1A5.2CB4F066--
Re: How to insert "empty" or "default" values when SQL is first preparedand then executed
am 27.09.2006 00:38:27 von Alexander
It depends on the database you connect to. Often, you either INSERT NULL
or you simply do not specify the column, sometimes, both methods are
allowed.
To insert NULL into the database, you use undef as value (which is also
what you get back when reading NULL values).
Alexander
Pai Peng wrote:
> In my project I first prepare an INSERT statement 'INSERT INTO table
> (col1, col2, col3, ...) VALUES (?, ?, ?, ...)' once, then insert
> multiple records using 'execute(@values)'. The problem is that not all
> values of all columns are available. So I should either leave them empty
> or set them as default values. I try to use 'NULL' or 'DEFAULT' for
> those unavailable values in '@values', but it didn't work. I know I
> probably can set '0' for numerical columns and 'space' for varchar
> columns. But is there a simpler way so I don't need to worry about data
> types?
>
>
>
> Thanks,
>
> Pai
>
>
>
--
Alexander Foken
mailto:alexander@foken.de http://www.foken.de/alexander/
Re: How to insert "empty" or "default" values when SQL is first prepared and then executed
am 27.09.2006 12:04:32 von hjp
--Nq2Wo0NMKNjxTN9z
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
On 2006-09-26 12:51:35 -0700, Pai Peng wrote:
> In my project I first prepare an INSERT statement 'INSERT INTO table
> (col1, col2, col3, ...) VALUES (?, ?, ?, ...)' once, then insert
> multiple records using 'execute(@values)'. The problem is that not all
> values of all columns are available. So I should either leave them empty
> or set them as default values. I try to use 'NULL' or 'DEFAULT' for
> those unavailable values in '@values', but it didn't work.
That would insert the literal string 'NULL' or 'DEFAULT'. To insert a
null value, use undef.
hp
--=20
_ | Peter J. Holzer | If I wanted to be "academically correct",
|_|_) | Sysadmin WSR | I'd be programming in Java.
| | | hjp@wsr.ac.at | I don't, and I'm not.
__/ | http://www.hjp.at/ | -- Jesse Erlbaum on dbi-users
--Nq2Wo0NMKNjxTN9z
Content-Type: application/pgp-signature
Content-Disposition: inline
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
iQDQAwUBRRpMsFLjemazOuKpAQJ27gXTB9/jatInJvxgzm4r1fRfnj6ou6DO 4+lk
9kmP9EziFBqXt1lMuqmwtUfYx4BdX/Vu6ypE1oQQWXzGaEQfKOVhU1rvVn2G qH/h
6Am+nmrkzP5dQt/Ec5pAurJYtMxYKH15O+ZNlH5Y6wTJjJbPwoUuAZWyjnKa vPhP
NLoiAyITF7UeDEOOnIoctQdz5bLqWqmYz0SdrEh7TgDGlHR5eDpRgKrJ6/2V TWF1
mu/BjiDWIzV5kc6SyDEcIekgqg==
=+IAM
-----END PGP SIGNATURE-----
--Nq2Wo0NMKNjxTN9z--