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