11-15-2012 01:11 AM
Hi everyone,
I'd appreciate some help. I'm basically new at this, and trying to do something probably out of my league.. Here goes. I'm trying to get data from a MySQL database housed on a server, and import it to my app to use, where it would then be pushed back into the database when the user updates info. I began by this piece of code:
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("fxxxxxxs.com");
db.setDatabaseName("formissi_cross");
db.setUserName("formissi_cross");
db.setPassword("password5");
bool ok = db.open();
However, at this point, I'm no longer sure how to proceed in creating a database that I can run queries in. A little like what they do below (not my code):
const QVariantList sqlData = sqlDataAccess.execute("SELECT * FROM quotes").value<QVariantList>();
Any help is appreciated!! If you need additonal explanations, please ask me. I'm really stuck.
11-15-2012 05:00 PM
SqlDataAccess m_Sda;
QString query("SELECT version as version FROM db_version");
QVariant result = m_Sda.execute(query);
QVariantMap versionMap = result.toList().first().toMap();
--- or --
QVariant result = m_Sda.execute(querySql);
QVariantList fencesList = result.toList();
foreach(QVariant v, fencesList)
{
...
}
11-15-2012 05:02 PM
Another one from "quotes" example
// Load database entries using a SqlDataAccess object into a QVariantList
// which can be used in a GroupDataModel to present a sorted list.
mDbNameWithPath = "data/" + databaseName;
// Set up a SqlDataAccess object.
SqlDataAccess sqlDataAccess(mDbNameWithPath);
// Set a query to obtain all entries in the table and load into our QVariantList.
sqlData = sqlDataAccess.execute("select * from " + table).value<QVariantList>();
if (sqlDataAccess.hasError()) {
DataAccessError err = sqlDataAccess.error();
qWarning() << "SQL error: type=" << err.errorType() << ": " << err.errorMessage();
return sqlData;
}
11-15-2012 05:05 PM