On Sun, 03 Aug 2003 09:49:12 +0000 Stephen Collyer <[EMAIL PROTECTED]> wrote:
> Michael A Chase wrote:
>
> >On Sat, 02 Aug 2003 12:32:42 +0000 Stephen Collyer
> <[EMAIL PROTECTED]> wrote:
>>>2. When @bind_params contains, say, ('NOW()', 'Doctor', 30, 'Bill'),
>>>it all goes horribly wrong, and MySQL fails to interpret the 'NOW()'
>>>string as an attempt to call a MySQL specific function.
>>>
>>>
>>
>>DBD::mysql is doing what is it supposed to do. 'NOW()' is a 5
>>character string, not a function. Placeholders pass values, not
>>syntactic elements.
>>
> Right. This is a distinction I've not seen made in any of the DBI docs,
> but it's a pretty important one.
It's in http://search.cpan.org/author/TIMB/DBI-1.37/DBI.pm where
bind_param() is described. I recently submitted a patch to move the
discussion to the section on placeholders where it will hopefully be
easier to find.
> That's more of a pain. I guess that implies that any SQL of the form:
>
> INSERT INTO TestTable
> (dob, profession, age, name)
> VALUES
> (<function>,<value1>,<value2>,<value2>)
>
> where <function> is an arbitrary combination of functions and values
> must be prepared like:
>
> INSERT INTO TestTable
> (dob, profession, age, name)
> VALUES
> (<function>,?,?,?)
>
> and executed like:
>
> $sth->execute(<value1>, <value2>, <value3>);
The function must be in the prepared SQL, the values do not. A common
example in Oracle is:
$dbh -> {RaiseError} = 1;
my $sth = $dbh -> prepare( join "\n",
'INSERT INTO testtable ( dob, profession, age, name )',
' VALUES ( TO_DATE( ?, 'YYYY-MM-DD' ), ?, ?, ? )' );
END_SQL
$sth -> execute( $date, $proffession, $age, $name );
--
Mac :})
** I usually forward private questions to the appropriate mail list. **
Ask Smarter: http://www.catb.org/~esr/faqs/smart-questions.html
Give a hobbit a fish and he eats fish for a day.
Give a hobbit a ring and he eats fish for an age.