Changeset View
Changeset View
Standalone View
Standalone View
src/plugins/scripting/kexidb/kexidbschema.cpp
Show All 17 Lines | |||||
18 | ***************************************************************************/ | 18 | ***************************************************************************/ | ||
19 | 19 | | |||
20 | #include "kexidbschema.h" | 20 | #include "kexidbschema.h" | ||
21 | #include "kexidbfieldlist.h" | 21 | #include "kexidbfieldlist.h" | ||
22 | 22 | | |||
23 | #include <QRegularExpression> | 23 | #include <QRegularExpression> | ||
24 | #include <QDebug> | 24 | #include <QDebug> | ||
25 | 25 | | |||
26 | #include <KDbExpression> | ||||
27 | | ||||
26 | using namespace Scripting; | 28 | using namespace Scripting; | ||
27 | 29 | | |||
28 | /*************************************************************************** | 30 | /*************************************************************************** | ||
29 | *KexiDBSchema | 31 | *KexiDBSchema | ||
30 | */ | 32 | */ | ||
31 | 33 | | |||
32 | KexiDBSchema::KexiDBSchema(QObject* parent, const QString& name, KDbObject* schema, KDbFieldList* fieldlist, bool owner) | 34 | KexiDBSchema::KexiDBSchema(QObject* parent, const QString& name, KDbObject* schema, KDbFieldList* fieldlist, bool owner) | ||
33 | : QObject(parent) | 35 | : QObject(parent) | ||
34 | , m_schema(schema) | 36 | , m_schema(schema) | ||
35 | , m_fieldlist(fieldlist) | 37 | , m_fieldlist(fieldlist) | ||
36 | , m_owner(owner) | 38 | , m_owner(owner) | ||
37 | { | 39 | { | ||
38 | setObjectName(name); | 40 | setObjectName(name); | ||
39 | } | 41 | } | ||
40 | 42 | | |||
41 | KexiDBSchema::~KexiDBSchema() | 43 | KexiDBSchema::~KexiDBSchema() | ||
42 | { | 44 | { | ||
43 | } | 45 | } | ||
44 | 46 | | |||
45 | const QString KexiDBSchema::name() const | 47 | QString KexiDBSchema::name() const | ||
46 | { | 48 | { | ||
47 | return m_schema->name(); | 49 | return m_schema->name(); | ||
48 | } | 50 | } | ||
49 | void KexiDBSchema::setName(const QString& name) | 51 | void KexiDBSchema::setName(const QString& name) | ||
50 | { | 52 | { | ||
51 | m_schema->setName(name); | 53 | m_schema->setName(name); | ||
52 | } | 54 | } | ||
53 | const QString KexiDBSchema::caption() const | 55 | QString KexiDBSchema::caption() const | ||
54 | { | 56 | { | ||
55 | return m_schema->caption(); | 57 | return m_schema->caption(); | ||
56 | } | 58 | } | ||
57 | void KexiDBSchema::setCaption(const QString& caption) | 59 | void KexiDBSchema::setCaption(const QString& caption) | ||
58 | { | 60 | { | ||
59 | m_schema->setCaption(caption); | 61 | m_schema->setCaption(caption); | ||
60 | } | 62 | } | ||
61 | const QString KexiDBSchema::description() const | 63 | QString KexiDBSchema::description() const | ||
62 | { | 64 | { | ||
63 | return m_schema->description(); | 65 | return m_schema->description(); | ||
64 | } | 66 | } | ||
65 | void KexiDBSchema::setDescription(const QString& description) | 67 | void KexiDBSchema::setDescription(const QString& description) | ||
66 | { | 68 | { | ||
67 | m_schema->setDescription(description); | 69 | m_schema->setDescription(description); | ||
68 | } | 70 | } | ||
69 | QObject* KexiDBSchema::fieldlist() | 71 | QObject* KexiDBSchema::fieldlist() | ||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Line(s) | 112 | if (m_owner) | |||
111 | delete queryschema(); | 113 | delete queryschema(); | ||
112 | } | 114 | } | ||
113 | 115 | | |||
114 | KDbQuerySchema* KexiDBQuerySchema::queryschema() | 116 | KDbQuerySchema* KexiDBQuerySchema::queryschema() | ||
115 | { | 117 | { | ||
116 | return static_cast< KDbQuerySchema* >(m_schema); | 118 | return static_cast< KDbQuerySchema* >(m_schema); | ||
117 | } | 119 | } | ||
118 | 120 | | |||
119 | const QString KexiDBQuerySchema::statement() const | 121 | QString KexiDBQuerySchema::statement() const | ||
staniek: const QString -> QString | |||||
120 | { | 122 | { | ||
121 | return static_cast< KDbQuerySchema* >(m_schema)->statement(); | 123 | return static_cast< KDbQuerySchema* >(m_schema)->statement().toString(); | ||
122 | } | 124 | } | ||
123 | 125 | | |||
124 | void KexiDBQuerySchema::setStatement(const QString& statement) | 126 | void KexiDBQuerySchema::setStatement(const QString& statement) | ||
125 | { | 127 | { | ||
126 | static_cast< KDbQuerySchema* >(m_schema)->setStatement(statement); | 128 | static_cast< KDbQuerySchema* >(m_schema)->setStatement(KDbEscapedString(statement)); | ||
127 | } | 129 | } | ||
128 | 130 | | |||
129 | bool KexiDBQuerySchema::setWhereExpression(const QString& whereexpression) | 131 | bool KexiDBQuerySchema::setWhereExpression(const QString& whereexpression) | ||
130 | { | 132 | { | ||
131 | KDbExpression* oldexpr = static_cast< KDbQuerySchema* >(m_schema)->whereExpression(); | 133 | KDbExpression oldexpr = static_cast< KDbQuerySchema* >(m_schema)->whereExpression(); | ||
staniek: Not needed line? | |||||
132 | Q_UNUSED(oldexpr); | 134 | Q_UNUSED(oldexpr); | ||
133 | 135 | | |||
134 | ///@todo use KDbParser for such kind of parser-functionality. | 136 | ///@todo use KDbParser for such kind of parser-functionality. | ||
135 | QString s = whereexpression; | 137 | QString s = whereexpression; | ||
136 | QRegularExpression re("[\"',]{1,1}"); | 138 | QRegExp re("[\"',]{1,1}"); | ||
staniek: QRegularExpression is the current API, can we use it? | |||||
Ok, ive moved this to the new API, but I dont know if ive done it correct,y. Please check thoroughly. I suspect a test case would be good here! (infact, some test scripts to check the whole KDb wrapper would be very handy) piggz: Ok, ive moved this to the new API, but I dont know if ive done it correct,y. Please check… | |||||
137 | while (true) { | 139 | while (true) { | ||
138 | s.remove(QRegularExpression("^[\\s,]+")); | 140 | s.remove(QRegExp("^[\\s,]+")); | ||
139 | int pos = s.indexOf('='); | 141 | int pos = s.indexOf('='); | ||
140 | if (pos < 0) break; | 142 | if (pos < 0) break; | ||
141 | QString key = s.left(pos).trimmed(); | 143 | QString key = s.left(pos).trimmed(); | ||
142 | s = s.mid(pos + 1).trimmed(); | 144 | s = s.mid(pos + 1).trimmed(); | ||
143 | 145 | | |||
144 | QString value; | 146 | QString value; | ||
145 | int sp = s.indexOf(re); | 147 | int sp = s.indexOf(re); | ||
146 | if (sp >= 0) { | 148 | if (sp >= 0) { | ||
Show All 19 Lines | |||||
166 | QVariant v(value); | 168 | QVariant v(value); | ||
167 | if (! v.convert(field->variantType())) { | 169 | if (! v.convert(field->variantType())) { | ||
168 | qWarning() << QString("Invalid WHERE-expression: The for Field \"%1\" defined value is of type \"%2\" rather then the expected type \"%3\"").arg(key).arg(v.typeName()).arg(field->variantType()); | 170 | qWarning() << QString("Invalid WHERE-expression: The for Field \"%1\" defined value is of type \"%2\" rather then the expected type \"%3\"").arg(key).arg(v.typeName()).arg(field->variantType()); | ||
169 | return false; | 171 | return false; | ||
170 | } | 172 | } | ||
171 | 173 | | |||
172 | QString errorMessage; | 174 | QString errorMessage; | ||
173 | QString errorDescription; | 175 | QString errorDescription; | ||
174 | if (!static_cast<KDbQuerySchema *>(m_schema)->addToWhereExpression( | 176 | if (!static_cast<KDbQuerySchema *>(m_schema)->addToWhereExpression(field, v, KDbToken('='), &errorMessage, &errorDescription)) | ||
175 | field, v, &errorMessage, &errorDescription)) | | |||
176 | { | 177 | { | ||
177 | qWarning() << "addToWhereExpression() failed, message=" << errorMessage | 178 | qWarning() << "addToWhereExpression() failed, message=" << errorMessage | ||
178 | << "description=" << errorDescription; | 179 | << "description=" << errorDescription; | ||
179 | return false; | 180 | return false; | ||
180 | } | 181 | } | ||
181 | } | 182 | } | ||
182 | return true; | 183 | return true; | ||
183 | } | 184 | } | ||
184 | 185 | |
const QString -> QString