diff options
author | Russ Allbery <rra@stanford.edu> | 2007-08-30 00:07:02 +0000 |
---|---|---|
committer | Russ Allbery <rra@stanford.edu> | 2007-08-30 00:07:02 +0000 |
commit | f13c283a3f5347631a301403176dd749766c9ab5 (patch) | |
tree | 2b2df4a4b95e3992771ac2d7aaf2622228b3c28f /perl/Wallet | |
parent | 5997fe12586a33a865ed68d3628e09e68b562e50 (diff) |
Adjust for SQL syntax differences for auto-increment keys between MySQL
and SQLite.
Diffstat (limited to 'perl/Wallet')
-rw-r--r-- | perl/Wallet/Schema.pm | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/perl/Wallet/Schema.pm b/perl/Wallet/Schema.pm index 69ea8e1..3538ef4 100644 --- a/perl/Wallet/Schema.pm +++ b/perl/Wallet/Schema.pm @@ -62,12 +62,18 @@ sub sql { # Given a database handle, try to create our database by running the SQL. Do # this in a transaction regardless of the database settings and throw an -# exception if this fails. +# exception if this fails. We have to do a bit of fiddling to get syntax that +# works with both MySQL and SQLite. sub create { my ($self, $dbh) = @_; + my $driver = $dbh->{Driver}->{Name}; eval { - $dbh->begin_work; + $dbh->begin_work if $dbh->{AutoCommit}; for my $sql (@{ $self->{sql} }) { + if ($driver eq 'SQLite') { + $sql =~ s{auto_increment primary key} + {primary key autoincrement}; + } $dbh->do ($sql, { RaiseError => 1, PrintError => 0 }); } $dbh->commit; |