Study Notes (25): 21 days clearance Python (Video Lesson only) - execute the query

Learning immediately: https://edu.csdn.net/course/play/24797/282205?utm_source=blogtoedu

the sqlite3 Import 

Conn = sqlite3.connect ( 'test52.db') 
C = conn.cursor () 
# execute a query 
c.execute ( 'SELECT * from user_tb') 
# Description property (tuple) Returns the class information 
for col in c .description: 
    Print (COL [0], End = '\ T') 
Print () 

# or fetchall () returns all the data, the use of large amounts of data do not mind 
# for Val in c.fetchall (): 
# Print (Val) 

# either fetchone () returns a row of data 
# the while True: 
# c.fetchone row = () 
# IF row: 
# for Val in row: 
# Print (Val, End = '\ T') 
# Print () 
# the else: 
# BREAK 
# fetchmany (n) n is less than the number of list 
# for Val in c.fetchmany (2): 
# Print (Val)

for val in c:
    print(val)
c.close()
conn.close()
Published 39 original articles · won praise 29 · views 902

Guess you like

Origin blog.csdn.net/happyk213/article/details/105232322