wysota,
I followed the example given for the 'sqlite3' driver (see link that I posted).
I linked to the library (libmysql) in the .pro file, and I added the QSqldriver/QMySqlDriver
I declared a QVariant obj and can read the driver handle with qdebug (which returns "MYSQL*").
I tried to play with the code below, after looking into mysql.h but MYSQL stays undeclared whatever I do...?!?
In mysql.h the MYSQL refers to a connection??
This code below allows me to connect to MySQL - but without SSL.
bool p2Sql::createConnection()
{
db.setHostName(sMySqlIpAddress);
db.setDatabaseName(sMySqlDbName);
db.setUserName(sMySqlAdminName);
db.setPassword(sMySqlPwd);
db.setConnectOptions("CLIENT_SSL=1;CLIENT_IGNORE_SPACE=1");
if (!db.open())
{
QMessageBox::critical(0, qApp
->tr
("Cannot open database"),
qApp->tr("Unable to establish a database connection.\n\n"
return false;
}
return true;
}
bool p2Sql::createConnection()
{
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName(sMySqlIpAddress);
db.setDatabaseName(sMySqlDbName);
db.setUserName(sMySqlAdminName);
db.setPassword(sMySqlPwd);
db.setConnectOptions("CLIENT_SSL=1;CLIENT_IGNORE_SPACE=1");
if (!db.open())
{
QMessageBox::critical(0, qApp->tr("Cannot open database"),
qApp->tr("Unable to establish a database connection.\n\n"
"Click Cancel to exit."), QMessageBox::Cancel);
return false;
}
return true;
}
To copy to clipboard, switch view to plain text mode
I tried the code (below) as I mentioned, I can't get it to work...
qdebug() << v.typename(); // returns "MYSQL*
MYSQL *handle = static_cast<MYSQL *>(v.data()); //what is MYSQL?, or what is the pointer to handle?
if (handle != NULL) // handle stays undeclared even after including QSqlDriver or QMySqlDriver (which errors on the mysql.h - not found)
{
mysql_ssl_set(handle, p2pro-application-key, p2pro-application-cert, p2pro-ca-cert, NULL, NULL); // QStrings p2pro-* are set in functions in my p2Sql class.
}
QVariant v = db.driver()->handle();
qdebug() << v.typename(); // returns "MYSQL*
MYSQL *handle = static_cast<MYSQL *>(v.data()); //what is MYSQL?, or what is the pointer to handle?
if (handle != NULL) // handle stays undeclared even after including QSqlDriver or QMySqlDriver (which errors on the mysql.h - not found)
{
mysql_ssl_set(handle, p2pro-application-key, p2pro-application-cert, p2pro-ca-cert, NULL, NULL); // QStrings p2pro-* are set in functions in my p2Sql class.
}
To copy to clipboard, switch view to plain text mode
I assume that somehow I can add specifc arguments to QSqlDatabase as mentioned in the MySQL C API - needless to mention is not documented in Qt Documentation.
Thanks for any hints or help...
Bookmarks