Parsing .mdb File in Qt4
-
Here's what I am trying to do:
I have multiple .mdb files on my desktop containing 3 tables in each with specific data that I need. I would like to parse these tables, and get data from them. Is there a way to do this in Qt4/c++ libraries?My overall goal:
I would like to take this data, and plot it in a Qwt plot (which I have already played around with already).Thanks in advance.
-
you will use the file as a database (use SQL to query data).
Here a small code to connect to a mdb file using ODBC
@QString filePath = "DRIVER={Driver do Microsoft Access (*.mdb)};FIL={CONN_NAME};DBQ=file.mdb";
QSqlDatabase db = QSqlDatabase::addDatabase("QODBC", "odbc");
db.setDatabaseName(filePath);
QSqlQuery query(db)
query.exec("SELECT * FROM TABLE;")
...
@ -
I apologize for the double post, for some reason I cannot get your code snipet to work. I have the odbc driver installed on linux, and i have the QtSql/SqlDatabae, QtSql/QODBCDriver incuded. I get the error when I try to run "sql.h: no such file or directory".
@
#include <QtCore>
#include <QtSql/QSqlDatabase>
#include <QtSql/QSqlQuery>
#include <QtSql/QODBCDriver>
#include <QtSql/qsql.h>
#include "globals.h"
#include "graph.h"
#include "graphscrollbar.h"
#include "buttonheader.h"
#include "buttonsidebar.h"
#include "mainwindow.h"
#include "ui_mainwindow.h"// file prototype
void connectODBCdatabase(QString selectedfile);void connectODBCdatabase(QString selectedfile)
{
// build database string
QString filePath = "DRIVER={Driver do Microsoft Access (*.mdb)};FIL={CONN_NAME};DBQ=";
filePath.append(selectedfile);// create database QSqlDatabase db = QSqlDatabase::addDatabase("QODBC", "odbc"); db.setDatabaseName(filePath); // get data from .mdb file QSqlQuery query(db); query.exec("SELECT * FROM TABLE tablename;");
}
@
-
Unfortunately there is a separate software suit that creates the .mdb files, which is out of my control at the moment. I thought the unixODBC driver allows the user to communicate to that specific database format, which in turn, should allow me to access the database file correct? I guess my understanding on .mdb files is vague though...
I could convert the file to a comma delimited file using tools already available in the Linux world, but lets be real here, that's unacceptable to my standards :) I would like to automate this process.
There's gotta be a way to connect using SQL query's to the file.
I thank you for your insight, I will keep searching around.
-
[quote author="Andre" date="1313780603"]On linux, you are probably out of luck. AFAIK, there is no ODBC driver for mdb on non-windows systems.[/quote]
yes, does exist, but it is paid http://www.easysoft.com/products/data_access/odbc-access-driver/You can use mdb tools to extract the data into a csv and parse as plain text (http://mdbtools.sourceforge.net/)
-
[quote author="Wagner Reck" date="1313781485"]
[quote author="Andre" date="1313780603"]On linux, you are probably out of luck. AFAIK, there is no ODBC driver for mdb on non-windows systems.[/quote]
yes, does exist, but it is paid http://www.easysoft.com/products/data_access/odbc-access-driver/You can use mdb tools to extract the data into a csv and parse as plain text (http://mdbtools.sourceforge.net/)
[/quote]
I stand corrected. Thanks for the information!
-
-
Not sure if this is an option, but...
Could you keep the actual files on a windows machine and connect to that machine over the network? If so, than it should be doable to either expose the ODBC data connection to the network, or perhaps create a Qt based server that does the actual data querying for its connected (linux) clients.