QODBC in QML? Not Able to find tables
-
I am currently trying to make a few simple queries through js in a qml file. I am working on a Windows XP machine where I have an ODBC connection to an Oracle RDB. In my main.cpp I was able to figure out how to get connected to the database but the connection doesn't seem to be reachable in my knowledge in the QML file. This is what I have so far.
main.cpp
@ #define DB_DRIVER "QODBC"
// you need to replace the following macros with the values relevant to
// your DSN.
// DB_DBNAME = the name of the DSN.
#define DB_DBNAME "level2dave"
// DB_USER = a username valid for your database
#define DB_USER ""
// DB_PASSWD = password for DB_USER
#define DB_PASSWD ""
// DB_HOST is not relevant to DSNs
#define DB_HOST ""QSqlDatabase level2 = QSqlDatabase::addDatabase(DB_DRIVER); level2.setDatabaseName(DB_DBNAME); level2.setUserName(DB_USER); level2.setPassword(DB_PASSWD); level2.setHostName(DB_HOST); if (!level2.open()) { QMessageBox::critical(0, qApp->tr("Cannot open database"), qApp->tr("Unable to establish a database connection.\n" "Click Cancel to exit."), QMessageBox::Cancel); return false; }
@
I am 99% sure this is working because I don't get the QMessageBox anymore. That took a good long while, but now over in the qml file it seems that I can't get access to the database that I just linked to. This what I have there.
@ function linkthedb() {
var level2 = openDatabaseSync("level2", "1.0", "ODBC Connect", 10000000000000);level2.transaction( function(tx) { // Show all var rs = tx.executeSql('SELECT * FROM knowntable'); } ) }
@
When I run all of this it just tells me the knowntable is not there. I know it is. I must not be really connecting to the database in the qml file. I thought that the addDatabase would put the ODBC database on the same level as the SqLite ones that are on the device. If anyone can help I would love a hand.
-
Database API is for offline storage, it's SQLite database.
So at the moment I don't think it's possible to connect to ODBC database, you will need to provide bridge in C++. Shouldn't be that hard.
-
I am no good at C++, which why I wanted to do it in QML in the first place, but oh well. Thanks for the reply. I guess i might have to get my hands a little dirtier.
-
Is it still not possible do this without c++?
-
[quote author="shullw" date="1314391681"]I am currently trying to make a few simple queries through js in a qml file. I am working on a Windows XP machine where I have an ODBC connection to an Oracle RDB. In my main.cpp I was able to figure out how to get connected to the database but the connection doesn't seem to be reachable in my knowledge in the QML file. This is what I have so far.
main.cpp
@ #define DB_DRIVER "QODBC"
// you need to replace the following macros with the values relevant to
// your DSN.
// DB_DBNAME = the name of the DSN.
#define DB_DBNAME "level2dave"
// DB_USER = a username valid for your database
#define DB_USER ""
// DB_PASSWD = password for DB_USER
#define DB_PASSWD ""
// DB_HOST is not relevant to DSNs
#define DB_HOST ""QSqlDatabase level2 = QSqlDatabase::addDatabase(DB_DRIVER); level2.setDatabaseName(DB_DBNAME); level2.setUserName(DB_USER); level2.setPassword(DB_PASSWD); level2.setHostName(DB_HOST); if (!level2.open()) { QMessageBox::critical(0, qApp->tr("Cannot open database"), qApp->tr("Unable to establish a database connection.\n" "Click Cancel to exit."), QMessageBox::Cancel); return false; }
@
I am 99% sure this is working because I don't get the QMessageBox anymore. That took a good long while, but now over in the qml file it seems that I can't get access to the database that I just linked to. This what I have there.
@ function linkthedb() {
var level2 = openDatabaseSync("level2", "1.0", "ODBC Connect", 10000000000000);level2.transaction( function(tx) { // Show all var rs = tx.executeSql('SELECT * FROM knowntable'); } ) }
@
When I run all of this it just tells me the knowntable is not there. I know it is. I must not be really connecting to the database in the qml file. I thought that the addDatabase would put the ODBC database on the same level as the SqLite ones that are on the device. If anyone can help I would love a hand.[/quote]
you will need to provide bridge in C++