[Bps-public-commit] r17274 - Prophet/branches/sqlite/lib/Prophet/Replica

sunnavy at bestpractical.com sunnavy at bestpractical.com
Wed Dec 17 07:59:39 EST 2008


Author: sunnavy
Date: Wed Dec 17 07:59:38 2008
New Revision: 17274

Modified:
   Prophet/branches/sqlite/lib/Prophet/Replica/sqlite.pm

Log:
add record_type to changes table

Modified: Prophet/branches/sqlite/lib/Prophet/Replica/sqlite.pm
==============================================================================
--- Prophet/branches/sqlite/lib/Prophet/Replica/sqlite.pm	(original)
+++ Prophet/branches/sqlite/lib/Prophet/Replica/sqlite.pm	Wed Dec 17 07:59:38 2008
@@ -240,7 +240,8 @@
     id INTEGER PRIMARY KEY AUTOINCREMENT,
     record text,
     changeset integer, 
-    change_type text
+    change_type text,
+    record_type text
 )
 }, q{
 CREATE TABLE prop_changes (
@@ -276,7 +277,7 @@
 
     my $sth = $self->dbh->prepare("SELECT MAX(sequence_no) FROM changesets");
     $sth->execute();
-    return $sth->fetchrow_array;
+    return $sth->fetchrow_array || 0;
 }
 
 =head2 uuid
@@ -437,13 +438,11 @@
     my $changeset = Prophet::ChangeSet->new(%$data, source_uuid => $self->uuid );
 
     
-    my $sth = $self->dbh->prepare("SELECT id, record, change_type from changes WHERE changeset = ?");
+    my $sth = $self->dbh->prepare("SELECT id, record, change_type, record_type from changes WHERE changeset = ?");
     $sth->execute($changeset->sequence_no);
     while (my $row = $sth->fetchrow_hashref) {
         my $change_id = delete $row->{id};
-        my $record_sth = $self->dbh->prepare("SELECT type FROM records WHERE uuid = ?");
-        $record_sth->execute( $row->{record} );
-        my $record_type = $record_sth->fetchrow_array() || '';
+        my $record_type = delete $row->{record_type};
 
         my $change = Prophet::Change->new( record_uuid => $row->{record},
                 change_type => $row->{change_type}, record_type => $record_type );
@@ -530,7 +529,11 @@
     my $change = shift;
     my $changeset_id = shift;
 
-    $self->dbh->do("INSERT INTO changes (record, changeset, change_type) VALUES (?,?,?)", {}, $change->record_uuid, $changeset_id, $change->change_type);
+    $self->dbh->do(
+        "INSERT INTO changes (record, changeset, change_type,
+        record_type) VALUES (?,?,?,?)", {}, $change->record_uuid, $changeset_id,
+        $change->change_type, $change->record_type
+    );
     my $change_id = $self->dbh->last_insert_id(undef, undef, 'changes', 'id');
     for my $pc (@{$change->prop_changes}) {
         $self->_write_prop_change_to_db($change_id, $pc);



More information about the Bps-public-commit mailing list