Skip to content

Commit

Permalink
[SQLite] 스크립트 내용을 트랜잭션에 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
hyunmin94 committed May 31, 2020
1 parent c4fa2fa commit acc3e30
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions SQLite/scriptMemoryExam.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import sqlite3

try:
conn = sqlite3.connect(':memory:')
cur = conn.cursor()

# 스크립트 파일 불러오기
f = open('C:\\DBExam\SQLiteExam\scriptFile.sql', encoding='cp949')
# 스크립트 내용 불러오기
script = f.read()
# 스크립트 내용 실행
cur.executescript(script)
# 스크립트의 테이블(phonebook) 데이터 조회
cur.execute('select * from phonebook;')
# 조회 결과에서 위에서 2개 레코드 출력
for row in cur.fetchmany(2):
print(row)

finally:
f.close()
conn.close()

0 comments on commit acc3e30

Please sign in to comment.