I'm building some QT application to convert DBF files to SQL database.
I have a class derived from QThread to convert one DBF file containing information from one month. This class is defined as :
class KonwertJedenMiesiac :
{
Q_OBJECT
public:
~KonwertJedenMiesiac(void);
void KonwertJedenMiesiac::stopKonwerter( void );
void zrobIncProgressBarOperacja( void );
signals:
void incProgressBarOperacja( void );
protected:
inline long nowyKod( char litera, long kod )
{ if(litera == ' ' )
return 0;
return(litera*1000000L + kod);
}
protected:
bool run_konwerter;
Code4 cb;
};
class KonwertJedenMiesiac :
public QThread
{
Q_OBJECT
public:
KonwertJedenMiesiac(QString katDBF,QString bazaDBF);
~KonwertJedenMiesiac(void);
void KonwertJedenMiesiac::stopKonwerter( void );
void zrobIncProgressBarOperacja( void );
signals:
void incProgressBarOperacja( void );
protected:
inline long nowyKod( char litera, long kod )
{ if(litera == ' ' )
return 0;
return(litera*1000000L + kod);
}
protected:
bool run_konwerter;
mutable QMutex mutex;
QSqlDatabase db;
Code4 cb;
QDate d88;
QString katDBF, bazaDBF;
};
To copy to clipboard, switch view to plain text mode
The constructor look s like :
KonwertJedenMiesiac
::KonwertJedenMiesiac(QString katDBF,
QString bazaDBF
){
run_konwerter = true;
this->bazaDBF = bazaDBF;
this->katDBF = katDBF;
// wczytujemy parametry bazy danych
settings.beginGroup("DbSetup");
db
= QSqlDatabase::addDatabase(settings.
value("DbType").
toString(),bazaDBF
);
db.setHostName(settings.value("HostName").toString());
db.setDatabaseName(settings.value("DatabaseName").toString());
db.setUserName(settings.value("UserName").toString());
db.setPassword(settings.value("Password").toString());
}
KonwertJedenMiesiac::KonwertJedenMiesiac(QString katDBF, QString bazaDBF )
{
run_konwerter = true;
d88 = QDate(1988,01,01);
this->bazaDBF = bazaDBF;
this->katDBF = katDBF;
// wczytujemy parametry bazy danych
QSettings settings( "dworzec.ini", QSettings::IniFormat);
settings.beginGroup("DbSetup");
db = QSqlDatabase::addDatabase(settings.value("DbType").toString(),bazaDBF);
db.setHostName(settings.value("HostName").toString());
db.setDatabaseName(settings.value("DatabaseName").toString());
db.setUserName(settings.value("UserName").toString());
db.setPassword(settings.value("Password").toString());
}
To copy to clipboard, switch view to plain text mode
SQL database is opened in method run().
All monthly DBF files must be merged to one SQL table.
When I create only one thread KonwerterJedenMiesiac all is working correctly. But when I create more than one thread from time to time INSERT rows generated in program are broken like this :
"INSERT INTO pozycje_paragonow (litera,kod,pozycja,id_towaru,nazwa_towaru,jm,ilosc,cena,kod_vat,stawka_vat,rabat1,rabat2,bonifikata,kwota_ulgi,sww) VALUES ('F',7429,1,65000031,'A
QSqlError(-1, "", "")
"INSERT INTO pozycje_paragonow (litera,kod,pozycja,id_towaru,nazwa_towaru,jm,ilosc,cena,kod_vat,stawka_vat,rabat1,rabat2,bonifikata,kwota_ulgi,sww) VALUES ('F',7429,1,65000031,'A
To copy to clipboard, switch view to plain text mode
I don't observe this behavior when SQL database is Firebird.
Is something special to do with PostgreSQL driver ?
Qt 4.3.3 OpenSource on Windows XP compiled with Visual C++ 2005 Express Edition. PostgreSQL developer library v.8.2.
Bookmarks