ruben.rodrigues
5th October 2010, 07:06
Hi all!
I am doing an application that for now connects to a mysql database but in the future should connect to oracle and msql (odbc). We want to have the database classes as plugins, that meaning 1 plugin per database capability.
My question is if after I have the QSqlQuery object the syntax is the same for all kinds of databases.
For example, if I do the implementation to the mysql class, after doing the query I could return it to the main class and it will handle the data from there.
MySql:
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL"); //select database type
db.setHostName(_hostName);
db.setDatabaseName(_databaseName);
db.setUserName(_userName);
db.setUserName(_userPassword);
QSqlQuery query("USE " + _table);
query.exec("Select * from "+ _table);
//then put the query inside a QByteArray and return it to the class that has called it.
return qbytearray;
then the class that has called it opens the QSqlQuery object and get the information.
//open qbytearray and read the QSqlQuery
while (query.next()) {
QSqlRecord record = query.record();
loginName = query.value(0).toString();
loginPassword = query.value(1).toString();
firstName = query.value(2).toString();
surname = query.value(3).toString();
phone = query.value(4).toString();
email = query.value(5).toString();
}
Does this syntax work for all database types?
Thanks
I am doing an application that for now connects to a mysql database but in the future should connect to oracle and msql (odbc). We want to have the database classes as plugins, that meaning 1 plugin per database capability.
My question is if after I have the QSqlQuery object the syntax is the same for all kinds of databases.
For example, if I do the implementation to the mysql class, after doing the query I could return it to the main class and it will handle the data from there.
MySql:
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL"); //select database type
db.setHostName(_hostName);
db.setDatabaseName(_databaseName);
db.setUserName(_userName);
db.setUserName(_userPassword);
QSqlQuery query("USE " + _table);
query.exec("Select * from "+ _table);
//then put the query inside a QByteArray and return it to the class that has called it.
return qbytearray;
then the class that has called it opens the QSqlQuery object and get the information.
//open qbytearray and read the QSqlQuery
while (query.next()) {
QSqlRecord record = query.record();
loginName = query.value(0).toString();
loginPassword = query.value(1).toString();
firstName = query.value(2).toString();
surname = query.value(3).toString();
phone = query.value(4).toString();
email = query.value(5).toString();
}
Does this syntax work for all database types?
Thanks