with <eli$22091...@qaz.wtf> Eli the Bearded wrote:
_Disclaimer_ I don't MySQL, SQLite is enough for me. But,..
> First some code:
>
> use DBI;
*SKIP*
> print "Insert row 1 via do(), NULL DEFAULT DEFAULT\n";
> $dbh->do('
> INSERT INTO `foobar` VALUES (NULL, DEFAULT, DEFAULT);
> ');
>
> $sth = $dbh->prepare('
> INSERT INTO `foobar` VALUES (?, ?, ?);
> ');
>
> print "Insert row 2 via prepared statement, undef undef undef\n";
> $sth->execute( undef, undef, undef );
>
> print "Insert row 3 via prepared statement, undef 34 DEFAULT\n";
> $sth->execute( undef, 34, DEFAULT );
>
> print "Insert row 4 via prepared statement, undef DEFAULT 'Fault'\n";
> $sth->execute( undef, DEFAULT, 'Fault' );
For this to compile, either 'DEFAULT' is Perl's constant sub (so to
speak) or you do 'no warnings' for real (boilerplate isn't omitted for
brevity).
*SKIP*
> Insert row 1 via do(), NULL DEFAULT DEFAULT
> Insert row 2 via prepared statement, undef undef undef
> Insert row 3 via prepared statement, undef 34 DEFAULT
> Insert row 4 via prepared statement, undef DEFAULT 'Fault'
> DBD::mysql::st execute failed: Incorrect integer value: 'DEFAULT'
> for column 'one' at row 1 at test-default line 41.
My understanding is, this isn't DBD::mysql what issues devastating blow.
DBD::mysql just reports how MySQL has failed.
> What have we got? SELECT *
> Row: 1 17 number
> Row: 2
> Row: 3 34 DEFAULT
>
> I'd like to be able to use the column defaults in a Mysql table via Perl
> DBI. Ideally, I'd have some flag that makes binding "undef" work as
> DEFAULT, but an explicit bind value (either in ->bind_param() or
> ->execute()) would be okay.
Now (also disclaimer), how should I put it?
* There is no hope to support what you want by DBI. DBI just doesn't
care about each and every feature, quirk, or whatever of underlying
SQL engine.
* AIUI, "perldoc DBD::mysql" has been studied extensively to no avail
already. If backends to MySQL from other ecosystems (especially
C-land) do stuff like this then there is hope -- DBD::mysql is lagging
behind (or it might be dead, because upstream of MySQL?).
* Claiming 'undef' (of perl) for 'DEFAULT' of SQL is not feasable.
Because 'undef' is already taken for 'NULL' of SQL. Now, I can see as
desirable, probable, hopeful some kind of pseudo binding that would
translate into 'INSERT INTO foobar VALUES (NULL, 34, DEFAULT )' but...
* Then you can go like this instead:
$dbh->prepare('INSERT INTO foobar VALUES (?, ?, DEFAULT)');
Because binding is for inserting literal values and not sprintfing
'quote's (or forbiden interpolation). Thus such pseudo binding
somewhat defeats purpose.
*CUT*
--
Torvalds' goal for Linux is very simple: World Domination
Stallman's goal for GNU is even simpler: Freedom