Changeset View
Changeset View
Standalone View
Standalone View
src/plugins/queries/kexiqueryview.cpp
Show All 38 Lines | |||||
39 | class Q_DECL_HIDDEN KexiQueryView::Private | 39 | class Q_DECL_HIDDEN KexiQueryView::Private | ||
40 | { | 40 | { | ||
41 | public: | 41 | public: | ||
42 | Private() | 42 | Private() | ||
43 | : cursor(0), | 43 | : cursor(0), | ||
44 | currentParams() | 44 | currentParams() | ||
45 | {} | 45 | {} | ||
46 | ~Private() {} | 46 | ~Private() {} | ||
47 | KDbQuerySchema* query = nullptr; | ||||
47 | KDbCursor *cursor; | 48 | KDbCursor *cursor; | ||
48 | QList<QVariant> currentParams; | 49 | QList<QVariant> currentParams; | ||
49 | /*! Used in storeNewData(), storeData() to decide whether | 50 | /*! Used in storeNewData(), storeData() to decide whether | ||
50 | we should ask other view to save changes. | 51 | we should ask other view to save changes. | ||
51 | Stores information about view mode. */ | 52 | Stores information about view mode. */ | ||
52 | }; | 53 | }; | ||
53 | 54 | | |||
54 | //--------------------------------------------------------------------------------- | 55 | //--------------------------------------------------------------------------------- | ||
Show All 13 Lines | |||||
68 | 69 | | |||
69 | KexiQueryView::~KexiQueryView() | 70 | KexiQueryView::~KexiQueryView() | ||
70 | { | 71 | { | ||
71 | if (d->cursor) | 72 | if (d->cursor) | ||
72 | d->cursor->connection()->deleteCursor(d->cursor); | 73 | d->cursor->connection()->deleteCursor(d->cursor); | ||
73 | delete d; | 74 | delete d; | ||
74 | } | 75 | } | ||
75 | 76 | | |||
76 | tristate KexiQueryView::executeQuery(KDbQuerySchema *query) | 77 | tristate KexiQueryView::setQuery(KDbQuerySchema *query) | ||
77 | { | 78 | { | ||
78 | if (!query) | 79 | if (d->query == query) { | ||
79 | return false; | 80 | return true; | ||
81 | } | ||||
82 | KDbCursor* newCursor; | ||||
83 | if (query) { | ||||
80 | KexiUtils::WaitCursor wait; | 84 | KexiUtils::WaitCursor wait; | ||
81 | KDbCursor *oldCursor = d->cursor; | | |||
82 | KDbConnection * conn = KexiMainWindowIface::global()->project()->dbConnection(); | 85 | KDbConnection * conn = KexiMainWindowIface::global()->project()->dbConnection(); | ||
83 | qDebug() << query->parameters(conn); | 86 | qDebug() << query->parameters(conn); | ||
84 | bool ok; | 87 | bool ok; | ||
85 | { | 88 | { | ||
86 | KexiUtils::WaitCursorRemover remover; | 89 | KexiUtils::WaitCursorRemover remover; | ||
87 | d->currentParams = KexiQueryParameters::getParameters(this, conn, query, &ok); | 90 | d->currentParams = KexiQueryParameters::getParameters(this, conn, query, &ok); | ||
88 | } | 91 | } | ||
89 | if (!ok) {//input cancelled | 92 | if (!ok) {//input cancelled | ||
90 | return cancelled; | 93 | return cancelled; | ||
91 | } | 94 | } | ||
92 | d->cursor = conn->executeQuery(query, d->currentParams); | 95 | newCursor = conn->executeQuery(query, d->currentParams); | ||
93 | if (!d->cursor) { | 96 | if (!newCursor) { | ||
94 | window()->setStatus( | 97 | window()->setStatus(conn, xi18n("Query executing failed.")); | ||
95 | conn, | | |||
96 | xi18n("Query executing failed.")); | | |||
97 | //! @todo also provide server result and sql statement | 98 | //! @todo also provide server result and sql statement | ||
98 | return false; | 99 | return false; | ||
99 | } | 100 | } | ||
101 | } else { | ||||
102 | newCursor = nullptr; | ||||
103 | } | ||||
104 | | ||||
105 | if (d->cursor) { | ||||
106 | d->cursor->connection()->deleteCursor(d->cursor); | ||||
107 | } | ||||
108 | d->cursor = newCursor; | ||||
109 | d->query = query; | ||||
100 | setData(d->cursor); | 110 | setData(d->cursor); | ||
101 | 111 | | |||
102 | //! @todo remove close() when dynamic cursors arrive | 112 | //! @todo remove close() when dynamic cursors arrive | ||
103 | if (!d->cursor->close()) { | 113 | if (d->cursor && !d->cursor->close()) { | ||
104 | return false; | 114 | return false; | ||
105 | } | 115 | } | ||
106 | 116 | | |||
107 | if (oldCursor) | | |||
108 | oldCursor->connection()->deleteCursor(oldCursor); | | |||
109 | | ||||
110 | //! @todo maybe allow writing and inserting for single-table relations? | 117 | //! @todo maybe allow writing and inserting for single-table relations? | ||
111 | tableView()->setReadOnly(true); | 118 | tableView()->setReadOnly(true); | ||
112 | //! @todo maybe allow writing and inserting for single-table relations? | 119 | //! @todo maybe allow writing and inserting for single-table relations? | ||
113 | //set data model itself read-only too | 120 | //set data model itself read-only too | ||
121 | if (tableView()->data()) { | ||||
114 | tableView()->data()->setReadOnly(true); | 122 | tableView()->data()->setReadOnly(true); | ||
123 | } | ||||
115 | tableView()->setInsertingEnabled(false); | 124 | tableView()->setInsertingEnabled(false); | ||
116 | return true; | 125 | return true; | ||
117 | } | 126 | } | ||
118 | 127 | | |||
128 | KDbQuerySchema* KexiQueryView::query() | ||||
129 | { | ||||
130 | return d->query; | ||||
131 | } | ||||
132 | | ||||
119 | tristate KexiQueryView::afterSwitchFrom(Kexi::ViewMode mode) | 133 | tristate KexiQueryView::afterSwitchFrom(Kexi::ViewMode mode) | ||
120 | { | 134 | { | ||
121 | if (mode == Kexi::NoViewMode) { | 135 | if (mode == Kexi::NoViewMode) { | ||
122 | KDbQuerySchema *querySchema = static_cast<KDbQuerySchema *>(window()->schemaObject()); | 136 | KDbQuerySchema *querySchema = static_cast<KDbQuerySchema *>(window()->schemaObject()); | ||
123 | const tristate result = executeQuery(querySchema); | 137 | const tristate result = setQuery(querySchema); | ||
124 | if (true != result) | 138 | if (true != result) | ||
125 | return result; | 139 | return result; | ||
126 | } else if (mode == Kexi::DesignViewMode || mode == Kexi::TextViewMode) { | 140 | } else if (mode == Kexi::DesignViewMode || mode == Kexi::TextViewMode) { | ||
127 | KexiQueryPartTempData * temp = static_cast<KexiQueryPartTempData*>(window()->data()); | 141 | KexiQueryPartTempData * temp = static_cast<KexiQueryPartTempData*>(window()->data()); | ||
128 | const tristate result = executeQuery(temp->query()); | 142 | const tristate result = setQuery(temp->query()); | ||
129 | if (true != result) | 143 | if (true != result) | ||
130 | return result; | 144 | return result; | ||
131 | } | 145 | } | ||
132 | return true; | 146 | return true; | ||
133 | } | 147 | } | ||
134 | 148 | | |||
135 | KDbObject* KexiQueryView::storeNewData(const KDbObject& object, | 149 | KDbObject* KexiQueryView::storeNewData(const KDbObject& object, | ||
136 | KexiView::StoreNewDataOptions options, | 150 | KexiView::StoreNewDataOptions options, | ||
Show All 32 Lines |