aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBadlop <badlop@process-one.net>2011-09-02 13:49:46 +0200
committerBadlop <badlop@process-one.net>2011-09-02 13:50:03 +0200
commitad6218cdf265eda264e38ab57dcacfc131d528f8 (patch)
treeab8c19cbe477d1dded659a8aeee24778e0e539e4 /src
parentUpdated mysql schema with current dump (EJAB-1474) (diff)
Use the syntax PRIMARY KEY (field(int)) only for MySQL (EJAB-1337)
Diffstat (limited to 'src')
-rw-r--r--src/gen_storage_odbc.erl23
1 files changed, 17 insertions, 6 deletions
diff --git a/src/gen_storage_odbc.erl b/src/gen_storage_odbc.erl
index 9fd56b4a7..5702df05f 100644
--- a/src/gen_storage_odbc.erl
+++ b/src/gen_storage_odbc.erl
@@ -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) ->