]> ruin.nu Git - ND.git/blob - DB.pm
Use new more intelligent default for pg_enable_utf8
[ND.git] / DB.pm
1 package ND::DB;
2 use strict;
3 use DBI;
4 use DBD::Pg qw(:pg_types);
5 require Exporter;
6
7 our @ISA = qw/Exporter/;
8
9 our @EXPORT = qw/DB/;
10
11
12 sub DB {
13         #Use domain sockets by default
14         my $dbh = DBI->connect_cached("dbi:Pg:dbname=ndawn", "ndawn", "", {AutoCommit => 0, RaiseError => 1, PrintError => 0, pg_enable_utf8 => -1});
15
16         #Easy to also use /etc/postgresql/pg_services.conf
17         #my $dbh =  DBI->connect_cached("dbi:Pg:service=ndawn","", "", {AutoCommit => 0, RaiseError => 1, pg_enable_utf8 => 1});
18         $dbh->rollback;
19         #Need to set autocommit after, to be able to rollback old incomplete transactions.
20         $dbh->{AutoCommit}  = 1;
21         return $dbh;
22 }
23
24 1;
25