python
  • sql
  • database
  • python-2.7
  • kinterbasdb
  • 2012-09-24 86 views -5 likes 
    -5

    我寫了這個程序:錯誤SQL請求

    con=kinterbasdb.create_database("create database 'D:/ThirdTask/test.db' user 'sysdba' password 'masterkey'") 
    conn=kinterbasdb.connect(host='localhost',database='D:/ThirdTask/test.db', user='sysdba', password='masterkey') 
    cur=con.cursor() 
    s=""" 
    create table CLIENTS 
        (  
        ID FMTBCD PRIMARY KEY, 
        COMPANY CHAR(50), 
        LAST NAME CHAR(50), 
        FIRST NAME CHAR(50), 
        E-MAIL ADDRESS CHAR(50), 
        JOB TITLE CHAR(50), 
        BUSINESS PHONE CHAR(25), 
        HOME PHONE CHAR(25), 
        MOBILE PHONE CHAR(25), 
        FAX NUMBER CHAR(25), 
        ADDRESS MEMO, 
        CITY CHAR(50), 
        STATE/PROVINCE CHAR(50), 
        ZIP/POSTAL CODE CHAR(15), 
        COUNTRY/REGION CHAR(50), 
        WEB-SITE CHAR(25), 
        NOTES MEMO, 
        INCLUDING BLOB 
        )""" 
        print s 
        cur.execute(s) 
        con.close() 
        conn.close() 
    

    編譯器給出了以下錯誤:

    create table CLIENTS 
    (
        ID FMTBCD PRIMARY KEY, 
        COMPANY CHAR(50), 
        LAST NAME CHAR(50), 
        FIRST NAME CHAR(50), 
        E-MAIL ADDRESS CHAR(50), 
        JOB TITLE CHAR(50), 
        BUSINESS PHONE CHAR(25), 
        HOME PHONE CHAR(25), 
        MOBILE PHONE CHAR(25), 
        FAX NUMBER CHAR(25), 
        ADDRESS MEMO, 
        CITY CHAR(50), 
        STATE/PROVINCE CHAR(50), 
        ZIP/POSTAL CODE CHAR(15), 
        COUNTRY/REGION CHAR(50), 
        WEB-SITE CHAR(25), 
        NOTES MEMO, 
        INCLUDING BLOB 
        ) 
    
    Traceback (most recent call last): 
    File "D:\ThirdTask\connect.py", line 119, in <module> 
         cur.execute(s) 
    ProgrammingError: (-104, 'isc_dsql_prepare: \n Dynamic SQL Error\n SQL error code = -104\n Token unknown - line 6, column 16\n CHAR') 
    

    可能是什麼錯誤的原因是什麼?

    +6

    閱讀問題時'bla'錯誤豐富。 (提示:如果你想讓任何人閱讀這個令人震驚的介紹,請更改這個問題) – xtofl

    +0

    正如你所提出的那樣,很少有人會打擾你回答你的問題。請訪問http://www.whathaveyoutried.com並按照這些說明進行操作。 – HerrKaputt

    回答

    2

    您正在使用空格定義列名以及使用-破折號和\斜槓。把這樣的名字在雙引號:

    s=""" 
    create table CLIENTS 
        (  
        ID FMTBCD PRIMARY KEY, 
        COMPANY CHAR(50), 
        "LAST NAME" CHAR(50), 
        "FIRST NAME" CHAR(50), 
        "E-MAIL ADDRESS" CHAR(50), 
        "JOB TITLE" CHAR(50), 
        "BUSINESS PHONE" CHAR(25), 
        "HOME PHONE" CHAR(25), 
        "MOBILE PHONE" CHAR(25), 
        "FAX NUMBER" CHAR(25), 
        ADDRESS MEMO, 
        CITY CHAR(50), 
        "STATE/PROVINCE" CHAR(50), 
        "ZIP/POSTAL CODE" CHAR(15), 
        "COUNTRY/REGION" CHAR(50), 
        "WEB-SITE" CHAR(25), 
        NOTES MEMO, 
        INCLUDING BLOB 
        )""" 
    

    火鳥堅持相當嚴格的ANSI SQL標準,參見Interbase/Firebird identifiers關於什麼標識符可以與不引用定義詳細的規則。

    +0

    作爲結果,Traceback(最近調用最後一次): 文件「D:\ ThirdTask \ connect.py」,行119,在 cur.execute(s) ProgrammingError:(-607,'isc_dsql_prepare:\ n動態SQL錯誤\ n SQL錯誤代碼= -607 \ n無效命令\ n指定的域或源列FMTBCD不存在') – dva

    +2

    @dva:我不太清楚FMTBcd *是什麼*;這似乎與德爾福有關。你試過把它刪除嗎?看來你不知道你在做什麼;只是在Firebird上拋出一個SQL表? –

    相關問題