Python/SQLite 6

[Python] sqlite3 iterdump( ) - SQL 쿼리 형식으로 데이터베이스를 덤프

# 현재 DB를 SQL 쿼리 형식으로 리턴 import sqlite3 conn = sqlite3.connect(r'C:\Temp\test.db') cur = conn.cursor() for row in conn.iterdump(): print(row) ---------------------------------------------------------- BEGIN TRANSACTION; CREATE TABLE Score(nation, point); INSERT INTO "Score" VALUES('kr',90); INSERT INTO "Score" VALUES('jp',80); INSERT INTO "Score" VALUES('cn',85); INSERT INTO "Score" VALUES('cn',8..

Python/SQLite 2019.01.02

[Python] SQLite3 Cursor.executemany() - iterator를 이용한 레코드 추가

DOCS : https://docs.python.org/3/library/sqlite3.html?highlight=cur%20executemany#sqlite3.Cursor.executemany Cursor.execute를 이용한 레코드 입력 import sqlite3 conn = sqlite3.connect(':memory:') cur = conn.cursor() cur.execute('CREATE TABLE Score(nation, point)') cur.execute('INSERT INTO Score (nation, point) VALUES(?,?)',('kr',90)) cur.execute('INSERT INTO Score (nation, point) VALUES(?,?)',('jp',80)) c..

Python/SQLite 2018.05.18

[SQLite3] 내장 집계함수 (max, min, avg, sum)

DOCS : https://www.sqlite.org/lang_aggfunc.html 함수 설명 avg(x) 평균값 max(x) 최대값 min(x) 최소값 sum(x), total(x) 총합 abs(x) 절대값 count(x) Null이 아닌 튜플의 갯수 count(*) 조회결과 튜플의 갯수 lenth(x) 문자열의 길이 lower(x) 입력받은 문자열을 소문자 변환 upper(x) 입력받은 문자열을 대문자 변환 1. point 필드의 평균값, 최대값, 최소값 import sqlite3 conn = sqlite3.connect(':memory:') cur = conn.cursor() cur.execute('CREATE TABLE Score(nation, point)') value = (('kr',90),..

Python/SQLite 2018.05.18

[Python] API SQLite

디스크 기반의 가벼운 데이터 베이스이고, 속도도 빠르다. 자세한 특징은 홈페이지에 요약sqlite3 모듈은 'Gerhard Häring'에 작성되었고, DB-API 2.0 스펙을 따르는 인터페이스를 제공하는 모듈 - 소개 홈페이지 : http://www.sqlite.org/about.html- 파이썬 SQLite : https://docs.python.org/3/library/sqlite3.html?highlight=pysqlite SQLite API 사용 순서 작업 1 Connection Open 2 Curosr Open 3 Select / insert / update / delete 4 Curosr Close 5 Connection Close example.db 생성import sqlite3 conn..

Python/SQLite 2018.04.23