Skip to content

Commit

Permalink
unixtimeをとれるようにした
Browse files Browse the repository at this point in the history
dbdにアクセスできるようにした
updateの挙動かえた(まだ微調整)

git-svn-id: http://svn.coderepos.org/share/lang/perl/DBIx-Skinny/trunk@28863 d0d07461-0603-4401-acd4-de1884942a52
  • Loading branch information
nekokak committed Jan 22, 2009
1 parent 27742d8 commit e9f215a
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 23 deletions.
16 changes: 6 additions & 10 deletions lib/DBIx/Skinny.pm
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ sub import {

my @functions = qw/
schema profiler
dbh _connect connect_info _dbd_type
dbh dbd _connect connect_info _dbd_type
call_schema_trigger
do resultset search single search_by_sql count
data2itr find_or_new
Expand Down Expand Up @@ -94,6 +94,7 @@ sub _connect {
$class->attribute->{dbh};
}

sub dbd { shift->attribute->{dbd} }
sub dbh { shift->_connect }

sub _dbd_type {
Expand Down Expand Up @@ -315,17 +316,12 @@ sub update {
my $sql = "UPDATE $table SET " . join(', ', @set) . ' ' . $stmt->as_sql_where;

$class->profiler($sql, \@bind);
$class->_execute($sql, \@bind);
my $sth = $class->dbh->prepare($sql);
my $rows = $sth->execute(@bind);

for my $col (@{$class->schema->schema_info->{$table}->{columns}}) {
$stmt->add_select($col);
}
$stmt->from([$table]);
my $row = $stmt->retrieve->first;

$class->call_schema_trigger('post_update', $table, $row);
$class->call_schema_trigger('post_update', $table, $rows);

return $row;
return $rows;
}

sub delete {
Expand Down
2 changes: 2 additions & 0 deletions lib/DBIx/Skinny/DBD/SQLite.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use warnings;

sub last_insert_id { $_[1]->func('last_insert_rowid') }

sub sql_for_unixtime { return time() }

sub bulk_insert {
my ($skinny, $table, $args) = @_;

Expand Down
4 changes: 4 additions & 0 deletions lib/DBIx/Skinny/DBD/mysql.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ use warnings;

sub last_insert_id { $_[2]->{mysql_insertid} || $_[2]->{insertid} }

sub sql_for_unixtime {
return "UNIX_TIMESTAMP()";
}

sub bulk_insert {
my ($skinny, $table, $args) = @_;

Expand Down
8 changes: 5 additions & 3 deletions t/102_update.t
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ describe 'update test' => run {
};

test 'update mock_basic data' => run {
my $row = Mock::Basic->update('mock_basic',{name => 'python'},{id => 1});
ok +Mock::Basic->update('mock_basic',{name => 'python'},{id => 1});
my $row = Mock::Basic->single('mock_basic',{id => 1});

isa_ok $row, 'DBIx::Skinny::Row';
is $row->name, 'python';
Expand All @@ -28,8 +29,9 @@ describe 'update test' => run {
my $row = Mock::Basic->single('mock_basic',{id => 1});
is $row->name, 'python';

$row = $row->update({name => 'perl'});
is $row->name, 'perl';
ok $row->update({name => 'perl'});
my $new_row = Mock::Basic->single('mock_basic',{id => 1});
is $new_row->name, 'perl';
};
};

3 changes: 2 additions & 1 deletion t/106_inflate.t
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ describe 'inflate/deflate test' => run {
test 'update mock_inflate data' => run {
my $name = Mock::Inflate::Name->new(name => 'ruby');

my $row = Mock::Inflate->update('mock_inflate',{name => $name},{id => 1});
ok +Mock::Inflate->update('mock_inflate',{name => $name},{id => 1});
my $row = Mock::Inflate->single('mock_inflate',{id => 1});

isa_ok $row, 'DBIx::Skinny::Row';
isa_ok $row->name, 'Mock::Inflate::Name';
Expand Down
3 changes: 2 additions & 1 deletion t/107_utf8.t
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ describe 'utf8 test' => run {
};

test 'update mock_utf8 data' => run {
my $row = Mock::UTF8->update('mock_utf8',{name => 'るびー'},{id => 1});
ok +Mock::UTF8->update('mock_utf8',{name => 'るびー'},{id => 1});
my $row = Mock::UTF8->single('mock_utf8',{id => 1});

isa_ok $row, 'DBIx::Skinny::Row';
ok utf8::is_utf8($row->name);
Expand Down
5 changes: 2 additions & 3 deletions t/108_trigger.t
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,12 @@ describe 'trigger test' => run {
};

test 'pre_update/post_update' => run {
my $row = Mock::Trigger->update('mock_trigger_pre',{});
isa_ok $row, 'DBIx::Skinny::Row';
is $row->name, 'pre_update';
ok +Mock::Trigger->update('mock_trigger_pre',{});

my $p_row = Mock::Trigger->single('mock_trigger_post',{id => 1});
isa_ok $p_row, 'DBIx::Skinny::Row';
is $p_row->name, 'post_update';

};

test 'pre_delete/post_delete' => run {
Expand Down
6 changes: 1 addition & 5 deletions t/117_data2row.t
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,7 @@ describe 'data to iterator object' => run {
isa_ok $row->name, 'Mock::Inflate::Name';

my $new_name = Mock::Inflate::Name->new(name => 'c++');
my $new_row = $row->update({name => $new_name});

isa_ok $new_row, 'DBIx::Skinny::Row';
isa_ok $new_row->name, 'Mock::Inflate::Name';
is $new_row->name, 'c++';
ok $row->update({name => $new_name});
};
};

0 comments on commit e9f215a

Please sign in to comment.