Changeset e662750 for src/sql


Ignore:
Timestamp:
01/21/10 10:49:41 (12 years ago)
Author:
timkoma <timkoma@…>
Branches:
master, qt5
Children:
72cd3af
Parents:
842f5f9
Message:

first working version of the search

Location:
src/sql
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/sql/sqlengine.cpp

    r842f5f9 re662750  
    3838        result = createTables(database);
    3939    }
    40 
    41     database.open();
     40    else
     41    {
     42        database.open();
     43    }
    4244
    4345    //LOG_INFO(QString("Opening '%1' database '%2'").arg(aDatabaseType).arg(aDatabaseName));
     
    318320        return -1;
    319321
    320     QString query = QString(
    321         "DROP TABLE IF EXISTS SEARCH_EVENT;"
    322         "CREATE TEMP TABLE SEARCH_EVENT ( xid_conference INTEGER  NOT NULL, id INTEGER NOT NULL );"
    323         "INSERT INTO SEARCH_EVENT ( xid_conference, id) "
    324             "SELECT xid_conference, id FROM EVENT AS e INNER JOIN VIRTUAL_EVENT AS ve USING (xid_conference, id) "
    325             "WHERE xid_conference = %1 AND (").arg( aConferenceId );
    326 
     322
     323    // DROP
     324    execQuery( db, "DROP TABLE IF EXISTS SEARCH_EVENT;");
     325    // CREATE
     326    execQuery( db, "CREATE TABLE SEARCH_EVENT ( xid_conference INTEGER  NOT NULL, id INTEGER NOT NULL );");
     327    // INSERT
     328    QString query = QString("INSERT INTO SEARCH_EVENT ( xid_conference, id) "
     329                "SELECT xid_conference, id FROM EVENT AS e INNER JOIN VIRTUAL_EVENT AS ve USING (xid_conference, id) "
     330                "WHERE xid_conference = %1 AND (").arg( aConferenceId );
    327331    int i = 0;
    328332    foreach (QString str, aColumns){
     
    332336    query += QString(");");
    333337
    334     qDebug() << "\nSQL: " << query;
    335 
    336     db.exec();
    337 
    338     if( db.lastError().isValid() && db.lastError().number() != 0 ){
    339         qDebug() << "SQL ERR: " << db.lastError().number() << ", " << db.lastError().text();
    340         return 0;
     338    execQuery( db, query );
     339
     340    //TODO: retun number of rows from SEARCH_EVENT
     341    return 1;
     342}
     343
     344bool SqlEngine::execQuery(QSqlDatabase &aDatabase, const QString &aQuery)
     345{
     346    qDebug() << "\nSQL: " << aQuery;
     347
     348    QSqlQuery sqlQuery(aDatabase);
     349    if( !sqlQuery.exec(aQuery) ){
     350       qDebug() << "SQL ERR: " << sqlQuery.lastError().number() << ", " << sqlQuery.lastError().text();
     351       return false;
    341352    }
    342353    else{
    343         qDebug() << "SQL OK.\n";
    344         return 1;
    345     }
    346 
    347 }
     354       qDebug() << "SQL OK.\n";
     355       return true;
     356    }
     357}
  • src/sql/sqlengine.h

    r842f5f9 re662750  
    2525        QString login(const QString &aDatabaseType, const QString &aDatabaseName);
    2626        bool createTables(QSqlDatabase &aDatabase);
     27        bool execQuery(QSqlDatabase &aDatabase, const QString &aQuery);
    2728};
    2829
Note: See TracChangeset for help on using the changeset viewer.