我正在处理一个项目并启动了一个小项目来获取Serial上的一些数据.数据来自Serial,但没有任何内容添加到数据库中.表已创建,但实际数据不会被推送.那里出了点问题.
这是我的代码:
#!/usr/bin/env python
import serial
import time
import sqlite3
import os
from datetime import datetime
conn = sqlite3.connect("elements78.db") # or use :memory: to put it in RAM
cursor = conn.cursor()
sql_file = os.path.join(os.path.dirname(__file__), 'elements78.db')
needs_creation = not os.path.exists(sql_file)
db_connection = sqlite3.connect(sql_file)
db_connection.row_factory = sqlite3.Row
# create a table
if needs_creation:
print 'Creating initial database...'
cursor = db_connection.cursor()
db_connection.commit()
print 'Database created.'
cursor.executescript("""
DROP TABLE IF EXISTS elements;
CREATE TABLE elements (id INTEGER PRIMARY KEY AUTOINCREMENT, Name, date CURDATE ) …Run Code Online (Sandbox Code Playgroud)