void Q3DataBrowser::del() { QSqlRecord* buf = d->frm.record(); Q3SqlCursor* cur = d->cur.cursor(); if (!buf || !cur) return; QSql::Confirm conf = QSql::Yes; switch (d->dat.mode()){ case QSql::Insert: if (confirmCancels()) conf = confirmCancel(QSql::Insert); if (conf == QSql::Yes) { cur->editBuffer(true); /* restore from cursor */ readFields(); d->dat.setMode(QSql::Update); } else d->dat.setMode(QSql::Insert); break; default: if (confirmDelete()) conf = confirmEdit(QSql::Delete); switch (conf) { case QSql::Yes: emit primeDelete(buf); deleteCurrent(); break; case QSql::No: case QSql::Cancel: break; } d->dat.setMode(QSql::Update); break; } }
bool Q3SqlCursorManager::refresh() { Q3SqlCursor* cur = cursor(); if (!cur) return false; QString currentFilter = d->ftr; QStringList currentSort = d->srt; QSqlIndex newSort = indexFromStringList(currentSort, cur); return cur->select(currentFilter, newSort); }
bool Q3DataBrowser::seek(int i, bool relative) { int b = 0; Q3SqlCursor* cur = d->cur.cursor(); if (!cur) return false; if (preNav()) b = cur->seek(i, relative); postNav(b); return b; }
void Q3DataBrowser::postNav(bool primeUpd) { if (primeUpd) { QSqlRecord* buf = d->frm.record(); Q3SqlCursor* cur = d->cur.cursor(); if (!buf || !cur) return; currentChanged(cur); cur->primeUpdate(); emit primeUpdate(buf); readFields(); } updateBoundary(); }
bool Q3DataBrowser::deleteCurrent() { if (isReadOnly()) return false; QSqlRecord* buf = d->frm.record(); Q3SqlCursor* cur = d->cur.cursor(); if (!buf || !cur) return false; writeFields(); int n = cur->at(); emit beforeDelete(buf); int ar = cur->del(); if (ar) { refresh(); updateBoundary(); cursorChanged(Q3SqlCursor::Delete); if (!cur->seek(n)) last(); if (cur->isValid()) { cur->editBuffer(true); readFields(); } else { clearValues(); } return true; } else { if (!cur->isActive()) { handleError(cur->lastError()); refresh(); updateBoundary(); } } return false; }
bool Q3DataBrowser::currentEdited() { QSqlRecord* buf = d->frm.record(); Q3SqlCursor* cur = d->cur.cursor(); if (!buf || !cur) return false; if (!cur->isActive() || !cur->isValid()) return false; writeFields(); for (int i = 0; i < cur->count(); ++i) { if (cur->value(i) != buf->value(i)) return true; } return false; }
bool Q3DataBrowser::updateCurrent() { if (isReadOnly()) return false; QSqlRecord* buf = d->frm.record(); Q3SqlCursor* cur = d->cur.cursor(); if (!buf || !cur) return false; writeFields(); emit beforeUpdate(buf); int ar = cur->update(); if (!ar || !cur->isActive()) { handleError(cur->lastError()); refresh(); updateBoundary(); } else { refresh(); d->cur.findBuffer(cur->primaryIndex()); updateBoundary(); cur->editBuffer(true); cursorChanged(Q3SqlCursor::Update); readFields(); return true; } return false; }
void Q3DataBrowser::update() { QSqlRecord* buf = d->frm.record(); Q3SqlCursor* cur = d->cur.cursor(); if (!buf || !cur) return; QSql::Confirm conf = QSql::Yes; switch (d->dat.mode()){ case QSql::Insert: if (confirmInsert()) conf = confirmEdit(QSql::Insert); switch (conf) { case QSql::Yes: if (insertCurrent()) d->dat.setMode(QSql::Update); break; case QSql::No: d->dat.setMode(QSql::Update); cur->editBuffer(true); readFields(); break; case QSql::Cancel: break; } break; default: d->dat.setMode(QSql::Update); if (confirmUpdate()) conf = confirmEdit(QSql::Update); switch (conf) { case QSql::Yes: updateCurrent(); break; case QSql::No: case QSql::Cancel: break; } break; } }
Q3SqlCursor::Q3SqlCursor(const Q3SqlCursor & other) : QSqlRecord(other), QSqlQuery(other) { d = new Q3SqlCursorPrivate(other.d->nm, other.d->db); d->lastAt = other.d->lastAt; d->nm = other.d->nm; d->srt = other.d->srt; d->ftr = other.d->ftr; d->priIndx = other.d->priIndx; d->editBuffer = other.d->editBuffer; d->infoBuffer = other.d->infoBuffer; d->q = 0; // do not share queries setMode(other.mode()); }
//## possibly add sizeHint parameter bool Q3SqlCursorManager::findBuffer(const QSqlIndex& idx, int atHint) { #ifdef QT_DEBUG_DATAMANAGER qDebug("Q3SqlCursorManager::findBuffer:"); #endif Q3SqlCursor* cur = cursor(); if (!cur) return false; if (!cur->isActive()) return false; if (!idx.count()) { if (cur->at() == QSql::BeforeFirst) cur->next(); return false; } QSqlRecord* buf = cur->editBuffer(); bool indexEquals = false; #ifdef QT_DEBUG_DATAMANAGER qDebug(" Checking hint..."); #endif /* check the hint */ if (cur->seek(atHint)) indexEquals = index_matches(cur, buf, idx); if (!indexEquals) { #ifdef QT_DEBUG_DATAMANAGER qDebug(" Checking current page..."); #endif /* check current page */ int pageSize = 20; int startIdx = qMax(atHint - pageSize, 0); int endIdx = atHint + pageSize; for (int j = startIdx; j <= endIdx; ++j) { if (cur->seek(j)) { indexEquals = index_matches(cur, buf, idx); if (indexEquals) break; } } } if (!indexEquals && cur->driver()->hasFeature(QSqlDriver::QuerySize) && cur->sort().count()) { #ifdef QT_DEBUG_DATAMANAGER qDebug(" Using binary search..."); #endif // binary search based on record buffer and current sort fields int lo = 0; int hi = cur->size(); int mid; if (compare_recs(buf, cur, cur->sort()) >= 0) lo = cur->at(); while (lo != hi) { mid = lo + (hi - lo) / 2; if (!cur->seek(mid)) break; if (index_matches(cur, buf, idx)) { indexEquals = true; break; } int c = compare_recs(buf, cur, cur->sort()); if (c < 0) { hi = mid; } else if (c == 0) { // found it, but there may be duplicates int at = mid; do { mid--; if (!cur->seek(mid)) break; if (index_matches(cur, buf, idx)) { indexEquals = true; break; } } while (compare_recs(buf, cur, cur->sort()) == 0); if (!indexEquals) { mid = at; do { mid++; if (!cur->seek(mid)) break; if (index_matches(cur, buf, idx)) { indexEquals = true; break; } } while (compare_recs(buf, cur, cur->sort()) == 0); } break; } else if (c > 0) { lo = mid + 1; } } } if (!indexEquals) { #ifdef QT_DEBUG_DATAMANAGER qDebug(" Using brute search..."); #endif #ifndef QT_NO_CURSOR QApplication::setOverrideCursor(Qt::WaitCursor); #endif /* give up, use brute force */ int startIdx = 0; if (cur->at() != startIdx) { cur->seek(startIdx); } for (;;) { indexEquals = false; indexEquals = index_matches(cur, buf, idx); if (indexEquals) break; if (!cur->next()) break; } #ifndef QT_NO_CURSOR QApplication::restoreOverrideCursor(); #endif } #ifdef QT_DEBUG_DATAMANAGER qDebug(" Done, result:" + QString::number(indexEquals)); #endif return indexEquals; }
Q3DataBrowser::Boundary Q3DataBrowser::boundary() { Q3SqlCursor* cur = d->cur.cursor(); if (!cur || !cur->isActive()) return Unknown; if (!cur->isValid()) { if (cur->at() == QSql::BeforeFirst) return BeforeBeginning; if (cur->at() == QSql::AfterLast) return AfterEnd; return Unknown; } if (cur->at() == 0) return Beginning; int currentAt = cur->at(); Boundary b = None; if (!cur->previous()) b = Beginning; else cur->seek(currentAt); if (b == None && !cur->next()) b = End; cur->seek(currentAt); return b; }
/*! * \~english * Return system icon for display object record state. * \russian * Возвращает иконку для отображения состояния строки. * \~ */ QPixmap wDBTable::systemIcon() { aWidget *container = aWidget::parentContainer( this ); QString ctype=""; QPixmap pm; Q3SqlCursor *r = sqlCursor(); int df=0, cf=0, mf=0; if ( container ) ctype = container->className(); if ( r ) { if ( r->contains("df") ) df = r->field("df").value().toInt(); if ( r->contains("cf") ) cf = r->field("cf").value().toInt(); else { if(ctype=="wJournal") { aDocJournal* sysObj = new aDocJournal(db); if(sysObj) { //for(int i=0; i<r->count(); i++) // printf("f[%d]=%s, %s\n",i, r->fieldName(i).ascii(), r->field(i)->value().toString().ascii()); if(sysObj->findDocument(r->field("id").value().toULongLong())) { aDocument *doc = sysObj->CurrentDocument(); cf = doc->IsConducted(); delete doc; } else { printf(">>doc select failed!\n"); } //doc = 0; //cf = sysObj->sysValue("cf").toInt(); } delete sysObj; } //>>>>>>> 1.71.2.13 } if ( r->contains("mf") ) mf = r->field("mf").value().toInt(); if(ctype=="wJournal") { pm = t_doc; if ( df ) pm = t_doc_d; if ( cf && !df ) pm = t_doc_t; if ( mf && !df ) pm = t_doc_m; if ( cf && mf && !df ) pm = t_doc_tm; } else if(ctype=="wCatalogue") { pm = t_cat_e; if ( df ) pm = t_cat_ed; } else if(ctype=="wCatGroupe") { pm = t_cat_g; if ( df ) pm = t_cat_gd; } } return pm; }
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." ** ** $QT_END_LICENSE$ ** ****************************************************************************/ //! [0] QLineEdit myEditor(this); Q3SqlForm myForm(this); Q3SqlCursor myCursor("mytable"); // Execute a query to make the cursor valid myCursor.select(); // Move the cursor to a valid record (the first record) myCursor.next(); // Set the form's record pointer to the cursor's edit buffer (which // contains the current record's values) myForm.setRecord(myCursor.primeUpdate()); // Insert a field into the form that uses myEditor to edit the // field 'somefield' in 'mytable' myForm.insert(&myEditor, "somefield"); // Update myEditor with the value from the mapped database field myForm.readFields();