Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
New Developer
marc25v
Posts: 27
Registered: ‎07-24-2012
My Device: Blackberry Dev Alpha

Working with an External mySQL Database

  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.

Please use plain text.
Developer
noahhuang
Posts: 100
Registered: ‎10-01-2012
My Device: BB10 Dev Alpha

Re: Working with an External mySQL Database

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)
{

...

}

Please use plain text.
Developer
noahhuang
Posts: 100
Registered: ‎10-01-2012
My Device: BB10 Dev Alpha

Re: Working with an External mySQL Database

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;
}

Please use plain text.
Developer
noahhuang
Posts: 100
Registered: ‎10-01-2012
My Device: BB10 Dev Alpha

Re: Working with an External mySQL Database

Please use plain text.