[EMAIL PROTECTED] wrote:

>I'm dealing with:
>
>INSERT INTO MyTbl (col1,record_ts,col2) 
>       VALUES (7,CURRENT TIMESTAMP,'o''brian') };
>
That calls for a combination of SQL::Statement and your method. You have
to trick SQL::Statement into thinking that "CURRENT TIMESTAMP" is a
string (because it doesn't currently handle functions with spaces in
their names. So the code below takes your input and returns:

INSERT INTO MYTBL
(COL1,RECORD_TS,COL2)
VALUES (?,CURRENT TIMESTAMP,?)

With [7 o'brian] as the values.

sub make_pholders {
my($sql) = @_;
$sql =~ s/(CURRENT TIMESTAMP)/'$1'/g;
my $stmt = SQL::Statement->new( $sql );
my($table) = map {$_->name} $stmt->tables;
my($columns) = join ',',map {$_->name} $stmt->columns;
my @values;
my @pholders = map {
if (/^CURRENT TIMESTAMP$/) {
$_
}
else {
push @values => $_;
'?';
}
} $stmt->row_values;
my $pholder = join ',',@pholders;
my $pholder_sql =
"INSERT INTO $table ($columns) VALUES ($pholder)"
;
return $pholder_sql,@values;
}

I hope this helps.

-- 
Jeff

Reply via email to