Skip to content

A patch for table_info

mwpark edited this page Sep 13, 2010 · 1 revision

I got an error like this:


2> sqlite:table_info(csi, H). =ERROR REPORT==== 22-Jan-2009::16:44:48 ===
  • Generic server csi terminating
  • Last message in was {table_info,system}
  • When Server state == {state,#Port<0.1740>,[{db,“/tmp/csi.db”}]}
  • Reason for termination ==
  • {function_clause,[{sqlite,build_table_info,
    [[[“\n”,“name”,“text”,“PRIMARY”,“KEY”],
    [“\n”,“value”,“text\n”]],
    []]},
    {sqlite,handle_call,3},
    {gen_server,handle_msg,5},
    {proc_lib,init_p_do_apply,3}]}
  • exception exit: function_clause
    in function sqlite:build_table_info/2
    called as sqlite:build_table_info([[“\n”,“name”,“text”,“PRIMARY”,
    KEY”],
    [“\n”,“value”,“text\n”]],
    [])
    in call from sqlite:handle_call/3
    in call from gen_server:handle_msg/5
    in call from proc_lib:init_p_do_apply/3


i don’t know this is the right way. but, solved my current problem.

my patch:


diff --git a/src/sqlite.erl b/src/sqlite.erl
index 0bdb7c9..d9671e5 100644
--- a/src/sqlite.erl
+++ b/src/sqlite.erl
@@ -459,8 +459,8 @@ exec(Port, Cmd) ->


 parse_table_info(Info) ->
-    [_, Tail] = string:tokens(Info, "()"),
-    Cols = string:tokens(Tail, ","),
+    [_| Tail] = string:tokens(Info, "\n()"),
+    Cols = string:tokens(lists:flatten(Tail), ","),
     build_table_info(lists:map(fun(X) ->
                                       string:tokens(X, " ")
                               end, Cols), []).
@@ -468,7 +468,7 @@ parse_table_info(Info) ->
 build_table_info([], Acc) ->
     lists:reverse(Acc);
 build_table_info([[ColName, ColType] | Tl], Acc) ->
-    build_table_info(Tl, [{list_to_atom(ColName), sqlite_lib:col_type(ColType)}| Acc]);
+    build_table_info(Tl, [{list_to_atom(ColName), sqlite_lib:col_type(string:to_upper(ColType))}| Acc]);
 build_table_info([[ColName, ColType, "PRIMARY", "KEY"] | Tl], Acc) ->
-    build_table_info(Tl, [{list_to_atom(ColName), sqlite_lib:col_type(ColType)}| Acc]).
+    build_table_info(Tl, [{list_to_atom(ColName), sqlite_lib:col_type(string:to_upper(ColType))}| Acc]).

Clone this wiki locally