mirror of
https://github.com/processone/ejabberd
synced 2025-10-03 09:49:18 +02:00
Make sqlite update_primary_key when copying data use list of columns and not *
Since * depends on order of columns, if original table have different column layout we could get resulting columns in wrong order. This is fix for issue #4365
This commit is contained in:
parent
85d0e93af5
commit
5008947e32
1 changed files with 7 additions and 4 deletions
|
@ -410,18 +410,21 @@ sqlite_table_copy_t(SchemaInfo, Table) ->
|
|||
NewTableName = <<"new_", TableName/binary>>,
|
||||
NewTable = Table#sql_table{name = NewTableName},
|
||||
create_table_t(SchemaInfo, NewTable),
|
||||
SQL2 = <<"INSERT INTO ", NewTableName/binary,
|
||||
" SELECT * FROM ", TableName/binary>>,
|
||||
Columns = lists:join(<<",">>,
|
||||
lists:map(fun(C) -> escape_name(SchemaInfo, C#sql_column.name) end,
|
||||
Table#sql_table.columns)),
|
||||
SQL2 = [<<"INSERT INTO ">>, NewTableName,
|
||||
<<" SELECT ">>, Columns, <<" FROM ">>, TableName],
|
||||
?INFO_MSG("Copying table ~s to ~s:~n~s~n",
|
||||
[TableName, NewTableName, SQL2]),
|
||||
ejabberd_sql:sql_query_t(SQL2),
|
||||
SQL3 = <<"DROP TABLE ", TableName/binary>>,
|
||||
?INFO_MSG("Droping old table ~s:~n~s~n",
|
||||
[TableName, SQL2]),
|
||||
[TableName, SQL3]),
|
||||
ejabberd_sql:sql_query_t(SQL3),
|
||||
SQL4 = <<"ALTER TABLE ", NewTableName/binary,
|
||||
" RENAME TO ", TableName/binary>>,
|
||||
?INFO_MSG("Renameing table ~s to ~s:~n~s~n",
|
||||
?INFO_MSG("Renaming table ~s to ~s:~n~s~n",
|
||||
[NewTableName, TableName, SQL4]),
|
||||
ejabberd_sql:sql_query_t(SQL4).
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue