Skip to content
This repository
Browse code

Merge pull request #4100 from koying/fixmysql

Mysql fixes (fixes #14883)
  • Loading branch information...
commit 86b108c16c70ba9ede6899ca74d1cf6e5f4875ef 2 parents bf671d4 + 62a330f
Chris Browet koying authored
7 xbmc/dbwrappers/mysqldataset.cpp
@@ -155,7 +155,7 @@ int MysqlDatabase::connect(bool create_new) {
155 155 char sqlcmd[512];
156 156 int ret;
157 157
158   - sprintf(sqlcmd, "CREATE DATABASE `%s`", db.c_str());
  158 + sprintf(sqlcmd, "CREATE DATABASE `%s` CHARACTER SET utf8 COLLATE utf8_general_ci", db.c_str());
159 159 if ( (ret=query_with_reconnect(sqlcmd)) != MYSQL_OK )
160 160 {
161 161 throw DbErrors("Can't create new database: '%s' (%d)", db.c_str(), ret);
@@ -250,7 +250,7 @@ int MysqlDatabase::copy(const char *backup_name) {
250 250 }
251 251
252 252 // create the new database
253   - sprintf(sql, "CREATE DATABASE `%s`", backup_name);
  253 + sprintf(sql, "CREATE DATABASE `%s` CHARACTER SET utf8 COLLATE utf8_general_ci", backup_name);
254 254 if ( (ret=query_with_reconnect(sql)) != MYSQL_OK )
255 255 {
256 256 mysql_free_result(res);
@@ -1375,7 +1375,8 @@ int MysqlDataset::exec(const string &sql) {
1375 1375 }
1376 1376
1377 1377 // force the charset and collation to UTF-8
1378   - if ( ci_find(qry, "CREATE TABLE") != string::npos )
  1378 + if ( ci_find(qry, "CREATE TABLE") != string::npos
  1379 + || ci_find(qry, "CREATE TEMPORARY TABLE") != string::npos )
1379 1380 {
1380 1381 qry += " CHARACTER SET utf8 COLLATE utf8_general_ci";
1381 1382 }
11 xbmc/music/MusicDatabase.cpp
@@ -2498,10 +2498,13 @@ bool CMusicDatabase::CleanupArtists()
2498 2498 // (nested queries by Bobbin007)
2499 2499 // must be executed AFTER the song, album and their artist link tables are cleaned.
2500 2500 // don't delete the "Various Artists" string
2501   - CStdString strSQL = "delete from artist where idArtist not in (select idArtist from song_artist)";
2502   - strSQL += " and idArtist not in (select idArtist from album_artist)";
2503   - CStdString strSQL2;
2504   - m_pDS->exec(strSQL.c_str());
  2501 +
  2502 + // Create temp table to avoid 1442 trigger hell on mysql
  2503 + m_pDS->exec("CREATE TEMPORARY TABLE tmp_delartists (idArtist integer)");
  2504 + m_pDS->exec("INSERT INTO tmp_delartists select idArtist from song_artist");
  2505 + m_pDS->exec("INSERT INTO tmp_delartists select idArtist from album_artist");
  2506 + m_pDS->exec("delete from artist where idArtist not in (select idArtist from tmp_delartists)");
  2507 + m_pDS->exec("DROP TABLE tmp_delartists");
2505 2508 return true;
2506 2509 }
2507 2510 catch (...)

0 comments on commit 86b108c

Please sign in to comment.
Something went wrong with that request. Please try again.