简体   繁体   English

在sqlite3中创建表时出错

[英]Error with create tables in sqlite3

I am learning sqlite3 in python3. 我正在python3中学习sqlite3。 I have added 4 columns in my table using the syntax 我使用语法在表中添加了4列

c.execute("CREATE table raman(ATOMIC NUMBER INT, SYMBOL TEXT, ROW INT , COLUMN INT)")     

and I want to insert values for them so I am writing 我想为它们插入值,所以我在写

c.execute("INSERT INTO raman VALUES(1,'H',1,'1')");      

After this if I print the table its not showing me the inserted values. 此后,如果我打印表,则不会显示插入的值。 I am using this command to print print c.execute("SELECT * FROM SQLITE_ master type='table'").fetchall() 我正在使用此命令来打印打印c.execute(“ SELECT * FROM SQLITE_ master type ='table'”)。fetchall()

The complete (minimal) sequence is this. 完整(最小)顺序是这样的。

>>> conn = sqlite3.connect(':memory:')
>>> c = conn.cursor()
>>> c.execute("CREATE table raman(ATOMIC NUMBER INT, SYMBOL TEXT, ROW INT , COLUMN INT)")
<sqlite3.Cursor object at 0x000000000296E490>
>>> c.execute("INSERT INTO raman VALUES(1,'H',1,'1')"); 
<sqlite3.Cursor object at 0x000000000296E490>
>>> conn.commit()
>>> for row in c.execute('SELECT * FROM raman'):
...     row
... 
(1, 'H', 1, 1)

Until you issue the commit the values won't be (or won't necessarily be) present in the table. 在您发出commit ,表中将不会(或不一定会存在)这些值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM