| ... | ... |
@@ -1,3 +1,5 @@ |
| 1 |
+0.1676 |
|
| 2 |
+ - fixed test bug |
|
| 1 | 3 |
0.1675 |
| 2 | 4 |
- removed DEPRECATED DBIx::Custom::MySQL and DBIx::Custom::SQLite |
| 3 | 5 |
these implementations remine in https://github.com/yuki-kimoto/DBIx-Custom/wiki |
| ... | ... |
@@ -1,6 +1,6 @@ |
| 1 | 1 |
package DBIx::Custom; |
| 2 | 2 |
|
| 3 |
-our $VERSION = '0.1675'; |
|
| 3 |
+our $VERSION = '0.1676'; |
|
| 4 | 4 |
|
| 5 | 5 |
use 5.008001; |
| 6 | 6 |
use strict; |
| ... | ... |
@@ -34,8 +34,39 @@ my $dbname; |
| 34 | 34 |
my $rows; |
| 35 | 35 |
my $result; |
| 36 | 36 |
|
| 37 |
-# Constant varialbes for test |
|
| 38 |
-use DBIx::Custom::MySQL; |
|
| 37 |
+{
|
|
| 38 |
+ package DBIx::Custom::MySQL; |
|
| 39 |
+ |
|
| 40 |
+ use strict; |
|
| 41 |
+ use warnings; |
|
| 42 |
+ |
|
| 43 |
+ use base 'DBIx::Custom'; |
|
| 44 |
+ |
|
| 45 |
+ __PACKAGE__->attr([qw/database host port/]); |
|
| 46 |
+ |
|
| 47 |
+ sub connect {
|
|
| 48 |
+ my $proto = shift; |
|
| 49 |
+ |
|
| 50 |
+ # Create a new object |
|
| 51 |
+ my $self = ref $proto ? $proto : $proto->new(@_); |
|
| 52 |
+ |
|
| 53 |
+ # Data source |
|
| 54 |
+ if (!$self->data_source) {
|
|
| 55 |
+ my $database = $self->database; |
|
| 56 |
+ my $host = $self->host; |
|
| 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); |
|
| 63 |
+ } |
|
| 64 |
+ |
|
| 65 |
+ return $self->SUPER::connect; |
|
| 66 |
+ } |
|
| 67 |
+ |
|
| 68 |
+ 1; |
|
| 69 |
+} |
|
| 39 | 70 |
|
| 40 | 71 |
test 'connect'; |
| 41 | 72 |
$dbi = DBIx::Custom::MySQL->new(user => $USER, password => $PASSWORD, |
| ... | ... |
@@ -1,58 +0,0 @@ |
| 1 |
-use Test::More; |
|
| 2 |
-use strict; |
|
| 3 |
-use warnings; |
|
| 4 |
-use utf8; |
|
| 5 |
- |
|
| 6 |
-BEGIN {
|
|
| 7 |
- eval { require DBD::SQLite; 1 }
|
|
| 8 |
- or plan skip_all => 'DBD::SQLite required'; |
|
| 9 |
- eval { DBD::SQLite->VERSION >= 1.25 }
|
|
| 10 |
- or plan skip_all => 'DBD::SQLite >= 1.25 required'; |
|
| 11 |
- |
|
| 12 |
- plan 'no_plan'; |
|
| 13 |
- use_ok('DBIx::Custom::SQLite');
|
|
| 14 |
-} |
|
| 15 |
- |
|
| 16 |
-# Function for test name |
|
| 17 |
-sub test { print "# $_[0]\n" }
|
|
| 18 |
- |
|
| 19 |
-# Constant varialbes for test |
|
| 20 |
-my $CREATE_TABLE = {
|
|
| 21 |
- 0 => 'create table table1 (key1 char(255), key2 char(255));', |
|
| 22 |
- 1 => 'create table table1 (key1 char(255), key2 char(255), key3 char(255), key4 char(255), key5 char(255));', |
|
| 23 |
- 2 => 'create table table2 (key1 char(255), key3 char(255));' |
|
| 24 |
-}; |
|
| 25 |
- |
|
| 26 |
- |
|
| 27 |
-# Variables for tests |
|
| 28 |
-my $dbi; |
|
| 29 |
-my $ret_val; |
|
| 30 |
-my $rows; |
|
| 31 |
-my $db_file; |
|
| 32 |
-my $id; |
|
| 33 |
- |
|
| 34 |
-test 'connect_memory'; |
|
| 35 |
-$dbi = DBIx::Custom::SQLite->connect_memory; |
|
| 36 |
-$ret_val = $dbi->execute($CREATE_TABLE->{0});
|
|
| 37 |
-ok(defined $ret_val); |
|
| 38 |
-$dbi->insert(table => 'table1', param => {key1 => 'a', key2 => 2});
|
|
| 39 |
-$rows = $dbi->select(table => 'table1', where => {key1 => 'a'})->fetch_hash_all;
|
|
| 40 |
-is_deeply($rows, [{key1 => 'a', key2 => 2}], "select rows");
|
|
| 41 |
- |
|
| 42 |
-test 'connect'; |
|
| 43 |
-$db_file = 't/test.db'; |
|
| 44 |
-unlink $db_file if -f $db_file; |
|
| 45 |
-$dbi = DBIx::Custom::SQLite->new(database => $db_file); |
|
| 46 |
-$dbi->connect; |
|
| 47 |
-ok(-f $db_file, "database file"); |
|
| 48 |
-$ret_val = $dbi->execute($CREATE_TABLE->{0});
|
|
| 49 |
-ok(defined $ret_val, "database"); |
|
| 50 |
-$dbi->dbh->disconnect; |
|
| 51 |
- |
|
| 52 |
-unlink $db_file if -f $db_file; |
|
| 53 |
-$dbi = DBIx::Custom::SQLite->connect(database => $db_file); |
|
| 54 |
-ok($dbi, "called from class name"); |
|
| 55 |
- |
|
| 56 |
-unlink $db_file if -f $db_file; |
|
| 57 |
-$dbi = DBIx::Custom::SQLite->connect(data_source => "dbi:SQLite:dbname=$db_file"); |
|
| 58 |
-ok($dbi, "specified data source"); |