Re: DBI update



* Bigus schrieb:

> In the following snippet of code, I'm trying to update several fields in a
> database record:
>
> my $sth = $db->prepare("UPDATE items SET $set WHERE id = '$form{selitem}'");
> $sth->execute($quoted);
>
> $set, in the prepare statement, is a string that contains field/value pairs
> like this:
>
> "type = ?, size = ?, description = NULL"
>
> then in the execute line $quoted is a string containing the bind variables
>
> "$form{type},$form{size}"
>
> So what I'm trying to achieve is the equivalent of:
>
> my $sth = $db->prepare("UPDATE items SET type = ?, size = ?, description =
> NULL WHERE id = '$form{selitem}'");
> $sth->execute($form{type},$form{size});
>
> Now the prepare statement works fine but the db error:
>
> "called with 1 bind variables when 2 are needed"

Sure, the whole content of $quoted is seen as one argument. It would be
used for the "type = ?" part of your sql-statement. What you want to do
is some kind of splitting into an array with 2 elements:

my @bind = split /,/, $quoted, 2;
$sth->execute( @bind );

# shortened to:
$sth->execute( split /,/, $quoted, 2 );

Perhaps you could pay attention on this when building the var $quoted
and save your values in an array rather than a skalar.

regards,
fabian
.



Relevant Pages

  • Re: Adding a NULL to an array then adding array to a data table
    ... Here is a snippet of my code ... string by;'s and put in strTokens ... I'm reading the data from a text file, parsing it out into an array then ... correct format. ...
    (microsoft.public.dotnet.framework.adonet)
  • count array element in word vba
    ... I have a snippet of code that take a given string and uses 'split' to pop it ... is there a way to count or return the number of array elements being created ...
    (microsoft.public.word.vba.general)
  • Re: How to convert array to string, and vice versa
    ... Tim Streater wrote: ... All these items need to be represented in a single already existing database record. ... and converting it to a single string: ... I can't see any array or string function that looks designed for this or a similar purpose. ...
    (comp.lang.php)
  • Re: count array element in word vba
    ... > I have a snippet of code that take a given string and uses 'split' to pop ... > is there a way to count or return the number of array elements being ...
    (microsoft.public.word.vba.general)
  • Re: How to convert array to string, and vice versa
    ... So, I thought of taking an array, as ... and converting it to a single string: ... then I have a string I can write to the database record. ...
    (comp.lang.php)