PDA

View Full Version : Database Drivers Related to Qt



StarRocks
5th October 2012, 08:16
Dear Forums,


I want some information related to the database drivers that to be included for QT....As we know that Sqlite is inbuilt given in QT SDK but i want it to be done using Mysql,Psql etc i have google searched and came to know through that,that we can use other db's too.....So can anyone help me out in letting me know how to use drivers for those databases as of Sqlite and dump data from device to machine and vice versa.........Do let me know if so any reviews and answers..........Thanks in Advance.........



Regards,

wysota
5th October 2012, 08:49
Supported Databases

StarRocks
5th October 2012, 11:00
Hi Wysota,

Thanks for the review....I havent asked anything other than QT related issues i was asking can i use db which is not Sqlite as i have google searched and found that we can use Mysql,Psql i guess thats completely related to QT if im not wrong.......I just want to know how to add plugins,drivers related to Mysql,Psql in QT........that was my Question Wysota.......Thanks in Advance ....Any solution would be appreciable..........


Regards,

sonulohani
5th October 2012, 11:23
Yes you can use it, that what he was telling.

These all are supported database list.

Supported Databases

The table below lists the drivers included with Qt. Due to license incompatibilities with the GPL, not all of the plugins are provided with Open Source Versions of Qt.

Driver name

QDB2 , QIBASE, QMYSQL, QOCI, QODBC, QPSQL, QSQLITE2, QSQLITE, QTDS

StarRocks
5th October 2012, 12:39
Hi sonulohani,

Thanks for the solutions.........As you said bcoz of few licences issue we dont have other db's inbulit in the opensource.....i completely agree with it see for using Sqlite i have written this in the .pro file QT += sql \ in the same way my question is,is there any statements that i can use for Mysql and other db's so that db connection shouldnt be a problem like having those in the .pro files that was my query..........Hope you understood me..........Thanks in advance ........Any Solution would be appreciable.......



Regards,

Lesiok
5th October 2012, 16:33
In wysota's link is described how to build plugins (drivers) for another dbs. Just read this.

StarRocks
6th October 2012, 10:00
Hi Leslok,

Thanks for the Advice.........I came to know very before through that link only that we can access different databases using Qt.....but i just wanted to know how exactly can i create a pluginn for Mysql i have gone through the links and a bit confused with it.......Wanna know what line or statement can i add in the .pro file ........Thats whai i am looking for i found in the link that mysql is stored in /usr/local where in my system its stored in /usr/share so im a bit confused with it....Can anyone give me a better solution......Any Solution would be appreciable.....Thanks in advance......


Regards,

wysota
7th October 2012, 16:45
Thanks for the review....I havent asked anything other than QT related issues i was asking can i use db which is not Sqlite as i have google searched and found that we can use Mysql,Psql i guess thats completely related to QT if im not wrong.......I just want to know how to add plugins,drivers related to Mysql,Psql in QT........that was my Question Wysota.......Thanks in Advance ....Any solution would be appreciable..........
I think you are referring to my signature.


Thanks for the Advice.........I came to know very before through that link only that we can access different databases using Qt.....but i just wanted to know how exactly can i create a pluginn for Mysql i have gone through the links and a bit confused with it.......Wanna know what line or statement can i add in the .pro file ........Thats whai i am looking for i found in the link that mysql is stored in /usr/local where in my system its stored in /usr/share so im a bit confused with it....Can anyone give me a better solution......Any Solution would be appreciable.....Thanks in advance......
You don't have to create any plugins. A plugin for MySQL is already available. As long as you have it installed, using it is just a matter of calling QSqlDatabase::addDatabase().

sonulohani
8th October 2012, 05:04
All the plugin are already available. For using it just write QT += sql in .pro file.

See the ewxample:-


#include <QtGui>
#include <QtSql>
int main(int argc,char* argv[])
{
QApplication app(argc,argv);
QTableWidget* table = new QTableWidget();
table->setWindowTitle("Connect to Mysql Database Example");

QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setHostName("192.168.11.3");
db.setDatabaseName("menudb");
db.setUserName("root");
db.setPassword("test");
if (!db.open())
{
QMessageBox::critical(0, QObject::tr("Database Error"),
db.lastError().text());
}

QSqlQuery query("SELECT * FROM test");

table->setColumnCount(query.record().count());
table->setRowCount(query.size());

int index=0;
while (query.next())
{
table->setItem(index,0,new QTableWidgetItem(query.value(0).toString()));
table->setItem(index,1,new QTableWidgetItem(query.value(1).toString()));
index++;
}

table->show();
return app.exec();
}


This is how you connect the QT with MySql.

