freeside/FS/FS/part_export acct_sql.pm,1.9,1.10
ivan
ivan at pouncequick.420.am
Thu Apr 21 04:35:49 PDT 2005
Update of /home/cvs/cvsroot/freeside/FS/FS/part_export
In directory pouncequick:/tmp/cvs-serv8853
Modified Files:
acct_sql.pm
Log Message:
support multiple primary keys
Index: acct_sql.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/part_export/acct_sql.pm,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- acct_sql.pm 20 Apr 2005 07:12:14 -0000 1.9
+++ acct_sql.pm 21 Apr 2005 11:35:44 -0000 1.10
@@ -133,7 +133,17 @@
my($self, $new, $old) = (shift, shift, shift);
my %map = $self->_map;
- my $keymap = $map{$self->option('primary_key')};
+
+ my @primary_key = ();
+ if ( $self->option('primary_key') =~ /,/ ) {
+ foreach my $key ( split(/\s*,\s*/, $self->option('primary_key') ) ) {
+ my $keymap = $map{$key};
+ push @primary_key, $old->$keymap();
+ }
+ } else {
+ my $keymap = $map{$self->option('primary_key')};
+ push @primary_key, $old->$keymap();
+ }
my %record = map { my $value = $map{$_};
my @arg = ();
@@ -146,7 +156,7 @@
$new->svcnum,
'replace',
$self->option('table'),
- $self->option('primary_key') => $old->$keymap(),
+ $self->option('primary_key'), @primary_key,
%record,
);
return $err_or_queue unless ref($err_or_queue);
@@ -155,13 +165,26 @@
sub _export_delete {
my ( $self, $svc_acct ) = (shift, shift);
+
my %map = $self->_map;
- my $keymap = $map{$self->option('primary_key')};
+
+ my %primary_key = ();
+ if ( $self->option('primary_key') =~ /,/ ) {
+ foreach my $key ( split(/\s*,\s*/, $self->option('primary_key') ) ) {
+ my $keymap = $map{$key};
+ $primary_key{ $key } = $svc_acct->$keymap();
+ }
+ } else {
+ my $keymap = $map{$self->option('primary_key')};
+ $primary_key{ $self->option('primary_key') } = $svc_acct->$keymap(),
+ }
+
my $err_or_queue = $self->acct_sql_queue(
$svc_acct->svcnum,
'delete',
$self->option('table'),
- $self->option('primary_key') => $svc_acct->$keymap(),
+ %primary_key,
+ #$self->option('primary_key') => $svc_acct->$keymap(),
);
return $err_or_queue unless ref($err_or_queue);
'';
@@ -212,14 +235,27 @@
sub acct_sql_replace { #subroutine, not method
my $dbh = acct_sql_connect(shift, shift, shift);
- my( $table, $pkey, $old_pkey, %record ) = @_;
+
+ my( $table, $pkey ) = ( shift, shift );
+
+ my %primary_key = ();
+ if ( $pkey =~ /,/ ) {
+ foreach my $key ( split(/\s*,\s*/, $pkey ) ) {
+ $primary_key{$key} = shift;
+ }
+ } else {
+ $primary_key{$pkey} = shift;
+ }
+
+ my %record = @_;
my $sth = $dbh->prepare(
- "UPDATE $table SET ". join(', ', map "$_ = ?", keys %record ).
- "WHERE $pkey = ?"
+ "UPDATE $table".
+ ' SET '. join(', ', map "$_ = ?", keys %record ).
+ ' WHERE '. join(' AND ', map "$_ = ?", keys %primary_key )
) or die $dbh->errstr;
- $sth->execute( values(%record), $old_pkey );
+ $sth->execute( values(%record), values(%primary_key) );
$dbh->disconnect;
}
More information about the freeside-commits
mailing list