Page 1 of 2 12 LastLast
Results 1 to 20 of 23

Thread: Connectingto MySQL with QODBC3

  1. #1
    Join Date
    Apr 2006
    Posts
    40
    Thanks
    12
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Question Connectingto MySQL with QODBC3

    Hi I'm trying to connect to a MySQL 3.23 on a Fedora Core 1 with an app I made on Qt 3.1.2
    I installed the QODBC3 plugin through yum
    yum install qt-ODBC
    it installed also the Unix-ODBC driver

    so I connect to MySQL server as this:

    Qt Code:
    1. QSqlDatabase *defaultDB;
    2. bool creaConexion()
    3. {
    4.  
    5. defaultDB = QSqlDatabase::addDatabase( DBDRIVER );
    6. defaultDB->setHostName( DB_HOSTNAME );
    7. defaultDB->setDatabaseName( "DRIVER={MySQL};Server="+DB_HOSTNAME+";Database="+DB_NOM+";Uid= "+DB_USR+";Pwd="+DB_PASS+";" );
    8. defaultDB->setUserName( DB_USR );
    9. defaultDB->setPassword( DB_PASS );
    10.  
    11. if ( ! defaultDB->open() ) {
    12. QMessageBox::warning(0, "Fallo de conexión", "No se pudo conectar con la base de datos: " + DB_NOM + "tabla: " + DB_TABLA + "\n" + defaultDB->lastError().driverText());
    13. return FALSE;
    14. }
    15. QMessageBox::information(0,"Conexión estabecida","Conectado a: " + DB_HOSTNAME + " " + "tabla: " + DB_TABLA + " "+ DB_NOM);
    16. return TRUE;
    17. }
    To copy to clipboard, switch view to plain text mode 

    I don't see what's wrong so I ask you for help

    I'm geting this error:

    Warning: QSqlDatabaseManager unable to open database: [unixODBC][Driver Manager]Data source name not found, and no default driver specified : QODBC3: Unable to connect
    Battle Programmer Ph1L
    Philip_Anselmo
    Greetings From Osorno - Chile

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

    Default Re: Connectingto MySQL with QODBC3

    You have to setup the database in Unix-ODBC. Unfortunately I know nothing about it Maybe mr Google does.

  3. #3
    Join Date
    Apr 2006
    Posts
    40
    Thanks
    12
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Question Re: Connectingto MySQL with QODBC3

    I checked the driver configuration in odbc

    the /etc/odbcnist.ini looks like this:

    Qt Code:
    1. # Example driver definitinions
    2. #
    3. #
    4.  
    5. # Included in the unixODBC package
    6. [PostgreSQL]
    7. Description = ODBC for PostgreSQL
    8. Driver = /usr/lib/libodbcpsql.so
    9. Setup = /usr/lib/libodbcpsqlS.so
    10. FileUsage = 1
    11.  
    12.  
    13. # Driver from the MyODBC package
    14. # Setup from the unixODBC package
    15. [MySQL]
    16. Description = ODBC for MySQL
    17. Driver = /usr/lib/libmyodbc.so
    18. Setup = /usr/lib/libodbcmyS.so
    19. FileUsage = 1
    To copy to clipboard, switch view to plain text mode 

    the only problem is that I can't find /usr/lib/libmyodbc.so
    that file is missing on this fedora core 1 wich uses unixODBC 2.2.8 and I can't install other version because of the dependencies and I just can't find the 2.2.8 version on the net

    I just can't work like that
    How can I get that damn .so file?
    Battle Programmer Ph1L
    Philip_Anselmo
    Greetings From Osorno - Chile

  4. #4
    Join Date
    Apr 2006
    Posts
    40
    Thanks
    12
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Red face Re: Connectingto MySQL with QODBC3

    jjaja nevermind I just founded the myodbc on the fedora website :P

    but now it throwsme a segment violation :S:S:S

    is this code right?:

    Qt Code:
    1. QSqlDatabase *defaultDB;
    2. bool creaConexion()
    3. {
    4.  
    5. defaultDB = QSqlDatabase::addDatabase( DBDRIVER );
    6. defaultDB->setHostName( DB_HOSTNAME );
    7. defaultDB->setDatabaseName( "DRIVER={MySQL};Server="+DB_HOSTNAME+";Database="+DB_NOM+";Uid= "+DB_USR+";Pwd="+DB_PASS+";" );
    8. defaultDB->setUserName( DB_USR );
    9. defaultDB->setPassword( DB_PASS );
    10.  
    11. if ( ! defaultDB->open() ) {
    12. QMessageBox::warning(0, "Fallo de conexión", "No se pudo conectar con la base de datos: " + DB_NOM + "tabla: " + DB_TABLA + "\n" + defaultDB->lastError().driverText());
    13. return FALSE;
    14. }
    15. QMessageBox::information(0,"Conexión estabecida","Conectado a: " + DB_HOSTNAME + " " + "tabla: " + DB_TABLA + " "+ DB_NOM);
    16. return TRUE;
    17. }
    To copy to clipboard, switch view to plain text mode 
    Battle Programmer Ph1L
    Philip_Anselmo
    Greetings From Osorno - Chile

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

    Default Re: Connectingto MySQL with QODBC3

    Check if defaultDB!=0 before dereferencing the pointer (line 6).

  6. #6
    Join Date
    Apr 2006
    Posts
    40
    Thanks
    12
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Unhappy Re: Connectingto MySQL with QODBC3

    Qt Code:
    1. QSqlDatabase *defaultDB;
    2. bool creaConexion()
    3. {
    4.  
    5. defaultDB = QSqlDatabase::addDatabase( DBDRIVER );
    6. if (defaultDB!=0)
    7. {
    8. defaultDB->setHostName( DB_HOSTNAME );
    9. qWarning("host seteado");
    10. defaultDB->setDatabaseName( "DRIVER={MySQL};Server="+DB_HOSTNAME+";Database="+DB_NOM+";Uid= "+DB_USR+";Pwd="+DB_PASS+";" );
    11. defaultDB->setUserName( DB_USR );
    12. defaultDB->setPassword( DB_PASS );
    13.  
    14. if ( ! defaultDB->open() )
    15. {
    16. QMessageBox::warning(0, "Fallo de conexión", "No se pudo conectar con la base de datos: " + DB_NOM + "tabla: " + DB_TABLA + "\n" + defaultDB->lastError().driverText());
    17. return FALSE;
    18. }
    19. QMessageBox::information(0,"Conexión estabecida","Conectado a: " + DB_HOSTNAME + " " + "tabla: " + DB_TABLA + " "+ DB_NOM);
    20. qWarning("No pesko");
    21. return FALSE;
    22. }
    23. }
    To copy to clipboard, switch view to plain text mode 

    It stills says segment violation

    If I comment the last part.. from if ( ! defaultDB->open() ) 'till the last return
    It doesn't tells me the segment violation stuff.. but when I try to fill the qdatatable with a qsqlcursor the segment violation stuff comes out

    so I have to find a way to do that :S any ideas?
    because I don't have any
    Battle Programmer Ph1L
    Philip_Anselmo
    Greetings From Osorno - Chile

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

    Default Re: Connectingto MySQL with QODBC3

    Try with some other driver (like QSQLITE or better yet with QMYSQL) to see if your code is alright. If it won't crash, then it means there is something wrong with the driver.

  8. #8
    Join Date
    Apr 2006
    Posts
    40
    Thanks
    12
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Question Re: Connectingto MySQL with QODBC3

    I've tryed with QMySQL3 and it works perfectly, but i'm not able to use the qmysql on windows so I can't use it now because I need to work with the same code on Linux Qt 3.1.2 and windows Qt 4.1.2-3

    My question is.. once I made the connection with odbc, the workaround with qsqlcursor is the same as with qmysql3?
    Battle Programmer Ph1L
    Philip_Anselmo
    Greetings From Osorno - Chile

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

    Default Re: Connectingto MySQL with QODBC3

    Quote Originally Posted by Philip_Anselmo
    I've tryed with QMySQL3 and it works perfectly, but i'm not able to use the qmysql on windows
    Why not?
    so I can't use it now because I need to work with the same code on Linux Qt 3.1.2 and windows Qt 4.1.2-3
    You won't be, because Qt3 and Qt4 database interfaces differ (for example addDatabase of one of them returns a pointer and in the other -- an object).

    My question is.. once I made the connection with odbc, the workaround with qsqlcursor is the same as with qmysql3?
    The general idea of using Qt database abstraction is that it is abstract -- it doesn't depend on the driver used. You should be able to use ODBC and MYSQL drivers using the same code. The only line which differs will be the one which chooses the driver type, but you can work it around using #ifdef-#endif constructions.

  10. The following user says thank you to wysota for this useful post:

    Philip_Anselmo (7th June 2006)

  11. #10
    Join Date
    Apr 2006
    Posts
    40
    Thanks
    12
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Unhappy Re: Connectingto MySQL with QODBC3

    I know the diference on qt3 and 4 with the pointer on the database connection

    the problem on using qmysql on windows... well at this time I just think it's imposible... at least everything I've tryed didn't work I just give up on that.. if you search all my posts here I think you'll find out that 4/5 of them are about the qmysql pluginI even made a how-to about it and it worked for others but not here on 3 windows!!! Qt hates me

    I just hope ODBC works... if not.. well.. no more qt+mysql for me


    by the way I think it isn't connecting:

    Qt Code:
    1. QSqlDatabase *defaultDB;
    2. bool creaConexion()
    3. {
    4. defaultDB = QSqlDatabase::addDatabase( DBDRIVER );
    5. if (defaultDB!=0)
    6. {
    7. defaultDB->setHostName( DB_HOSTNAME );
    8. qWarning("host seteado");
    9. defaultDB->setDatabaseName( "Driver={MySQL};Server="+DB_HOSTNAME+";Database="+DB_NOM+";Uid="+DB_USR+";Pwd="+DB_PASS+";" );
    10. defaultDB->setUserName( DB_USR );
    11. defaultDB->setPassword( DB_PASS );
    12.  
    13. if ( ! defaultDB->open() )
    14. {
    15. QMessageBox::warning(0, "Fallo de conexión", "No se pudo conectar con la base de datos: " + DB_NOM + "tabla: " + DB_TABLA + "\n" + defaultDB->lastError().driverText());
    16. return FALSE;
    17. }
    18. QMessageBox::information(0,"Conexión estabecida","Conectado a: " + DB_HOSTNAME + " " + "tabla: " + DB_TABLA + " "+ DB_NOM);
    19. qWarning("No pesko");
    20. return TRUE;
    21. }
    22. }
    To copy to clipboard, switch view to plain text mode 
    the qWarning tells me:
    QODBC3: Unable to connect
    and on console:
    QODBCDriver::disconnect: Unable to disconnect datasource Error: [unixODBC][Driver Manager]Connnection does not exist
    Battle Programmer Ph1L
    Philip_Anselmo
    Greetings From Osorno - Chile

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

    Default Re: Connectingto MySQL with QODBC3

    Quote Originally Posted by Philip_Anselmo
    the problem on using qmysql on windows... well at this time I just think it's imposible... at least everything I've tryed didn't work I just give up on that.. if you search all my posts here I think you'll find out that 4/5 of them are about the qmysql pluginI even made a how-to about it and it worked for others but not here on 3 windows!!! Qt hates me
    You're probably making the same mistake all the time. But doesn't Qt for Windows come with a precompiled binary mysql driver? Or maybe you could ask someone else to compile the driver for you? There is really no reason to reinvent the wheel...

  13. #12
    Join Date
    Apr 2006
    Posts
    40
    Thanks
    12
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Connectingto MySQL with QODBC3

    I-ve done that
    but even when the plugin is present it tells me driver not loaded
    Battle Programmer Ph1L
    Philip_Anselmo
    Greetings From Osorno - Chile

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

    Default Re: Connectingto MySQL with QODBC3

    Did you check its dependencies? Among other, it depends on mysqlclient library... It has to be available and has to be found by the plugin.

  15. The following user says thank you to wysota for this useful post:

    Philip_Anselmo (8th June 2006)

  16. #14
    Join Date
    Apr 2006
    Posts
    40
    Thanks
    12
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Talking Re: Connectingto MySQL with QODBC3

    yeap I checked that too
    and it also depends on MSJAVA.dll but it weren't available
    but I've never even thought about using java on neither one of the 2 pcs where i've compiled and made my app, and according to JaCek and I belived him that, that's not the problem

    but well about the ODBC? any ideas? anyone else read this?
    I don't want to bother you too much wysota

    can anyone post an example code of a connection to mysql through ODBC that fills a datatable or some structure like that or simplily uses a cursor? Please

    I uploaded my proyect so you could dowload it from this address
    Last edited by Philip_Anselmo; 8th June 2006 at 15:33.
    Battle Programmer Ph1L
    Philip_Anselmo
    Greetings From Osorno - Chile

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

    Default Re: Connectingto MySQL with QODBC3

    You're not bothering me, don't worry.

    Which version of mysql do you use anyway?

    BTW. I don't know if MySQL through ODBC supports cursors...

  18. #16
    Join Date
    Apr 2006
    Posts
    40
    Thanks
    12
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Red face Re: Connectingto MySQL with QODBC3

    I'm using mysql Ver 11.18 Distrib 3.23.58, for redhat-linux-gnu (i386), Qt 3.1.2,Fedora Core 1,ODBC 2.2.8, MyODBC-2.50.39-17, g++ (GCC) 3.3.2 20031022

    here you can see a log of my app's strace
    Battle Programmer Ph1L
    Philip_Anselmo
    Greetings From Osorno - Chile

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

    Default Re: Connectingto MySQL with QODBC3

    I'm starting to be getting lost... Last time you were talking about Qt4 and Windows, now about Qt3 and Linux... Could you make up your mind? Which driver can't you enable?

  20. #18
    Join Date
    Apr 2006
    Posts
    40
    Thanks
    12
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Red face Re: Connectingto MySQL with QODBC3

    jajaja

    I'm programming on the fedora everything is made here on the fedora, the qmysql3 pluging works perfect here on Linux but not on windows with qt4 and I have to make it so it works on both Linux Qt 3.1.2 and windows Qt 4.1.2
    on windows I can't make the plugin to work.. it compiles some times but it still tells me driver not loaded so the qmysql3 is out of the question because it works only on linux
    now the odbc isn't working here on the linux so I haven't tested it yet on windows
    the most important right now is that it has to work on windows, because the final users will, the most of the time (not to say always), work on windows. Personaly I prefer Linux to work and wintendo as a game console and the office, but that's me.
    So I have to make it work on windows.
    Battle Programmer Ph1L
    Philip_Anselmo
    Greetings From Osorno - Chile

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

    Default Re: Connectingto MySQL with QODBC3

    Quote Originally Posted by Philip_Anselmo
    I'm programming on the fedora everything is made here on the fedora, the qmysql3 pluging works perfect here on Linux but not on windows with qt4 and I have to make it so it works on both Linux Qt 3.1.2 and windows Qt 4.1.2
    So maybe it's better to switch to Qt4 on Linux too? Why develop two apps instead of one?

    on windows I can't make the plugin to work.. it compiles some times but it still tells me driver not loaded
    Maybe it can't find some required component? Like the mysql library I already mentioned.

    so the qmysql3 is out of the question because it works only on linux
    So what? Use qmysql on Linux and qodbc on Windows... Who said you have to use the same driver?

  22. #20
    Join Date
    Apr 2006
    Posts
    40
    Thanks
    12
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Red face Re: Connectingto MySQL with QODBC3

    I can't install qt 4.1.2 here because of some libraries.. fedora core 1......

    the libmysqlclient is present when i compile

    and well the lastone.. i don't know maybe I just could do that but that depends on my boss's opinion..
    and the 1º one also depends on my boss xD
    if I could I would use Debian Sarge...
    I need a notebook
    I just wish I had an Alienware

    so any ideas about this?:

    QODBCDriver::disconnect: Unable to disconnect datasource Error: [unixODBC][Driver Manager]Connnection does not exist
    I just founded a post on qtforum that someone has the same problem.. but on that forum none ever answers
    Battle Programmer Ph1L
    Philip_Anselmo
    Greetings From Osorno - Chile

Similar Threads

  1. Embedded Mysql Windows Qt4.1
    By benguela in forum Qt Programming
    Replies: 7
    Last Post: 17th January 2007, 00:13
  2. connecting to MySQL through it's API
    By Philip_Anselmo in forum Installation and Deployment
    Replies: 20
    Last Post: 30th May 2006, 23:22
  3. Replies: 1
    Last Post: 21st March 2006, 12:54
  4. mySql Result Datatype issues!!!
    By bera82 in forum Qt Programming
    Replies: 2
    Last Post: 21st March 2006, 10:26
  5. Qt 4.1 OS on Windows & mysql
    By neeko in forum Installation and Deployment
    Replies: 10
    Last Post: 31st January 2006, 20:22

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
  •  
Qt is a trademark of The Qt Company.