Phone: +65-8585-1750

Address: 30 Holland Close, Singapore

Some MySQL compatibility functions for sqlite

Mon, Jul 28, 2008 mdda OSS Blog Comments

Some MySQL compatibility functions for sqlite

Here are a couple of additional functions to increase interoperability between MySQL code and sqlite :

unless($dbh = DBI->connect("DBI:SQLite:dbname=$db_login{file}", "", "") ) {  
die "Cannot connect to database - version : ".$dbh->{sqlite_version};  
$dbh->func( 'UNIX_TIMESTAMP', 1, sub { return POSIX::mktime(POSIX::strptime($_[0], '%Y-%m-%d %H:%M:%S')); }, 'create_function' );  
$dbh->func( 'FROM_UNIXTIME', 1,  sub { return POSIX::strftime('%Y-%m-%d %H:%M:%S', localtime($_[0])); }, 'create_function' );  

to make this work, you’ll need to install the following packages from CPAN :


Also recommended : the SQLite Manager addon for Firefox.

mysql perl sqlite

blog comments powered by Disqus