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