Changes between Version 1 and Version 2 of jazz/10-05-11


Ignore:
Timestamp:
May 11, 2010, 1:57:00 AM (14 years ago)
Author:
jazz
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • jazz/10-05-11

    v1 v2  
    44
    55 * [專案] 實作 Perl + SQLite
    6    * 環境: Debian 5.0.4 ,
     6   * [參考] [http://mailliststock.wordpress.com/2007/03/01/sqlite-examples-with-bash-perl-and-python/ SQLite examples with Bash, Perl and Python] (2007-03-01)
     7   * 環境: Debian 5.0.4 , amd64 核心
    78{{{
    89jazz@drbl:~$ lsb_release -a
     
    2324ii  sqlite3                          3.5.9-6                        A command line interface for SQLite 3
    2425}}}
     26    * 使用範例程式建立 test.db
     27{{{
     28jazz@drbl:~$ vi perlsqlite3.pl
     29jazz@drbl:~$ chmod a+x perlsqlite3.pl
     30jazz@drbl:~$ ./perlsqlite3.pl
     31jazz@drbl:~$ file test.db
     32test.db: SQLite 3.x database
     33jazz@drbl:~$ sqlite3 test.db "select * from n"
     341|john|smith
     35}}}
     36{{{
     37#!perl
     38#!/usr/bin/perl -w
     39use DBI;
     40use strict;
     41my $db = DBI->connect("dbi:SQLite:test.db", "", "",
     42{RaiseError => 1, AutoCommit => 1});
     43
     44$db->do("CREATE TABLE n (id INTEGER PRIMARY KEY, f TEXT, l TEXT)");
     45$db->do("INSERT INTO n VALUES (NULL, 'john', 'smith')");
     46my $all = $db->selectall_arrayref("SELECT * FROM n");
     47
     48foreach my $row (@$all) {
     49my ($id, $first, $last) = @$row;
     50print "$id|$first|$last";
     51}
     52}}}