Saturday, July 13, 2013

Unicode, Perl and SQLite database on Debian Linux

As shown below, the green line is the one for telling SQLite to use Unicode in perl. This is useful especially if I need to use Chinese, Korean, Japanese or other non-English characters.



#!/usr/bin/perl -w

# load module
use strict;
use utf8;
use encoding "utf-8";
use DBI;




    my $SQLiteDB = DBI->connect( "dbi:SQLite:dbname=myDB.db", "", "" );
     $SQLiteDB->{sqlite_unicode} = 1;
    my $x = '';


   my $sth =  $SQLiteDB->prepare("SELECT count(*) FROM TABLEX LIMIT 1");
    $sth->execute();

     while(my $ref = $sth->fetchrow_hashref()) {
       $x = $ref->{'count(*)'} ;
    } # while(my $ref = $sth->fetchrow_hashref())

No comments: