Changeset View
Changeset View
Standalone View
Standalone View
src/KDbQuerySchema.cpp
Show First 20 Lines • Show All 50 Lines • ▼ Show 20 Line(s) | |||||
51 | 51 | | |||
52 | KDbQuerySchema::KDbQuerySchema(KDbTableSchema *tableSchema) | 52 | KDbQuerySchema::KDbQuerySchema(KDbTableSchema *tableSchema) | ||
53 | : KDbFieldList(false)//fields are not owned by KDbQuerySchema object | 53 | : KDbFieldList(false)//fields are not owned by KDbQuerySchema object | ||
54 | , KDbObject(KDb::QueryObjectType) | 54 | , KDbObject(KDb::QueryObjectType) | ||
55 | , d(new Private(this)) | 55 | , d(new Private(this)) | ||
56 | { | 56 | { | ||
57 | if (tableSchema) { | 57 | if (tableSchema) { | ||
58 | d->masterTable = tableSchema; | 58 | d->masterTable = tableSchema; | ||
59 | d->conn = tableSchema->connection(); | | |||
60 | /*if (!d->masterTable) { | 59 | /*if (!d->masterTable) { | ||
61 | kdbWarning() << "!d->masterTable"; | 60 | kdbWarning() << "!d->masterTable"; | ||
62 | m_name.clear(); | 61 | m_name.clear(); | ||
63 | return; | 62 | return; | ||
64 | }*/ | 63 | }*/ | ||
65 | addTable(d->masterTable); | 64 | addTable(d->masterTable); | ||
66 | //defaults: | 65 | //defaults: | ||
67 | //inherit name from a table | 66 | //inherit name from a table | ||
68 | setName(d->masterTable->name()); | 67 | setName(d->masterTable->name()); | ||
69 | //inherit caption from a table | 68 | //inherit caption from a table | ||
70 | setCaption(d->masterTable->caption()); | 69 | setCaption(d->masterTable->caption()); | ||
71 | 70 | | |||
72 | // add explicit field list to avoid problems (e.g. with fields added outside of the app): | 71 | // add explicit field list to avoid problems (e.g. with fields added outside of the app): | ||
73 | foreach(KDbField* f, *d->masterTable->fields()) { | 72 | foreach(KDbField* f, *d->masterTable->fields()) { | ||
74 | addField(f); | 73 | addField(f); | ||
75 | } | 74 | } | ||
76 | } | 75 | } | ||
77 | } | 76 | } | ||
78 | 77 | | |||
79 | KDbQuerySchema::KDbQuerySchema(const KDbQuerySchema& querySchema) | 78 | KDbQuerySchema::KDbQuerySchema(const KDbQuerySchema& querySchema, KDbConnection *conn) | ||
80 | : KDbFieldList(querySchema, false /* !deepCopyFields */) | 79 | : KDbFieldList(querySchema, false /* !deepCopyFields */) | ||
81 | , KDbObject(querySchema) | 80 | , KDbObject(querySchema) | ||
82 | , d(new Private(this, querySchema.d)) | 81 | , d(new Private(this, querySchema.d)) | ||
83 | { | 82 | { | ||
84 | //only deep copy query asterisks | 83 | //only deep copy query asterisks | ||
85 | foreach(KDbField* f, *querySchema.fields()) { | 84 | foreach(KDbField* f, *querySchema.fields()) { | ||
86 | KDbField *copiedField; | 85 | KDbField *copiedField; | ||
87 | if (dynamic_cast<KDbQueryAsterisk*>(f)) { | 86 | if (dynamic_cast<KDbQueryAsterisk*>(f)) { | ||
88 | copiedField = f->copy(); | 87 | copiedField = f->copy(); | ||
89 | if (static_cast<const KDbFieldList *>(f->parent()) == &querySchema) { | 88 | if (static_cast<const KDbFieldList *>(f->parent()) == &querySchema) { | ||
90 | copiedField->setParent(this); | 89 | copiedField->setParent(this); | ||
91 | } | 90 | } | ||
92 | } | 91 | } | ||
93 | else { | 92 | else { | ||
94 | copiedField = f; | 93 | copiedField = f; | ||
95 | } | 94 | } | ||
96 | addField(copiedField); | 95 | addField(copiedField); | ||
97 | } | 96 | } | ||
98 | // this deep copy must be after the 'd' initialization because fieldsExpanded() is used there | 97 | // this deep copy must be after the 'd' initialization because fieldsExpanded() is used there | ||
99 | d->orderByColumnList = new KDbOrderByColumnList(*querySchema.d->orderByColumnList, | 98 | d->orderByColumnList = new KDbOrderByColumnList(*querySchema.d->orderByColumnList, conn, | ||
100 | const_cast<KDbQuerySchema*>(&querySchema), this); | 99 | const_cast<KDbQuerySchema*>(&querySchema), this); | ||
101 | } | 100 | } | ||
102 | 101 | | |||
103 | KDbQuerySchema::KDbQuerySchema(KDbConnection *conn) | | |||
104 | : KDbFieldList(false)//fields are not owned by KDbQuerySchema object | | |||
105 | , KDbObject(KDb::QueryObjectType) | | |||
106 | , d(new Private(this)) | | |||
107 | { | | |||
108 | d->conn = conn; | | |||
109 | } | | |||
110 | | ||||
111 | KDbQuerySchema::~KDbQuerySchema() | 102 | KDbQuerySchema::~KDbQuerySchema() | ||
112 | { | 103 | { | ||
113 | delete d; | 104 | delete d; | ||
114 | } | 105 | } | ||
115 | 106 | | |||
116 | void KDbQuerySchema::clear() | 107 | void KDbQuerySchema::clear() | ||
117 | { | 108 | { | ||
118 | KDbFieldList::clear(); | 109 | KDbFieldList::clear(); | ||
▲ Show 20 Lines • Show All 192 Lines • ▼ Show 20 Line(s) | 301 | { | |||
311 | return addAsteriskInternal(asterisk, true); | 302 | return addAsteriskInternal(asterisk, true); | ||
312 | } | 303 | } | ||
313 | 304 | | |||
314 | bool KDbQuerySchema::addInvisibleAsterisk(KDbQueryAsterisk *asterisk) | 305 | bool KDbQuerySchema::addInvisibleAsterisk(KDbQueryAsterisk *asterisk) | ||
315 | { | 306 | { | ||
316 | return addAsteriskInternal(asterisk, false); | 307 | return addAsteriskInternal(asterisk, false); | ||
317 | } | 308 | } | ||
318 | 309 | | |||
319 | KDbConnection* KDbQuerySchema::connection() const | 310 | QDebug operator<<(QDebug dbg, const KDbConnectionAndQuerySchema &connectionAndSchema) | ||
320 | { | | |||
321 | if (d->conn) { | | |||
322 | return d->conn; | | |||
323 | } | | |||
324 | if (!d->tables.isEmpty()) { | | |||
325 | return d->tables.first()->connection(); | | |||
326 | } | | |||
327 | return nullptr; | | |||
328 | } | | |||
329 | | ||||
330 | QDebug operator<<(QDebug dbg, const KDbQuerySchema& query) | | |||
331 | { | 311 | { | ||
312 | KDbConnection* conn = std::get<0>(connectionAndSchema); | ||||
313 | const KDbQuerySchema& query = std::get<1>(connectionAndSchema); | ||||
332 | //fields | 314 | //fields | ||
333 | KDbTableSchema *mt = query.masterTable(); | 315 | KDbTableSchema *mt = query.masterTable(); | ||
334 | dbg.nospace() << "QUERY"; | 316 | dbg.nospace() << "QUERY"; | ||
335 | dbg.space() << static_cast<const KDbObject&>(query) << '\n'; | 317 | dbg.space() << static_cast<const KDbObject&>(query) << '\n'; | ||
336 | dbg.nospace() << " - MASTERTABLE=" << (mt ? mt->name() : QLatin1String("<NULL>")) | 318 | dbg.nospace() << " - MASTERTABLE=" << (mt ? mt->name() : QLatin1String("<NULL>")) | ||
337 | << "\n - COLUMNS:\n"; | 319 | << "\n - COLUMNS:\n"; | ||
338 | if (query.fieldCount() > 0) | 320 | if (query.fieldCount() > 0) | ||
339 | dbg.nospace() << static_cast<const KDbFieldList&>(query) << '\n'; | 321 | dbg.nospace() << static_cast<const KDbFieldList&>(query) << '\n'; | ||
340 | else | 322 | else | ||
341 | dbg.nospace() << "<NONE>\n"; | 323 | dbg.nospace() << "<NONE>\n"; | ||
342 | 324 | | |||
343 | if (query.fieldCount() == 0) | 325 | if (query.fieldCount() == 0) | ||
344 | dbg.nospace() << " - NO FIELDS\n"; | 326 | dbg.nospace() << " - NO FIELDS\n"; | ||
345 | else | 327 | else | ||
346 | dbg.nospace() << " - FIELDS EXPANDED ("; | 328 | dbg.nospace() << " - FIELDS EXPANDED ("; | ||
347 | 329 | | |||
348 | int fieldsExpandedCount = 0; | 330 | int fieldsExpandedCount = 0; | ||
349 | bool first; | 331 | bool first; | ||
350 | if (query.fieldCount() > 0) { | 332 | if (query.fieldCount() > 0) { | ||
351 | const KDbQueryColumnInfo::Vector fe(query.fieldsExpanded()); | 333 | const KDbQueryColumnInfo::Vector fe(query.fieldsExpanded(conn)); | ||
352 | fieldsExpandedCount = fe.size(); | 334 | fieldsExpandedCount = fe.size(); | ||
353 | dbg.nospace() << fieldsExpandedCount << "):\n"; | 335 | dbg.nospace() << fieldsExpandedCount << "):\n"; | ||
354 | first = true; | 336 | first = true; | ||
355 | for (int i = 0; i < fieldsExpandedCount; i++) { | 337 | for (int i = 0; i < fieldsExpandedCount; i++) { | ||
356 | KDbQueryColumnInfo *ci = fe[i]; | 338 | KDbQueryColumnInfo *ci = fe[i]; | ||
357 | if (first) | 339 | if (first) | ||
358 | first = false; | 340 | first = false; | ||
359 | else | 341 | else | ||
▲ Show 20 Lines • Show All 318 Lines • ▼ Show 20 Line(s) | 659 | { | |||
678 | return d->sql; | 660 | return d->sql; | ||
679 | } | 661 | } | ||
680 | 662 | | |||
681 | void KDbQuerySchema::setStatement(const KDbEscapedString& sql) | 663 | void KDbQuerySchema::setStatement(const KDbEscapedString& sql) | ||
682 | { | 664 | { | ||
683 | d->sql = sql; | 665 | d->sql = sql; | ||
684 | } | 666 | } | ||
685 | 667 | | |||
686 | const KDbField* KDbQuerySchema::field(const QString& identifier) const | 668 | const KDbField* KDbQuerySchema::field(KDbConnection *conn, const QString& identifier, | ||
669 | ExpandMode mode) const | ||||
687 | { | 670 | { | ||
688 | KDbQueryColumnInfo *ci = columnInfo(identifier, true /*expanded*/); | 671 | KDbQueryColumnInfo *ci = columnInfo(conn, identifier, mode); | ||
689 | return ci ? ci->field() : nullptr; | 672 | return ci ? ci->field() : nullptr; | ||
690 | } | 673 | } | ||
691 | 674 | | |||
692 | KDbField* KDbQuerySchema::field(const QString& identifier) | 675 | KDbField* KDbQuerySchema::field(KDbConnection *conn, const QString& identifier, ExpandMode mode) | ||
693 | { | 676 | { | ||
694 | return const_cast<KDbField*>(static_cast<const KDbQuerySchema*>(this)->field(identifier)); | 677 | return const_cast<KDbField *>( | ||
695 | } | 678 | static_cast<const KDbQuerySchema *>(this)->field(conn, identifier, mode)); | ||
696 | | ||||
697 | const KDbField* KDbQuerySchema::unexpandedField(const QString& identifier) const | | |||
698 | { | | |||
699 | KDbQueryColumnInfo *ci = columnInfo(identifier, false /*unexpanded*/); | | |||
700 | return ci ? ci->field() : nullptr; | | |||
701 | } | | |||
702 | | ||||
703 | KDbField* KDbQuerySchema::unexpandedField(const QString& identifier) | | |||
704 | { | | |||
705 | return const_cast<KDbField*>(static_cast<const KDbQuerySchema*>(this)->unexpandedField(identifier)); | | |||
706 | } | 679 | } | ||
707 | 680 | | |||
708 | KDbField* KDbQuerySchema::field(int id) | 681 | KDbField* KDbQuerySchema::field(int id) | ||
709 | { | 682 | { | ||
710 | return KDbFieldList::field(id); | 683 | return KDbFieldList::field(id); | ||
711 | } | 684 | } | ||
712 | 685 | | |||
713 | const KDbField* KDbQuerySchema::field(int id) const | 686 | const KDbField* KDbQuerySchema::field(int id) const | ||
714 | { | 687 | { | ||
715 | return KDbFieldList::field(id); | 688 | return KDbFieldList::field(id); | ||
716 | } | 689 | } | ||
717 | 690 | | |||
718 | KDbQueryColumnInfo* KDbQuerySchema::columnInfo(const QString& identifier, bool expanded) const | 691 | KDbQueryColumnInfo *KDbQuerySchema::columnInfo(KDbConnection *conn, const QString &identifier, | ||
692 | ExpandMode mode) const | ||||
719 | { | 693 | { | ||
720 | computeFieldsExpanded(); | 694 | computeFieldsExpanded(conn); | ||
721 | return expanded ? d->columnInfosByNameExpanded.value(identifier) | 695 | return mode == ExpandMode::Expanded ? d->columnInfosByNameExpanded.value(identifier) | ||
722 | : d->columnInfosByName.value(identifier); | 696 | : d->columnInfosByName.value(identifier); | ||
723 | } | 697 | } | ||
724 | 698 | | |||
725 | KDbQueryColumnInfo::Vector KDbQuerySchema::fieldsExpandedInternal( | 699 | KDbQueryColumnInfo::Vector KDbQuerySchema::fieldsExpandedInternal( | ||
726 | FieldsExpandedOptions options, bool onlyVisible) const | 700 | KDbConnection *conn, FieldsExpandedMode mode, bool onlyVisible) const | ||
701 | { | ||||
702 | if (!conn) { | ||||
703 | kdbWarning() << "Connection required"; | ||||
704 | return KDbQueryColumnInfo::Vector(); | ||||
705 | } | ||||
706 | computeFieldsExpanded(conn); | ||||
707 | KDbQueryColumnInfo::Vector *realFieldsExpanded | ||||
708 | = onlyVisible ? d->visibleFieldsExpanded : d->fieldsExpanded; | ||||
709 | if (mode == FieldsExpandedMode::WithInternalFields | ||||
710 | || mode == FieldsExpandedMode::WithInternalFieldsAndRecordId) | ||||
727 | { | 711 | { | ||
728 | computeFieldsExpanded(); | | |||
729 | KDbQueryColumnInfo::Vector *realFieldsExpanded = onlyVisible ? d->visibleFieldsExpanded | | |||
730 | : d->fieldsExpanded; | | |||
731 | if (options == WithInternalFields || options == WithInternalFieldsAndRecordId) { | | |||
732 | //a ref to a proper pointer (as we cache the vector for two cases) | 712 | //a ref to a proper pointer (as we cache the vector for two cases) | ||
733 | KDbQueryColumnInfo::Vector*& tmpFieldsExpandedWithInternal = | 713 | KDbQueryColumnInfo::Vector*& tmpFieldsExpandedWithInternal = | ||
734 | (options == WithInternalFields) ? | 714 | (mode == FieldsExpandedMode::WithInternalFields) ? | ||
735 | (onlyVisible ? d->visibleFieldsExpandedWithInternal : d->fieldsExpandedWithInternal) | 715 | (onlyVisible ? d->visibleFieldsExpandedWithInternal : d->fieldsExpandedWithInternal) | ||
736 | : (onlyVisible ? d->visibleFieldsExpandedWithInternalAndRecordId : d->fieldsExpandedWithInternalAndRecordId); | 716 | : (onlyVisible ? d->visibleFieldsExpandedWithInternalAndRecordId : d->fieldsExpandedWithInternalAndRecordId); | ||
737 | //special case | 717 | //special case | ||
738 | if (!tmpFieldsExpandedWithInternal) { | 718 | if (!tmpFieldsExpandedWithInternal) { | ||
739 | //glue expanded and internal fields and cache it | 719 | //glue expanded and internal fields and cache it | ||
740 | const int internalFieldCount = d->internalFields ? d->internalFields->size() : 0; | 720 | const int internalFieldCount = d->internalFields ? d->internalFields->size() : 0; | ||
741 | const int fieldsExpandedVectorSize = realFieldsExpanded->size(); | 721 | const int fieldsExpandedVectorSize = realFieldsExpanded->size(); | ||
742 | const int size = fieldsExpandedVectorSize + internalFieldCount | 722 | const int size = fieldsExpandedVectorSize + internalFieldCount | ||
743 | + ((options == WithInternalFieldsAndRecordId) ? 1 : 0) /*ROWID*/; | 723 | + ((mode == FieldsExpandedMode::WithInternalFieldsAndRecordId) ? 1 : 0) /*ROWID*/; | ||
744 | tmpFieldsExpandedWithInternal = new KDbQueryColumnInfo::Vector(size); | 724 | tmpFieldsExpandedWithInternal = new KDbQueryColumnInfo::Vector(size); | ||
745 | for (int i = 0; i < fieldsExpandedVectorSize; ++i) { | 725 | for (int i = 0; i < fieldsExpandedVectorSize; ++i) { | ||
746 | (*tmpFieldsExpandedWithInternal)[i] = realFieldsExpanded->at(i); | 726 | (*tmpFieldsExpandedWithInternal)[i] = realFieldsExpanded->at(i); | ||
747 | } | 727 | } | ||
748 | if (internalFieldCount > 0) { | 728 | if (internalFieldCount > 0) { | ||
749 | for (int i = 0; i < internalFieldCount; ++i) { | 729 | for (int i = 0; i < internalFieldCount; ++i) { | ||
750 | KDbQueryColumnInfo *info = d->internalFields->at(i); | 730 | KDbQueryColumnInfo *info = d->internalFields->at(i); | ||
751 | (*tmpFieldsExpandedWithInternal)[fieldsExpandedVectorSize + i] = info; | 731 | (*tmpFieldsExpandedWithInternal)[fieldsExpandedVectorSize + i] = info; | ||
752 | } | 732 | } | ||
753 | } | 733 | } | ||
754 | if (options == WithInternalFieldsAndRecordId) { | 734 | if (mode == FieldsExpandedMode::WithInternalFieldsAndRecordId) { | ||
755 | if (!d->fakeRecordIdField) { | 735 | if (!d->fakeRecordIdField) { | ||
756 | d->fakeRecordIdField = new KDbField(QLatin1String("rowID"), KDbField::BigInteger); | 736 | d->fakeRecordIdField = new KDbField(QLatin1String("rowID"), KDbField::BigInteger); | ||
757 | d->fakeRecordIdCol = new KDbQueryColumnInfo(d->fakeRecordIdField, QString(), true); | 737 | d->fakeRecordIdCol = new KDbQueryColumnInfo(d->fakeRecordIdField, QString(), true); | ||
758 | } | 738 | } | ||
759 | (*tmpFieldsExpandedWithInternal)[fieldsExpandedVectorSize + internalFieldCount] = d->fakeRecordIdCol; | 739 | (*tmpFieldsExpandedWithInternal)[fieldsExpandedVectorSize + internalFieldCount] = d->fakeRecordIdCol; | ||
760 | } | 740 | } | ||
761 | } | 741 | } | ||
762 | return *tmpFieldsExpandedWithInternal; | 742 | return *tmpFieldsExpandedWithInternal; | ||
763 | } | 743 | } | ||
764 | 744 | | |||
765 | if (options == Default) { | 745 | if (mode == FieldsExpandedMode::Default) { | ||
766 | return *realFieldsExpanded; | 746 | return *realFieldsExpanded; | ||
767 | } | 747 | } | ||
768 | 748 | | |||
769 | //options == Unique: | 749 | //mode == Unique: | ||
770 | QSet<QString> columnsAlreadyFound; | 750 | QSet<QString> columnsAlreadyFound; | ||
771 | const int fieldsExpandedCount(realFieldsExpanded->count()); | 751 | const int fieldsExpandedCount(realFieldsExpanded->count()); | ||
772 | KDbQueryColumnInfo::Vector result(fieldsExpandedCount); //initial size is set | 752 | KDbQueryColumnInfo::Vector result(fieldsExpandedCount); //initial size is set | ||
773 | //compute unique list | 753 | //compute unique list | ||
774 | int uniqueListCount = 0; | 754 | int uniqueListCount = 0; | ||
775 | for (int i = 0; i < fieldsExpandedCount; i++) { | 755 | for (int i = 0; i < fieldsExpandedCount; i++) { | ||
776 | KDbQueryColumnInfo *ci = realFieldsExpanded->at(i); | 756 | KDbQueryColumnInfo *ci = realFieldsExpanded->at(i); | ||
777 | if (!columnsAlreadyFound.contains(ci->aliasOrName())) { | 757 | if (!columnsAlreadyFound.contains(ci->aliasOrName())) { | ||
778 | columnsAlreadyFound.insert(ci->aliasOrName()); | 758 | columnsAlreadyFound.insert(ci->aliasOrName()); | ||
779 | result[uniqueListCount++] = ci; | 759 | result[uniqueListCount++] = ci; | ||
780 | } | 760 | } | ||
781 | } | 761 | } | ||
782 | result.resize(uniqueListCount); //update result size | 762 | result.resize(uniqueListCount); //update result size | ||
783 | return result; | 763 | return result; | ||
784 | } | 764 | } | ||
785 | 765 | | |||
786 | KDbQueryColumnInfo::Vector KDbQuerySchema::internalFields() const | 766 | KDbQueryColumnInfo::Vector KDbQuerySchema::internalFields(KDbConnection *conn) const | ||
787 | { | 767 | { | ||
788 | computeFieldsExpanded(); | 768 | computeFieldsExpanded(conn); | ||
789 | return d->internalFields ? *d->internalFields : KDbQueryColumnInfo::Vector(); | 769 | return d->internalFields ? *d->internalFields : KDbQueryColumnInfo::Vector(); | ||
790 | } | 770 | } | ||
791 | 771 | | |||
792 | KDbQueryColumnInfo* KDbQuerySchema::expandedOrInternalField(int index) const | 772 | KDbQueryColumnInfo* KDbQuerySchema::expandedOrInternalField(KDbConnection *conn, int index) const | ||
793 | { | 773 | { | ||
794 | return fieldsExpanded(WithInternalFields).value(index); | 774 | return fieldsExpanded(conn, FieldsExpandedMode::WithInternalFields).value(index); | ||
795 | } | 775 | } | ||
796 | 776 | | |||
797 | inline static QString lookupColumnKey(KDbField *foreignField, KDbField* field) | 777 | inline static QString lookupColumnKey(KDbField *foreignField, KDbField* field) | ||
798 | { | 778 | { | ||
799 | QString res; | 779 | QString res; | ||
800 | if (field->table()) // can be 0 for anonymous fields built as joined multiple visible columns | 780 | if (field->table()) // can be 0 for anonymous fields built as joined multiple visible columns | ||
801 | res = field->table()->name() + QLatin1Char('.'); | 781 | res = field->table()->name() + QLatin1Char('.'); | ||
802 | return res + field->name() + QLatin1Char('_') + foreignField->table()->name() | 782 | return res + field->name() + QLatin1Char('_') + foreignField->table()->name() | ||
803 | + QLatin1Char('.') + foreignField->name(); | 783 | + QLatin1Char('.') + foreignField->name(); | ||
804 | } | 784 | } | ||
805 | 785 | | |||
806 | void KDbQuerySchema::computeFieldsExpanded() const | 786 | void KDbQuerySchema::computeFieldsExpanded(KDbConnection *conn) const | ||
807 | { | 787 | { | ||
808 | if (d->fieldsExpanded) | 788 | if (d->fieldsExpanded) | ||
809 | return; | 789 | return; | ||
810 | 790 | | |||
811 | if (!d->columnsOrder) { | 791 | if (!d->columnsOrder) { | ||
812 | d->columnsOrder = new QHash<KDbQueryColumnInfo*, int>(); | 792 | d->columnsOrder = new QHash<KDbQueryColumnInfo*, int>(); | ||
813 | d->columnsOrderWithoutAsterisks = new QHash<KDbQueryColumnInfo*, int>(); | 793 | d->columnsOrderWithoutAsterisks = new QHash<KDbQueryColumnInfo*, int>(); | ||
814 | } else { | 794 | } else { | ||
▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Line(s) | 836 | } else { | |||
867 | if (!lookupFieldSchema || lookupFieldSchema->boundColumn() < 0) | 847 | if (!lookupFieldSchema || lookupFieldSchema->boundColumn() < 0) | ||
868 | continue; | 848 | continue; | ||
869 | // Lookup field schema found: | 849 | // Lookup field schema found: | ||
870 | // Now we also need to fetch "visible" value from the lookup table, not only the value of binding. | 850 | // Now we also need to fetch "visible" value from the lookup table, not only the value of binding. | ||
871 | // -> build LEFT OUTER JOIN clause for this purpose (LEFT, not INNER because the binding can be broken) | 851 | // -> build LEFT OUTER JOIN clause for this purpose (LEFT, not INNER because the binding can be broken) | ||
872 | // "LEFT OUTER JOIN lookupTable ON thisTable.thisField=lookupTable.boundField" | 852 | // "LEFT OUTER JOIN lookupTable ON thisTable.thisField=lookupTable.boundField" | ||
873 | KDbLookupFieldSchemaRecordSource recordSource = lookupFieldSchema->recordSource(); | 853 | KDbLookupFieldSchemaRecordSource recordSource = lookupFieldSchema->recordSource(); | ||
874 | if (recordSource.type() == KDbLookupFieldSchemaRecordSource::Table) { | 854 | if (recordSource.type() == KDbLookupFieldSchemaRecordSource::Table) { | ||
875 | KDbTableSchema *lookupTable = connection()->tableSchema(recordSource.name()); | 855 | KDbTableSchema *lookupTable = conn->tableSchema(recordSource.name()); | ||
876 | KDbFieldList* visibleColumns = nullptr; | 856 | KDbFieldList* visibleColumns = nullptr; | ||
877 | KDbField *boundField = nullptr; | 857 | KDbField *boundField = nullptr; | ||
878 | if (lookupTable | 858 | if (lookupTable | ||
879 | && lookupFieldSchema->boundColumn() < lookupTable->fieldCount() | 859 | && lookupFieldSchema->boundColumn() < lookupTable->fieldCount() | ||
880 | && (visibleColumns = lookupTable->subList(lookupFieldSchema->visibleColumns())) | 860 | && (visibleColumns = lookupTable->subList(lookupFieldSchema->visibleColumns())) | ||
881 | && (boundField = lookupTable->field(lookupFieldSchema->boundColumn()))) { | 861 | && (boundField = lookupTable->field(lookupFieldSchema->boundColumn()))) { | ||
882 | KDbField *visibleColumn = nullptr; | 862 | KDbField *visibleColumn = nullptr; | ||
883 | // for single visible column, just add it as-is | 863 | // for single visible column, just add it as-is | ||
Show All 24 Lines | 885 | if (!findTableField( visibleField->table()->name()+"."+visibleField->name() )) { | |||
908 | if (!sql.isEmpty()) | 888 | if (!sql.isEmpty()) | ||
909 | sql += QString::fromLatin1(", "); | 889 | sql += QString::fromLatin1(", "); | ||
910 | sql += (escapeIdentifier(visibleField->table()->name(), drvEscaping) + "." | 890 | sql += (escapeIdentifier(visibleField->table()->name(), drvEscaping) + "." | ||
911 | + escapeIdentifier(visibleField->name(), drvEscaping)); | 891 | + escapeIdentifier(visibleField->name(), drvEscaping)); | ||
912 | }*/ | 892 | }*/ | ||
913 | } | 893 | } | ||
914 | delete visibleColumns; | 894 | delete visibleColumns; | ||
915 | } else if (recordSource.type() == KDbLookupFieldSchemaRecordSource::Query) { | 895 | } else if (recordSource.type() == KDbLookupFieldSchemaRecordSource::Query) { | ||
916 | KDbQuerySchema *lookupQuery = connection()->querySchema(recordSource.name()); | 896 | KDbQuerySchema *lookupQuery = conn->querySchema(recordSource.name()); | ||
917 | if (!lookupQuery) | 897 | if (!lookupQuery) | ||
918 | continue; | 898 | continue; | ||
919 | const KDbQueryColumnInfo::Vector lookupQueryFieldsExpanded(lookupQuery->fieldsExpanded()); | 899 | const KDbQueryColumnInfo::Vector lookupQueryFieldsExpanded( | ||
900 | lookupQuery->fieldsExpanded(conn)); | ||||
920 | if (lookupFieldSchema->boundColumn() >= lookupQueryFieldsExpanded.count()) | 901 | if (lookupFieldSchema->boundColumn() >= lookupQueryFieldsExpanded.count()) | ||
921 | continue; | 902 | continue; | ||
922 | KDbQueryColumnInfo *boundColumnInfo = nullptr; | 903 | KDbQueryColumnInfo *boundColumnInfo = nullptr; | ||
923 | if (!(boundColumnInfo = lookupQueryFieldsExpanded.value(lookupFieldSchema->boundColumn()))) | 904 | if (!(boundColumnInfo = lookupQueryFieldsExpanded.value(lookupFieldSchema->boundColumn()))) | ||
924 | continue; | 905 | continue; | ||
925 | KDbField *boundField = boundColumnInfo->field(); | 906 | KDbField *boundField = boundColumnInfo->field(); | ||
926 | if (!boundField) | 907 | if (!boundField) | ||
927 | continue; | 908 | continue; | ||
▲ Show 20 Lines • Show All 162 Lines • ▼ Show 20 Line(s) | 1070 | for (i = 0; i < d->fieldsExpanded->size(); i++) { | |||
1090 | KDbQueryColumnInfo* ci = d->fieldsExpanded->at(i); | 1071 | KDbQueryColumnInfo* ci = d->fieldsExpanded->at(i); | ||
1091 | //! @todo KDbQuerySchema itself will also support lookup fields... | 1072 | //! @todo KDbQuerySchema itself will also support lookup fields... | ||
1092 | KDbLookupFieldSchema *lookupFieldSchema | 1073 | KDbLookupFieldSchema *lookupFieldSchema | ||
1093 | = ci->field()->table() ? ci->field()->table()->lookupFieldSchema(*ci->field()) : nullptr; | 1074 | = ci->field()->table() ? ci->field()->table()->lookupFieldSchema(*ci->field()) : nullptr; | ||
1094 | if (!lookupFieldSchema || lookupFieldSchema->boundColumn() < 0) | 1075 | if (!lookupFieldSchema || lookupFieldSchema->boundColumn() < 0) | ||
1095 | continue; | 1076 | continue; | ||
1096 | const KDbLookupFieldSchemaRecordSource recordSource = lookupFieldSchema->recordSource(); | 1077 | const KDbLookupFieldSchemaRecordSource recordSource = lookupFieldSchema->recordSource(); | ||
1097 | if (recordSource.type() == KDbLookupFieldSchemaRecordSource::Table) { | 1078 | if (recordSource.type() == KDbLookupFieldSchemaRecordSource::Table) { | ||
1098 | KDbTableSchema *lookupTable = connection()->tableSchema(recordSource.name()); | 1079 | KDbTableSchema *lookupTable = conn->tableSchema(recordSource.name()); | ||
1099 | KDbFieldList* visibleColumns = nullptr; | 1080 | KDbFieldList* visibleColumns = nullptr; | ||
1100 | if (lookupTable | 1081 | if (lookupTable | ||
1101 | && lookupFieldSchema->boundColumn() < lookupTable->fieldCount() | 1082 | && lookupFieldSchema->boundColumn() < lookupTable->fieldCount() | ||
1102 | && (visibleColumns = lookupTable->subList(lookupFieldSchema->visibleColumns()))) { | 1083 | && (visibleColumns = lookupTable->subList(lookupFieldSchema->visibleColumns()))) { | ||
1103 | // for single visible column, just add it as-is | 1084 | // for single visible column, just add it as-is | ||
1104 | if (visibleColumns->fieldCount() == 1) { | 1085 | if (visibleColumns->fieldCount() == 1) { | ||
1105 | KDbField *visibleColumn = visibleColumns->fields()->first(); | 1086 | KDbField *visibleColumn = visibleColumns->fields()->first(); | ||
1106 | const QString key(lookupColumnKey(ci->field(), visibleColumn)); | 1087 | const QString key(lookupColumnKey(ci->field(), visibleColumn)); | ||
1107 | int index = lookup_dict.value(key, -99); | 1088 | int index = lookup_dict.value(key, -99); | ||
1108 | if (index != -99) | 1089 | if (index != -99) | ||
1109 | ci->setIndexForVisibleLookupValue(d->fieldsExpanded->size() + index); | 1090 | ci->setIndexForVisibleLookupValue(d->fieldsExpanded->size() + index); | ||
1110 | } else { | 1091 | } else { | ||
1111 | const QString key(QString::fromLatin1("[multiple_visible_fields_%1]_%2.%3") | 1092 | const QString key(QString::fromLatin1("[multiple_visible_fields_%1]_%2.%3") | ||
1112 | .arg(++numberOfColumnsWithMultipleVisibleFields) | 1093 | .arg(++numberOfColumnsWithMultipleVisibleFields) | ||
1113 | .arg(ci->field()->table()->name(), ci->field()->name())); | 1094 | .arg(ci->field()->table()->name(), ci->field()->name())); | ||
1114 | int index = lookup_dict.value(key, -99); | 1095 | int index = lookup_dict.value(key, -99); | ||
1115 | if (index != -99) | 1096 | if (index != -99) | ||
1116 | ci->setIndexForVisibleLookupValue(d->fieldsExpanded->size() + index); | 1097 | ci->setIndexForVisibleLookupValue(d->fieldsExpanded->size() + index); | ||
1117 | } | 1098 | } | ||
1118 | } | 1099 | } | ||
1119 | delete visibleColumns; | 1100 | delete visibleColumns; | ||
1120 | } else if (recordSource.type() == KDbLookupFieldSchemaRecordSource::Query) { | 1101 | } else if (recordSource.type() == KDbLookupFieldSchemaRecordSource::Query) { | ||
1121 | KDbQuerySchema *lookupQuery = connection()->querySchema(recordSource.name()); | 1102 | KDbQuerySchema *lookupQuery = conn->querySchema(recordSource.name()); | ||
1122 | if (!lookupQuery) | 1103 | if (!lookupQuery) | ||
1123 | continue; | 1104 | continue; | ||
1124 | const KDbQueryColumnInfo::Vector lookupQueryFieldsExpanded(lookupQuery->fieldsExpanded()); | 1105 | const KDbQueryColumnInfo::Vector lookupQueryFieldsExpanded( | ||
1106 | lookupQuery->fieldsExpanded(conn)); | ||||
1125 | if (lookupFieldSchema->boundColumn() >= lookupQueryFieldsExpanded.count()) | 1107 | if (lookupFieldSchema->boundColumn() >= lookupQueryFieldsExpanded.count()) | ||
1126 | continue; | 1108 | continue; | ||
1127 | KDbQueryColumnInfo *boundColumnInfo = nullptr; | 1109 | KDbQueryColumnInfo *boundColumnInfo = nullptr; | ||
1128 | if (!(boundColumnInfo = lookupQueryFieldsExpanded.value(lookupFieldSchema->boundColumn()))) | 1110 | if (!(boundColumnInfo = lookupQueryFieldsExpanded.value(lookupFieldSchema->boundColumn()))) | ||
1129 | continue; | 1111 | continue; | ||
1130 | KDbField *boundField = boundColumnInfo->field(); | 1112 | KDbField *boundField = boundColumnInfo->field(); | ||
1131 | if (!boundField) | 1113 | if (!boundField) | ||
1132 | continue; | 1114 | continue; | ||
Show All 16 Lines | 1130 | if (index != -99) | |||
1149 | ci->setIndexForVisibleLookupValue(d->fieldsExpanded->size() + index); | 1131 | ci->setIndexForVisibleLookupValue(d->fieldsExpanded->size() + index); | ||
1150 | } | 1132 | } | ||
1151 | } else { | 1133 | } else { | ||
1152 | kdbWarning() << "unsupported record source type" << recordSource.typeName(); | 1134 | kdbWarning() << "unsupported record source type" << recordSource.typeName(); | ||
1153 | } | 1135 | } | ||
1154 | } | 1136 | } | ||
1155 | } | 1137 | } | ||
1156 | 1138 | | |||
1157 | QHash<KDbQueryColumnInfo*, int> KDbQuerySchema::columnsOrder(ColumnsOrderOptions options) const | 1139 | QHash<KDbQueryColumnInfo*, int> KDbQuerySchema::columnsOrder(KDbConnection *conn, | ||
1140 | ColumnsOrderMode mode) const | ||||
1158 | { | 1141 | { | ||
1159 | if (!d->columnsOrder) | 1142 | if (!d->columnsOrder) { | ||
1160 | computeFieldsExpanded(); | 1143 | computeFieldsExpanded(conn); | ||
1161 | if (options == UnexpandedList) | 1144 | } | ||
1145 | if (mode == ColumnsOrderMode::UnexpandedList) { | ||||
1162 | return *d->columnsOrder; | 1146 | return *d->columnsOrder; | ||
1163 | else if (options == UnexpandedListWithoutAsterisks) | 1147 | } else if (mode == ColumnsOrderMode::UnexpandedListWithoutAsterisks) { | ||
1164 | return *d->columnsOrderWithoutAsterisks; | 1148 | return *d->columnsOrderWithoutAsterisks; | ||
1149 | } | ||||
1165 | return *d->columnsOrderExpanded; | 1150 | return *d->columnsOrderExpanded; | ||
1166 | } | 1151 | } | ||
1167 | 1152 | | |||
1168 | QVector<int> KDbQuerySchema::pkeyFieldsOrder() const | 1153 | QVector<int> KDbQuerySchema::pkeyFieldsOrder(KDbConnection *conn) const | ||
1169 | { | 1154 | { | ||
1170 | if (d->pkeyFieldsOrder) | 1155 | if (d->pkeyFieldsOrder) | ||
1171 | return *d->pkeyFieldsOrder; | 1156 | return *d->pkeyFieldsOrder; | ||
1172 | 1157 | | |||
1173 | KDbTableSchema *tbl = masterTable(); | 1158 | KDbTableSchema *tbl = masterTable(); | ||
1174 | if (!tbl || !tbl->primaryKey()) | 1159 | if (!tbl || !tbl->primaryKey()) | ||
1175 | return QVector<int>(); | 1160 | return QVector<int>(); | ||
1176 | 1161 | | |||
1177 | //get order of PKEY fields (e.g. for records updating or inserting ) | 1162 | //get order of PKEY fields (e.g. for records updating or inserting ) | ||
1178 | KDbIndexSchema *pkey = tbl->primaryKey(); | 1163 | KDbIndexSchema *pkey = tbl->primaryKey(); | ||
1179 | kdbDebug() << *pkey; | 1164 | kdbDebug() << *pkey; | ||
1180 | d->pkeyFieldsOrder = new QVector<int>(pkey->fieldCount(), -1); | 1165 | d->pkeyFieldsOrder = new QVector<int>(pkey->fieldCount(), -1); | ||
1181 | 1166 | | |||
1182 | const int fCount = fieldsExpanded().count(); | 1167 | const int fCount = fieldsExpanded(conn).count(); | ||
1183 | d->pkeyFieldCount = 0; | 1168 | d->pkeyFieldCount = 0; | ||
1184 | for (int i = 0; i < fCount; i++) { | 1169 | for (int i = 0; i < fCount; i++) { | ||
1185 | KDbQueryColumnInfo *fi = d->fieldsExpanded->at(i); | 1170 | KDbQueryColumnInfo *fi = d->fieldsExpanded->at(i); | ||
1186 | const int fieldIndex = fi->field()->table() == tbl ? pkey->indexOf(*fi->field()) : -1; | 1171 | const int fieldIndex = fi->field()->table() == tbl ? pkey->indexOf(*fi->field()) : -1; | ||
1187 | if (fieldIndex != -1/* field found in PK */ | 1172 | if (fieldIndex != -1/* field found in PK */ | ||
1188 | && d->pkeyFieldsOrder->at(fieldIndex) == -1 /* first time */) { | 1173 | && d->pkeyFieldsOrder->at(fieldIndex) == -1 /* first time */) { | ||
1189 | kdbDebug() << "FIELD" << fi->field()->name() << "IS IN PKEY AT POSITION #" << fieldIndex; | 1174 | kdbDebug() << "FIELD" << fi->field()->name() << "IS IN PKEY AT POSITION #" << fieldIndex; | ||
1190 | (*d->pkeyFieldsOrder)[fieldIndex] = i; | 1175 | (*d->pkeyFieldsOrder)[fieldIndex] = i; | ||
1191 | d->pkeyFieldCount++; | 1176 | d->pkeyFieldCount++; | ||
1192 | } | 1177 | } | ||
1193 | } | 1178 | } | ||
1194 | kdbDebug() << d->pkeyFieldCount | 1179 | kdbDebug() << d->pkeyFieldCount | ||
1195 | << " OUT OF " << pkey->fieldCount() << " PKEY'S FIELDS FOUND IN QUERY " << name(); | 1180 | << " OUT OF " << pkey->fieldCount() << " PKEY'S FIELDS FOUND IN QUERY " << name(); | ||
1196 | return *d->pkeyFieldsOrder; | 1181 | return *d->pkeyFieldsOrder; | ||
1197 | } | 1182 | } | ||
1198 | 1183 | | |||
1199 | int KDbQuerySchema::pkeyFieldCount() | 1184 | int KDbQuerySchema::pkeyFieldCount(KDbConnection *conn) | ||
1200 | { | 1185 | { | ||
1201 | (void)pkeyFieldsOrder(); /* rebuild information */ | 1186 | (void)pkeyFieldsOrder(conn); /* rebuild information */ | ||
1202 | return d->pkeyFieldCount; | 1187 | return d->pkeyFieldCount; | ||
1203 | } | 1188 | } | ||
1204 | 1189 | | |||
1205 | KDbRelationship* KDbQuerySchema::addRelationship(KDbField *field1, KDbField *field2) | 1190 | KDbRelationship* KDbQuerySchema::addRelationship(KDbField *field1, KDbField *field2) | ||
1206 | { | 1191 | { | ||
1207 | //@todo: find existing global db relationships | 1192 | //@todo: find existing global db relationships | ||
1208 | KDbRelationship *r = new KDbRelationship(this, field1, field2); | 1193 | KDbRelationship *r = new KDbRelationship(this, field1, field2); | ||
1209 | if (r->isEmpty()) { | 1194 | if (r->isEmpty()) { | ||
1210 | delete r; | 1195 | delete r; | ||
1211 | return nullptr; | 1196 | return nullptr; | ||
1212 | } | 1197 | } | ||
1213 | 1198 | | |||
1214 | d->relations.append(r); | 1199 | d->relations.append(r); | ||
1215 | return r; | 1200 | return r; | ||
1216 | } | 1201 | } | ||
1217 | 1202 | | |||
1218 | KDbQueryColumnInfo::List* KDbQuerySchema::autoIncrementFields() const | 1203 | KDbQueryColumnInfo::List* KDbQuerySchema::autoIncrementFields(KDbConnection *conn) const | ||
1219 | { | 1204 | { | ||
1220 | if (!d->autoincFields) { | 1205 | if (!d->autoincFields) { | ||
1221 | d->autoincFields = new KDbQueryColumnInfo::List(); | 1206 | d->autoincFields = new KDbQueryColumnInfo::List(); | ||
1222 | } | 1207 | } | ||
1223 | KDbTableSchema *mt = masterTable(); | 1208 | KDbTableSchema *mt = masterTable(); | ||
1224 | if (!mt) { | 1209 | if (!mt) { | ||
1225 | kdbWarning() << "no master table!"; | 1210 | kdbWarning() << "no master table!"; | ||
1226 | return d->autoincFields; | 1211 | return d->autoincFields; | ||
1227 | } | 1212 | } | ||
1228 | if (d->autoincFields->isEmpty()) {//no cache | 1213 | if (d->autoincFields->isEmpty()) {//no cache | ||
1229 | KDbQueryColumnInfo::Vector fexp = fieldsExpanded(); | 1214 | KDbQueryColumnInfo::Vector fexp = fieldsExpanded(conn); | ||
1230 | for (int i = 0; i < fexp.count(); i++) { | 1215 | for (int i = 0; i < fexp.count(); i++) { | ||
1231 | KDbQueryColumnInfo *ci = fexp[i]; | 1216 | KDbQueryColumnInfo *ci = fexp[i]; | ||
1232 | if (ci->field()->table() == mt && ci->field()->isAutoIncrement()) { | 1217 | if (ci->field()->table() == mt && ci->field()->isAutoIncrement()) { | ||
1233 | d->autoincFields->append(ci); | 1218 | d->autoincFields->append(ci); | ||
1234 | } | 1219 | } | ||
1235 | } | 1220 | } | ||
1236 | } | 1221 | } | ||
1237 | return d->autoincFields; | 1222 | return d->autoincFields; | ||
1238 | } | 1223 | } | ||
1239 | 1224 | | |||
1240 | // static | 1225 | // static | ||
1241 | KDbEscapedString KDbQuerySchema::sqlColumnsList(const KDbQueryColumnInfo::List& infolist, KDbConnection *conn, | 1226 | KDbEscapedString KDbQuerySchema::sqlColumnsList(const KDbQueryColumnInfo::List &infolist, | ||
1227 | KDbConnection *conn, | ||||
1242 | KDb::IdentifierEscapingType escapingType) | 1228 | KDb::IdentifierEscapingType escapingType) | ||
1243 | { | 1229 | { | ||
1244 | KDbEscapedString result; | 1230 | KDbEscapedString result; | ||
1245 | result.reserve(256); | 1231 | result.reserve(256); | ||
1246 | bool start = true; | 1232 | bool start = true; | ||
1247 | foreach(KDbQueryColumnInfo* ci, infolist) { | 1233 | foreach(KDbQueryColumnInfo* ci, infolist) { | ||
1248 | if (!start) | 1234 | if (!start) | ||
1249 | result += ","; | 1235 | result += ","; | ||
1250 | else | 1236 | else | ||
1251 | start = false; | 1237 | start = false; | ||
1252 | result += escapeIdentifier(ci->field()->name(), conn, escapingType); | 1238 | result += escapeIdentifier(ci->field()->name(), conn, escapingType); | ||
1253 | } | 1239 | } | ||
1254 | return result; | 1240 | return result; | ||
1255 | } | 1241 | } | ||
1256 | 1242 | | |||
1257 | KDbEscapedString KDbQuerySchema::autoIncrementSqlFieldsList(KDbConnection *conn) const | 1243 | KDbEscapedString KDbQuerySchema::autoIncrementSqlFieldsList(KDbConnection *conn) const | ||
1258 | { | 1244 | { | ||
1259 | // QWeakPointer<const KDbDriver> driverWeakPointer | 1245 | // QWeakPointer<const KDbDriver> driverWeakPointer | ||
1260 | // = DriverManagerInternal::self()->driverWeakPointer(*conn->driver()); | 1246 | // = DriverManagerInternal::self()->driverWeakPointer(*conn->driver()); | ||
1261 | if ( /*d->lastUsedDriverForAutoIncrementSQLFieldsList != driverWeakPointer | 1247 | if ( /*d->lastUsedDriverForAutoIncrementSQLFieldsList != driverWeakPointer | ||
1262 | ||*/ d->autoIncrementSqlFieldsList.isEmpty()) | 1248 | ||*/ d->autoIncrementSqlFieldsList.isEmpty()) | ||
1263 | { | 1249 | { | ||
1264 | d->autoIncrementSqlFieldsList = KDbQuerySchema::sqlColumnsList(*autoIncrementFields(), conn); | 1250 | d->autoIncrementSqlFieldsList = KDbQuerySchema::sqlColumnsList(*autoIncrementFields(conn), conn); | ||
1265 | //d->lastUsedDriverForAutoIncrementSQLFieldsList = driverWeakPointer; | 1251 | //d->lastUsedDriverForAutoIncrementSQLFieldsList = driverWeakPointer; | ||
1266 | } | 1252 | } | ||
1267 | return d->autoIncrementSqlFieldsList; | 1253 | return d->autoIncrementSqlFieldsList; | ||
1268 | } | 1254 | } | ||
1269 | 1255 | | |||
1270 | static void setResult(const KDbParseInfoInternal &parseInfo, | 1256 | static void setResult(const KDbParseInfoInternal &parseInfo, | ||
1271 | QString *errorMessage, QString *errorDescription) | 1257 | QString *errorMessage, QString *errorDescription) | ||
1272 | { | 1258 | { | ||
▲ Show 20 Lines • Show All 87 Lines • ▼ Show 20 Line(s) | |||||
1360 | KDbExpression KDbQuerySchema::whereExpression() const | 1346 | KDbExpression KDbQuerySchema::whereExpression() const | ||
1361 | { | 1347 | { | ||
1362 | return d->whereExpr; | 1348 | return d->whereExpr; | ||
1363 | } | 1349 | } | ||
1364 | 1350 | | |||
1365 | void KDbQuerySchema::setOrderByColumnList(const KDbOrderByColumnList& list) | 1351 | void KDbQuerySchema::setOrderByColumnList(const KDbOrderByColumnList& list) | ||
1366 | { | 1352 | { | ||
1367 | delete d->orderByColumnList; | 1353 | delete d->orderByColumnList; | ||
1368 | d->orderByColumnList = new KDbOrderByColumnList(list, nullptr, nullptr); | 1354 | d->orderByColumnList = new KDbOrderByColumnList(list, nullptr, nullptr, nullptr); | ||
1369 | // all field names should be found, exit otherwise ..........? | 1355 | // all field names should be found, exit otherwise ..........? | ||
1370 | } | 1356 | } | ||
1371 | 1357 | | |||
1372 | KDbOrderByColumnList* KDbQuerySchema::orderByColumnList() | 1358 | KDbOrderByColumnList* KDbQuerySchema::orderByColumnList() | ||
1373 | { | 1359 | { | ||
1374 | return d->orderByColumnList; | 1360 | return d->orderByColumnList; | ||
1375 | } | 1361 | } | ||
1376 | 1362 | | |||
1377 | const KDbOrderByColumnList* KDbQuerySchema::orderByColumnList() const | 1363 | const KDbOrderByColumnList* KDbQuerySchema::orderByColumnList() const | ||
1378 | { | 1364 | { | ||
1379 | return d->orderByColumnList; | 1365 | return d->orderByColumnList; | ||
1380 | } | 1366 | } | ||
1381 | 1367 | | |||
1382 | QList<KDbQuerySchemaParameter> KDbQuerySchema::parameters() const | 1368 | QList<KDbQuerySchemaParameter> KDbQuerySchema::parameters(KDbConnection *conn) const | ||
1383 | { | 1369 | { | ||
1384 | QList<KDbQuerySchemaParameter> params; | 1370 | QList<KDbQuerySchemaParameter> params; | ||
1385 | const KDbQueryColumnInfo::Vector fieldsExpanded(this->fieldsExpanded()); | 1371 | const KDbQueryColumnInfo::Vector fieldsExpanded(this->fieldsExpanded(conn)); | ||
1386 | for (int i = 0; i < fieldsExpanded.count(); ++i) { | 1372 | for (int i = 0; i < fieldsExpanded.count(); ++i) { | ||
1387 | KDbQueryColumnInfo *ci = fieldsExpanded[i]; | 1373 | KDbQueryColumnInfo *ci = fieldsExpanded[i]; | ||
1388 | if (!ci->field()->expression().isNull()) { | 1374 | if (!ci->field()->expression().isNull()) { | ||
1389 | ci->field()->expression().getQueryParameters(¶ms); | 1375 | ci->field()->expression().getQueryParameters(¶ms); | ||
1390 | } | 1376 | } | ||
1391 | } | 1377 | } | ||
1392 | KDbExpression where = whereExpression(); | 1378 | KDbExpression where = whereExpression(); | ||
1393 | if (!where.isNull()) { | 1379 | if (!where.isNull()) { | ||
Show All 22 Lines |