sqlite3 sqlite3:表
我试图从sqlite数据库中使用sqlite3:table_info / 2函数提取表信息,并得到一个错误消息。
{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)
有任何想法吗?
我已经用INTEGER PRIMARY KEY
解决了这个问题。 default
很难支持,但我已经添加了回退,所以至少不会崩溃。 正如@CL所提到的,无论如何这种解析是不可靠的(因为SQLite不幸的是没有公开任何方式来使用它自己的解析器)。