Results 1 to 20 of 23

Thread: Connectingto MySQL with QODBC3

Hybrid View

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

    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,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    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
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    12

    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
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    12

    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,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    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
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    12

    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,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    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
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    12

    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,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    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
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    12

    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,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    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...

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.