Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
f7101d4
Some databases support a timestamp with a number of digits.
May 18, 2011
fe0f6fe
Pushed the type list down to the driver layer.
May 18, 2011
047ec71
Many more values are now passed in execute() instead of as raw string…
May 18, 2011
77adef1
First serious pass at Oracle support: Oracle supports rownum, not limit.
May 18, 2011
6f24d4d
Added Oracle support.
May 18, 2011
72cd674
Added support for connect identifiers.
May 18, 2011
0667534
Implemented Oracle support.
May 18, 2011
46bfee7
String comparisons are slow. This new caching greatly improved map l…
May 18, 2011
f47b334
Oracle supports VARCHAR2.
May 23, 2011
07824f4
Added a few functions that are useful for schema dumping and loading.
May 23, 2011
79b603c
Implemented Oracle support for table aliasing.
May 24, 2011
626e506
Fixed bug in multiple tables in the from clause.
May 25, 2011
6dec7a2
Added more information about the original table per column.
May 25, 2011
4989c81
Implemented support for subqueries in columns.
May 26, 2011
44d727a
Fixed bug introduced by allowing binds in columns.
May 31, 2011
6623a01
Implemented query cloning.
Jul 28, 2011
79af139
Select queries now support add_inner_join() and add_left_join().
Jul 29, 2011
3902aaa
Implemented support for escaping LIKE clauses.
Oct 28, 2011
c1ea2f4
DBIx::ObjectMapper can now operate on an externally-provided DBI handle.
Mar 5, 2012
48fd8e1
One can now call union from a metadata.
May 31, 2012
fd688f3
Someone had a typo; this _function does not exist anywhere.
Aug 2, 2012
f8c9bf8
Be nice to externally provided DBHs.
Aug 4, 2012
42c2920
Oracle has a concept of a recycle bin for dropped tables. Ignoring it.
Jan 23, 2013
4900956
Looks like "0" was a bad assumption.
Mar 11, 2013
c86208f
if it is union, put parenthesis around it.
Mar 26, 2013
cbf5565
DBD::Oracle overrides to remove deprecated RULE* hint until we can up…
Jan 28, 2014
5e7ea49
Removed use of Hash::Merge.
Jun 26, 2014
224f21f
Removed Module::Find dependency.
Jun 26, 2014
c123f6f
Incorrect use of parameters to Col fixed.
Jun 26, 2014
b61abad
polymorphic_identity is not a number. Use string comparison.
Jun 26, 2014
5c986f1
Dependency on Devel::Cycle is not explicitly declared; earlier versio…
Jun 26, 2014
5ad69e9
Fixed table inheritance assumptions.
Jun 26, 2014
cd59962
Merged in an Oracle HINT fix.
Jun 26, 2014
d0722d9
Revert "First serious pass at Oracle support: Oracle supports rownum,…
Jul 7, 2014
0438711
Easier to do straight eq comparisons if we are always a string.
Jul 7, 2014
3da2e3d
Implemented proper Oracle three-nested-select strategy for rownum.
Jul 8, 2014
8602f41
Performed cartesian join of column info in Perl instead of Oracle.
Aug 26, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions META.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,8 @@ requires:
DateTime::Format::SQLite: 0
Digest::MD5: 0
Filter::Util::Call: 0
Hash::Merge: 0.12
List::MoreUtils: 0
Log::Any: 0
Module::Find: 0
Params::Validate: 0
Scalar::Util: 0
Sub::Exporter: 0
Expand Down
2 changes: 0 additions & 2 deletions Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ requires 'Class::MOP';
requires 'Class::Inspector';
requires 'Class::Data::Inheritable';
requires 'Data::Page' => 2.00;
requires 'Hash::Merge' => 0.12;
requires 'Params::Validate';
requires 'Log::Any';
requires 'Digest::MD5';
Expand All @@ -31,7 +30,6 @@ requires 'DateTime';
requires 'Sub::Exporter';
requires 'Capture::Tiny';
requires 'Data::Dump';
requires 'Module::Find';
requires 'Cache::LRU';

build_requires 'Test::More' => 0.88;
Expand Down
1 change: 1 addition & 0 deletions lib/DBIx/ObjectMapper/Engine.pm
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ sub update { }
sub insert { }
sub create { }
sub delete { }
sub union { }
sub iterator { }