StarRocks
8th October 2012, 11:15
Hi Sonulohani,

Thanks for the reply............I have worked on the example that you send me and its working fine.....
Regards,

Added after 51 minutes:

Dear Sonulohani,


I have one more doubt can i connect to SqlServer and QPSQL from QT because when i try to connect to the given databases it not allowing me to retrieve data rather showing me an error that "Drivers not supported" .......So please let me know is it possible to connect if so how can i create pluginns for it..............Thanks in Advance...........Any solution would be appreciable......


Regards,

sonulohani
8th October 2012, 11:50
Check the installed SQL Database drivers from this:-



QSqlDatabase db;
qDebug()<<db.drivers();


It will display a list of sql drivers installed in your system.

If you don't have that driver then you have to build it.

StarRocks
8th October 2012, 12:15
Dear sonulohani,


Thanks for the reply..........I already know that i have only Mqsql and Sqlite in my System...I would like to know how to build a library file because that solves problems of most of the database connectivity if im not wrong......Thnaks in Advance....Any Solution would be appreciable..........


Regards,

sonulohani
8th October 2012, 12:20
Hey,hit on the thanks button.

Here is the tutorial for how to build the QPSQL plugin:-

http://www.qtcentre.org/wiki/index.php?title=Building_the_QPSQL_plugin_on_Windo ws_using_MinGW

StarRocks
8th October 2012, 12:54
Dear sonulohani,


Thanks for the reply..........Im not using Windows im using Linux OS(Ubuntu).........So can you send me the steps related to building of drivers it would be good if you send me for those........Thanks in advance.........Any solution would be appreciable.........


Regards,

sonulohani
8th October 2012, 13:03
QPSQL for PostgreSQL (Version 7.3 and Above)

General Information about the QPSQL driver

The QPSQL driver supports version 7.3 and higher of the PostgreSQL server. We recommend that you use a client library from version 7.3.15, 7.4.13, 8.0.8, 8.1.4 or more recent as these versions contain security fixes, and as the QPSQL driver might not build with older versions of the client library depending on your platform.
For more information about PostgreSQL visit http://www.postgresql.org.

QPSQL Unicode Support
The QPSQL driver automatically detects whether the PostgreSQL database you are connecting to supports Unicode or not. Unicode is automatically used if the server supports it. Note that the driver only supports the UTF-8 encoding. If your database uses any other encoding, the server must be compiled with Unicode conversion support.
Unicode support was introduced in PostgreSQL version 7.1 and it will only work if both the server and the client library have been compiled with multibyte support. More information about how to set up a multibyte enabled PostgreSQL server can be found in the PostgreSQL Administrator Guide, Chapter 5.

QPSQL BLOB Support
Binary Large Objects are supported through the BYTEA field type in PostgreSQL server versions >= 7.1.
How to Build the QPSQL Plugin on Unix and Mac OS X
You need the PostgreSQL client library and headers installed.
To make qmake find the PostgreSQL header files and shared libraries, run qmake the following way (assuming that the PostgreSQL client is installed in /usr):


cd $QTDIR/src/plugins/sqldrivers/psql
qmake "INCLUDEPATH+=/usr/include/pgsql" "LIBS+=-L/usr/lib -lpq" psql.pro
make


