60 lines
2.5 KiB
Python
60 lines
2.5 KiB
Python
"""SQLite 읽기 시험 (test/sqlite_reader_test.dart) 의 시험 파일을 만든다: python tool/fixtures/make_sqlite_fixtures.py
|
|
X-plore 비교 5-1 ④ (관리자 지시 10/21). 앱은 SQLite 라이브러리 없이 파일 형식을 직접 읽으므로, 진짜 SQLite (파이썬 sqlite3) 가 만든
|
|
파일로 시험한다. 만든 파일은 test/fixtures/sqlite 에 두고 git 에 넣는다 (시험 때 파이썬이 없어도 되게).
|
|
- basic.db: 페이지 1024 바이트 · INTEGER PRIMARY KEY · 한글 · NULL · 음수 · 64비트 정수 · 실수 · BLOB · 넘친 페이지 (긴 글) ·
|
|
이상한 열 이름 · 제약 줄 · WITHOUT ROWID 테이블
|
|
- big.db: 2000 행 (안쪽 페이지가 여러 단계)
|
|
- utf16.db: UTF-16LE 인코딩
|
|
"""
|
|
import os
|
|
import sqlite3
|
|
|
|
OUT = os.path.join(os.path.dirname(__file__), '..', '..', 'test', 'fixtures', 'sqlite')
|
|
|
|
|
|
def fresh(name, encoding=None):
|
|
path = os.path.join(OUT, name)
|
|
if os.path.exists(path):
|
|
os.remove(path)
|
|
con = sqlite3.connect(path)
|
|
con.execute('PRAGMA page_size = 1024')
|
|
if encoding:
|
|
con.execute("PRAGMA encoding = '%s'" % encoding)
|
|
con.execute('PRAGMA journal_mode = DELETE')
|
|
return con
|
|
|
|
|
|
def main():
|
|
os.makedirs(OUT, exist_ok=True)
|
|
|
|
con = fresh('basic.db')
|
|
con.execute('CREATE TABLE people (id INTEGER PRIMARY KEY, name TEXT, age INTEGER, score REAL, photo BLOB, note TEXT)')
|
|
con.executemany('INSERT INTO people VALUES (?, ?, ?, ?, ?, ?)', [
|
|
(1, '홍길동', 30, 91.5, b'\x00\x01\x02', None),
|
|
(2, 'Alice', -5, -0.25, None, 'x' * 5000),
|
|
(5, '日本語', 9007199254740993, 1e100, b'', 'short'),
|
|
(7, None, 0, 0.0, None, '줄\n바꿈'),
|
|
])
|
|
con.execute('CREATE TABLE "odd name" ("a b" TEXT, [c] INT, `d` INT, e INT DEFAULT (1+2), CONSTRAINT u UNIQUE (c))')
|
|
con.execute('INSERT INTO "odd name" VALUES (?, ?, ?, ?)', ('v', 1, 2, 3))
|
|
con.execute('CREATE TABLE kv (k TEXT PRIMARY KEY, v) WITHOUT ROWID')
|
|
con.execute("INSERT INTO kv VALUES ('a', 1)")
|
|
con.commit()
|
|
con.close()
|
|
|
|
con = fresh('big.db')
|
|
con.execute('CREATE TABLE t (id INTEGER PRIMARY KEY, label TEXT)')
|
|
con.executemany('INSERT INTO t VALUES (?, ?)', [(i, 'row %04d %s' % (i, 'y' * (i % 50))) for i in range(1, 2001)])
|
|
con.commit()
|
|
con.close()
|
|
|
|
con = fresh('utf16.db', 'UTF-16le')
|
|
con.execute('CREATE TABLE w (word TEXT)')
|
|
con.executemany('INSERT INTO w VALUES (?)', [('가나다',), ('abc',)])
|
|
con.commit()
|
|
con.close()
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|