简体   繁体   English

C ++ DB2在QTEMP中清除非日记表

[英]C++ DB2 Clearing a non Journal table in QTEMP

I am developing a C++ program to fetch and filter through the data, and store it into a temporal table (P6SUBFCH) in the QTEMP library on DB2 AS400. 我正在开发一个C ++程序来获取和过滤数据,并将其存储到DB2 AS400上QTEMP库中的临时表(P6SUBFCH)中。

Reason for doing this, we using PLEX that has a defined method of fetching data in blocks of 64 records at a time, so the function called a SQLBlockFetch, fetches all the records into a temporal table, and only 64 records are returned at a time from this temporary table, and processed as such. 这样做的原因是,我们使用PLEX,它具有一种定义的方法,一次可在64个记录的块中提取数据,因此称为SQLBlockFetch的函数将所有记录提取到一个临时表中,一次仅返回64个记录从此临时表中进行处理。

I am developing my own SQLBockfetch, and the C++ part of it, is using embedded SQL, to do all SQL queries. 我正在开发自己的SQLBockfetch,其中的C ++部分使用嵌入式SQL来执行所有SQL查询。 Which is fetching all the data creating the table (P6SUBFCH) in the QTEMP library. 这将获取所有在QTEMP库中创建表(P6SUBFCH)的数据。

The QTEMP library is active for a session, as soon as a session ends all tables are drops in that library. QTEMP库在会话中处于活动状态,会话结束后,所有表都将立即丢弃到该库中。

Also to note is that all tables in QTEMP are not journaled, and from what I have researched on google is that it can't be. 还需要注意的是,QTEMP中的所有表均未记录日志,而根据我在google上的研究,它不能被记录。

The problem 问题
My C++ program works great the first time it is called in a session, but the second time, it just appends the data to the previous data in the table QTEMP/P6SUBFCH. 我的C ++程序在第一次在会话中被调用时效果很好,但是第二次,它只是将数据追加到表QTEMP / P6SUBFCH中的先前数据中。 which is a problem, I tried clearing the data first (SQL DELETE statement) but I get this SQL error on the AS400 job logs. 这是一个问题,我尝试先清除数据(SQL DELETE语句),但在AS400作业日志上收到此SQL错误。

Member P6SUBFCH not journaled to journal *N.
P6SUBFCH in QTEMP not valid for operation.  

SQL ERROR:-7008 SQL错误:-7008

I have read the following ql7008-error-workaround 我已阅读以下ql7008-错误解决方法

To disable transaction isolation 禁用事务隔离

Not sure if this is maybe my problem? 不知道这是否是我的问题? I am still new to embedded SQL, not sure how I'll go about doing this. 我还是嵌入式SQL的新手,不确定如何进行此操作。

Here is my code: 这是我的代码:

void LinkRepository::SaveResultsToTable(InputParameters inputParameters)
{
EXEC SQL INCLUDE SQLCA;
EXEC SQL BEGIN DECLARE SECTION;
char Query2[2000] = { "" };
char Query3[2000] = { "" };

EXEC SQL END DECLARE SECTION;

strcpy(Query2, "CREATE TABLE QTEMP/P6SUBFCH");
strcat(Query2, " (PAOPIID CHAR(21) NOT NULL,");
strcat(Query2, " POPITPE CHAR(10),");
strcat(Query2, " POPISTPE CHAR(10),");
strcat(Query2, " POPIKNID CHAR(20),");
strcat(Query2, " PINSTAT CHAR(10),");
strcat(Query2, " PLEAFIND CHAR(1),");
strcat(Query2, " CLOPIID CHAR(21),");
strcat(Query2, " COPITPE CHAR(10),");
strcat(Query2, " COPISTPE CHAR(10),");
strcat(Query2, " COPIKNID CHAR(20),");
strcat(Query2, " CINSTAT CHAR(10),");
strcat(Query2, " CLEAFIND CHAR(1),");
strcat(Query2, " LINKIN CHAR(10))");

EXEC SQL EXECUTE IMMEDIATE :Query2;

// Error handling
if (sqlca.sqlcode == -601)
{
     strcpy(Query2, "DELETE FROM QTEMP/P6SUBFCH");

     EXEC SQL EXECUTE IMMEDIATE :Query2;

}

EXEC SQL COMMIT;

// Datalinks is a vector that has all the filter data to insert into the QTEMP/P6SUBFCH table
for(vector<Datalink*>::iterator dl = Datalinks.begin(); dl != Datalinks.end(); ++dl)
{
     EXEC SQL SET TRANSACTION ISOLATION LEVEL NO COMMIT;

     strcpy(Query3, "INSERT INTO QTEMP/P6SUBFCH (PAOPIID,POPITPE,");
     strcat(Query3, "POPISTPE,POPIKNID,PINSTAT,PLEAFIND,");
     strcat(Query3, "CLOPIID,COPITPE,COPISTPE,COPIKNID,CINSTAT,");
     strcat(Query3, "CLEAFIND,LINKIN)");
     strcat(Query3, "VALUES('");
     strcat(Query3, (*dl)->ParentOperationsItemId);
     strcat(Query3, "','");
     strcat(Query3, (*dl)->ParentOperationsItemType);
     strcat(Query3, "','");
     strcat(Query3, (*dl)->ParentOperationsItemSubType);
     strcat(Query3, "','");
     strcat(Query3, (*dl)->ParentKnownbyId);
     strcat(Query3, "','");
     strcat(Query3, (*dl)->ParentInternalStatus);
     strcat(Query3, "','");
     append_char(Query3, (*dl)->ParentLeafIndicator);
     strcat(Query3, "','");
     strcat(Query3, (*dl)->ChildOperationsItemId);
     strcat(Query3, "','");
     strcat(Query3, (*dl)->ChildOperationsItemType);
     strcat(Query3, "','");
     strcat(Query3, (*dl)->ChildOperationsItemSubType);
     strcat(Query3, "','");
     strcat(Query3, (*dl)->ChildKnownbyId);
     strcat(Query3, "','");
     strcat(Query3, (*dl)->ChildInternalStatus);
     strcat(Query3, "','");
     append_char(Query3, (*dl)->ChildLeafIndicator);
     strcat(Query3, "','");
     strcat(Query3, (*dl)->LinkInternalStatus);
     strcat(Query3, "')");

     EXEC SQL EXECUTE IMMEDIATE :Query3;

     EXEC SQL COMMIT;
}
};

