diff options
author | Dylan William Hardison <dylan@hardison.net> | 2018-06-21 16:28:53 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-21 16:28:53 +0200 |
commit | 454a5dcf66f9b3eafb61badc6ce61c8ebe52dd96 (patch) | |
tree | f376f31bbd2da14bbbbdd2f221aa5da01bf1af38 /Bugzilla/DB/Sqlite.pm | |
parent | 52100a9f4f2e5b5d3249934143fb9a7097f156f9 (diff) | |
download | bugzilla-454a5dcf66f9b3eafb61badc6ce61c8ebe52dd96.tar.gz bugzilla-454a5dcf66f9b3eafb61badc6ce61c8ebe52dd96.tar.xz |
Bug 1461379 - refactor Bugzilla::DB to not subclass DBI
Diffstat (limited to 'Bugzilla/DB/Sqlite.pm')
-rw-r--r-- | Bugzilla/DB/Sqlite.pm | 37 |
1 files changed, 17 insertions, 20 deletions
diff --git a/Bugzilla/DB/Sqlite.pm b/Bugzilla/DB/Sqlite.pm index 87f45415b..3890d0795 100644 --- a/Bugzilla/DB/Sqlite.pm +++ b/Bugzilla/DB/Sqlite.pm @@ -8,10 +8,9 @@ package Bugzilla::DB::Sqlite; use 5.10.1; -use strict; -use warnings; +use Moo; -use base qw(Bugzilla::DB); +extends qw(Bugzilla::DB); use Bugzilla::Constants; use Bugzilla::Error; @@ -69,7 +68,7 @@ sub _sqlite_position_ci { # Constructor # ############### -sub new { +sub BUILDARGS { my ($class, $params) = @_; my $db_name = $params->{db_name}; @@ -97,10 +96,11 @@ sub new { sqlite_unicode => Bugzilla->params->{'utf8'}, }; - my $self = $class->db_new({ dsn => $dsn, user => '', - pass => '', attrs => $attrs }); - # Needed by TheSchwartz - $self->{private_bz_dsn} = $dsn; + return { dsn => $dsn, user => '', pass => '', attrs => $attrs }; +} + +sub on_dbi_connected { + my ($class, $dbh) = @_; my %pragmas = ( # Make sure that the sqlite file doesn't grow without bound. @@ -122,23 +122,20 @@ sub new { ); while (my ($name, $value) = each %pragmas) { - $self->do("PRAGMA $name = $value"); + $dbh->do("PRAGMA $name = $value"); } - $self->sqlite_create_collation('bugzilla', \&_sqlite_collate_ci); - $self->sqlite_create_function('position', 2, \&_sqlite_position); - $self->sqlite_create_function('iposition', 2, \&_sqlite_position_ci); + $dbh->sqlite_create_collation('bugzilla', \&_sqlite_collate_ci); + $dbh->sqlite_create_function('position', 2, \&_sqlite_position); + $dbh->sqlite_create_function('iposition', 2, \&_sqlite_position_ci); # SQLite has a "substr" function, but other DBs call it "SUBSTRING" # so that's what we use, and I don't know of any way in SQLite to # alias the SQL "substr" function to be called "SUBSTRING". - $self->sqlite_create_function('substring', 3, \&CORE::substr); - $self->sqlite_create_function('mod', 2, \&_sqlite_mod); - $self->sqlite_create_function('now', 0, \&_sqlite_now); - $self->sqlite_create_function('localtimestamp', 1, \&_sqlite_now); - $self->sqlite_create_function('floor', 1, \&POSIX::floor); - - bless ($self, $class); - return $self; + $dbh->sqlite_create_function('substring', 3, \&CORE::substr); + $dbh->sqlite_create_function('mod', 2, \&_sqlite_mod); + $dbh->sqlite_create_function('now', 0, \&_sqlite_now); + $dbh->sqlite_create_function('localtimestamp', 1, \&_sqlite_now); + $dbh->sqlite_create_function('floor', 1, \&POSIX::floor); } ############### |