Changeset View
Changeset View
Standalone View
Standalone View
src/drivers/mysql/MysqlConnection_p.cpp
Show First 20 Lines • Show All 107 Lines • ▼ Show 20 Line(s) | 105 | { | |||
---|---|---|---|---|---|
108 | serverVersion = 0; | 108 | serverVersion = 0; | ||
109 | mysqlDebug(); | 109 | mysqlDebug(); | ||
110 | return true; | 110 | return true; | ||
111 | } | 111 | } | ||
112 | 112 | | |||
113 | bool MysqlConnectionInternal::useDatabase(const QString &dbName) | 113 | bool MysqlConnectionInternal::useDatabase(const QString &dbName) | ||
114 | { | 114 | { | ||
115 | //! @todo is here escaping needed? | 115 | //! @todo is here escaping needed? | ||
116 | if (!executeVoidSQL(KDbEscapedString("USE ") + escapeIdentifier(dbName))) { | 116 | if (!executeSql(KDbEscapedString("USE ") + escapeIdentifier(dbName))) { | ||
117 | return false; | 117 | return false; | ||
118 | } | 118 | } | ||
119 | if (!executeVoidSQL(KDbEscapedString("SET SESSION sql_mode='TRADITIONAL'"))) { | 119 | if (!executeSql(KDbEscapedString("SET SESSION sql_mode='TRADITIONAL'"))) { | ||
120 | // needed to turn warnings about trimming string values into SQL errors | 120 | // needed to turn warnings about trimming string values into SQL errors | ||
121 | return false; | 121 | return false; | ||
122 | } | 122 | } | ||
123 | return true; | 123 | return true; | ||
124 | } | 124 | } | ||
125 | 125 | | |||
126 | bool MysqlConnectionInternal::executeVoidSQL(const KDbEscapedString& sql) | 126 | bool MysqlConnectionInternal::executeSql(const KDbEscapedString& sql) | ||
127 | { | 127 | { | ||
128 | return 0 == mysql_real_query(mysql, sql.constData(), sql.length()); | 128 | return 0 == mysql_real_query(mysql, sql.constData(), sql.length()); | ||
129 | } | 129 | } | ||
130 | 130 | | |||
131 | //static | 131 | //static | ||
132 | QString MysqlConnectionInternal::serverResultName(MYSQL *mysql) | 132 | QString MysqlConnectionInternal::serverResultName(MYSQL *mysql) | ||
133 | { | 133 | { | ||
134 | //! @todo use mysql_stmt_sqlstate() for prepared statements | 134 | //! @todo use mysql_stmt_sqlstate() for prepared statements | ||
Show All 20 Lines | |||||
155 | } | 155 | } | ||
156 | 156 | | |||
157 | MysqlCursorData::~MysqlCursorData() | 157 | MysqlCursorData::~MysqlCursorData() | ||
158 | { | 158 | { | ||
159 | } | 159 | } | ||
160 | 160 | | |||
161 | //-------------------------------------- | 161 | //-------------------------------------- | ||
162 | 162 | | |||
163 | static inline KDbSqlString mysqlTypeName(MysqlSqlResult *result, QScopedPointer<MysqlSqlRecord> *recordPtr) | 163 | static inline KDbSqlString mysqlTypeName(MysqlSqlResult *result) | ||
164 | { | 164 | { | ||
165 | KDbSqlString name; | 165 | KDbSqlString name; | ||
166 | if (result && result->fieldsCount() >= 2) { | 166 | if (result && result->fieldsCount() >= 2) { | ||
167 | recordPtr->reset(static_cast<MysqlSqlRecord*>(result->fetchRecord())); | 167 | QSharedPointer<KDbSqlRecord> record = result->fetchRecord(); | ||
168 | if (*recordPtr) { | 168 | if (record) { | ||
169 | name = (*recordPtr)->cstringValue(1); | 169 | name = static_cast<MysqlSqlRecord*>(record.data())->cstringValue(1); | ||
170 | } | 170 | } | ||
171 | } | 171 | } | ||
172 | return name; | 172 | return name; | ||
173 | } | 173 | } | ||
174 | 174 | | |||
175 | //! @todo From Kexi MysqlMigrate, unused for now because enum type isn't supported by KDb | 175 | //! @todo From Kexi MysqlMigrate, unused for now because enum type isn't supported by KDb | ||
176 | #if 0 | 176 | #if 0 | ||
177 | //! Get the strings that identify values in an enum field | 177 | //! Get the strings that identify values in an enum field | ||
178 | /*! Parse the type of a MySQL enum field as returned by the server in a | 178 | /*! Parse the type of a MySQL enum field as returned by the server in a | ||
179 | 'DESCRIBE table' or 'SHOW COLUMNS FROM table' statement. The string | 179 | 'DESCRIBE table' or 'SHOW COLUMNS FROM table' statement. The string | ||
180 | returned by the server is in the form 'enum('option1','option2'). | 180 | returned by the server is in the form 'enum('option1','option2'). | ||
181 | In this example, the result should be a string list containing two | 181 | In this example, the result should be a string list containing two | ||
182 | strings, "option1", "option2". | 182 | strings, "option1", "option2". | ||
183 | \return list of possible values the field can take | 183 | \return list of possible values the field can take | ||
184 | */ | 184 | */ | ||
185 | QStringList examineEnumField(const QString& table, const KDbSqlField* field) | 185 | QStringList examineEnumField(const QString& table, const KDbSqlField* field) | ||
186 | { | 186 | { | ||
187 | QString vals; | 187 | QString vals; | ||
188 | const KDbEscapedString query | 188 | const KDbEscapedString query | ||
189 | = KDbEscapedString("SHOW COLUMNS FROM `") + conn->escapeIdentifier(table) + | 189 | = KDbEscapedString("SHOW COLUMNS FROM `") + conn->escapeIdentifier(table) + | ||
190 | "` LIKE '" + conn->escapeIdentifier(fld->name) + '\''; | 190 | "` LIKE '" + conn->escapeIdentifier(fld->name) + '\''; | ||
191 | 191 | | |||
192 | if (!conn->executeVoidSQL(query)) | 192 | if (!conn->executeSql(query)) | ||
193 | // Huh? MySQL wont tell us what values it can take. | 193 | // Huh? MySQL wont tell us what values it can take. | ||
194 | return QStringList(); | 194 | return QStringList(); | ||
195 | 195 | | |||
196 | MYSQL_RES *res = mysql_store_result(d->mysql); | 196 | MYSQL_RES *res = mysql_store_result(d->mysql); | ||
197 | 197 | | |||
198 | if (!res) { | 198 | if (!res) { | ||
199 | //qWarning() << "null result"; | 199 | //qWarning() << "null result"; | ||
200 | } | 200 | } | ||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Line(s) | |||||
247 | #endif // examineEnumField | 247 | #endif // examineEnumField | ||
248 | 248 | | |||
249 | KDbField::Type MysqlSqlResult::blobType(const QString& tableName, MysqlSqlField *field) | 249 | KDbField::Type MysqlSqlResult::blobType(const QString& tableName, MysqlSqlField *field) | ||
250 | { | 250 | { | ||
251 | KDbField::Type kdbType = KDbField::LongText; | 251 | KDbField::Type kdbType = KDbField::LongText; | ||
252 | const KDbEscapedString sql = KDbEscapedString("SHOW COLUMNS FROM %1 LIKE '%2'") | 252 | const KDbEscapedString sql = KDbEscapedString("SHOW COLUMNS FROM %1 LIKE '%2'") | ||
253 | .arg(escapeIdentifier(tableName)).arg(field->name()); | 253 | .arg(escapeIdentifier(tableName)).arg(field->name()); | ||
254 | //! @todo this conflicts with active query | 254 | //! @todo this conflicts with active query | ||
255 | QScopedPointer<MysqlSqlResult> result(static_cast<MysqlSqlResult*>(conn->executeSQL(sql))); | 255 | QSharedPointer<KDbSqlResult> result = conn->prepareSql(sql); | ||
256 | if (result) { | 256 | if (result) { | ||
257 | QScopedPointer<MysqlSqlRecord> record; | 257 | MysqlSqlResult* mysqlResult = static_cast<MysqlSqlResult*>(result.data()); | ||
258 | const KDbSqlString typeName(mysqlTypeName(result.data(), &record)); | 258 | const KDbSqlString typeName(mysqlTypeName(mysqlResult)); | ||
259 | if (typeName.rawDataToByteArray().toLower().contains("blob")) { | 259 | if (typeName.rawDataToByteArray().toLower().contains("blob")) { | ||
260 | // Doesn't matter how big it is, it's binary | 260 | // Doesn't matter how big it is, it's binary | ||
261 | kdbType = KDbField::BLOB; | 261 | kdbType = KDbField::BLOB; | ||
262 | } else if (field->length() < 200) { | 262 | } else if (field->length() < 200) { | ||
263 | kdbType = KDbField::Text; | 263 | kdbType = KDbField::Text; | ||
264 | } | 264 | } | ||
265 | } | 265 | } | ||
266 | return kdbType; | 266 | return kdbType; | ||
▲ Show 20 Lines • Show All 106 Lines • Show Last 20 Lines |