From ad6218cdf265eda264e38ab57dcacfc131d528f8 Mon Sep 17 00:00:00 2001 From: Badlop Date: Fri, 2 Sep 2011 13:49:46 +0200 Subject: [PATCH] Use the syntax PRIMARY KEY (field(int)) only for MySQL (EJAB-1337) --- src/gen_storage_odbc.erl | 23 +++++++++++++++++------ 1 file 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) ->