$sth->execute;
my $cols = $sth->fetchall_hashref('name');
+ my ($num_pk, $pk_col) = (0);
+ # SQLite doesn't give us the info we need to do this nicely :(
+ # If there is exactly one column marked PK, and its type is integer,
+ # set it is_auto_increment. This isn't 100%, but it's better than the
+ # alternatives.
while (my ($col_name, $info) = each %$result) {
- if ($cols->{$col_name}{pk} && lc($cols->{$col_name}{type}) eq 'integer') {
- $info->{is_auto_increment} = 1;
+ if ($cols->{$col_name}{pk}) {
+ $num_pk ++;
+ if (lc($cols->{$col_name}{type}) eq 'integer') {
+ $pk_col = $col_name;
+ }
}
}
if ((eval { ${ $info->{default_value} } }||'') eq 'CURRENT_TIMESTAMP') {
${ $info->{default_value} } = 'current_timestamp';
}
+ if ($num_pk == 1 and defined $pk_col and $pk_col eq $col) {
+ $info->{is_auto_increment} = 1;
+ }
}
return $result;