Changeset View
Changeset View
Standalone View
Standalone View
src/plugins/importexport/csv/kexicsvexport.cpp
Show First 20 Lines • Show All 76 Lines • ▼ Show 20 Line(s) | 55 | { | |||
---|---|---|---|---|---|
77 | if (args->contains("addColumnNames")) | 77 | if (args->contains("addColumnNames")) | ||
78 | addColumnNames = (args->value("addColumnNames") == "1"); | 78 | addColumnNames = (args->value("addColumnNames") == "1"); | ||
79 | useTempQuery = (args->value("useTempQuery") == "1"); | 79 | useTempQuery = (args->value("useTempQuery") == "1"); | ||
80 | return result; | 80 | return result; | ||
81 | } | 81 | } | ||
82 | 82 | | |||
83 | //------------------------------------ | 83 | //------------------------------------ | ||
84 | 84 | | |||
85 | bool KexiCSVExport::exportData(KDbTableOrQuerySchema *tableOrQuery, | 85 | bool KexiCSVExport::exportData(KDbConnection* conn, KDbTableOrQuerySchema *tableOrQuery, | ||
86 | const Options& options, int recordCount, QTextStream *predefinedTextStream) | 86 | const Options& options, int recordCount, QTextStream *predefinedTextStream) | ||
87 | { | 87 | { | ||
88 | KDbConnection* conn = tableOrQuery->connection(); | | |||
89 | if (!conn) | 88 | if (!conn) | ||
90 | return false; | 89 | return false; | ||
91 | 90 | | |||
92 | KDbQuerySchema* query = tableOrQuery->query(); | 91 | KDbQuerySchema* query = tableOrQuery->query(); | ||
93 | QList<QVariant> queryParams; | 92 | QList<QVariant> queryParams; | ||
94 | if (!query) { | 93 | if (!query) { | ||
95 | query = tableOrQuery->table()->query(); | 94 | query = tableOrQuery->table()->query(); | ||
96 | } | 95 | } | ||
97 | else { | 96 | else { | ||
98 | queryParams = KexiMainWindowIface::global()->currentParametersForQuery(query->id()); | 97 | queryParams = KexiMainWindowIface::global()->currentParametersForQuery(query->id()); | ||
99 | } | 98 | } | ||
100 | 99 | | |||
101 | if (recordCount == -1) | 100 | if (recordCount == -1) | ||
102 | recordCount = KDb::recordCount(tableOrQuery, queryParams); | 101 | recordCount = conn->recordCount(tableOrQuery, queryParams); | ||
103 | if (recordCount == -1) | 102 | if (recordCount == -1) | ||
104 | return false; | 103 | return false; | ||
105 | 104 | | |||
106 | //! @todo move this to non-GUI location so it can be also used via command line | 105 | //! @todo move this to non-GUI location so it can be also used via command line | ||
107 | //! @todo add a "finish" page with a progressbar. | 106 | //! @todo add a "finish" page with a progressbar. | ||
108 | //! @todo look at recordCount whether the data is really large; | 107 | //! @todo look at recordCount whether the data is really large; | ||
109 | //! if so: avoid copying to clipboard (or ask user) because of system memory | 108 | //! if so: avoid copying to clipboard (or ask user) because of system memory | ||
110 | 109 | | |||
111 | //! @todo OPTIMIZATION: use fieldsExpanded(true /*UNIQUE*/) | 110 | //! @todo OPTIMIZATION: use fieldsExpanded(true /*UNIQUE*/) | ||
112 | //! @todo OPTIMIZATION? (avoid multiple data retrieving) look for already fetched data within KexiProject.. | 111 | //! @todo OPTIMIZATION? (avoid multiple data retrieving) look for already fetched data within KexiProject.. | ||
113 | 112 | | |||
114 | KDbQueryColumnInfo::Vector fields(query->fieldsExpanded(KDbQuerySchema::WithInternalFields)); | 113 | const KDbQueryColumnInfo::Vector fields( | ||
114 | query->fieldsExpanded(conn, KDbQuerySchema::FieldsExpandedMode::WithInternalFields)); | ||||
115 | QString buffer; | 115 | QString buffer; | ||
116 | 116 | | |||
117 | QScopedPointer<QSaveFile> kSaveFile; | 117 | QScopedPointer<QSaveFile> kSaveFile; | ||
118 | QTextStream *stream = 0; | 118 | QTextStream *stream = 0; | ||
119 | QScopedPointer<QTextStream> kSaveFileTextStream; | 119 | QScopedPointer<QTextStream> kSaveFileTextStream; | ||
120 | 120 | | |||
121 | const bool copyToClipboard = options.mode == Clipboard; | 121 | const bool copyToClipboard = options.mode == Clipboard; | ||
122 | if (copyToClipboard) { | 122 | if (copyToClipboard) { | ||
Show All 38 Lines | |||||
161 | 161 | | |||
162 | #define APPEND(what) \ | 162 | #define APPEND(what) \ | ||
163 | if (copyToClipboard) buffer.append(what); else (*stream) << (what) | 163 | if (copyToClipboard) buffer.append(what); else (*stream) << (what) | ||
164 | 164 | | |||
165 | // use native line ending for copying, RFC 4180 one for saving to file | 165 | // use native line ending for copying, RFC 4180 one for saving to file | ||
166 | #define APPEND_EOLN \ | 166 | #define APPEND_EOLN \ | ||
167 | if (copyToClipboard) { APPEND('\n'); } else { APPEND("\r\n"); } | 167 | if (copyToClipboard) { APPEND('\n'); } else { APPEND("\r\n"); } | ||
168 | 168 | | |||
169 | qDebug() << 0 << "Columns: " << query->fieldsExpanded().count(); | | |||
170 | // 0. Cache information | 169 | // 0. Cache information | ||
171 | const int fieldsCount = query->fieldsExpanded().count(); //real fields count without internals | 170 | const int fieldsCount = query->fieldsExpanded(conn).count(); //real fields count without internals | ||
172 | const QChar delimiter(options.delimiter.at(0)); | 171 | const QChar delimiter(options.delimiter.at(0)); | ||
piggz: needed? | |||||
staniek: Fixed, thanks. | |||||
173 | const bool hasTextQuote = !options.textQuote.isEmpty(); | 172 | const bool hasTextQuote = !options.textQuote.isEmpty(); | ||
174 | const QString textQuote(options.textQuote.at(0)); | 173 | const QString textQuote(options.textQuote.at(0)); | ||
175 | const QByteArray escapedTextQuote((textQuote + textQuote).toLatin1()); //ok? | 174 | const QByteArray escapedTextQuote((textQuote + textQuote).toLatin1()); //ok? | ||
176 | //cache for faster checks | 175 | //cache for faster checks | ||
177 | QScopedArrayPointer<bool> isText(new bool[fieldsCount]); | 176 | QScopedArrayPointer<bool> isText(new bool[fieldsCount]); | ||
178 | QScopedArrayPointer<bool> isDateTime(new bool[fieldsCount]); | 177 | QScopedArrayPointer<bool> isDateTime(new bool[fieldsCount]); | ||
179 | QScopedArrayPointer<bool> isTime(new bool[fieldsCount]); | 178 | QScopedArrayPointer<bool> isTime(new bool[fieldsCount]); | ||
180 | QScopedArrayPointer<bool> isBLOB(new bool[fieldsCount]); | 179 | QScopedArrayPointer<bool> isBLOB(new bool[fieldsCount]); | ||
181 | QScopedArrayPointer<int> visibleFieldIndex(new int[fieldsCount]); | 180 | QScopedArrayPointer<int> visibleFieldIndex(new int[fieldsCount]); | ||
182 | // bool isInteger[fieldsCount]; //cache for faster checks | 181 | // bool isInteger[fieldsCount]; //cache for faster checks | ||
183 | // bool isFloatingPoint[fieldsCount]; //cache for faster checks | 182 | // bool isFloatingPoint[fieldsCount]; //cache for faster checks | ||
184 | for (int i = 0; i < fieldsCount; i++) { | 183 | for (int i = 0; i < fieldsCount; i++) { | ||
185 | KDbQueryColumnInfo* ci; | 184 | KDbQueryColumnInfo* ci; | ||
186 | const int indexForVisibleLookupValue = fields[i]->indexForVisibleLookupValue(); | 185 | const int indexForVisibleLookupValue = fields[i]->indexForVisibleLookupValue(); | ||
187 | if (-1 != indexForVisibleLookupValue) { | 186 | if (-1 != indexForVisibleLookupValue) { | ||
188 | ci = query->expandedOrInternalField(indexForVisibleLookupValue); | 187 | ci = query->expandedOrInternalField(conn, indexForVisibleLookupValue); | ||
189 | visibleFieldIndex[i] = indexForVisibleLookupValue; | 188 | visibleFieldIndex[i] = indexForVisibleLookupValue; | ||
190 | } else { | 189 | } else { | ||
191 | ci = fields[i]; | 190 | ci = fields[i]; | ||
192 | visibleFieldIndex[i] = i; | 191 | visibleFieldIndex[i] = i; | ||
193 | } | 192 | } | ||
194 | 193 | | |||
195 | const KDbField::Type t = ci->field()->type(); // cache: evaluating type of expressions can be expensive | 194 | const KDbField::Type t = ci->field()->type(); // cache: evaluating type of expressions can be expensive | ||
196 | isText[i] = KDbField::isTextType(t); | 195 | isText[i] = KDbField::isTextType(t); | ||
▲ Show 20 Lines • Show All 88 Lines • Show Last 20 Lines |
needed?