sqlite3

Bash Shell Script

Getting Start

$ sqlite3 dev.db
SQLite version 3.0.8
Enter ".help" for instructions
sqlite> .quit

Create DB

$ sqlite3 dev.db  "create table tb_host (id INTEGER PRIMARY KEY,url TEXT,datetime DATE);"

Insert

$ sqlite3 dev.db "insert into tb_host (url,datetime) values ('http://www.google.com/','DATETIME('NOW','LOCALTIME'));"

Select

$ sqlite3 dev.db  "select * from tb_host;"

Python

Python 2.5 is a minimum requirement.

Start Connection

import sqlite3
conn = sqlite.connect('dev.db')

Create Cursor

c = conn.cursor()

Create Table

c.execute("create table tb_host (id INTEGER PRIMARY KEY,url TEXT,datetime DATE)")

Insert

c.execute("insert into tb_host (url,datetime) values ('http://www.google.com/','DATETIME('NOW','LOCALTIME'))")

Commit (save the changes)

conn.commit()

Close connections

conn.close()

References

 
sqlite.txt · Last modified: 2010/02/02 01:25 (external edit) · [Old revisions]
Recent changes RSS feed Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki