+sub connect {
+ my ($self, @args) = @_;
+ @args = $self->get_connect_args if !@args;
+ my $initial_sql = $self->get_initial_sql;
+
+ if (my $cached_dbh = SL::DBConnect::Cache->get(@args, $initial_sql)) {
+ return $cached_dbh;
+ }
+
+ my $dbh = $self->_connect(@args);
+ return undef if !$dbh;
+
+ if ($initial_sql) {
+ $dbh->do($initial_sql);
+ $dbh->commit if !$dbh->{AutoCommit};
+ }
+ SL::DBConnect::Cache->store($dbh, @args, $initial_sql);
+
+ return $dbh;
+}
+
+sub get_datestyle {
+ my ($self, $dateformat) = @_;
+ return $dateformat_to_datestyle{ $dateformat || $::myconfig{dateformat} // '' };
+}
+
+sub get_initial_sql {
+ my ($self) = @_;
+
+ return undef if !%::myconfig || !$::myconfig{dateformat};
+
+ my $datestyle = $self->get_datestyle;
+ return $datestyle ? qq|SET DateStyle to '${datestyle}'| : '';
+}
+