Ok I worked it out, I just added the EXEC SQL SET TRANSACTION ISOLATION LEVEL NO COMMIT; 好的,我已经解决了,我刚刚添加了EXEC SQL SET TRANSACTION ISOLATION LEVEL NO COMMIT; before I called the strcpy(Query2, "DELETE FROM QTEMP/P6SUBFCH"); 在我调用strcpy(Query2, "DELETE FROM QTEMP/P6SUBFCH"); query. 查询。

Here is my full code: 这是我的完整代码:

void LinkRepository::SaveResultsToTable(InputParameters inputParameters)
{
    EXEC SQL INCLUDE SQLCA;
    EXEC SQL BEGIN DECLARE SECTION;
    char Query2[2000] = { "" };
    char Query3[2000] = { "" };

    EXEC SQL END DECLARE SECTION;

    strcpy(Query2, "CREATE TABLE QTEMP/P6SUBFCH");
    strcat(Query2, " (PAOPIID CHAR(21) NOT NULL,");
    strcat(Query2, " POPITPE CHAR(10),");
    strcat(Query2, " POPISTPE CHAR(10),");
    strcat(Query2, " POPIKNID CHAR(20),");
    strcat(Query2, " PINSTAT CHAR(10),");
    strcat(Query2, " PLEAFIND CHAR(1),");
    strcat(Query2, " CLOPIID CHAR(21),");
    strcat(Query2, " COPITPE CHAR(10),");
    strcat(Query2, " COPISTPE CHAR(10),");
    strcat(Query2, " COPIKNID CHAR(20),");
    strcat(Query2, " CINSTAT CHAR(10),");
    strcat(Query2, " CLEAFIND CHAR(1),");
    strcat(Query2, " LINKIN CHAR(10))");

    EXEC SQL EXECUTE IMMEDIATE :Query2;

    // Error handling
    if (sqlca.sqlcode == -601)
    {
         EXEC SQL SET TRANSACTION ISOLATION LEVEL NO COMMIT;

         strcpy(Query2, "DELETE FROM QTEMP/P6SUBFCH");

         EXEC SQL EXECUTE IMMEDIATE :Query2;

    }

    EXEC SQL COMMIT;

    // Datalinks is a vector that has all the filter data to insert into the QTEMP/P6SUBFCH table
    for(vector<Datalink*>::iterator dl = Datalinks.begin(); dl != Datalinks.end(); ++dl)
    {
         EXEC SQL SET TRANSACTION ISOLATION LEVEL NO COMMIT;

         strcpy(Query3, "INSERT INTO QTEMP/P6SUBFCH (PAOPIID,POPITPE,");
         strcat(Query3, "POPISTPE,POPIKNID,PINSTAT,PLEAFIND,");
         strcat(Query3, "CLOPIID,COPITPE,COPISTPE,COPIKNID,CINSTAT,");
         strcat(Query3, "CLEAFIND,LINKIN)");
         strcat(Query3, "VALUES('");
         strcat(Query3, (*dl)->ParentOperationsItemId);
         strcat(Query3, "','");
         strcat(Query3, (*dl)->ParentOperationsItemType);
         strcat(Query3, "','");
         strcat(Query3, (*dl)->ParentOperationsItemSubType);
         strcat(Query3, "','");
         strcat(Query3, (*dl)->ParentKnownbyId);
         strcat(Query3, "','");
         strcat(Query3, (*dl)->ParentInternalStatus);
         strcat(Query3, "','");
         append_char(Query3, (*dl)->ParentLeafIndicator);
         strcat(Query3, "','");
         strcat(Query3, (*dl)->ChildOperationsItemId);
         strcat(Query3, "','");
         strcat(Query3, (*dl)->ChildOperationsItemType);
         strcat(Query3, "','");
         strcat(Query3, (*dl)->ChildOperationsItemSubType);
         strcat(Query3, "','");
         strcat(Query3, (*dl)->ChildKnownbyId);
         strcat(Query3, "','");
         strcat(Query3, (*dl)->ChildInternalStatus);
         strcat(Query3, "','");
         append_char(Query3, (*dl)->ChildLeafIndicator);
         strcat(Query3, "','");
         strcat(Query3, (*dl)->LinkInternalStatus);
         strcat(Query3, "')");

         EXEC SQL EXECUTE IMMEDIATE :Query3;

         EXEC SQL COMMIT;
    }
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM