| 567 | } |
| 568 | |
| 569 | bool BatchOperateDialog::checkTable() { |
| 570 | |
| 571 | if(_tableName.isEmpty()) |
| 572 | return true; |
| 573 | |
| 574 | int count = 0; |
| 575 | QString sql; |
| 576 | DbMgr dbMgr; |
| 577 | QSqlDatabase *db = new QSqlDatabase(); |
| 578 | |
| 579 | if(_nowOperate == THREAD_BATCH_OIM_KEY_TASK || |
| 580 | _nowOperate == THREAD_BATCH_OEM_KEY_TASK || |
| 581 | _nowOperate == THREAD_BATCH_ODE_KEY_TASK) { |
| 582 | dbMgr.setCfg(ORACLE_DB, ORACLE_DRIVE); |
| 583 | sql = QString("select count(1) from user_tables where " |
| 584 | "table_name = '%1'").arg(_tableName); |
| 585 | if(!dbMgr.getDb(db)) { |
| 586 | QMessageBox::information(this, tr("错误"), dbMgr.error()); |
| 587 | return false; |
| 588 | } |
| 589 | |
| 590 | QSqlQuery sql_query(*db); |
| 591 | if(!sql_query.exec(sql)) { |
| 592 | QMessageBox::information(this, tr("错误"), sql_query.lastError().text()); |
| 593 | sql_query.clear(); |
| 594 | return false; |
| 595 | } |
| 596 | |
| 597 | if(sql_query.next()) { |
| 598 | count = sql_query.value(0).toInt(); |
| 599 | } else { |
| 600 | QMessageBox::information(this, tr("错误"), sql_query.lastError().text()); |
| 601 | return false; |
| 602 | } |
| 603 | sql_query.clear(); |
| 604 | |
| 605 | if(count == 0) { |
| 606 | sql = QString("CREATE TABLE %1 (ID NUMBER(16) PRIMARY KEY,KEY VARCHAR2(100), " |
| 607 | "KEY_TYPE VARCHAR2(8), FILED VARCHAR2(100), VALUE VARCHAR2(200), " |
| 608 | "TIME_OUT NUMBER(16), WEIGHT NUMBER(16), EXP_DATE DATE, DB_INDEX " |
| 609 | "NUMBER(9), STATE NUMBER(9))").arg(_tableName); |
| 610 | if(!sql_query.exec(sql)) { |
| 611 | QMessageBox::information(this, tr("错误"), sql_query.lastError().text()); |
| 612 | sql_query.clear(); |
| 613 | return false; |
| 614 | } |
| 615 | sql_query.clear(); |
| 616 | } |
| 617 | |
| 618 | sql = QString("SELECT MAX(ID) FROM %1").arg(_tableName); |
| 619 | if(!sql_query.exec(sql)) { |
| 620 | QMessageBox::information(this, tr("错误"), sql_query.lastError().text()); |
| 621 | sql_query.clear(); |
| 622 | return false; |
| 623 | } |
| 624 | |
| 625 | if(sql_query.next()) { |
| 626 | PubLib::setSequenceId(sql_query.value(0).toLongLong()); |