当前位置: 首页>>代码示例>>C++>>正文


C++ QSqlDriver::commitTransaction方法代码示例

本文整理汇总了C++中QSqlDriver::commitTransaction方法的典型用法代码示例。如果您正苦于以下问题:C++ QSqlDriver::commitTransaction方法的具体用法?C++ QSqlDriver::commitTransaction怎么用?C++ QSqlDriver::commitTransaction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QSqlDriver的用法示例。


在下文中一共展示了QSqlDriver::commitTransaction方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: savePrivateData

void tableTemplateWidget::savePrivateData(void)
{
  int lastId = 0, cc = 0;

  crossInfo *cross;
  QSqlQuery query, query2;
  QSqlError le;

  query.prepare("DELETE FROM crossword.private_data WHERE _template = ?;");
  query.addBindValue(QVariant(templateId));
  query.exec();

  le = query.lastError();
  if (le.type() == QSqlError::NoError)
    {
      query.prepare("DELETE FROM crossword.crosses WHERE _template = ?;");
      query.addBindValue(QVariant(templateId));
      query.exec();

      le = query.lastError();
      if (le.type() != QSqlError::NoError)
        qDebug() << "2. savePrivateData: " << le.text();
    }
  else
    qDebug() << "1.  savePrivateData: " << le.text();

  QVariantList tmp;
  QVariantList pdid;
  QVariantList cpos;
  QVariantList ctype;
  QVariantList nw;

  QSqlDriver *drv = db->driver();

  drv->beginTransaction();
  for (int i = 0; i < wi.count(); i++)
    {
      query.prepare("INSERT INTO crossword.private_data (_template, _numword, "
                    "_row, _column, _lenght, _crosscount, _orientation) "
                    "VALUES (?, ?, ?, ?, ?, ?, ?);");

      query.addBindValue(QVariant(templateId));
      query.addBindValue(QVariant(wi[i]->numWord));
      query.addBindValue(QVariant(wi[i]->row));
      query.addBindValue(QVariant(wi[i]->col));
      query.addBindValue(QVariant(wi[i]->length));
      query.addBindValue(QVariant(wi[i]->crossCount));
      query.addBindValue(QVariant(wi[i]->orient));
      query.exec();

      le = query.lastError();
      if (le.type() == QSqlError::NoError)
        {
          lastId = query.lastInsertId().toInt();

          query2.prepare("INSERT INTO crossword.crosses (_template, _pd_id, _cpos, "
                         "_ctype, _numword) VALUES (?, ?, ?, ?, ?);");

          cc = wi[i]->crossCount;
          for (int j = 0; j < cc; j++)
            {
              cross = wi[i]->cil[j];

              tmp << templateId;
              pdid << lastId;
              cpos << cross->crossPos;
              ctype << cross->crossType;
              nw << cross->numWord2;
            }

          query2.addBindValue(tmp);
          query2.addBindValue(pdid);
          query2.addBindValue(cpos);
          query2.addBindValue(ctype);
          query2.addBindValue(nw);

          query2.execBatch(QSqlQuery::ValuesAsRows);

          tmp.clear();
          pdid.clear();
          cpos.clear();
          ctype.clear();
          nw.clear();
        }
      else
        qDebug() << "3. savePrivateData: " << le.text();
    }
  drv->commitTransaction();
}
开发者ID:skydion,项目名称:qtcrossword,代码行数:89,代码来源:tabletemplatewidget.cpp

示例2: saveToDB

/*
 * Зберігаємо шаблон кросворду після редагування решітки
 */
void tableTemplateWidget::saveToDB()
{
  int previewSizeCell = 20, val;
  int W = numCol*previewSizeCell;
  int H = numRow*previewSizeCell;

  QPainter *pngPainter = new QPainter();
  QImage *image = new QImage(QSize(W, H), QImage::Format_ARGB32_Premultiplied);

  float t, l;
  QRectF src(0, 0, W, H);
  QRectF r;

  QTableWidgetItem *cell;
  QSqlQuery query;

  query.prepare("DELETE FROM crossword.grids WHERE _template = ?;");
  query.addBindValue(QVariant(templateId));
  query.exec();

  QSqlError le = query.lastError();
  if (le.type() != QSqlError::NoError)
    qDebug() << "saveToDB: " << le.text();

  query.prepare("INSERT INTO crossword.grids (_template, _row, _column, _value) "
                "VALUES (?, ?, ?, ?)");

  pb = new QProgressBar(this);
  pb->setRange(0, numRow*numCol);
  sb->addWidget(pb);

  QVariantList tmp, row, col, value;
  QString text;

  pngPainter->begin(image);
    int i, j, nw;
    for (i = 0; i < numRow; i++)
      {
        t = src.top() + i * previewSizeCell;
        for (j = 0; j < numCol; j++)
          {
            l = src.left() + j * previewSizeCell;

            r.setTop(t);
            r.setLeft(l);

            r.setRight(src.left() + l + previewSizeCell);
            r.setBottom(src.top() + t + previewSizeCell);

            cell = this->item(i, j);
            val = cell->data(Qt::UserRole).toInt();

            if (val)
              pngPainter->fillRect(r, fullCell);
            else
              pngPainter->fillRect(r, emptyCell);

            // прямокутник для ячейки
            pngPainter->drawRect(r);

            // виводимо номер слова
            nw = findWordByRC(i, j) + 1;
            if ( nw >= 1 )
              {
                text = QVariant(nw).toString();
                pngPainter->drawText(r, Qt::AlignLeft | Qt::AlignTop, text);
              }

            tmp << templateId;
            row << i;
            col << j;
            value << val;
          }

        pb->setValue(i*numRow + j*numCol);
      }
  pngPainter->end();

  query.addBindValue(tmp);
  query.addBindValue(row);
  query.addBindValue(col);
  query.addBindValue(value);

  QSqlDriver *drv = db->driver();
  drv->beginTransaction();
    query.execBatch(QSqlQuery::ValuesAsRows);
  drv->commitTransaction();

  le = query.lastError();
  if (le.type() != QSqlError::NoError)
    qDebug() << "saveToDB: " << le.text();

  QByteArray ba;
  QBuffer blob(&ba);
  blob.open(QIODevice::ReadWrite | QIODevice::Unbuffered);
    image->save(&blob, "PNG");
  blob.close();
//.........这里部分代码省略.........
开发者ID:skydion,项目名称:qtcrossword,代码行数:101,代码来源:tabletemplatewidget.cpp


注:本文中的QSqlDriver::commitTransaction方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。