Showing 8 changed files with 65 additions and 41 deletions
+2
Changes
... ...
@@ -1,3 +1,5 @@
1
+0.1683
2
+    - data_source is DEPRECATED! It is renamed to dsn
1 3
 0.1682
2 4
     - improved debug message
3 5
     - fixed merge_param bug
+18 -16
lib/DBIx/Custom.pm
... ...
@@ -1,6 +1,6 @@
1 1
 package DBIx::Custom;
2 2
 
3
-our $VERSION = '0.1682';
3
+our $VERSION = '0.1683';
4 4
 
5 5
 use 5.008001;
6 6
 use strict;
... ...
@@ -25,7 +25,7 @@ use constant DEBUG_ENCODING => $ENV{DBIX_CUSTOM_DEBUG_ENCODING} || 'UTF-8';
25 25
 our @COMMON_ARGS = qw/table query filter type/;
26 26
 
27 27
 __PACKAGE__->attr(
28
-    [qw/connector data_source password pid user/],
28
+    [qw/connector dsn password user/],
29 29
     cache => 0,
30 30
     cache_method => sub {
31 31
         sub {
... ...
@@ -192,9 +192,6 @@ sub connect {
192 192
     # Connect
193 193
     $self->dbh;
194 194
     
195
-    # Set process ID
196
-    $self->pid($$);
197
-    
198 195
     return $self;
199 196
 }
200 197
 
... ...
@@ -1209,16 +1206,16 @@ sub _connect {
1209 1206
     my $self = shift;
1210 1207
     
1211 1208
     # Attributes
1212
-    my $data_source = $self->data_source;
1213
-    croak qq{"data_source" must be specified } . _subname
1214
-      unless $data_source;
1209
+    my $dsn = $self->data_source || $self->dsn;
1210
+    croak qq{"dsn" must be specified } . _subname
1211
+      unless $dsn;
1215 1212
     my $user        = $self->user;
1216 1213
     my $password    = $self->password;
1217 1214
     my $dbi_option = {%{$self->dbi_options}, %{$self->dbi_option}};
1218 1215
     
1219 1216
     # Connect
1220 1217
     my $dbh = eval {DBI->connect(
1221
-        $data_source,
1218
+        $dsn,
1222 1219
         $user,
1223 1220
         $password,
1224 1221
         {
... ...
@@ -1375,6 +1372,9 @@ sub _where_to_obj {
1375 1372
     return $obj;
1376 1373
 }
1377 1374
 
1375
+# DEPRECATED!
1376
+__PACKAGE__->attr('data_source');
1377
+
1378 1378
 # DEPRECATED!
1379 1379
 __PACKAGE__->attr(
1380 1380
     dbi_options => sub { {} },
... ...
@@ -1492,7 +1492,7 @@ DBIx::Custom - Useful database access, respecting SQL!
1492 1492
     
1493 1493
     # Connect
1494 1494
     my $dbi = DBIx::Custom->connect(
1495
-        data_source => "dbi:mysql:database=dbname",
1495
+        dsn => "dbi:mysql:database=dbname",
1496 1496
         user => 'ken',
1497 1497
         password => '!LFKD%$&',
1498 1498
         dbi_option => {mysql_enable_utf8 => 1}
... ...
@@ -1619,12 +1619,14 @@ C<default_dbi_option> to L<DBIx::Connector>.
1619 1619
     
1620 1620
     my $dbi = DBIx::Custom->new(connector => $connector);
1621 1621
 
1622
-=head2 C<data_source>
1622
+=head2 C<dsn>
1623
+
1624
+    my $dsn = $dbi->dsn;
1625
+    $dbi    = $dbi->dsn("DBI:mysql:database=dbname");
1623 1626
 
1624
-    my $data_source = $dbi->data_source;
1625
-    $dbi            = $dbi->data_source("DBI:mysql:database=dbname");
1627
+Data source name, used when C<connect()> is executed.
1626 1628
 
1627
-Data source, used when C<connect()> is executed.
1629
+C<data_source> is DEPRECATED! It is renamed to C<dsn>.
1628 1630
 
1629 1631
 =head2 C<dbi_option>
1630 1632
 
... ...
@@ -1769,7 +1771,7 @@ This is equal to C<update_param_tag> exept that set is not added.
1769 1771
 =head2 C<connect>
1770 1772
 
1771 1773
     my $dbi = DBIx::Custom->connect(
1772
-        data_source => "dbi:mysql:database=dbname",
1774
+        dsn => "dbi:mysql:database=dbname",
1773 1775
         user => 'ken',
1774 1776
         password => '!LFKD%$&',
1775 1777
         dbi_option => {mysql_enable_utf8 => 1}
... ...
@@ -2297,7 +2299,7 @@ Create column clause for myself. The follwoing column clause is created.
2297 2299
 =head2 C<new>
2298 2300
 
2299 2301
     my $dbi = DBIx::Custom->new(
2300
-        data_source => "dbi:mysql:database=dbname",
2302
+        dsn => "dbi:mysql:database=dbname",
2301 2303
         user => 'ken',
2302 2304
         password => '!LFKD%$&',
2303 2305
         dbi_option => {mysql_enable_utf8 => 1}
+7 -7
lib/DBIx/Custom/Guide.pod
... ...
@@ -162,13 +162,13 @@ use C<connect()> to connect to database.
162 162
 Return value is L<DBIx::Custom> object.
163 163
 
164 164
     my $dbi = DBIx::Custom->connect(
165
-        data_source => "dbi:mysql:database=bookstore",
165
+        dsn => "dbi:mysql:database=bookstore",
166 166
         user => 'ken',
167 167
         password => '!LFKD%$&',
168 168
         dbi_options => {mysql_enable_utf8 => 1}
169 169
     );
170 170
 
171
-C<data_source> must be one corresponding to the database system.
171
+C<dsn> must be one corresponding to the database system.
172 172
 The following ones are data source example.
173 173
 
174 174
 B<MySQL>
... ...
@@ -1018,7 +1018,7 @@ You can pass L<DBIx::Custom::Where> object to C<where> of C<select()>.
1018 1018
     $where->param({title => 'Perl'});
1019 1019
     my $result = $dbi->select(table => 'book', where => $where);
1020 1020
 
1021
-You can also pass it to C<where> of C<update()>�AC<delete()>
1021
+You can also pass it to C<where> of C<update()>AC<delete()>
1022 1022
 
1023 1023
 =head3 With C<execute()>
1024 1024
 
... ...
@@ -1093,7 +1093,7 @@ without C<table> option.
1093 1093
 
1094 1094
 Model is L<DBIx::Custom::Model>.
1095 1095
 
1096
-If you need table name�Ayou can get it by C<table()>.
1096
+If you need table nameAyou can get it by C<table()>.
1097 1097
 
1098 1098
     my $table = $model->table;
1099 1099
 
... ...
@@ -1186,7 +1186,7 @@ Valude of C<table> and C<columns> is used.
1186 1186
 
1187 1187
     my $column_clause = $model->mycolumn;
1188 1188
 
1189
-If C<table> is 'book'�AC<column> is ['id', 'name'],
1189
+If C<table> is 'book'AC<column> is ['id', 'name'],
1190 1190
 the following clause is created.
1191 1191
 
1192 1192
     book.id as id, book.name as name
... ...
@@ -1197,7 +1197,7 @@ You can create column clause from columns of other table.
1197 1197
 
1198 1198
     my $column_clause = $model->column('company');
1199 1199
 
1200
-If C<table> is 'company'�AC<column> is ['id', 'name'],
1200
+If C<table> is 'company'AC<column> is ['id', 'name'],
1201 1201
 the following clause is created.
1202 1202
 
1203 1203
     company.id as company__id, company.name as company__name
... ...
@@ -1209,7 +1209,7 @@ Valude of C<table> and C<columns> is used.
1209 1209
 
1210 1210
     my $column_clause = $model->column_clause;
1211 1211
 
1212
-If C<table> is 'book'�AC<column> is ['id', 'name'],
1212
+If C<table> is 'book'AC<column> is ['id', 'name'],
1213 1213
 the following clause is created.
1214 1214
 
1215 1215
     book.id as id, book.name as name
+2 -2
lib/DBIx/Custom/Guide/Ja.pod
... ...
@@ -170,13 +170,13 @@ L<DBIx::Custom>を読み込みます。
170 170
 戻り値はL<DBIx::Custom>オブジェクトです。
171 171
 
172 172
     my $dbi = DBIx::Custom->connect(
173
-        data_source => "dbi:mysql:database=bookstore",
173
+        dsn => "dbi:mysql:database=bookstore",
174 174
         user => 'ken',
175 175
         password => '!LFKD%$&',
176 176
         dbi_options => {mysql_enable_utf8 => 1}
177 177
     );
178 178
 
179
-C<data_source>はデータベースシステムに応じたものである必要があります。
179
+C<dsn>はデータベースシステムに応じたものである必要があります。
180 180
 以下はデータソースのサンプルです。
181 181
 
182 182
 B<MySQL>
+2 -2
t/dbix-custom-core-mysql-private.t
... ...
@@ -15,7 +15,7 @@ use Scalar::Util 'blessed';
15 15
     my $dbi = DBIx::Custom->connect(
16 16
         user => $USER,
17 17
         password => $PASSWORD,
18
-        data_source => "dbi:mysql:dbname=$DATABASE"
18
+        dsn => "dbi:mysql:dbname=$DATABASE"
19 19
     );
20 20
     $dbi->connect;
21 21
     
... ...
@@ -29,7 +29,7 @@ use Scalar::Util 'blessed';
29 29
     my $dbi = DBIx::Custom->connect(
30 30
         user => $USER,
31 31
         password => $PASSWORD,
32
-        data_source => "dbi:mysql:dbname=$DATABASE",
32
+        dsn => "dbi:mysql:dbname=$DATABASE",
33 33
         dbi_options => {AutoCommit => 0, mysql_enable_utf8 => 1}
34 34
     );
35 35
     $dbi->connect;
+24 -4
t/dbix-custom-core-sqlite.t
... ...
@@ -42,7 +42,7 @@ my $DROP_TABLE = {
42 42
 };
43 43
 
44 44
 my $NEW_ARGS = {
45
-    0 => {data_source => 'dbi:SQLite:dbname=:memory:'}
45
+    0 => {dsn => 'dbi:SQLite:dbname=:memory:'}
46 46
 };
47 47
 
48 48
 # Variables
... ...
@@ -205,7 +205,7 @@ is_deeply($rows, [{key1 => 1, key2 => 1, key3 => 1, key4 => 1, key5 => 5},
205 205
                   {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}], "basic");
206 206
 
207 207
 test 'Error case';
208
-eval {DBIx::Custom->connect(data_source => 'dbi:SQLit')};
208
+eval {DBIx::Custom->connect(dsn => 'dbi:SQLit')};
209 209
 ok($@, "connect error");
210 210
 
211 211
 $dbi = DBIx::Custom->connect($NEW_ARGS->{0});
... ...
@@ -1371,10 +1371,10 @@ $result->default_filter('one');
1371 1371
 is($result->default_filter->(), 1);
1372 1372
 
1373 1373
 test 'dbi_option';
1374
-$dbi = DBIx::Custom->connect(data_source => 'dbi:SQLite:dbname=:memory:',
1374
+$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:',
1375 1375
                              dbi_option => {PrintError => 1});
1376 1376
 ok($dbi->dbh->{PrintError});
1377
-$dbi = DBIx::Custom->connect(data_source => 'dbi:SQLite:dbname=:memory:',
1377
+$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:',
1378 1378
                              dbi_options => {PrintError => 1});
1379 1379
 ok($dbi->dbh->{PrintError});
1380 1380
 
... ...
@@ -1991,6 +1991,26 @@ is_deeply($rows, [{table1_key1 => 1, table2_key1 => 1, key2 => 2, key3 => 5}],
1991 1991
     }
1992 1992
 }
1993 1993
 
1994
+$dbi = DBIx::Custom->connect($NEW_ARGS->{0});
1995
+$dbi->execute($CREATE_TABLE->{0});
1996
+$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
1997
+$sql = <<"EOS";
1998
+left outer join (
1999
+  select * from table1 as t1
2000
+  where t1.key2 = (
2001
+    select max(t2.key2) from table1 as t2
2002
+    where t1.key1 = t2.key1
2003
+  )
2004
+) as latest_table1 on table1.key1 = latest_table1.key1
2005
+EOS
2006
+$join = [$sql];
2007
+$rows = $dbi->select(
2008
+    table => 'table1',
2009
+    column => 'latest_table1.key1 as latest_table1__key1',
2010
+    join  => $join
2011
+)->fetch_hash_all;
2012
+is_deeply($rows, [{latest_table1__key1 => 1}]);
2013
+
1994 2014
 test 'mycolumn';
1995 2015
 $dbi = MyDBI8->connect($NEW_ARGS->{0});
1996 2016
 $dbi->execute($CREATE_TABLE->{0});
+2 -2
t/dbix-custom-core.t
... ...
@@ -18,7 +18,7 @@ $query_builder = DBIx::Custom::QueryBuilder->new;
18 18
 $dbi = DBIx::Custom->new(
19 19
     user => 'a',
20 20
     password => 'b',
21
-    data_source => 'c',
21
+    dsn => 'c',
22 22
     filters => {
23 23
         f => 3,
24 24
     },
... ...
@@ -27,7 +27,7 @@ $dbi = DBIx::Custom->new(
27 27
     result_class => 'g',
28 28
     query_builder => $query_builder,
29 29
 );
30
-is_deeply($dbi,{user => 'a', password => 'b', data_source => 'c', 
30
+is_deeply($dbi,{user => 'a', password => 'b', dsn => 'c', 
31 31
                 filters => {f => 3}, default_bind_filter => 'f',
32 32
                 default_fetch_filter => 'g', result_class => 'g',
33 33
                 query_builder => $query_builder});
+8 -8
t/dbix-custom-mysql-private.t
... ...
@@ -51,15 +51,15 @@ my $result;
51 51
         my $self = ref $proto ? $proto : $proto->new(@_);
52 52
         
53 53
         # Data source
54
-        if (!$self->data_source) {
54
+        if (!$self->dsn) {
55 55
             my $database = $self->database;
56 56
             my $host     = $self->host;
57 57
             my $port     = $self->port;
58
-            my $data_source = "dbi:mysql:";
59
-            $data_source .= "database=$database;" if $database;
60
-            $data_source .= "host=$host;"         if $host;
61
-            $data_source .= "port=$port;"         if $port;
62
-            $self->data_source($data_source);
58
+            my $dsn = "dbi:mysql:";
59
+            $dsn .= "database=$database;" if $database;
60
+            $dsn .= "host=$host;"         if $host;
61
+            $dsn .= "port=$port;"         if $port;
62
+            $self->dsn($dsn);
63 63
         }
64 64
         
65 65
         return $self->SUPER::connect;
... ...
@@ -72,7 +72,7 @@ test 'connect';
72 72
 $dbi = DBIx::Custom::MySQL->new(user => $USER, password => $PASSWORD,
73 73
                     database => $DATABASE, host => 'localhost', port => '10000');
74 74
 $dbi->connect;
75
-like($dbi->data_source, qr/dbi:mysql:database=.*;host=localhost;port=10000;/, "created data source");
75
+like($dbi->dsn, qr/dbi:mysql:database=.*;host=localhost;port=10000;/, "created data source");
76 76
 is(ref $dbi->dbh, 'DBI::db');
77 77
 
78 78
 test 'attributes';
... ...
@@ -84,7 +84,7 @@ is($dbi->port, 'b', "port");
84 84
 
85 85
 test 'limit';
86 86
 $dbi = DBIx::Custom->connect(
87
-    data_source => "dbi:mysql:database=$DATABASE",
87
+    dsn => "dbi:mysql:database=$DATABASE",
88 88
     user => $USER,
89 89
     password => $PASSWORD
90 90
 );