Akopia Akopia Services

[Date Prev][Date Next][Thread Prev][Thread Next][Minivend by date ][Minivend by thread ]

Re: [mv] New Interchange preview release 4.5.5 -- auto-increment problems



******    message to minivend-users from Ton Verhagen <ton@verhagen.net>     ******

Just to say THANKS Racke!

This is what I needed as I depend heavilly on auto_increment fields in my 
databases.

All the best and keep up the spirit.

Ton

At 12:59 PM 8/13/00 +0200, you wrote:
>******    message to minivend-users from Stefan Hornburg 
><racke@linuxia.de>     ******
>
>Mike Heins <mikeh@minivend.com> writes:
>
>
>[...]
>
> > >
> > > >     -- Improved auto-numbering support.
> > >
> > > Has this to do with the auto-increment fields of MySQL?
> >
> > No.  Currently, you cannot set an autonumbered field via the UI.
> > release. There might be some handling of this in the next release,
> > though. I am looking at alternatives; it is a complex issue if we
> > hope to handle it at all portably.
>
>I made the following hack for auto_increment (against IC 4.5.5):
>
>(DBI.pm):
># returns subroutine which updates/inserts a data record
># on insertion we don't need a key if the AUTO_INCREMENT
># configuration option for this database set
>
>sub row_settor {
>         my ($s, @columns) = @_;
>         my ($i, $haskey, @quote);
>         for ($i = 0; $i < @columns; $i++) {
>         $haskey = 1 if $columns[$i] eq $s->[$KEY];
>                 push @quote, $i
>                         unless $s->[$CONFIG]{NUMERIC}{$columns[$i]};
>         }
>         return sub {
>                 my(@values, @parts) = @_;
>                 my $query;
>                 my $update;
>
>         if ($haskey) {
>             # key is one of the columns check if record already exists
>             $update = $s->record_exists($values[0]) ? 1 : 0;
>         } elsif (! $s->[$CONFIG]{AUTO_INCREMENT}) {
>             ::logError('DBI insertion without key value and 
> AUTO_INCREMENT set');
>             return undef;
>         }
>
>                 for(@quote) {
>                         $values[$_] = $s->[$DBI]->quote($values[$_]);
>                 }
>                 my $key = $values[0];
>                 if($update) {
>             for (@columns) {
>                 push (@parts, " $_ = " . shift(@values));
>             }
>             $query = "update $s->[$TABLE] set "
>                 . join (', ', @parts)
>                     . " where $s->[$KEY] = $key";
>                 }
>                 else {
>                         $query = "insert into $s->[$TABLE] ("   .
>                                         join (",\n", @columns)          .
>                                         ") VALUES 
> ("                                    .
>                                         join (",\n", @values)           .
>                                         ")"
>                                         ;
>                 }
>                 my $sth = $s->[$DBI]->prepare($query);
>                 if(!$sth) {
>                         ::logError("DBI prepare row_settor for 
> table=$s->[$TABLE]: $DBI::errstr");
>                         return undef;
>                 }
>                 my $rc = $sth->execute();
>                 if(! defined $rc) {
>                         ::logError("DBI execute row_settor for 
> table=$s->[$TABLE]: $DBI::errstr (query: $query)");
>                         return undef;
>                 }
>                 return $rc;
>         };
>}
>
>minivend.PL:
>     if ($function eq 'insert' && $ref->{type} == 8
>         && $db->config('AUTO_INCREMENT')) {
>         # special insertion case => key not needed
>         my (@k, @v);
>
>                 for(keys %data) {
>             next if $_ eq $prikey && length($data{$_}->[0]) == 0;
>                         next unless (length($value = $data{$_}->[0]) || 
> $CGI::values{mv_update_empty});
>                         push(@k, $_);
># LEGACY
>                         HTML::Entities::decode($value) if $decode;
># END LEGACY
>                         if(defined $CGI::values{"mv_data_filter_$_"}) {
>                                 $value = Vend::Interpolate::filter_value(
> 
>$CGI::values{"mv_data_filter_$_"},
>                                                         $value,
>                                                         0
>                                                         );
>                         }
>                         push(@v, $value);
>                 }
>         my $func = $db->row_settor(@k);
>         return &$func(@v);
>     }
>
>         if (not defined $data{$prikey}) {
>      ....
>
>Ciao
>         Racke
>
>--
>LinuXia Systems && Cobolt NetServices, eCommerce and more
>Shop- und Datenbanklösungen mit MiniVend, Firewalls auf Debian-Basis
>http://www.linuxia.de - http://www.cobolt.net
>--> Coding from hell and back <---
>-
>To unsubscribe from the list, DO NOT REPLY to this message.  Instead, send
>email with 'UNSUBSCRIBE minivend-users' in the body to Majordomo@minivend.com.
>Archive of past messages: http://www.minivend.com/minivend/minivend-list

-
To unsubscribe from the list, DO NOT REPLY to this message.  Instead, send
email with 'UNSUBSCRIBE minivend-users' in the body to Majordomo@minivend.com.
Archive of past messages: http://www.minivend.com/minivend/minivend-list


Search for: Match: Format: Sort by: