summaryrefslogtreecommitdiff
path: root/FS/FS/Record.pm
diff options
context:
space:
mode:
authorivan <ivan>2002-09-20 15:46:29 +0000
committerivan <ivan>2002-09-20 15:46:29 +0000
commitb59cf43f0814ea4d484d4b09833dd3c2d493455f (patch)
treebd36c1ef0b577158339acc3b6cfb7aa84bb52962 /FS/FS/Record.pm
parent9c3fb2a84c655cbbaafed99586f1431e08c218d5 (diff)
fix database sequence code, closes: Bug#69
Diffstat (limited to 'FS/FS/Record.pm')
-rw-r--r--FS/FS/Record.pm16
1 files changed, 12 insertions, 4 deletions
diff --git a/FS/FS/Record.pm b/FS/FS/Record.pm
index 8778dee79..a23f37a62 100644
--- a/FS/FS/Record.pm
+++ b/FS/FS/Record.pm
@@ -480,10 +480,17 @@ sub insert {
my $db_seq = 0;
if ( $primary_key ) {
my $col = $self->dbdef_table->column($primary_key);
- my $db_seq =
+
+ $db_seq =
uc($col->type) eq 'SERIAL'
- || ( driver_name eq 'Pg' && $col->default =~ /^nextval\(/i )
- || ( driver_name eq 'mysql' && $col->local =~ /AUTO_INCREMENT/i );
+ || ( driver_name eq 'Pg'
+ && defined($col->default)
+ && $col->default =~ /^nextval\(/i
+ )
+ || ( driver_name eq 'mysql'
+ && defined($col->local)
+ && $col->local =~ /AUTO_INCREMENT/i
+ );
$self->unique($primary_key) unless $self->getfield($primary_key) || $db_seq;
}
@@ -515,11 +522,12 @@ sub insert {
$sth->execute or return $sth->errstr;
if ( $db_seq ) { # get inserted id from the database, if applicable
+ warn "[debug]$me retreiving sequence from database\n" if $DEBUG;
my $insertid = '';
if ( driver_name eq 'Pg' ) {
my $oid = $sth->{'pg_oid_status'};
- my $i_sql = "SELECT id FROM $table WHERE oid = ?";
+ my $i_sql = "SELECT $primary_key FROM $table WHERE oid = ?";
my $i_sth = dbh->prepare($i_sql) or do {
dbh->rollback if $FS::UID::AutoCommit;
return dbh->errstr;