Results 1 to 13 of 13

Thread: QThread and PostgreSQL - a problem

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,540
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanked 284 Times in 279 Posts

    Default Re: QThread and PostgreSQL - a problem

    OK, all code related to creating connection to database is moved to run() method :
    Qt Code:
    1. void KonwertBJM::run(void)
    2. {
    3.  
    4. QSettings settings( "dworzec.ini", QSettings::IniFormat);
    5. settings.beginGroup("DbSetup");
    6. db_connection_name = UniqueDbName();
    7. db = QSqlDatabase::addDatabase(settings.value("DbType").toString(),db_connection_name);
    8.  
    9. db.setHostName(settings.value("HostName").toString());
    10. db.setDatabaseName(settings.value("DatabaseName").toString());
    11. db.setUserName(settings.value("UserName").toString());
    12. db.setPassword(settings.value("Password").toString());
    13. if( !db.open() )
    14. {
    15. qDebug() << "KonwerterBJM"
    16. << QObject::tr("Can't connect to database")
    17. << db.lastError().text();
    18. return;
    19. }
    20. char miesiac[7];
    21.  
    22. strcpy_s(miesiac,sizeof(miesiac),bazaDBF.mid(1,6 ).toLocal8Bit().data());
    23. robKonwersje(katDBF.toLocal8Bit().data(),miesiac);
    24.  
    25. db.close();
    26. }
    To copy to clipboard, switch view to plain text mode 
    No difference.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts

    Default Re: QThread and PostgreSQL - a problem

    Quote Originally Posted by Lesiok View Post
    Qt Code:
    1. char miesiac[7];
    2. strcpy_s(miesiac,sizeof(miesiac),bazaDBF.mid(1,6).toLocal8Bit().data());
    To copy to clipboard, switch view to plain text mode 
    Doesn't this leave the last character uninitialized? What does KonwertBJM::robKonwersje() do? Why does it take char* and not QString in the first place?
    J-P Nurmi

  3. #3
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,540
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanked 284 Times in 279 Posts

    Default Re: QThread and PostgreSQL - a problem

    Quote Originally Posted by jpn View Post
    Doesn't this leave the last character uninitialized? What does KonwertBJM::robKonwersje() do? Why does it take char* and not QString in the first place?
    1. No, strcpy_s writes to the new location string WITH ending 0x00 byte.

    2. KonwertBJM::robKonwersje() is a main method to doing conversion from DBF to SQL. It opens 3 DBF files named as Byyyymm.DBF, KByyyymm.DBF and Pyyyymm.DBF, where yyyymm is saved in var miesiac, and record by record convert it to SQL INSERT statements. A few records from KB and P is related to one record in B. So every record from B produce some INSERT statements in one transaction.

    As I wrote in post opening this thread, on Firebird I can do this in many threads and all is OK. Problem is only with PostgreSQL.

  4. #4
    Join Date
    Jan 2008
    Posts
    40
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QThread and PostgreSQL - a problem

    In addition, the third party libraries used by the QSqlDrivers can impose further restrictions on using the SQL Module in a multithreaded program. Consult the manual of your database client for more information
    This may be the problem

  5. #5
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,540
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanked 284 Times in 279 Posts

    Default Re: QThread and PostgreSQL - a problem

    Quote Originally Posted by C167 View Post
    This may be the problem
    Yes I know.
    Theoretically libpq is compiled in thread-safe mode. PQisthreadsafe() returns 1 (the libpq is thread-safe).

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.