【问题标题】:QT ODBC driver .mdb ms-access inserts not working above 1000 rows (windows)QT ODBC 驱动程序 .mdb ms-access 插入在 1000 行以上时不起作用(Windows)
【发布时间】:2018-02-23 01:06:46
【问题描述】:

我已经在 Windows 上多次测试了我的代码。

(我需要使用 ms-access 来升级旧应用)

尝试使用事务或不使用绑定值在查询中插入行,插入不会超过 1061 行。

我已经用这段代码测试过:

this->db_ = QSqlDatabase::addDatabase("QODBC");

QString archivo_elegido = QString(ruta_inicial_ + "cods.mdb");

cout << "archivo: " << archivo_elegido.toStdString() << endl;

this->db_.setDatabaseName(QString("DRIVER={Microsoft Access Driver (*.mdb)};FIL={MS Access};DBQ=%1;").arg(QDir::toNativeSeparators(archivo_elegido)));

if(!this->db_.open("",""))
{
cout << this->db_.lastError().text().toStdString() << endl;
}

int i = 0;
this->query = QSqlQuery(this->db_);

for(i=0; i< 20000;i++)
{
QString q;
q.append("INSERT INTO claves ");
q.append("(claveacceso) " );
q.append( "VALUES (:claveacceso) ");
this->query.prepare(q);
this->query.bindValue(":claveacceso", QString::number(i));
this->query.exec(); // No errors here.
cout << endl << " " << i;
}

this->db_.close();

【问题讨论】:

  • 您需要从 query.exec() 评估错误。
  • query.exec(),在“this->db_.lastError()”上不返回任何错误。

标签: qt ms-access odbc


【解决方案1】:
QString q;
q.append("INSERT INTO claves ");
q.append("(claveacceso) " );
q.append( "VALUES (?) ");
this->query.prepare(q);
QVariantList varLst;
for(i=0; i< 20000;i++)
{
  varLst << QVariant::fromValue(i);
}
this->query.addBindValue(varLst);
this->query.execBatch();

【讨论】:

  • 有趣。但结果是一样的,只有 1000 行写入文件。
【解决方案2】:

我有一个错误。 我正在使用基于http://mdbtools.sourceforge.net/ 的 GNOME MDB Viewer 0.7.1 进行测试。

mdb 查看器只显示前 1000 行,即使在我应用查询时也是如此。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-08
    • 2011-10-30
    相关资源
    最近更新 更多