Re: how to set a DEFAULT value !!




-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


I would like to do in SQL
" INSERT table VALUES (DEFAULT, NOW()); "
...
is there any simple way I can write like this?

I'm not exactly sure how DBI::Class does things, but currently
in plain old DBI your only real option is to create a separate statement
handle like this:

my %sth;

$sth{nodefault} = $dbh->prepare("INSERT INTO mytable(foo,bar) VALUES (?, ?)");
$sth{nodefault}->execute(11,12);

$sth{default} = $dbh->prepare("INSERT INTO mytable(foo,bar) VALUES (DEFAULT, ?)");
$sth{default}->execute(12);

In recent versions of DBD::Pg, you can also pass in a special variable to the
execute method which allows using only one statement handle:

$sth{nodefault}->execute($DBDPG_DEFAULT, 12);

I've proposed adding something simlilar to DBI itself, but I don't recall getting
any feedback on it. Presumably once in place DBIx::Class will someday support it.

- --
Greg Sabino Mullane greg@xxxxxxxxxxxx
PGP Key: 0x14964AC8 200604241124
http://biglumber.com/x/web?pk=2529DF6AB8F79407E94445B4BC9B906714964AC8
-----BEGIN PGP SIGNATURE-----

iD8DBQFETO4zvJuQZxSWSsgRApL3AKDLdmt0B+G0d5eziZYMnEW3LyULsQCgzj5n
gJWNshh94iV5vrdHDLnuA7k=
=DgPG
-----END PGP SIGNATURE-----


.



Relevant Pages

  • Re: Is mysql.pm part of DBI?
    ... > Hash: SHA1 ... If I have DBI, do I have to ... install DBD::mysql? ...
    (comp.lang.perl.misc)
  • Re: Performance issue
    ... Put the SQL statements into a hash, ... use DBI qw; ... SELECT TAB_NAME FROM TABLE1 WHERE TAB_IN =? ... Not only would this allow me to have an easier to maintain group of prepare statements, I also would be doing the prepare only once in the program instead of for each line of input file. ...
    (perl.dbi.users)
  • Re: adding key to DB object
    ... It may look like a hash, but when you set or query ... T>> j> the DBD and by DBI, ...
    (perl.dbi.users)
  • Re: how do i tie a reference to a hash
    ... > I'm trying to tie a hash that is returned from a DBI ... One is to pass the reference as a parameter to TIEHASH, ...
    (comp.lang.perl)