erlang-sqlite3 sqlite3:table_info错误

时间:2015-03-01 18:42:39

标签: sqlite erlang

我尝试使用sqlite3:table_info / 2函数从sqlite数据库中提取表信息,并收到错误消息。

{ok,Pid} = sqlite3:open(db3).

Sql = <<"CREATE TABLE test (
           id INTEGER PRIMARY KEY,
           ts TEXT default (datetime('now')),
           key TEXT,
           val TEXT
           );">>.
sqlite3:sql_exec(db3,Sql).

检查表格列表:

sqlite3:list_tables(db3).
[test]

尝试获取表信息:

sqlite3:table_info(db3,test). 

现在出现错误消息:


    `=ERROR REPORT==== 1-Mar-2015::19:37:46 ===
    ** Generic server db3 terminating 
    ** Last message in was {table_info,test}
    ** When Server state == {state,#Port,
                                   [{file,"../tmp/db3.sqlite"}],
                                   {dict,0,16,16,8,80,48,
                                         {[],[],[],[],[],[],[],[],[],[],[],[],[],
                                          [],[],[]},
                                         {{[],[],[],[],[],[],[],[],[],[],[],[],[],
                                           [],[],[]}}}}
    ** Reason for termination == 
    ** {function_clause,[{sqlite3,build_constraints,
                                  [["INTEGER","PRIMARY","KEY"]],
                                  [{file,"src/sqlite3.erl"},{line,1169}]},
                         {sqlite3,build_table_info,2,
                                  [{file,"src/sqlite3.erl"},{line,1166}]},
                         {sqlite3,handle_call,3,
                                  [{file,"src/sqlite3.erl"},{line,833}]},
                         {gen_server,try_handle_call,4,
                                     [{file,"gen_server.erl"},{line,607}]},
                         {gen_server,handle_msg,5,
                                     [{file,"gen_server.erl"},{line,639}]},
                         {proc_lib,init_p_do_apply,3,
                                   [{file,"proc_lib.erl"},{line,237}]}]}
    ** exception exit: function_clause
         in function  sqlite3:build_constraints/1
            called as sqlite3:build_constraints(["INTEGER","PRIMARY","KEY"])
         in call from sqlite3:build_table_info/2 (src/sqlite3.erl, line 1166)
         in call from sqlite3:handle_call/3 (src/sqlite3.erl, line 833)
         in call from gen_server:try_handle_call/4 (gen_server.erl, line 607)
         in call from gen_server:handle_msg/5 (gen_server.erl, line 639)
         in call from proc_lib:init_p_do_apply/3 (proc_lib.erl, line 237)

有什么想法吗?

1 个答案:

答案 0 :(得分:2)

fixed the problemINTEGER PRIMARY KEYdefault更难以支持,但我添加了一个后备,所以它至少不会崩溃。正如@CL提到的那样,这种解析无论如何都是不可靠的(因为不幸的是,SQLite没有公开任何使用它自己的解析器的方法)。