]> granicus.if.org Git - ejabberd/commitdiff
Use the syntax PRIMARY KEY (field(int)) only for MySQL (EJAB-1337)
authorBadlop <badlop@process-one.net>
Fri, 2 Sep 2011 11:49:46 +0000 (13:49 +0200)
committerBadlop <badlop@process-one.net>
Fri, 2 Sep 2011 11:50:03 +0000 (13:50 +0200)
src/gen_storage_odbc.erl

index 9fd56b4a7ae04bc26de067c9d2ba707d97f92431..5702df05ff11f60b00e773a3c729e723885aad7c 100644 (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) ->