aboutsummaryrefslogtreecommitdiffstats
path: root/SQLiteStudio3/coreSQLiteStudio/plugins/dbpluginstdfilebase.cpp
blob: 5887eac2cba4a2bf84fa7f6c2ee4bb197c674571 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include "dbpluginstdfilebase.h"
#include "common/unused.h"
#include "db/sqlquery.h"
#include <QFileInfo>

Db *DbPluginStdFileBase::getInstance(const QString &name, const QString &path, const QHash<QString, QVariant> &options, QString *errorMessage)
{
    UNUSED(errorMessage);

    Db* db = newInstance(name, path, options);

    if (!db->openForProbing())
    {
        if (errorMessage)
            *errorMessage = db->getErrorText();

        delete db;
        return nullptr;
    }

    SqlQueryPtr results = db->exec("SELECT * FROM sqlite_master");
    if (results->isError())
    {
        if (errorMessage)
            *errorMessage = db->getErrorText();

        delete db;
        return nullptr;
    }

    db->closeQuiet();
    return db;
}

QString DbPluginStdFileBase::generateDbName(const QVariant &baseValue)
{
    QFileInfo file(baseValue.toString());
    return file.completeBaseName();
}