Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/341.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 我的sqlite3脚本有什么问题?_Python_Sqlite - Fatal编程技术网

Python 我的sqlite3脚本有什么问题?

Python 我的sqlite3脚本有什么问题?,python,sqlite,Python,Sqlite,回溯说: c = conn.cursor() c.executescript(""" CREATE TABLE IF NOT EXISTS dvdlist ( title text,

回溯说:

c = conn.cursor()                                                       
c.executescript("""                                                     
    CREATE TABLE IF NOT EXISTS dvdlist (                                    
        title text,                                                         
        barcode,                                                            
        added_date text,                                                    
        out numeric,                                                        
        borrower text,                                                      
        price real                                                          
        );                                                                  

    CREATE TABLE IF NOT EXISTS userdb (                                     
        username text,                                                      
        password text,                                                      
        address text,                                                       
        phone text,                                                         
        email text,                                                         
        borrowed integer
        );                                                                  

    CREATE TABLE IF NOT EXISTS staffdb (                                    
        username text,                                                      
        password text,                                                      
        address text,                                                       
        phone text,                                                         
        email text,                                                         
        group integer
        );                                                                  
    """)
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
文件“shopdatabase.py”,第52行,在__
self._db_init()
文件“shopdatabase.py”,第108行,在
""")
sqlite3.error:靠近“组”:语法错误
我已经在中查找了sqlite中的数据类型,我不太确定发生了什么。请帮助。

组是其中之一。您不能以这种方式使用它

正如@MartijnPieters在他的回答中所说的那样,你可以用引号将
括起来,使问题得以解决。

组是其中之一。你不能这样使用它

正如@MartijnPieters在他的回答中所说的,您可以用引号将
group
括起来以解决问题。

group
是a(它是SQL语言的一部分)。如果您想将其用作列名,则需要引用它:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "shopdatabase.py", line 52, in __init__
    self.__db_init()
  File "shopdatabase.py", line 108, in __db_init
    """)
sqlite3.OperationalError: near "group": syntax error
您可以使用单引号(
'group'
)、双引号(
“group”
)或方括号或反勾(
[group]
`group`
),但后两种形式仅支持与不兼容的数据库引擎兼容

您必须在SQL语句中使用该名称的任何位置引用该名称:

CREATE TABLE IF NOT EXISTS staffdb (                                    
    username text,                                                      
    password text,                                                      
    address text,                                                       
    phone text,                                                         
    email text,                                                         
    'group' integer
    );                                                                  
例如。

组是一个(它是SQL语言的一部分)。如果要将其用作列名,则需要引用它:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "shopdatabase.py", line 52, in __init__
    self.__db_init()
  File "shopdatabase.py", line 108, in __db_init
    """)
sqlite3.OperationalError: near "group": syntax error
您可以使用单引号(
'group'
)、双引号(
“group”
)或方括号或反勾(
[group]
`group`
),但后两种形式仅支持与不兼容的数据库引擎兼容

您必须在SQL语句中使用该名称的任何位置引用该名称:

CREATE TABLE IF NOT EXISTS staffdb (                                    
    username text,                                                      
    password text,                                                      
    address text,                                                       
    phone text,                                                         
    email text,                                                         
    'group' integer
    );                                                                  

例如。

如果你引用它,你可以。如果你引用它,你可以。