Changes between Version 17 and Version 18 of jazz/10-05-11


Ignore:
Timestamp:
May 11, 2010, 7:27:06 PM (14 years ago)
Author:
jazz
Comment:

--

Legend:

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

    v17 v18  
    149149== Python + SQLite3 ==
    150150
     151 * [參考] [http://mailliststock.wordpress.com/2007/03/01/sqlite-examples-with-bash-perl-and-python/ SQLite examples with Bash, Perl and Python] (2007-03-01)
     152 * 環境: Debian 5.0.4 , amd64 核心
     153{{{
     154jazz@drbl:~$ lsb_release -a
     155No LSB modules are available.
     156Distributor ID: Debian
     157Description:    Debian GNU/Linux 5.0.4 (lenny)
     158Release:        5.0.4
     159Codename:       lenny
     160jazz@drbl:~$ uname -a
     161Linux drbl 2.6.26-lustre-amd64 #1 SMP Sun Jun 28 18:28:02 CST 2009 x86_64 GNU/Linux
     162}}}
     163 * 相關套件: [http://packages.debian.org/sqlite3 sqlite3],[http://packages.debian.org/python-pysqlite2 python-pysqlite2]
     164{{{
     165jazz@drbl:~$ sudo apt-get install python-pysqlite2 sqlite3
     166jazz@drbl:~$ dpkg -l | grep sqlite
     167ii  python-pysqlite2                 2.4.1-1                        Python interface to SQLite 3
     168ii  sqlite3                          3.5.9-6                        A command line interface for SQLite 3
     169}}}
     170 * 使用範例程式建立 test.db
     171{{{
     172jazz@drbl:~$ vi pythonsqlite.py
     173jazz@drbl:~$ chmod a+x pythonsqlite.py
     174jazz@drbl:~$ ./pythonsqlite.py
     175jazz@drbl:~$ file test.db
     176test.db: SQLite 3.x database
     177jazz@drbl:~$ sqlite3 test.db "select * from n"
     1781|john|smith
     179}}}
     180{{{
     181#!python
     182#!/usr/bin/python
     183from pysqlite2 import dbapi2 as sqlite
     184
     185db = sqlite.connect('test.db')
     186cur = db.cursor()
     187cur.execute('CREATE TABLE n (id INTEGER PRIMARY KEY, f TEXT, l TEXT)')
     188db.commit()
     189cur.execute('INSERT INTO n (id, f, l) VALUES(NULL, "john", "smith")')
     190db.commit()
     191cur.execute('SELECT * FROM n')
     192print cur.fetchall()
     193}}}
    151194
    152195== Open Hardware ==