Results 1 to 13 of 13

Thread: What does QSqlDatabase::removeDatabase do exactly?

  1. #1
    Join Date
    Feb 2010
    Posts
    10
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default What does QSqlDatabase::removeDatabase do exactly?

    I was testing the sqlbrowser example provided in the QTDIR/demos/sqlbrowser directory but somehow ran into a "segmantation fault"

    Here is what I did:
    1. try to connect to a bogus database by purposely providing a wrong database name,
    and it return "An error occurred while opening the connection: Unknown database 'bogus' QMYSQL: Unable to connect" as expected.
    2. Now, try to connect to the correct database, and I got "segmantation fault"!!

    The key here is "when" this unable to connect happens... I mean if I created a successful connection on the very first try, then any subsequent attempts to make a correct/incorrect connection will just work as they are supposed to without causing any segmentation fault. However, if the very first attempt failed like when I provided a wrong database name, then the subsequent attempt to make another connection will cause the segmentation fault.

    here is the code that's causing the headache..

    Qt Code:
    1. QSqlError Browser::addConnection(const QString &driver, const QString &dbName, const QString &host,
    2. const QString &user, const QString &passwd, int port)
    3. {
    4. static int cCount = 0;
    5.  
    6. QSqlError err;
    7. QSqlDatabase db = QSqlDatabase::addDatabase(driver, QString("Browser%1").arg(++cCount));
    8. db.setDatabaseName(dbName);
    9. db.setHostName(host);
    10. db.setPort(port);
    11. if (!db.open(user, passwd)) {
    12. err = db.lastError();
    13. db = QSqlDatabase();
    14. QSqlDatabase::removeDatabase(QString("Browser%1").arg(cCount));
    15. }
    16. connectionWidget->refresh();
    17.  
    18. return err;
    19. }
    To copy to clipboard, switch view to plain text mode 

    What I found is that if I commented out "QSqlDatabase::removeDatabase(QString("Browser%1") .arg(cCount));", then the segmentation fault goes away...but QSqlDatabase::connectionNames() will return both good and bad connections.....not very useful...

    I also found that this seems to be happening to the Solaris platform only. As I have the same version of Qt and MySQL loaded on another Windows machine, and this segmentation faults never happened to that Windows version of sqlbrowser demo.

    so the question is what does QSqlDatabase::removeDatabase ( const QString & connectionName ) do exactly other than remove the database connection connectionName from the list of database connections ?

    I'm using
    Qt 4.5.3
    MySQL 5.1.44

    any feedback is appreciated....
    Last edited by wysota; 19th March 2010 at 09:04.

  2. #2
    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: What does QSqlDatabase::removeDatabase do exactly?

    Qt is open-source so...

    Qt Code:
    1. void QSqlDatabase::removeDatabase(const QString& connectionName)
    2. {
    3. QSqlDatabasePrivate::removeDatabase(connectionName);
    4. }
    5.  
    6. void QSqlDatabasePrivate::removeDatabase(const QString &name)
    7. {
    8. QConnectionDict *dict = dbDict();
    9. Q_ASSERT(dict);
    10. QWriteLocker locker(&dict->lock);
    11.  
    12. if (!dict->contains(name))
    13. return;
    14.  
    15. invalidateDb(dict->take(name), name);
    16. }
    To copy to clipboard, switch view to plain text mode 

    ... and ...

    Qt Code:
    1. void QSqlDatabasePrivate::invalidateDb(const QSqlDatabase &db, const QString &name)
    2. {
    3. if (db.d->ref != 1) {
    4. qWarning("QSqlDatabasePrivate::removeDatabase: connection '%s' is still in use, "
    5. "all queries will cease to work.", name.toLocal8Bit().constData());
    6. db.d->disable();
    7. db.d->connName.clear();
    8. }
    9. }
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Feb 2010
    Posts
    10
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: What does QSqlDatabase::removeDatabase do exactly?

    Hi wysota,

    thanks for the replay. I can see the definition of QSqlDatabase::removeDatabase. But this doesn't explain why the segmentation fault, does it? Can you duplicate the same segmentation fault when running this sqlbrowser demo on solaris or unix-like machine?

  4. #4
    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: What does QSqlDatabase::removeDatabase do exactly?

    Quote Originally Posted by ML View Post
    I can see the definition of QSqlDatabase::removeDatabase. But this doesn't explain why the segmentation fault, does it?
    It shows potential places and situation where such a crash could occur. As you see there is more or less nothing here that could lead to a crash. I'd say the problem is elsewhere. You can get a backtrace from the debugger to see if the crash is in your app, Qt's database driver or MySQL's client library.

    Can you duplicate the same segmentation fault when running this sqlbrowser demo on solaris or unix-like machine?
    I don't have solaris at hand If you prepare a minimal compilable example reproducing the problem, I will run it on my Linux box and see if I can reproduce it.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: What does QSqlDatabase::removeDatabase do exactly?

    Works fine here connecting to a MYSQL db on localhost. I'm on a Debian box.

  6. #6
    Join Date
    Feb 2010
    Posts
    10
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: What does QSqlDatabase::removeDatabase do exactly?

    To Norobro,

    Did you try to connect to a bogus database on the very first try? this should return Unknown database 'bogus' QMYSQL: Unable to connect" as expected....then try to connect again...this is where the segmentation fault happens to me....

    To wysota,

    you should find this sqlbrowser app in the standard Qt installation directory...etc QTDIR/demos/sqlbrowser
    if you don't have it...I have attached this app for you to try...

    thanks for all your feedback..
    Attached Files Attached Files

  7. #7
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: What does QSqlDatabase::removeDatabase do exactly?

    Yep. I did exactly what you described in your first post. I got real creative and used "bogus" as the db name, got the popup dialog "unable to open database", clicked ok and entered a valid db. No segfault.

  8. #8
    Join Date
    Feb 2010
    Posts
    10
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: What does QSqlDatabase::removeDatabase do exactly?

    I'm real confused now...Could it be the problem with QMYSQL driver? But, that doesn't make much sense because I'm able to connect successfully to the MySQL server if entered the correct database name and thereafter.....

    any help is appreciated..

  9. #9
    Join Date
    Feb 2010
    Posts
    10
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: What does QSqlDatabase::removeDatabase do exactly?

    I ran through the gdb debugger, and here is the output:

    Program received signal SIGSEGV, Segmentation fault.
    my_strcasecmp_8bit (cs=0x0, s=0xffffffff <Address 0xffffffff out of bounds>, t=0x6c <Address 0x6c out of bounds>) at ctype-simple.c:244
    244 ctype-simple.c: No such file or directory.
    in ctype-simple.c
    Current language: auto; currently minimal



    And from (gdb) backtrace:

    my_strcasecmp_8bit (cs=0x1, s=0xffcfb6b6 <Address 0xffcfb6b6 out of bounds>, t=0x6c <Address 0x6c out of bounds>) at ctype-simple.c:244
    #1 0xfd76c57c in get_charset_number (charset_name=0x69f38 "latin1", cs_flags=32) at charset.c:447
    #2 0xfd76c9a0 in get_charset_by_csname (cs_name=0x69f38 "latin1", cs_flags=32, flags=16) at charset.c:564
    #3 0xfd78ebfc in mysql_init_character_set (mysql=0x112b00) at client.c:1806
    #4 0xfd78f5f0 in mysql_real_connect (mysql=0x112b00, host=0xfd8044cc "localhost", user=0xbcd78 "", passwd=0xe6150 "",
    db=0x28 <Address 0x28 out of bounds>, port=0, unix_socket=0xfd801c6c "/tmp/mysql.sock", client_flag=3631699) at client.c:2222
    #5 0xfd75c8ac in QMYSQLDriver:pen () from /homes/mlin/Qt-4.5.3/plugins/sqldrivers/libqsqlmysql.so
    #6 0xff346c00 in QSqlDatabase:pen () from /homes/mlin/Qt-4.5.3/lib/libQtSql.so.4
    #7 0x0001812c in Browser::addConnection ()
    #8 0x00018b88 in Browser::addConnection ()
    #9 0x0001cbb0 in Browser::qt_metacall ()
    #10 0xfe00eba0 in QMetaObject::activate () from /homes/mlin/Qt-4.5.3/lib/libQtCore.so.4
    #11 0xfe6258a4 in QAction::triggered () from /homes/mlin/Qt-4.5.3/lib/libQtGui.so.4
    #12 0xfe625c34 in QAction::activate () from /homes/mlin/Qt-4.5.3/lib/libQtGui.so.4
    #13 0xfea38cd8 in QMenuPrivate::activateCausedStack () from /homes/mlin/Qt-4.5.3/lib/libQtGui.so.4
    #14 0xfea3c05c in QMenuPrivate::activateAction () from /homes/mlin/Qt-4.5.3/lib/libQtGui.so.4
    #15 0xfea3efbc in QMenu::mouseReleaseEvent () from /homes/mlin/Qt-4.5.3/lib/libQtGui.so.4
    #16 0xfe67ea9c in QWidget::event () from /homes/mlin/Qt-4.5.3/lib/libQtGui.so.4
    #17 0xfea39974 in QMenu::event () from /homes/mlin/Qt-4.5.3/lib/libQtGui.so.4
    #18 0xfe62c62c in QApplicationPrivate::notify_helper () from /homes/mlin/Qt-4.5.3/lib/libQtGui.so.4
    #19 0xfe62e60c in QApplication::notify () from /homes/mlin/Qt-4.5.3/lib/libQtGui.so.4
    #20 0xfdffa64c in QCoreApplication::notifyInternal () from /homes/mlin/Qt-4.5.3/lib/libQtCore.so.4
    #21 0xfe62d590 in QApplicationPrivate::sendMouseEvent () from /homes/mlin/Qt-4.5.3/lib/libQtGui.so.4
    #22 0xfe69d5d8 in QETWidget::translateMouseEvent () from /homes/mlin/Qt-4.5.3/lib/libQtGui.so.4
    #23 0xfe69baa4 in QApplication::x11ProcessEvent () from /homes/mlin/Qt-4.5.3/lib/libQtGui.so.4
    #24 0xfe6c25ec in QEventDispatcherX11:rocessEvents () from /homes/mlin/Qt-4.5.3/lib/libQtGui.so.4
    #25 0xfdff9e44 in QEventLoop:rocessEvents () from /homes/mlin/Qt-4.5.3/lib/libQtCore.so.4
    #26 0xfdffa000 in QEventLoop::exec () from /homes/mlin/Qt-4.5.3/lib/libQtCore.so.4
    #27 0xfdfff04c in QCoreApplication::exec () from /homes/mlin/Qt-4.5.3/lib/libQtCore.so.4
    #28 0x00017dfc in main ()

    It seems like the problem is with the parameter pointers passed in to my_strcasecmp_8bit(). Anyone knows how to get around this problem? I installed the pre-compiled MySQL package on Solaris machine so don't necessarily have the source code to modify and rebuild the libmysqlclient_r.so.16.0.0 library.

    any help is appreciated, thanks

    ML

  10. #10
    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: What does QSqlDatabase::removeDatabase do exactly?

    Are you using threads in your program?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. #11
    Join Date
    Feb 2010
    Posts
    10
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: What does QSqlDatabase::removeDatabase do exactly?

    This is the sqlbrowser demo example in the QTDIR/demo/sqlbrowser directory, and I don't think it is using threads.
    I tried to build the Qt MySQL driver(libqsqlmysql.so) with either thread safe library "-lmysqlclient_r" or non-thread safe library "-lmysqlclient". But, it produced the same gdb output.

    any idea?

    thanks

    ML

  12. #12
    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: What does QSqlDatabase::removeDatabase do exactly?

    To be honest I can't replicate your bug using Qt's sqlbrowser demo. Can you try to replicate the problem on a different system? Maybe you did something to your mysqlclient library or have some other incompatibility in your system...
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  13. #13
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: What does QSqlDatabase::removeDatabase do exactly?

    For me it looks rather like mysql library problem. You can try using different version and/or compiling from scratch.
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

Similar Threads

  1. QSQLDatabase
    By hoshy in forum Qt Programming
    Replies: 5
    Last Post: 25th September 2009, 15:09
  2. Passing around a QSqlDatabase
    By darkadept in forum Qt Programming
    Replies: 2
    Last Post: 8th September 2007, 08:41
  3. QSqlDatabase
    By Pragya in forum Qt Programming
    Replies: 3
    Last Post: 26th June 2007, 17:53
  4. QSqlDatabase
    By raphaelf in forum Qt Programming
    Replies: 10
    Last Post: 10th May 2006, 15:15
  5. Replies: 10
    Last Post: 6th March 2006, 16:08

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.