1;
Expand Down
69 changes: 51 additions & 18 deletions lib/DBIx/ObjectMapper/Engine/DBI.pm
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ sub _init {
my $param = shift || confess 'invalid parameter.';
$param = [ $param, @_ ] unless ref $param;

my $external_dbh;
my @connect_info;
my $option;
if ( ref $param eq 'ARRAY' ) {
@connect_info = @$param[ 0 .. 2 ];
$option = $param->[3] if $param->[3];
}
elsif ( ref $param eq 'HASH' ) {
$external_dbh = delete $param->{external_dbh};
@connect_info = (
delete $param->{dsn},
delete $param->{username},
Expand All @@ -47,7 +49,7 @@ sub _init {
= ref $disconnect_do eq 'ARRAY' ? $disconnect_do : [$disconnect_do];

for my $name ( qw(db_schema namesep quote datetime_parser iterator
time_zone disable_prepare_caching cache) ) {
time_zone disable_prepare_caching cache connect_identifier) ) {
$self->{$name} = delete $option->{$name} || undef;
}

Expand All @@ -60,6 +62,7 @@ sub _init {
%{ $option || {} }
};

$self->{external_dbh} = $external_dbh;
$self->{connect_info} = \@connect_info;
$self->{driver_type} = undef;
$self->{driver} = undef;
Expand Down Expand Up @@ -156,11 +159,16 @@ sub _connect {
my $self = shift;

my $dbh = do {
if ($INC{'Apache/DBI.pm'} && $ENV{MOD_PERL}) {
local $DBI::connect_via = 'connect'; # Disable Apache::DBI.
DBI->connect( @{ $self->{connect_info} } );
} else {
DBI->connect( @{ $self->{connect_info} } );
if ($self->{external_dbh}) {
$self->{external_dbh};
}
else {
if ($INC{'Apache/DBI.pm'} && $ENV{MOD_PERL}) {
local $DBI::connect_via = 'connect'; # Disable Apache::DBI.
DBI->connect( @{ $self->{connect_info} } );
} else {
DBI->connect( @{ $self->{connect_info} } );
}
}
};

Expand All @@ -175,13 +183,14 @@ sub _connect {
$self->{driver} = DBIx::ObjectMapper::Engine::DBI::Driver->new(
$driver_type,
$dbh,
db_schema => $self->{db_schema} || undef,
namesep => $self->{namesep} || undef,
quote => $self->{quote} || undef,
query => $self->query,
log => $self->log,
datetime_parser => $self->{datetime_parser} || undef,
time_zone => $self->{time_zone},
db_schema => $self->{db_schema} || undef,
connect_identifier => $self->{connect_identifier} || undef,
namesep => $self->{namesep} || undef,
quote => $self->{quote} || undef,
query => $self->query,
log => $self->log,
datetime_parser => $self->{datetime_parser} || undef,
time_zone => $self->{time_zone},
);

if ( $self->{time_zone}
Expand All @@ -200,10 +209,17 @@ sub _connect {

sub disconnect {
my ($self) = @_;
if( my $dbh = $self->{_dbh} ) {
my $dbh = $self->{_dbh};
if (
$dbh &&
(
!defined($self->{external_dbh}) ||
$self->{external_dbh} != $dbh
)
) {
$self->dbh_do( $self->{disconnect_do}, $dbh );
while( $self->{txn_depth} > 0 ) {
$self->_txn_rollback;
$self->txn_rollback;
}
$dbh->disconnect;
$self->log_connect('DISCONNECT');
Expand Down Expand Up @@ -466,7 +482,8 @@ sub select_single {
else {
#$result = $self->dbh->selectrow_arrayref($sql, +{}, @bind);
my $sth = $self->_prepare($sql);
$sth->execute(@bind) || confess $sth->errstr;
my @raw_bind = $self->driver->bind_params($sth, @bind);
$sth->execute(@raw_bind) || confess $sth->errstr;
$result = $sth->fetchrow_arrayref;
$sth->finish;
$self->{sql_cnt}++;
Expand Down Expand Up @@ -505,7 +522,9 @@ sub update {

my ( $sql, @bind ) = $query->as_sql;
$self->log_sql($sql, @bind);
my $ret = $self->dbh->do($sql, {}, @bind);
my $sth = $self->dbh->prepare($sql);
my @raw_bind = $self->driver->bind_params($sth, @bind);
my $ret = $sth->execute(@raw_bind);
$self->{sql_cnt}++;
return $ret;
}
Expand All @@ -522,7 +541,9 @@ sub insert {

my ( $sql, @bind ) = $query->as_sql;
$self->log_sql($sql, @bind);
$self->dbh->do( $sql, {}, @bind );
my $sth = $self->dbh->prepare($sql);
my @raw_bind = $self->driver->bind_params($sth, @bind);
$sth->execute(@raw_bind);
$self->{sql_cnt}++;

my $ret_id = ref($query->values) eq 'HASH' ? $query->values : +{};
Expand Down Expand Up @@ -565,6 +586,16 @@ sub delete {
return $ret;
}

sub union {
my ( $self, $query, $callback ) = @_;
my $query_class = ref( $self->query ) . '::Union';
unless ( ref $query eq $query_class ) {
$query = $self->_as_query_object( 'union', $query );
}
return $self->iterator->new( $query, $self, $callback );
}


# XXXX TODO CREATE TABLE
# sub create { }

Expand Down Expand Up @@ -671,6 +702,7 @@ DBIx::ObjectMapper::Engine::DBI - the DBI engine
on_connect_do => [],
on_disconnect_do => [],
db_schema => 'public',
connect_identifier => undef,
namesep => '.',
quote => '"',
iterator => '',
Expand All @@ -692,6 +724,7 @@ DBIx::ObjectMapper::Engine::DBI - the DBI engine
on_connect_do => [],
on_disconnect_do => [],
db_schema => 'public',
connect_identifier => undef,
namesep => '.',
quote => '"',
iterator => '',
Expand Down
23 changes: 23 additions & 0 deletions lib/DBIx/ObjectMapper/Engine/DBI/BoundParam.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package DBIx::ObjectMapper::Engine::DBI::BoundParam;
use strict;
use warnings;
use Carp::Clan qw/^DBIx::ObjectMapper/;
use Params::Validate qw(:all);

my $ATTRIBUTES = {
value => { type => SCALAR },
type => { type => SCALAR },
column => { type => SCALAR },
};

sub new {
my $class = shift;
my %attr = validate( @_, $ATTRIBUTES );
return bless \%attr, $class;
}

sub value { $_[0]->{value} }
sub type { $_[0]->{type} }
sub column { $_[0]->{column} }

1;
74 changes: 74 additions & 0 deletions lib/DBIx/ObjectMapper/Engine/DBI/Driver.pm
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ sub log { $_[0]->{log} }
sub namesep { $_[0]->{namesep} }
sub quote { $_[0]->{quote} }
sub time_zone { $_[0]->{time_zone} }
sub connect_identifier { $_[0]->{connect_identifier} }

sub init { }

Expand Down Expand Up @@ -229,4 +230,77 @@ sub release_savepoint {}

sub rollback_savepoint {}

sub bind_params { my ($self, $sth, @binds) = @_; @binds }

sub _type_map_data {{
# String
'varchar' => 'String',
'character varying' => 'String',
'char' => 'String',
'character' => 'String',

# Int
'int' => 'Int',
'integer' => 'Int',
'mediumint' => 'Int',

# SmallInt
'tinyint' => 'SmallInt',
'smallint' => 'SmallInt',

# BigInt
'bigint' => 'BigInt',

# Boolean
'boolean' => 'Boolean',
'bool' => 'Boolean',

# Text
'text' => 'Text',

# Date
'date' => 'Date',

# DateTime
'datetime' => 'Datetime',
'timestamp' => 'Datetime',
'timestamp without time zone' => 'Datetime',
'timestamp with time zone' => 'Datetime',

# Time
'time' => 'Time',
'time without time zone' => 'Time',
'time with time zone' => 'Time',

# Interval
'interval' => 'Interval',

# float
'float' => 'Float',
'real' => 'Float',
'double precision' => 'Float',
'double' => 'Float',

# Numeric
'numeric' => 'Numeric',
'decimal' => 'Numeric',
'dec' => 'Numeric',
'money' => 'Numeric',

# Blob
'blob' => 'Binary',
'bytea' => 'Binary',
'longblob' => 'Binary',

# Bit
'bit' => 'Bit',
'bit varying' => 'Bit',
}}

sub type_map {
my $class = shift;
my $type = shift;
return $class->_type_map_data->{$type};
}

1;
Loading