-
Notifications
You must be signed in to change notification settings - Fork 0
/
lqfile.cpp
70 lines (55 loc) · 1.53 KB
/
lqfile.cpp
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "lqfile.h"
#include <QFile>
#include <QDomDocument>
#include <QDomAttr>
#include <QDomElement>
#include "sqlfile.h"
LqFile::LqFile(const QString &fileName) : _fileName(fileName)
{
_is_open = false;
}
bool LqFile::open() {
QDomDocument doc;
QString errorStr;
int errorLine;
int errorColumn;
QFile file(_fileName);
if (!file.open(QIODevice::ReadOnly))
{
_errorString = (QObject::tr("Could not open liquibase file '%1'").arg(_fileName));
return false;
}
if (!doc.setContent(&file, true, &errorStr, &errorLine,
&errorColumn))
{
_errorString = (QObject::tr("Liquibase file parse error at line %1, column %2:\n%3")
.arg(errorLine)
.arg(errorColumn)
.arg(errorStr));
file.close();
return false;
}
file.close();
QDomElement root = doc.documentElement();
if (root.tagName().toLower() != "databasechangelog")
{
_errorString = QObject::tr("Root element in liquibase file is not ""databaseChangeLog""");
return false;
}
QDomElement child = root.firstChildElement("include");
while (!child.isNull())
{
_files.append(child.attribute("file"));
child = child.nextSiblingElement("include");
}
_is_open = true;
return true;
}
int LqFile::count() const
{
return _files.count();
}
QString LqFile::fileName(int i) const
{
return _files[i];
}