擅长:python、mysql、java
<p>有一个使用字典的解决方案。首先,sql语句</p>
<pre><code>INSERT INTO Media VALUES (NULL, 'x');
</code></pre>
<p>不会起作用,因为它假设您按照abarnert声明的<code>CREATE TABLE</code>语句中定义的顺序引用所有列。(见<a href="http://www.sqlite.org/lang_insert.html">SQLite INSERT</a>。)</p>
<p>通过指定列修复后,可以使用命名占位符插入数据。这样做的好处是可以安全地转义关键字符,所以您不必担心。从<a href="http://docs.python.org/2.7/library/sqlite3.html#sqlite3.Cursor.execute">Python sqlite-documentation</a>:</p>
<pre><code>values = {'title':'jack', 'type':None, 'genre':'Action', 'onchapter':None,'chapters':6,'status':'Ongoing'}
cur.execute('INSERT INTO Media (id, title, type, onchapter, chapters, status) VALUES (:id, :title, :type, :onchapter, :chapters, :status);'), values)
</code></pre>