Changeset View
Changeset View
Standalone View
Standalone View
src/plugins/scripting/kexidb/kexidbcursor.cpp
Show All 34 Lines | 34 | { | |||
---|---|---|---|---|---|
35 | setObjectName("KexiDBCursor"); | 35 | setObjectName("KexiDBCursor"); | ||
36 | } | 36 | } | ||
37 | 37 | | |||
38 | KexiDBCursor::~KexiDBCursor() | 38 | KexiDBCursor::~KexiDBCursor() | ||
39 | { | 39 | { | ||
40 | clearBuffers(); | 40 | clearBuffers(); | ||
41 | if (m_owner) { | 41 | if (m_owner) { | ||
42 | m_cursor->close(); | 42 | m_cursor->close(); | ||
43 | delete m_cursor; | | |||
44 | } | 43 | } | ||
45 | } | 44 | } | ||
46 | 45 | | |||
47 | void KexiDBCursor::clearBuffers() | 46 | void KexiDBCursor::clearBuffers() | ||
48 | { | 47 | { | ||
49 | QMap<qint64, Record*>::ConstIterator | 48 | QMap<qint64, Record*>::ConstIterator | ||
50 | it(m_modifiedrecords.constBegin()), end(m_modifiedrecords.constEnd()); | 49 | it(m_modifiedrecords.constBegin()), end(m_modifiedrecords.constEnd()); | ||
51 | for (; it != end; ++it) | 50 | for (; it != end; ++it) | ||
▲ Show 20 Lines • Show All 70 Lines • ▼ Show 20 Line(s) | 113 | { | |||
122 | if (! column) { | 121 | if (! column) { | ||
123 | qWarning() << "Invalid column, index=" << index << " value=" << value; | 122 | qWarning() << "Invalid column, index=" << index << " value=" << value; | ||
124 | return false; | 123 | return false; | ||
125 | } | 124 | } | ||
126 | 125 | | |||
127 | const qint64 position = m_cursor->at(); | 126 | const qint64 position = m_cursor->at(); | ||
128 | if (! m_modifiedrecords.contains(position)) | 127 | if (! m_modifiedrecords.contains(position)) | ||
129 | m_modifiedrecords.insert(position, new Record(m_cursor)); | 128 | m_modifiedrecords.insert(position, new Record(m_cursor)); | ||
130 | m_modifiedrecords[position]->buffer->insert(*column, value); | 129 | m_modifiedrecords[position]->buffer->insert(column, value); | ||
131 | return true; | 130 | return true; | ||
132 | } | 131 | } | ||
133 | 132 | | |||
134 | bool KexiDBCursor::save() | 133 | bool KexiDBCursor::save() | ||
135 | { | 134 | { | ||
136 | if (m_modifiedrecords.count() < 1) | 135 | if (m_modifiedrecords.count() < 1) | ||
137 | return true; | 136 | return true; | ||
138 | 137 | | |||
139 | //It is needed to close the cursor before we are able to update the rows | 138 | //It is needed to close the cursor before we are able to update the rows | ||
140 | //since else the database could be locked (e.g. at the case of SQLite a | 139 | //since else the database could be locked (e.g. at the case of SQLite a | ||
141 | //KDb: Object ERROR: 6: SQLITE_LOCKED would prevent updating). | 140 | //KDb: Object ERROR: 6: SQLITE_LOCKED would prevent updating). | ||
142 | //Maybe it works fine with other drivers like MySQL or Postqre? | 141 | //Maybe it works fine with other drivers like MySQL or Postqre? | ||
143 | m_cursor->close(); | 142 | m_cursor->close(); | ||
144 | 143 | | |||
145 | bool ok = true; | 144 | bool ok = true; | ||
146 | QMap<qint64, Record*>::ConstIterator | 145 | QMap<qint64, Record*>::ConstIterator | ||
147 | it(m_modifiedrecords.constBegin()), end(m_modifiedrecords.constEnd()); | 146 | it(m_modifiedrecords.constBegin()), end(m_modifiedrecords.constEnd()); | ||
148 | for (; it != end; ++it) { | 147 | for (; it != end; ++it) { | ||
149 | bool b = m_cursor->updateRow(it.value()->rowdata, * it.value()->buffer, m_cursor->isBuffered()); | 148 | bool b = m_cursor->updateRecord(&it.value()->rowdata, it.value()->buffer, m_cursor->isBuffered()); | ||
150 | if (ok) { | 149 | if (ok) { | ||
151 | ok = b; | 150 | ok = b; | ||
152 | //break; | 151 | //break; | ||
153 | } | 152 | } | ||
154 | } | 153 | } | ||
155 | clearBuffers(); | 154 | clearBuffers(); | ||
156 | return ok; | 155 | return ok; | ||
157 | } | 156 | } | ||
158 | 157 | | |||
159 | 158 | |