Changeset View
Changeset View
Standalone View
Standalone View
src/drivers/sqlite/SqliteConnection_p.cpp
Show First 20 Lines • Show All 133 Lines • ▼ Show 20 Line(s) | 131 | { | |||
---|---|---|---|---|---|
134 | field->setPrimaryKey(isPrimaryKey); | 134 | field->setPrimaryKey(isPrimaryKey); | ||
135 | } | 135 | } | ||
136 | 136 | | |||
137 | bool SqliteSqlResult::cacheFieldInfo(const QString &tableName) | 137 | bool SqliteSqlResult::cacheFieldInfo(const QString &tableName) | ||
138 | { | 138 | { | ||
139 | if (!cachedFieldInfos.isEmpty()) { | 139 | if (!cachedFieldInfos.isEmpty()) { | ||
140 | return true; | 140 | return true; | ||
141 | } | 141 | } | ||
142 | QScopedPointer<KDbSqlResult> tableInfoResult(conn->executeSQL( | 142 | QSharedPointer<KDbSqlResult> tableInfoResult = conn->prepareSql( | ||
143 | KDbEscapedString("PRAGMA table_info(%1)").arg(conn->escapeIdentifier(tableName)))); | 143 | KDbEscapedString("PRAGMA table_info(%1)").arg(conn->escapeIdentifier(tableName))); | ||
144 | if (!tableInfoResult) { | 144 | if (!tableInfoResult) { | ||
145 | return false; | 145 | return false; | ||
146 | } | 146 | } | ||
147 | // Forward-compatible approach: find columns of table_info that we need | 147 | // Forward-compatible approach: find columns of table_info that we need | ||
148 | const int columns = tableInfoResult->fieldsCount(); | 148 | const int columns = tableInfoResult->fieldsCount(); | ||
149 | enum TableInfoColumns { | 149 | enum TableInfoColumns { | ||
150 | TableInfoFieldName, | 150 | TableInfoFieldName, | ||
151 | TableInfoNotNull, | 151 | TableInfoNotNull, | ||
Show All 22 Lines | 157 | for(int col = 0; col < columns; ++col) { | |||
174 | } | 174 | } | ||
175 | } | 175 | } | ||
176 | if (found != TableInfoPK + 1) { // not all columns found | 176 | if (found != TableInfoPK + 1) { // not all columns found | ||
177 | return false; | 177 | return false; | ||
178 | } | 178 | } | ||
179 | 179 | | |||
180 | bool ok = true; | 180 | bool ok = true; | ||
181 | Q_FOREVER { | 181 | Q_FOREVER { | ||
182 | QScopedPointer<KDbSqlRecord> record(tableInfoResult->fetchRecord()); | 182 | QSharedPointer<KDbSqlRecord> record = tableInfoResult->fetchRecord(); | ||
183 | if (!record) { | 183 | if (!record) { | ||
184 | ok = !tableInfoResult->lastResult().isError(); | 184 | ok = !tableInfoResult->lastResult().isError(); | ||
185 | break; | 185 | break; | ||
186 | } | 186 | } | ||
187 | QScopedPointer<SqliteSqlFieldInfo> info(new SqliteSqlFieldInfo); | 187 | QScopedPointer<SqliteSqlFieldInfo> info(new SqliteSqlFieldInfo); | ||
188 | const QString name = record->stringValue(columnIndex[TableInfoFieldName]); | 188 | const QString name = record->stringValue(columnIndex[TableInfoFieldName]); | ||
189 | if (name.isEmpty()) { | 189 | if (name.isEmpty()) { | ||
190 | ok = false; | 190 | ok = false; | ||
Show All 33 Lines |