Perl

For using litereplica with Perl we must do 2 things:

1. Replace the pre-installed SQLite library with the one we compiled containing the litereplica.

2. Compile the DBD:SQLite to use the installed SQLite module:


Linux

wget http://search.cpan.org/CPAN/authors/id/I/IS/ISHIGAKI/DBD-SQLite-1.54.tar.gz

tar zxvf DBD-SQLite-1.54.tar.gz

cd DBD-SQLite-1.54

sed -i 's/if ( 0 ) {/if ( 1 ) {/g' Makefile.PL

perl Makefile.PL USE_LOCAL_SQLITE=0 SQLITE_LOCATION=/usr

make

sudo make install


Windows

To do


Usage

Then we can use the DBI / DBD:SQLite module normally, passing a special URI.

Example code:

use DBI;

my $dbh = DBI->connect("dbi:SQLite:uri=file:data.db?replica=master&slave=tcp://server:port")

$dbh->do('CREATE TABLE t1 (id, name)');

$dbh->do('INSERT INTO t1 VALUES (1, "Hello World!")');

# wait for the new data to be replicated - only needed if the app will be closed

sleep(5);

print "done\n";