Qt技巧:sqlite数据库 判断表是否存在

前端之家收集整理的这篇文章主要介绍了Qt技巧:sqlite数据库 判断表是否存在前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。


    m_dbTest = QsqlDatabase::addDatabase("QsqlITE");
    m_dbTest.setDatabaseName("sqlite.db");
    if(m_dbTest.open())
    {
        qDebug() << "database succeeded to open";
    }
    else
    {
        qDebug() << "database Failed to open";
    }

    QsqlQuery query(m_dbTest);
    bool isTableExist = \
        query.exec(QString("select count(*) from sqlite_master where type='table' and name='%1'").arg(strTableName)));    //关键的判断
    if(!isTableExist)
    {
        qDebug() << "table does not exist";
    }
    else
    {
        qDebug() << "table exists";
    }



FROM: http://blog.chinaunix.net/xmlrpc.PHP?r=blog/article&uid=29650836&id=4457672

猜你在找的Sqlite相关文章