Changeset View
Changeset View
Standalone View
Standalone View
src/plugins/scripting/kexidb/kexidbconnection.cpp
Show All 18 Lines | |||||
19 | 19 | | |||
20 | #include "kexidbconnection.h" | 20 | #include "kexidbconnection.h" | ||
21 | #include "kexidbconnectiondata.h" | 21 | #include "kexidbconnectiondata.h" | ||
22 | #include "kexidbdriver.h" | 22 | #include "kexidbdriver.h" | ||
23 | #include "kexidbcursor.h" | 23 | #include "kexidbcursor.h" | ||
24 | #include "kexidbfieldlist.h" | 24 | #include "kexidbfieldlist.h" | ||
25 | #include "kexidbschema.h" | 25 | #include "kexidbschema.h" | ||
26 | #include "kexidbparser.h" | 26 | #include "kexidbparser.h" | ||
27 | 27 | | |||
staniek: Can we set include paths and have just #include "kexiscriptingdebug.h" ? | |||||
28 | #include <KDbTransaction> | 28 | #include <KDbTransaction> | ||
29 | 29 | | |||
30 | #include <QDebug> | 30 | #include <QDebug> | ||
31 | 31 | | |||
32 | using namespace Scripting; | 32 | using namespace Scripting; | ||
33 | 33 | | |||
34 | KexiDBConnection::KexiDBConnection(KDbConnection* connection, KexiDBDriver* driver, KexiDBConnectionData* connectiondata) | 34 | KexiDBConnection::KexiDBConnection(KDbConnection* connection, KexiDBConnectionData* connectiondata, KexiDBDriver* driver) | ||
35 | : QObject() | ||||
36 | , m_connection(connection) | ||||
37 | , m_driver(driver ? driver : new KexiDBDriver(this, connection->driver())) | ||||
38 | { | ||||
39 | m_connectiondata = connectiondata; | ||||
40 | setObjectName("KexiDBConnection"); | ||||
41 | } | ||||
42 | | ||||
43 | KexiDBConnection::KexiDBConnection(KDbConnection* connection, KexiDBDriver* driver) | ||||
35 | : QObject() | 44 | : QObject() | ||
36 | , m_connection(connection) | 45 | , m_connection(connection) | ||
37 | , m_connectiondata(connectiondata ? connectiondata : new KexiDBConnectionData(this, connection->data(), false)) | | |||
38 | , m_driver(driver ? driver : new KexiDBDriver(this, connection->driver())) | 46 | , m_driver(driver ? driver : new KexiDBDriver(this, connection->driver())) | ||
39 | { | 47 | { | ||
40 | setObjectName("KexiDBConnection"); | 48 | setObjectName("KexiDBConnection"); | ||
41 | } | 49 | } | ||
42 | 50 | | |||
43 | KexiDBConnection::~KexiDBConnection() | 51 | KexiDBConnection::~KexiDBConnection() | ||
44 | { | 52 | { | ||
45 | } | 53 | } | ||
46 | 54 | | |||
47 | bool KexiDBConnection::hadError() const | 55 | bool KexiDBConnection::hadError() const | ||
48 | { | 56 | { | ||
49 | return m_connection->error(); | 57 | return m_connection->result().isError(); | ||
50 | } | 58 | } | ||
51 | const QString KexiDBConnection::lastError() const | 59 | const QString KexiDBConnection::lastError() const | ||
staniek: const QString -> QString | |||||
52 | { | 60 | { | ||
53 | return m_connection->errorMsg(); | 61 | return m_connection->result().message(); | ||
54 | } | 62 | } | ||
55 | 63 | | |||
56 | QObject* KexiDBConnection::data() | 64 | QObject* KexiDBConnection::data() | ||
57 | { | 65 | { | ||
58 | return m_connectiondata; | 66 | return m_connectiondata; | ||
59 | } | 67 | } | ||
60 | QObject* KexiDBConnection::driver() | 68 | QObject* KexiDBConnection::driver() | ||
61 | { | 69 | { | ||
Show All 10 Lines | |||||
72 | } | 80 | } | ||
73 | bool KexiDBConnection::disconnect() | 81 | bool KexiDBConnection::disconnect() | ||
74 | { | 82 | { | ||
75 | return m_connection->disconnect(); | 83 | return m_connection->disconnect(); | ||
76 | } | 84 | } | ||
77 | 85 | | |||
78 | bool KexiDBConnection::isReadOnly() const | 86 | bool KexiDBConnection::isReadOnly() const | ||
79 | { | 87 | { | ||
80 | return m_connection->isReadOnly(); | 88 | return false; /*TODO m_connection->isReadOnly();*/ | ||
staniek: there's m_connection->options()->isReadOnly() | |||||
81 | } | 89 | } | ||
82 | 90 | | |||
83 | bool KexiDBConnection::databaseExists(const QString& dbname) | 91 | bool KexiDBConnection::databaseExists(const QString& dbname) | ||
84 | { | 92 | { | ||
85 | return m_connection->databaseExists(dbname); | 93 | return m_connection->databaseExists(dbname); | ||
86 | } | 94 | } | ||
87 | const QString KexiDBConnection::currentDatabase() const | 95 | const QString KexiDBConnection::currentDatabase() const | ||
staniek: const QString -> QString | |||||
88 | { | 96 | { | ||
89 | return m_connection->currentDatabase(); | 97 | return m_connection->currentDatabase(); | ||
90 | } | 98 | } | ||
91 | const QStringList KexiDBConnection::databaseNames() const | 99 | const QStringList KexiDBConnection::databaseNames() const | ||
92 | { | 100 | { | ||
93 | return m_connection->databaseNames(); | 101 | return m_connection->databaseNames(); | ||
94 | } | 102 | } | ||
95 | bool KexiDBConnection::isDatabaseUsed() const | 103 | bool KexiDBConnection::isDatabaseUsed() const | ||
Show All 18 Lines | 121 | { | |||
114 | return m_connection->tableNames(false); | 122 | return m_connection->tableNames(false); | ||
115 | } | 123 | } | ||
116 | 124 | | |||
117 | const QStringList KexiDBConnection::queryNames() const | 125 | const QStringList KexiDBConnection::queryNames() const | ||
118 | { | 126 | { | ||
119 | bool ok = true; | 127 | bool ok = true; | ||
120 | QStringList queries = m_connection->objectNames(KDb::QueryObjectType, &ok); | 128 | QStringList queries = m_connection->objectNames(KDb::QueryObjectType, &ok); | ||
121 | if (! ok) { | 129 | if (! ok) { | ||
122 | qDebug() << QString("Failed to determinate querynames."); | 130 | qDebug() << QString("Failed to determinate querynames."); | ||
staniek: -> KexiScriptingWarning, remove QString() | |||||
123 | return QStringList(); | 131 | return QStringList(); | ||
124 | } | 132 | } | ||
125 | return queries; | 133 | return queries; | ||
126 | } | 134 | } | ||
127 | 135 | | |||
128 | QObject* KexiDBConnection::executeQueryString(const QString& sqlquery) | 136 | QObject* KexiDBConnection::executeQueryString(const QString& sqlquery) | ||
129 | { | 137 | { | ||
130 | // The KDbConnection::executeQuery() method does not check if we pass a valid SELECT-statement | 138 | // The KDbConnection::executeQuery() method does not check if we pass a valid SELECT-statement | ||
131 | // or e.g. a DROP TABLE operation. So, let's check for such dangerous operations right now. | 139 | // or e.g. a DROP TABLE operation. So, let's check for such dangerous operations right now. | ||
132 | KDbParser parser(m_connection); | 140 | KDbParser parser(m_connection); | ||
133 | if (! parser.parse(sqlquery)) { | 141 | if (! parser.parse(KDbEscapedString(sqlquery))) { | ||
134 | qDebug() << QString("Failed to parse query: %1 %2").arg(parser.error().type()).arg(parser.error().error()); | 142 | qDebug() << QString("Failed to parse query: %1 %2").arg(parser.error().type()).arg(parser.error().message()); | ||
staniek: -> KexiScriptingWarning, remove QString() | |||||
135 | return 0; | 143 | return 0; | ||
136 | } | 144 | } | ||
137 | if (parser.query() == 0 || parser.operation() != KDbParser::OP_Select) { | 145 | if (parser.query() == 0 || parser.statementType() != KDbParser::Select) { | ||
138 | qDebug() << QString("Invalid query operation \"%1\"").arg(parser.operationString()); | 146 | qDebug() << QString("Invalid query operation \"%1\"").arg(parser.statementTypeString()); | ||
staniek: -> KexiScriptingWarning, remove QString() | |||||
139 | return 0; | 147 | return 0; | ||
140 | } | 148 | } | ||
141 | KDbCursor* cursor = m_connection->executeQuery(sqlquery); | 149 | KDbCursor* cursor = m_connection->executeQuery(KDbEscapedString(sqlquery)); | ||
142 | return cursor ? new KexiDBCursor(this, cursor, true) : 0; | 150 | return cursor ? new KexiDBCursor(this, cursor, true) : 0; | ||
143 | } | 151 | } | ||
144 | 152 | | |||
145 | QObject* KexiDBConnection::executeQuerySchema(KexiDBQuerySchema* queryschema) | 153 | QObject* KexiDBConnection::executeQuerySchema(KexiDBQuerySchema* queryschema) | ||
146 | { | 154 | { | ||
147 | KDbCursor* cursor = m_connection->executeQuery(queryschema->queryschema()); | 155 | KDbCursor* cursor = m_connection->executeQuery(queryschema->queryschema()); | ||
148 | return cursor ? new KexiDBCursor(this, cursor, true) : 0; | 156 | return cursor ? new KexiDBCursor(this, cursor, true) : 0; | ||
149 | } | 157 | } | ||
150 | 158 | | |||
151 | bool KexiDBConnection::insertRecord(QObject* obj, const QVariantList& values) | 159 | bool KexiDBConnection::insertRecord(QObject* obj, const QVariantList& values) | ||
152 | { | 160 | { | ||
153 | KexiDBFieldList* fieldlist = dynamic_cast< KexiDBFieldList* >(obj); | 161 | KexiDBFieldList* fieldlist = dynamic_cast< KexiDBFieldList* >(obj); | ||
154 | if (fieldlist) | 162 | if (fieldlist) | ||
155 | return m_connection->insertRecord(*fieldlist->fieldlist(), values); | 163 | return m_connection->insertRecord(fieldlist->fieldlist(), values); | ||
156 | KexiDBTableSchema* tableschema = dynamic_cast< KexiDBTableSchema* >(obj); | 164 | KexiDBTableSchema* tableschema = dynamic_cast< KexiDBTableSchema* >(obj); | ||
157 | if (tableschema) | 165 | if (tableschema) | ||
158 | return m_connection->insertRecord(*tableschema->tableschema(), values); | 166 | return m_connection->insertRecord(tableschema->tableschema(), values); | ||
159 | return false; | 167 | return false; | ||
160 | } | 168 | } | ||
161 | 169 | | |||
162 | bool KexiDBConnection::createDatabase(const QString& dbname) | 170 | bool KexiDBConnection::createDatabase(const QString& dbname) | ||
163 | { | 171 | { | ||
164 | return m_connection->createDatabase(dbname); | 172 | return m_connection->createDatabase(dbname); | ||
165 | } | 173 | } | ||
166 | bool KexiDBConnection::dropDatabase(const QString& dbname) | 174 | bool KexiDBConnection::dropDatabase(const QString& dbname) | ||
167 | { | 175 | { | ||
168 | return m_connection->dropDatabase(dbname); | 176 | return m_connection->dropDatabase(dbname); | ||
169 | } | 177 | } | ||
170 | 178 | | |||
171 | bool KexiDBConnection::createTable(KexiDBTableSchema* tableschema) | 179 | bool KexiDBConnection::createTable(KexiDBTableSchema* tableschema) | ||
172 | { | 180 | { | ||
173 | return m_connection->createTable(tableschema->tableschema(), false); | 181 | return m_connection->createTable(tableschema->tableschema(), KDbConnection::CreateTableOption::Default); | ||
staniek: KDbConnection::CreateTableOption::Default not needed | |||||
174 | } | 182 | } | ||
175 | bool KexiDBConnection::dropTable(const QString& tablename) | 183 | bool KexiDBConnection::dropTable(const QString& tablename) | ||
176 | { | 184 | { | ||
177 | return true == m_connection->dropTable(tablename); | 185 | return true == m_connection->dropTable(tablename); | ||
178 | } | 186 | } | ||
179 | bool KexiDBConnection::alterTable(KexiDBTableSchema* fromschema, KexiDBTableSchema* toschema) | 187 | bool KexiDBConnection::alterTable(KexiDBTableSchema* fromschema, KexiDBTableSchema* toschema) | ||
180 | { | 188 | { | ||
181 | return true == m_connection->alterTable(*fromschema->tableschema(), *toschema->tableschema()); | 189 | return true == m_connection->alterTable(fromschema->tableschema(), toschema->tableschema()); | ||
182 | } | 190 | } | ||
183 | bool KexiDBConnection::alterTableName(KexiDBTableSchema* tableschema, const QString& newtablename) | 191 | bool KexiDBConnection::alterTableName(KexiDBTableSchema* tableschema, const QString& newtablename) | ||
184 | { | 192 | { | ||
185 | return m_connection->alterTableName(*tableschema->tableschema(), newtablename); | 193 | return m_connection->alterTableName(tableschema->tableschema(), newtablename); | ||
186 | } | 194 | } | ||
187 | 195 | | |||
188 | QObject* KexiDBConnection::tableSchema(const QString& tablename) | 196 | QObject* KexiDBConnection::tableSchema(const QString& tablename) | ||
189 | { | 197 | { | ||
190 | KDbTableSchema* tableschema = m_connection->tableSchema(tablename); | 198 | KDbTableSchema* tableschema = m_connection->tableSchema(tablename); | ||
191 | return tableschema ? new KexiDBTableSchema(this, tableschema, false) : 0; | 199 | return tableschema ? new KexiDBTableSchema(this, tableschema, false) : 0; | ||
192 | } | 200 | } | ||
193 | 201 | | |||
194 | bool KexiDBConnection::isEmptyTable(KexiDBTableSchema* tableschema) const | 202 | bool KexiDBConnection::isEmptyTable(KexiDBTableSchema* tableschema) const | ||
195 | { | 203 | { | ||
196 | bool success; | 204 | return m_connection->isEmpty(tableschema->tableschema()) == true; | ||
197 | bool notempty = m_connection->isEmpty(*tableschema->tableschema(), success); | | |||
198 | return (!(success && notempty)); | | |||
199 | } | 205 | } | ||
200 | 206 | | |||
201 | QObject* KexiDBConnection::querySchema(const QString& queryname) | 207 | QObject* KexiDBConnection::querySchema(const QString& queryname) | ||
202 | { | 208 | { | ||
203 | KDbQuerySchema* queryschema = m_connection->querySchema(queryname); | 209 | KDbQuerySchema* queryschema = m_connection->querySchema(queryname); | ||
204 | return queryschema ? new KexiDBQuerySchema(this, queryschema, false) : 0; | 210 | return queryschema ? new KexiDBQuerySchema(this, queryschema, false) : 0; | ||
205 | } | 211 | } | ||
206 | 212 | | |||
Show All 14 Lines |
Can we set include paths and have just #include "kexiscriptingdebug.h" ?