After installing Qt, as described in the Installing Qt on X11 Platforms (http://doc.qt.digia.com/4.7.1/install-x11.html) document, you also need to install the plugin in the standard location:


cd $QTDIR/src/plugins/sqldrivers/psql
make install

wysota
8th October 2012, 13:07
Thanks for the reply..........Im not using Windows im using Linux OS(Ubuntu).........So can you send me the steps related to building of drivers it would be good if you send me for those........Thanks in advance.........Any solution would be appreciable.........


sudo apt-get install libqt4-sql-psql postgresql-client

StarRocks
8th October 2012, 13:26
Dear wysota,

Thanks for the reply..........I have already installed Postgresql in my system i query is how would i use it in Ubuntu i am very confused when to add the lines that you were asking me to do...........Let me know the suitable and understandable steps to build a .so file for the related database Postgresql and Sql Server.Thanks in advance........Any solution would be appreciable.......


Regards,

sonulohani
8th October 2012, 13:33
sudo apt-get install libqt4-sql-psql postgresql-client

This is the psql library for qt. There is no need to build the library. Just install it. It will automatically create the .so lib.

StarRocks
8th October 2012, 13:40
Dear sonulohani,

Thanks for your valuable favour..........But say me where can i find the above mentioned .so file ............Thanks in advance......Any solution would be appreciable is it the same for Sql Server..........

Regards,

Added after 4 minutes:

Dear sonulohani,


I have done with Postgresql and its working fine now i want to try with ODBC im very confused because ODBC means oracle related db but found in good search that it supports Sql server........So jus say me how to build a library for that..........Any solution would be appreciable.........Thanks n Advance................


Regards,

wysota
8th October 2012, 13:55
how would i use it in Ubuntu i am very confused when to add the lines that you were asking me to do

http://www.lmgtfy.com?q=apt-get+ubuntu

StarRocks
8th October 2012, 14:18
Dear Wysota,

I have done with Postgresql..........But having a problem with ODBC not knowing how to do it........Can you just help me out the way that you done for rest of the databases...........Thanks in advance......Any solution would be appreciable.......

Regards,

wysota
8th October 2012, 14:56
Is there any reason why you are trying all the database plugins?

For ODBC install appropriate packages for your system just like I have shown you for PostgreSQL.

StarRocks
9th October 2012, 06:31
Dear Wysota,

Thanks for the reply........Can you send me the same steps for ODBC like the way you sent me for PSQL ......I mean the commands that you sent me right similarly the same way can you give me in the form of step wise......Thanks in advance..........Any solution would be appreciable.....

Regards,

sonulohani
9th October 2012, 08:21
sudo apt-get install libqt4-sql-odbc

or download it from here:-

http://pkgs.org/download/libqt4-sql-odbc

StarRocks
9th October 2012, 10:28
Dear Wysota,

Thanks for the reply......As you gave me a link to find out right but im not knowing what this link will helpout me..I need to build drivers right for ODBC ....Can you give me in brief how do i run in Terminal of Ubuntu....That would be helpful......Thanks in advance....Any Solution would be appreciable....
http://www.lmgtfy.com?q=apt-get+ubuntu

Regards,

wysota
9th October 2012, 12:06
I need to build drivers right for ODBC ....
No, you don't.


Can you give me in brief how do i run in Terminal of Ubuntu
That's not a "I'm a Ubuntu luser, help me" forum. That's a Qt forum. To learn to use Linux, go to some other forum like www.linuxquestions.org

StarRocks
9th October 2012, 13:08
Dear Wysota,


Thanks for the reply..........I have builded Odbc driver,but when i run my program i am getting the following error message as " [unixODBC][Driver Manager]Data source name not found, and no default driver specified QODBC3: Unable to connect" ....I am not sure whether my program is wrong or the connection that i gave is wrong correct me if my program is wrong please find the code given below.........Thanks in Advance............Any solution would be appreciable.........



#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QTableWidget>
#include <QSqlDatabase>
#include <QMessageBox>
#include <qdebug.h>
#include <QtSql>

MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);

qDebug()<<"Im Venu-------------------------------";
QTableWidget* table = new QTableWidget();
table->setWindowTitle("Connect to Mysql Database Example");

qDebug()<<"Im coming Back to Rock";

// qDebug()<<"Im Waiting for the Value"<<app.libraryPaths();

QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");

// db.setDatabaseName("Data Source=192.168.1.73,1433;Network Library=DBMSSOCN;"
// );


db.setHostName("192.168.1.73");
db.setDatabaseName("Test");
db.setUserName("sa");
db.setPassword("sa@123");


// db.setDatabaseName( "Test" );
// db.setUserName( "sa" );
// db.setPassword( "sa@123" );
// db.setHostName( "192.168.1.73" );

// db.setHostName("localhost");
// db.setDatabaseName("test");
// db.setUserName("venugopal");
// db.setPassword("admin");

qDebug()<<db.drivers()<<"Lemme speak something";
if (!db.open())
{
QMessageBox::critical(0, QObject::tr("Database Error"),
db.lastError().text());
}

QSqlQuery query;
bool a= query.exec("SELECT * FROM Employee");
qDebug()<<a<<"111111111111111111111111111111111111111111111";

table->setColumnCount(query.record().count());
table->setRowCount(query.size());

int index=0;
while (query.next())
{
table->setItem(index,0,new QTableWidgetItem(query.value(0).toString()));
table->setItem(index,1,new QTableWidgetItem(query.value(1).toString()));
index++;
}

table->show();

}

MainWindow::~MainWindow()
{
delete ui;
}

void MainWindow::changeEvent(QEvent *e)
{
QMainWindow::changeEvent(e);



switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;

}
}






Regards,

wysota
9th October 2012, 13:30
Definitely your database name is wrong. It should comply to ODBC standards of choosing the data source.


For the QODBC driver, the name can either be a DSN, a DSN filename (in which case the file must have a .dsn extension), or a connection string.