Skip to content

Commit

Permalink
found two problems with set_slice:
Browse files Browse the repository at this point in the history
* set_slice modifies the arrays for fields and values if
  references are passed as argument, can cause problem
  in user's code if key isn't the first column

* passing a list like qw(os23445 price 2 color red) sucked
  all parameters from @_, e.g.:

> query was:insert into hit
(idf,Vend::Table::DBI=ARRAY(0xa0f3fc8),moment,useragent,userhost,referer,url,session,userip)
VALUES (?,?,?,?,?,?,?,?,?)
  • Loading branch information
racke committed Mar 31, 2004
1 parent 24253c1 commit 5d8d367
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions lib/Vend/Table/DBI.pm
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Vend::Table::DBI - Access a table stored in an DBI/DBD database
#
# $Id: DBI.pm,v 2.57 2003-08-22 16:15:30 jon Exp $
# $Id: DBI.pm,v 2.58 2004-03-31 15:52:36 racke Exp $
#
# Copyright (C) 2002-2003 Interchange Development Group
# Copyright (C) 2002-2004 Interchange Development Group
# Copyright (C) 1996-2002 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
Expand All @@ -21,7 +21,7 @@
# MA 02111-1307 USA.

package Vend::Table::DBI;
$VERSION = substr(q$Revision: 2.57 $, 10);
$VERSION = substr(q$Revision: 2.58 $, 10);

use strict;

Expand Down Expand Up @@ -1160,7 +1160,9 @@ sub get_slice {
}

sub set_slice {
my ($s, $key, $fary, $vary) = @_;
my ($s, $key, $fin, $vin) = @_;
my ($fary, $vary);

$s = $s->import_db() if ! defined $s->[$DBI];

if($s->[$CONFIG]{Read_only}) {
Expand All @@ -1175,10 +1177,14 @@ sub set_slice {
my $tkey;
my $sql;

if(ref $fary ne 'ARRAY') {
my $href = $fary;
if (ref $fin eq 'ARRAY') {
$fary = [@$fin];
$vary = [@$vin];
}
else {
my $href = $fin;
if(ref $href ne 'HASH') {
$href = { $fary, $vary, @_ }
$href = { splice (@_, 2) };
}
$vary = [ values %$href ];
$fary = [ keys %$href ];
Expand Down

0 comments on commit 5d8d367

Please sign in to comment.