■ Cursor 클래스를 사용해 레코드를 조회하는 방법을 보여준다.
▶ 예제 코드 (PY)
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 |
import sqlite3 connection = sqlite3.connect(":memory:") cursor = connection.cursor() cursor.execute("CREATE TABLE PHONE_BOOK (NAME TEXT, PHONE_NUMBER TEXT);") sql = "INSERT INTO PHONE_BOOK VALUES (?, ?);" parameterTupleTuple = \ ( ("Derick", "010-1234-5678"), ("Tom" , "010-5432-5432"), ("DSP" , "010-1234-1234") ) cursor.executemany(sql, parameterTupleTuple) cursor.execute("SELECT * FROM PHONE_BOOK;") for rowTuple in cursor: print(rowTuple) """ ('Derick', '010-1234-5678') ('Tom', '010-5432-5432') ('DSP', '010-1234-1234') """ |