| ClearPress documentation | Contained in the ClearPress distribution. |
ClearPress::driver::Pg - Pg-specific implementation of the database abstraction layer
** WARNING! ALPHA CODE **
$LastChangedRevision: 348 $
my $oDBH = $oDriver->dbh();
my $iAssignedId = $oDriver->create($query)
my $bounded_select = $driver->bounded_select($unbounded_select, $rows, $start_row);
$Author: Roger Pettett$
Copyright (C) 2008 Roger Pettett
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.4 or, at your option, any later version of Perl 5 you may have available.
| ClearPress documentation | Contained in the ClearPress distribution. |
######### # Author: rmp # Maintainer: $Author: zerojinx $ # Created: 2006-10-31 # Last Modified: $Date: 2010-01-04 13:02:42 +0000 (Mon, 04 Jan 2010) $ # Id: $Id: Pg.pm 348 2010-01-04 13:02:42Z zerojinx $ # Source: $Source$ # $HeadURL: https://clearpress.svn.sourceforge.net/svnroot/clearpress/trunk/lib/ClearPress/driver/Pg.pm $ # package ClearPress::driver::Pg; use strict; use warnings; use base qw(ClearPress::driver); use English qw(-no_match_vars); use Carp; use Readonly; our $VERSION = do { my ($r) = q$LastChangedRevision: 348 $ =~ /(\d+)/smx; $r; }; Readonly::Scalar our $TYPES => { 'primary key' => 'bigint unsigned not null auto_increment primary key', }; sub dbh { my $self = shift; if(!$self->{dbh} || !$self->{dbh}->ping()) { my $dsn = sprintf q(DBI:Pg:database=%s;host=%s;port=%s), $self->{dbname} || q[], $self->{dbhost} || q[localhost], $self->{dbport} || q[3306]; eval { $self->{dbh} = DBI->connect($dsn, $self->{dbuser} || q[], $self->{dbpass}, {RaiseError => 1, AutoCommit => 0}); } or do { croak qq[Failed to connect to $dsn using @{[$self->{dbuser}||q['']]}\n$EVAL_ERROR]; }; ######### # rollback any junk left behind if this is a cached handle # $self->{dbh}->rollback(); } return $self->{dbh}; } sub create { my ($self, $query, @args) = @_; my $dbh = $self->dbh(); $dbh->do($query, {}, @args); my $idref = $dbh->selectall_arrayref('SELECT LAST_INSERT_ID()'); return $idref->[0]->[0]; } sub create_table { my ($self, $table_name, $ref) = @_; return $self->SUPER::create_table($table_name, $ref, { engine=>'InnoDB'}); } sub types { return $TYPES; } sub bounded_select { my ($self, $query, $len, $start) = @_; if(defined $start && defined $len) { $query .= qq[ LIMIT $start, $len]; } elsif(defined $len) { $query .= qq[ LIMIT $len]; } return $query; } 1; __END__