Changeset 373:4e43bfec5741

Show
Ignore:
Timestamp:
05/13/2009 07:26:25 PM (3 years ago)
Author:
Dmitry Nezhevenko <dion@…>
Branch:
default
Message:

Fix some issues with jids that are in CAPS

Files:
1 added
2 modified

Legend:

Unmodified
Added
Removed
  • sqlconvert/main.cpp

    r372 r373  
    2424#include <QtSql> 
    2525 
     26#error This is very ugly. Please read code first 
     27 
    2628QTextStream stream(stdout); 
    2729 
     
    7072 
    7173        QCoreApplication app(argc, argv); 
    72  
     74#ifdef CONVERT_DB 
    7375        QSqlDatabase dbSrc = QSqlDatabase::addDatabase("QMYSQL", "src"); 
    7476        dbSrc.setHostName("localhost"); 
     
    8486                return 1; 
    8587        } 
     88#endif 
    8689 
    8790        QSqlDatabase dbDst = QSqlDatabase::addDatabase("QPSQL7", "dst"); 
     
    99102        } 
    100103 
     104#ifdef CONVERT_DB 
    101105        for(QStringList::iterator it = tables.begin(); it != tables.end(); ++it) { 
    102106                QString tbl = *it; 
     
    231235#endif 
    232236        } 
     237#else 
     238 
     239        stream << "Removing duplicate JID records" << endl; 
     240        QSqlQuery badCaseQuery(dbDst); 
     241        if (!badCaseQuery.exec("select conference_id, jid from (select conference_id, jid, count(jid) as cnt from conference_jids group by conference_id, jid) as tbl where cnt > 1")) 
     242        { 
     243                stream << "Unable to query for bad case JIDs" << endl; 
     244                return 1; 
     245        } 
     246        while (badCaseQuery.next()) { 
     247                int conference_id = badCaseQuery.value(0).toInt(); 
     248                QString jid = badCaseQuery.value(1).toString(); 
     249                stream << "conference_id: " << conference_id << ", jid=" << jid << endl; 
     250 
     251                QSqlQuery bestJidQuery(dbDst); 
     252                bestJidQuery.prepare("select id from conference_jids where conference_id=? and jid=? order by created limit 1"); 
     253                bestJidQuery.addBindValue(conference_id); 
     254                bestJidQuery.addBindValue(jid); 
     255                if (!bestJidQuery.exec() || !bestJidQuery.next()) { 
     256                        stream << "Unable to query for best jid" << endl; 
     257                        return 1; 
     258                } 
     259                int bestJidId = bestJidQuery.value(0).toInt(); 
     260                stream << " best jid id: " << bestJidId << endl; 
     261                QSqlQuery fixQuery(dbDst); 
     262                fixQuery.prepare( 
     263                                "UPDATE conference_nicks set jid=? where conference_id=? and jid in (" 
     264                                "select id from conference_jids where conference_id=? and jid=?)"); 
     265                fixQuery.addBindValue(bestJidId); 
     266                fixQuery.addBindValue(conference_id); 
     267                fixQuery.addBindValue(conference_id); 
     268                fixQuery.addBindValue(jid); 
     269                if (!fixQuery.exec()) { 
     270                        stream << "Unable to fix nicks" << endl; 
     271                        return 1; 
     272                } 
     273                stream << " fixed nicks: " << fixQuery.numRowsAffected() << endl; 
     274 
     275                fixQuery.prepare("DELETE from conference_jids where conference_id=? and jid=? and id<>?"); 
     276                fixQuery.addBindValue(conference_id); 
     277                fixQuery.addBindValue(jid); 
     278                fixQuery.addBindValue(bestJidId); 
     279                if (!fixQuery.exec()) { 
     280                        stream << "Unable to remove extra jids" << endl; 
     281                        return 1; 
     282                } 
     283                stream << " removed jids: " << fixQuery.numRowsAffected() << endl; 
     284        } 
     285 
     286        stream << "Removing duplicate nick records" << endl; 
     287 
     288        QSqlQuery dublNickQuery(dbDst); 
     289        if (!dublNickQuery.exec("select * from (select conference_id, nick, jid, count(jid) from conference_nicks group by conference_id, nick, jid) as tbl where count > 1")) 
     290        { 
     291                stream << "Unable to query for bad case JIDs" << endl; 
     292                return 1; 
     293        } 
     294        while (dublNickQuery.next()) { 
     295                int conference_id = dublNickQuery.value(0).toInt(); 
     296                QString nick = dublNickQuery.value(1).toString(); 
     297                int jid_id = dublNickQuery.value(2).toInt(); 
     298 
     299                stream << "conference_id: " << conference_id << ", nick:" << nick << ", jid_id:" << jid_id << endl; 
     300                QSqlQuery fixQuery(dbDst); 
     301                fixQuery.prepare( 
     302                                "delete from conference_nicks where conference_id=? and jid=? and nick=? and not id in (" 
     303                                "select id from conference_nicks where conference_id=? and jid=? and nick=? order by created LIMIT 1)"); 
     304                fixQuery.addBindValue(conference_id); 
     305                fixQuery.addBindValue(jid_id); 
     306                fixQuery.addBindValue(nick); 
     307                fixQuery.addBindValue(conference_id); 
     308                fixQuery.addBindValue(jid_id); 
     309                fixQuery.addBindValue(nick); 
     310 
     311                if (!fixQuery.exec()) 
     312                { 
     313                        stream << "Unable to remove duplicate nicks"; 
     314                } 
     315                stream << " removed nicks: " << fixQuery.numRowsAffected() << endl; 
     316        } 
     317 
     318#endif 
    233319} 
  • src/plugins/muc/jid.cpp

    r313 r373  
    1616        if (!jid.isEmpty()) 
    1717        { 
    18                 myJid=jid.section('/',0,0); 
     18                myJid=jid.section('/',0,0).toLower(); 
    1919                myResource=jid.section('/',1); 
    2020        } 
     
    2222        if (myJid.isEmpty()) 
    2323        { 
    24                 myJid=QString("%1@").arg(parent->nick()); 
     24                myJid=QString("%1@%2.local").arg(parent->nick()).arg(QDateTime::currentDateTime().toString()); 
    2525                myTemporary=true; 
    2626        } 
     
    125125        } 
    126126 
    127         myJid=fullJid.section('/',0,0); 
     127        myJid=fullJid.section('/',0,0).toLower(); 
    128128        myResource=fullJid.section('/',1); 
    129129        if (myId>0)