Depends on your DBHOST name and DBNAME.
Here is part of main.cpp:
#ifdef _WIN32 // on Windows
#define DBDRIVER "QOCI"
#define DBHOST "orc1"
#define DBNAME "orc1"
#else // must be on Linux and PostgreSQL 8
#define DBDRIVER "QPSQL"
#define DBHOST "localhost"
#define DBNAME "homestead"
#endif
int main( int argc, char * argv[] ) {
...
app.setQuitOnLastWindowClosed(false);
dlgLogin dlg; // gets name and password from login dialog
if( dlg.
exec() == QDialog::Accepted ){ hapdb.setHostName(DBHOST);
hapdb.setDatabaseName(DBNAME);
hapdb.setUserName(dlg.dui.leUserName->text());
hapdb.setPassword(dlg.dui.leUserPassword->text());
if ( hapdb.open() ) {
homestead ht;
ht.RevID = dlg.dui.leUserName->text();
ht.show();
app.setQuitOnLastWindowClosed(true);
return app.exec();
} else {
strRejected
= QString("Reason: %1").
arg(hapdb.
lastError().
text()).
toLatin1();
QMessageBox::information(0,
"Login Rejected!",strRejected,
return 1;
}
} else {
strRejected
= QString("User Canceled the login!").
toLatin1();
QMessageBox::information(0,
"Login Canceled!",strRejected,
return 2;
}
}
#ifdef _WIN32 // on Windows
#define DBDRIVER "QOCI"
#define DBHOST "orc1"
#define DBNAME "orc1"
#else // must be on Linux and PostgreSQL 8
#define DBDRIVER "QPSQL"
#define DBHOST "localhost"
#define DBNAME "homestead"
#endif
int main( int argc, char * argv[] ) {
...
QString strRejected = "";
QApplication app(argc, argv);
app.setQuitOnLastWindowClosed(false);
dlgLogin dlg; // gets name and password from login dialog
if( dlg.exec() == QDialog::Accepted ){
QSqlDatabase hapdb = QSqlDatabase::addDatabase(DBDRIVER);
hapdb.setHostName(DBHOST);
hapdb.setDatabaseName(DBNAME);
hapdb.setUserName(dlg.dui.leUserName->text());
hapdb.setPassword(dlg.dui.leUserPassword->text());
if ( hapdb.open() ) {
homestead ht;
ht.RevID = dlg.dui.leUserName->text();
ht.show();
app.setQuitOnLastWindowClosed(true);
return app.exec();
} else {
strRejected = QString("Reason: %1").arg(hapdb.lastError().text()).toLatin1();
QMessageBox::information(0,"Login Rejected!",strRejected,
QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton);
return 1;
}
} else {
strRejected = QString("User Canceled the login!").toLatin1();
QMessageBox::information(0,"Login Canceled!",strRejected,
QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton);
return 2;
}
}
To copy to clipboard, switch view to plain text mode
Now, because hapdb is the default database in the application, any queries, etc. are against that database, so it does not have to be referenced. For more than one db open at the same time consult the Qt Assistant.
In the app init code:
// create query string that selects for proprty_id in property table
this->propPIDqryStr = "SELECT proprty_id, county, cntyname, txdistrict, legal, ";
this->propPIDqryStr.append("parcel_id, pvalue, pctext, totincome, entry_id, entry_date, ");
this->propPIDqryStr.append("appstatus, offuse, itotinc, ivalue, ipctex, notes FROM ");
this->propPIDqryStr.append(this->propertydb);
this->propPIDqryStr.append(" WHERE proprty_id = ");
// create query string that selects for proprty_id in property table
this->propPIDqryStr = "SELECT proprty_id, county, cntyname, txdistrict, legal, ";
this->propPIDqryStr.append("parcel_id, pvalue, pctext, totincome, entry_id, entry_date, ");
this->propPIDqryStr.append("appstatus, offuse, itotinc, ivalue, ipctex, notes FROM ");
this->propPIDqryStr.append(this->propertydb);
this->propPIDqryStr.append(" WHERE proprty_id = ");
To copy to clipboard, switch view to plain text mode
In a search function:
if (ui.rbProprtyID->isChecked()) {
// user is searching for property id
requestString.append(" in Property");
ui.leStatus->setText(requestString);
propStr = this->propPIDqryStr;
propStr.append(ui.leSearch->text());
propQry->exec(propStr);
if (propQry->first()){
// found property record, now fetch associated persinfo record
foundProp = true;
persStr = this->persPIDqryStr;
persStr.append(ui.leSearch->text());
persQry->exec(persStr);
if (persQry->first()) {
foundPers = true;
}
}
} // end proprty_id
if (ui.rbProprtyID->isChecked()) {
// user is searching for property id
requestString.append(" in Property");
ui.leStatus->setText(requestString);
propStr = this->propPIDqryStr;
propStr.append(ui.leSearch->text());
propQry->exec(propStr);
if (propQry->first()){
// found property record, now fetch associated persinfo record
foundProp = true;
persStr = this->persPIDqryStr;
persStr.append(ui.leSearch->text());
persQry->exec(persStr);
if (persQry->first()) {
foundPers = true;
}
}
} // end proprty_id
To copy to clipboard, switch view to plain text mode
Other code retrieves the data from propQry and persQry and displays it.
Bookmarks