25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-26 16:26:24 +01:00

Use the syntax PRIMARY KEY (field(int)) only for MySQL (EJAB-1337)

This commit is contained in:
Badlop 2011-09-02 13:49:46 +02:00
parent edda5e1747
commit ad6218cdf2

View File

@ -162,12 +162,7 @@ create_table(#tabdef{name = Tab,
end, {"", []}, Attributes),
TabS = atom_to_list(Tab),
PKey = case TableType of
%% This 105 limits the size of fields in the primary key.
%% That prevents MySQL from complaining when setting the
%% last_activity key (text, text) with this error:
%% #42000Specified key was too long; max key length is 1000bytes"
%% Similarly for rosteritem and other tables, maybe also PgSQL.
set -> [", PRIMARY KEY (", string:join(K, "(105), "), "(105))"];
set -> primary_key_string(Host, K);
bag -> []
end,
case odbc_command(Host,
@ -192,6 +187,22 @@ create_table(#tabdef{name = Tab,
{aborted, Reason}
end.
%% This 105 limits the size of fields in the primary key.
%% That prevents MySQL from complaining when setting the
%% last_activity key (text, text) with this error:
%% #42000Specified key was too long; max key length is 1000bytes"
%% Similarly for rosteritem and other tables.
primary_key_string(Host, K) ->
Dbtype = ejabberd_odbc:db_type(Host),
case Dbtype of
mysql ->
[", PRIMARY KEY (", string:join(K, "(105), "), "(105))"];
odbc ->
[", PRIMARY KEY (", string:join(K, ", "), ")"];
pgsql ->
[", PRIMARY KEY (", string:join(K, ", "), ")"]
end.
type_to_sql_type(Type, false = _NoTextKeys) ->
type_to_sql_type(Type);
type_to_sql_type(Type, true = _NoTextKeys) ->