Add AUTOINCREMENT to primary keys
This commit is contained in:
@@ -376,11 +376,19 @@ column_sql_for_create_table({Name, Type, Constraints}) ->
|
||||
[atom_to_list(Name), " ", col_type_to_string(Type),
|
||||
" " | map_intersperse(fun constraint_sql/1, Constraints, " ")].
|
||||
|
||||
-spec pk_constraint_sql(any ()) -> iolist().
|
||||
pk_constraint_sql (Constraint) ->
|
||||
case Constraint of
|
||||
desc -> "DESK";
|
||||
autoincrement -> "AUTOINCREMENT";
|
||||
L -> lists:map (fun pk_constraint_sql/1, L)
|
||||
end.
|
||||
|
||||
-spec constraint_sql(any()) -> iolist().
|
||||
constraint_sql(Constraint) ->
|
||||
case Constraint of
|
||||
primary_key -> "PRIMARY KEY";
|
||||
{primary_key, desc} -> "PRIMARY KEY DESC";
|
||||
{primary_key, C} -> ["PRIMARY KEY ", pk_constraint_sql (C)];
|
||||
unique -> "UNIQUE";
|
||||
not_null -> "NOT NULL";
|
||||
{default, DefaultValue} -> ["DEFAULT ", value_to_sql(DefaultValue)]
|
||||
|
||||
@@ -61,7 +61,7 @@ basic_functionality() ->
|
||||
Columns = ["id", "name", "age", "wage"],
|
||||
AllRows = [{1, <<"abby">>, 20, 2000}, {2, <<"marge">>, 30, 2000}],
|
||||
AbbyOnly = [{1, <<"abby">>, 20, 2000}],
|
||||
TableInfo = [{id, integer, [primary_key]}, {name, text, [not_null, unique]}, {age, integer}, {wage, integer}],
|
||||
TableInfo = [{id, integer, [{primary_key, [autoincrement]}]}, {name, text, [not_null, unique]}, {age, integer}, {wage, integer}],
|
||||
drop_all_tables(ct),
|
||||
?WARN_ERROR_MESSAGE,
|
||||
?assertEqual(
|
||||
@@ -72,7 +72,7 @@ basic_functionality() ->
|
||||
sqlite3:list_tables(ct)),
|
||||
ok = sqlite3:create_table(ct, user, TableInfo),
|
||||
?assertEqual(
|
||||
[user],
|
||||
[user, sqlite_sequence],
|
||||
sqlite3:list_tables(ct)),
|
||||
?assertEqual(
|
||||
TableInfo,
|
||||
|
||||
Reference in New Issue
Block a user