Database connectivity
-
Qt supports connecting with server-type databases like MySql just fine, however, you will need to build the driver yourself (I think due to some legal concerns). The source code is there with your Qt sources.
-
@daliusd: our project is generating a hotel menu using touch interface...we are using intel atom kit...'
customer will be ordering the menu at the client side and server end will have the database..chefs pc also will be accessing the data...this our project in short...
we are doing the front end now...we are able to code for server part(server being the localhost)..like connecting to the database..but if server and client are located at different places where to specify the ip address ..so can u please suggest code for accessing the database located at separate server. -
OK. I see. My recommendation: create simple RESTful HTTP service that connects to DB. Now I think it is simpler to make client configurable: just add possibility to point client to server and that's it. You can give clients with predefined server value to customers because I guess you are in control here. Add possibility to save most commonly used servers (even if there is just single one now).
If you still want to make server discoverable you can look into broadcast/multicast but that will work only if client and server are in the same local network. As well it creates more problems in the end than solves (I'm saying that from my experience).
-
@daliusd: thanks a lot for the help..but we are new to qt so it would helpful if you could give us a code snippet of the same...
-
I'm not sure what you are asking for. Based on what you have written start learning Qt Quick (QML + JS). Go through tutorials and examples and try writing something. E.g. this http://doc.qt.digia.com/qt/declarative-tutorials-samegame-samegame4.html explains how to communicate with HTTP server from Qt Quick app. You can find more examples.
Now HTTP server/service itself is out of scope of Qt. You can use PHP, Node.js, ASP.NET, Python or almost anything else. Use whatever you understand (this way you will end up with cheapest solution for you).
-
I have written a program that needs to connect to a sqlite db installed on one of the computers in the network. All others computers in the network running the program should be able to connect to the db.
I have a script that connect to the server, it looks like this:
Source code
@
#include <QMessageBox>
#include <QSqlDatabase>
#include <QSqlError>
#include <QSqlQuery>
#include <QFile>
#include <QTextStream>
#include <QString>static bool createConnection()
{
QFile file;
file.setFileName("connection.txt");
if (!file.open(QFile::ReadOnly| QFile::Text)) {
QMessageBox::critical(0, qApp->tr("Error"),
qApp->tr("Cannot open connection file."
"Click Cancel to exit."), QMessageBox::Cancel);
return false;
}QTextStream in(&file);
QString DatabaseName = in.readLine();
QString UserName = in.readLine();
QString Password = in.readLine();
QString HostName = in.readLine();QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
db.setDatabaseName( DatabaseName );
db.setUserName( UserName );
db.setPassword( Password );
db.setHostName( HostName );if (!db.open()) { QMessageBox::critical(0, qApp->tr("Cannot open database"), qApp->tr("Unable to establish a database connection." "Click Cancel to exit."), QMessageBox::Cancel); return false;
}
return true;
}
#endif
@The program works when running on the computer where SQLITE is installed but fails to connect when running on all the computers in the network.
I am using the ip address of the SQLITE server as hostname.
Hope that someone could help me out in this. By the way the database is running on UBUNTU machine and I am using SQLITE 3.
Edit: please put @ tags around code sections to make them easier to read; Andre
-
SQLite is not a database server, it is a file-based database. You cannot connect to a database by setting a host and a port as if it is running as a service on a different system. It is just a file. If you can access it through the file system, you can access the database.
I'd recommend not using SQLite for networked purposes. SQLite is meant for simple local data stores. Use a real database server like MySQL or PostgreSQL for something like this.
-
[quote author="Andre" date="1359788658"]
I'd recommend not using SQLite for networked purposes. SQLite is meant for simple local data stores.[/quote]Andre, you are not exactly right http://www.sqlite.org/whentouse.html and it might work in preeth's case. However, preeth, don't use SQLite like that. You don't have enough experience clearly. Use MySQL, Percona, MariaDB or PostreSQL.
-
[quote author="daliusd" date="1359791075"][quote author="Andre" date="1359788658"]
I'd recommend not using SQLite for networked purposes. SQLite is meant for simple local data stores.[/quote]Andre, you are not exactly right http://www.sqlite.org/whentouse.html and it might work in preeth's case. [/quote]
Clearly, preeth's setup is a client/server setup. That is listed as point 1 under "When another DBMS may work better".Note that it is possible to use SQLite over a network, as long as you make sure you map the resource into the local file system (via NFS, SMB or whatever). In my experience: not all that stable, especially if your network is not very reliable.
-
[quote author="Andre" date="1359801847"]
[quote author="daliusd" date="1359791075"][quote author="Andre" date="1359788658"]
I'd recommend not using SQLite for networked purposes. SQLite is meant for simple local data stores.[/quote]Andre, you are not exactly right http://www.sqlite.org/whentouse.html and it might work in preeth's case. [/quote]
Clearly, preeth's setup is a client/server setup. That is listed as point 1 under "When another DBMS may work better".Note that it is possible to use SQLite over a network, as long as you make sure you map the resource into the local file system (via NFS, SMB or whatever). In my experience: not all that stable, especially if your network is not very reliable.
[/quote]
In short, I agree that preeth shouldn't use SQLite the way he/she wants to. I just wanted to point that SQLite might work for web sites as well as long as you understand what you are doing.