def insert(self, data):
insert_memo_sql = '''INSERT INTO minim(title, memo) VALUES(?, ?);'''
try:
cur = self.db_conn.cursor()
cur.execute(insert_memo_sql, (data[0], data[1]))
self.db_conn.commit()
print(cur.lastrowid)
return cur.lastrowid
except sqlite3.Error as e:
print(e)
return -1
[개선코드]
def insert_bigdata(self, big_data):
insert_memo_sql = '''INSERT INTO minim(title, memo) VALUES(?, ?);'''
try:
cur = self.db_conn.cursor()
cur.execute("BEGIN TRANSACTION")
for data in big_data:
cur.execute(insert_memo_sql, (data[0], data[1]))
self.db_conn.commit()
print(cur.lastrowid)
return cur.lastrowid
except sqlite3.Error as e:
print(e)
self.db_conn.rollback() # rollback the transaction if there's any error
return -1
echo [TEST]
echo main x0 %~x0
echo main n0 %~n0
echo main nx0 %~nx0
echo main p0 %~p0
echo main pnx0 %~pnx0
echo main d0 %~d0
echo main dpnx0 %~dpnx0
echo main f0 %~f0
실행 결과
C:\github>test
C:\github>echo [TEST]
[TEST]
C:\github>echo main x0 .bat
main x0 .bat
C:\github>echo main n0 test
main n0 test
C:\github>echo main nx0 test.bat
main nx0 test.bat
C:\github>echo main p0 \github\
main p0 \github\
C:\github>echo main pnx0 \github\test.bat
main pnx0 \github\test.bat
C:\github>echo main d0 C:
main d0 C:
C:\github>echo main dpnx0 C:\github\test.bat
main dpnx0 C:\github\test.bat
C:\github>echo main f0 C:\github\test.bat
main f0 C:\github\test.bat
C:\github>