sqlite command

在列模式下,每条记录在一个单独地行中以数据列对齐的方式显示。列如:

sqlite> .mode column

显示 列名.header on

查出所有的表:

select name from sqlite_master where type='table’ order by name;

通过以下语句可查询出某个表的所有字段信息

PRAGMA table_info([tablename])

cur.execute(“PRAGMA table_info(table)")

print cur.fetchall()

http://duduhehe.iteye.com/blog/1344858

http://www.cnblogs.com/riskyer/p/3333809.html

Go sqlite

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import (
    "database/sql"
    "fmt"
    _ "github.com/mattn/go-sqlite3"
    "rssx/utils/logger"
)

func test() {
    db, err := sql.Open("sqlite3", "./foo.db")
    checkErr(err)
    createTable := `CREATE TABLE if not exists users (
  id char(36) PRIMARY KEY NOT NULL,
  name varchar(50) DEFAULT NULL,
  create_time timestamp DEFAULT NULL
);
`
    r, err := db.Exec(createTable)
    checkErr(err)
    logger.Infof("%+v", r)
    stmt, err := db.Prepare("INSERT INTO `users` VALUES (?,?,?);")
    checkErr(err)
    res, err := stmt.Exec(0, "wiloon", "2017-12-07 22:10:49")
    checkErr(err)
    id, err := res.LastInsertId()
    checkErr(err)
    fmt.Println(id)
    db.Close()
}

func checkErr(err error) {
    if err != nil {
        logger.Errorf("err: %v", err)
    }
}


导出, export, dump, 导入, import, read

1
2
3
4
5
# export
sqlite3 db/boardsprofile.db ".dump" > /var/ftp/profile.sql

# import
sqlite3 test.db ".read /var/ftp/profile.sql"