Add fallback for constraint parsing
This commit is contained in:
@@ -1155,7 +1155,7 @@ parse_table_info(Info) ->
|
||||
Rest1 = list_init(Rest),
|
||||
Cols = string:tokens(Rest1, ","),
|
||||
build_table_info(lists:map(fun(X) ->
|
||||
string:tokens(X, " ")
|
||||
string:tokens(X, " \n\t")
|
||||
end, Cols), []).
|
||||
|
||||
build_table_info([], Acc) ->
|
||||
@@ -1174,12 +1174,15 @@ build_constraints(["UNIQUE" | Tail]) ->
|
||||
[unique | build_constraints(Tail)];
|
||||
build_constraints(["NOT", "NULL" | Tail]) ->
|
||||
[not_null | build_constraints(Tail)];
|
||||
build_constraints(["NULL" | Tail]) ->
|
||||
[null | build_constraints(Tail)];
|
||||
build_constraints(["DEFAULT", DefaultValue | Tail]) ->
|
||||
[{default, sqlite3_lib:sql_to_value(DefaultValue)} | build_constraints(Tail)];
|
||||
build_constraints(["CHECK", _ | Tail]) ->
|
||||
%% currently ignored
|
||||
build_constraints(Tail).
|
||||
% build_constraints(["CHECK", _ | Tail]) ->
|
||||
% build_constraints(Tail);
|
||||
% build_constraints(["REFERENCES", Check | Tail]) -> ...
|
||||
build_constraints(UnknownConstraints) ->
|
||||
[{cant_parse_constraints, string:join(UnknownConstraints, " ")}].
|
||||
|
||||
build_primary_key_constraint(Tokens) -> build_primary_key_constraint(Tokens, []).
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@ all_test_() ->
|
||||
fun open_db/0,
|
||||
fun close_db/1,
|
||||
[?FuncTest(basic_functionality),
|
||||
?FuncTest(table_info),
|
||||
?FuncTest(parametrized),
|
||||
?FuncTest(negative),
|
||||
?FuncTest(blob),
|
||||
@@ -131,6 +132,19 @@ basic_functionality() ->
|
||||
ok,
|
||||
sqlite3:drop_table(ct, user)).
|
||||
|
||||
table_info() ->
|
||||
Sql = <<"CREATE TABLE table_info_test (
|
||||
id INTEGER PRIMARY KEY,
|
||||
ts TEXT default (timestamp('now')),
|
||||
key TEXT);">>,
|
||||
ExpectedTableInfo =
|
||||
sqlite3:sql_exec(ct,Sql),
|
||||
?assertMatch(
|
||||
[{id, integer, [primary_key]},
|
||||
{ts, text, [{cant_parse_constraints, _}]},
|
||||
{key, text}],
|
||||
sqlite3:table_info(ct,table_info_test)).
|
||||
|
||||
parametrized() ->
|
||||
drop_table_if_exists(ct, user1),
|
||||
sqlite3:create_table(ct, user1, [{id, integer}, {name, text}]),
|
||||
|
||||
Reference in New Issue
Block a user