Results 1 to 11 of 11

Thread: Access an "embedded" MySQL-Database

  1. #1
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Access an "embedded" MySQL-Database

    Hi,

    I have MySQL4.* and Apache2 running and have created a database called 'qttest' with a table 'test'. All files are locatet at
    Qt Code:
    1. root@***:/var/lib/mysql/qttest# ll
    2. insgesamt 24
    3. -rw-rw---- 1 mysql mysql 65 2006-02-18 10:18 db.opt
    4. -rw-rw---- 1 mysql mysql 8578 2006-02-18 10:19 test.frm
    5. -rw-rw---- 1 mysql mysql 40 2006-02-18 10:19 test.MYD
    6. -rw-rw---- 1 mysql mysql 1024 2006-02-18 10:19 test.MYI
    To copy to clipboard, switch view to plain text mode 
    So if I connet in Qt via the localhost of my running Apache all works fine.
    Qt Code:
    1. QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
    2. db.setHostName("localhost");
    3. db.setDatabaseName("qttest");
    4. db.setUserName("root");
    5. db.setPassword("");
    6. bool ok = db.open();
    7. [... SELECT ...]
    To copy to clipboard, switch view to plain text mode 
    But how can I connect to the qttest.test table if no Apache and MySQL is running? What value I need for db.setHostName, and how tell I Qt to use the files in /var/lib/mysql/qttest?



    Thanks
    Lykurg

    P.s.: SQLite is no alternative for me.

  2. #2
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Access an "embedded" MySQL-Database

    Quote Originally Posted by Lykurg
    But how can I connect to the qttest.test table if no Apache and MySQL is running?
    check Open()
    a life without programming is like an empty bottle

  3. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Access an "embedded" MySQL-Database

    Quote Originally Posted by zlatko
    check Open()
    If I understand you right, I shuold read http://doc.trolltech.com/4.0/qsqldatabase.html#open, but I don't find things, that could help me.

    Just as well checking the output of lastError() dosen't help me much, because I know, that using QSqlDatabase::setHostName with the local dirpath produceses "Unknown MySQL Server Host '/var/lib/mysql/qttest'", but if I leave empty, it takes localhost, and without running mysql-server there is the warning, that it can't connect via socket...

    Also the dirpath/file in QSqlDatabase::setDatabaseName dosen't work, as with SQLite.


    So could you please give me some more information?



    Thanks

    Lykurg

  4. #4
    Join Date
    Feb 2006
    Location
    Enschede, NL, EU
    Posts
    19
    Thanks
    1
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: Access an "embedded" MySQL-Database

    As far as I know mysql always works in client-server mode... for using an embedded db engine you're stuck with one thats meant to operate in such a way like sqlite.

    mysql does support both unix sockets and tcp connections, but it's always gonna use some sort of transport layer to the mysqld

  5. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Access an "embedded" MySQL-Database

    Quote Originally Posted by ReilenBlaeyze
    mysql does support both unix sockets and tcp connections, but it's always gonna use some sort of transport layer to the mysqld
    That means, that I have to deliver MySQL with my programm, and start the MySQL-Server-Engine or what ever in main() to be abel to connect with my Databases at later time.

    Pfff, then I better use my time to try to get REGEXP run in SQLite with QT.


    Lykurg

  6. #6
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Access an "embedded" MySQL-Database

    Oh .....
    MySql must be run in server!
    And then your qt program via QSqlDatabase can conect to your db!
    a life without programming is like an empty bottle

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Access an "embedded" MySQL-Database

    You can run an embedded mysql server in your application. You need to link with "-lmysqld".

    More info on the subject:
    http://mysqld.active-venture.com/Nut...ded_MySQL.html
    http://dev.mysql.com/doc/refman/4.1/en/libmysqld.html

  8. #8
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Access an "embedded" MySQL-Database

    I already saw these urls and read it, but still what values do I need then for setHostName() and setDatabaseName(), when I want use provided tables (e.g. /home/me/db/testtable.frm, and the *MYD *MYI)?


    Thanks for helping

    Lykurg

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Access an "embedded" MySQL-Database

    If you use an embedded dbms, you can probably leave the fields empty.

    Here are some examples on using the embedded mysql server. The connection strings should be directly usable in Qt routines too (they use NULLs, so it's equal to leaving the connection fields blank). The database name is the database name of your database Just remember to set up the dbms properly (to use the database files of your choice).

  10. #10
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Access an "embedded" MySQL-Database

    Well at this time I yet have problems bilding QT with mysqld. Because I want not build a plugin, so that I can compile my program static. (Even if this is possible!?)

    What I have done is Downloading the sources of Qt4.1 and MySQL4.* and have configured Qt with:

    Qt Code:
    1. ./configure -v -release -fast -static -qt-sql-mysql -qt-sql-sqlite -I/usr/include/mysql/ -L/usr/local/lib -lmysqld
    To copy to clipboard, switch view to plain text mode 

    But I saw that ./configure outputs:
    Qt Code:
    1. qmake vars ...... [...] "CONFIG += use_libmysqlclient_r"
    2. [... but also ...] "LIBS+= -lmysqld"
    To copy to clipboard, switch view to plain text mode 

    So I hoped it will work anyway (even when there is the libmysql-flag), so 2h later I saw: it dosn't

    It still uses my local MySQL-server. So my big Question:

    Is it possible to compile Qt static with the embedded MySQL-driver mysqld?


    Lykurg

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Access an "embedded" MySQL-Database

    It is not Qt which needs to be linked with the embedded server but rather your application. Qt serves only as a client.

Similar Threads

  1. Putting and getting images from MySQL database?
    By allensr in forum Qt Programming
    Replies: 2
    Last Post: 13th May 2007, 22:47
  2. Database access issue
    By Gayathri in forum Newbie
    Replies: 3
    Last Post: 23rd November 2006, 08:41
  3. Database access from Qt
    By nimmyj in forum Qt Programming
    Replies: 1
    Last Post: 23rd November 2006, 07:51
  4. Qt and MySQL Database Connection
    By shamik in forum Qt Programming
    Replies: 41
    Last Post: 6th October 2006, 13:48
  5. Issues regarding QMySql drivers and mysql database
    By bera82 in forum Qt Programming
    Replies: 2
    Last Post: 10th August 2006, 18:50

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.