如何在ax 2009中控制临时表上的重复行?

时间:2022-10-04 09:22:10

I am inserting records to a temp table in a while select query. I need to control that if i added the record before, is it possible?

我在while select查询中将记录插入临时表。如果我之前添加了记录,我需要控制它,是否可能?

3 个解决方案

#1


1  

Use setTmpData method on a second buffer of the same type

在相同类型的第二个缓冲区上使用setTmpData方法

Example:

例:

SomeTable someTable;
TmpTable  tmpTable;
TmpTable  tmpTableCheck;

// Use tmpTable as primary data set, and tmpTableCheck to check for duplicates
while select someTable
{
     tmpTable.initFromSomeTable(someTable);

     // Check if key is already used.
     tmpTableCheck.setTmpData(tmpTable);
     select firstOnly tmpTableCheck
         where tmpTableCheck.Key == tmpTable.Key;

     // Only insert record in tmpTable if the key has not been used before.
     if (! tmpTableCheck)
     {
          tmpTable.insert();
     }
 }

#2


2  

Provided you have a unique index, you can catch the problem:

如果您有唯一索引,则可以发现问题:

SysInfoLogLevel prevLevel = infolog.infologLevel()
try 
{
    infolog.setInfoLogLevel(SysInfoLogLevel::None);
    whatever.insert();
    infolog.setInfoLogLevel(prevLevel); 
}
catch (Exception::DuplicateKeyException)
{
    infolog.setInfoLogLevel(prevLevel); 
}

#3


1  

Just check for the record by before calling the insert process.

只需在调用插入过程之前检查记录。

//Build query above
while (qr.next())
{
    SourceTable = qr.get(tablenum(SourceTable));

    select DestTable
        where DestTable.Field1 == SourceTable.Field1; //Replace with criteria that determines if records are the same

    if (!DestTable)
    {
        DestTable.Field1 = SourceTable.Field1;
        DestTable.Field2 = SourceTable.Field2;
        DestTable.Field3 = SourceTable.Field3;
        DestTable.Insert();
    }

}

//Once processing is finished
if (element.prompt())
{
    while select DestTable            
    {
        element.send(DestTable);
    }
}
else
{
    return false;
}

Basically, try to select the record that would match what would be inserted. If no records are returned, the insert it. Otherwise it just goes to the next record.

基本上,尝试选择与插入的匹配的记录。如果没有返回记录,则插入它。否则它只会进入下一条记录。

#1


1  

Use setTmpData method on a second buffer of the same type

在相同类型的第二个缓冲区上使用setTmpData方法

Example:

例:

SomeTable someTable;
TmpTable  tmpTable;
TmpTable  tmpTableCheck;

// Use tmpTable as primary data set, and tmpTableCheck to check for duplicates
while select someTable
{
     tmpTable.initFromSomeTable(someTable);

     // Check if key is already used.
     tmpTableCheck.setTmpData(tmpTable);
     select firstOnly tmpTableCheck
         where tmpTableCheck.Key == tmpTable.Key;

     // Only insert record in tmpTable if the key has not been used before.
     if (! tmpTableCheck)
     {
          tmpTable.insert();
     }
 }

#2


2  

Provided you have a unique index, you can catch the problem:

如果您有唯一索引,则可以发现问题:

SysInfoLogLevel prevLevel = infolog.infologLevel()
try 
{
    infolog.setInfoLogLevel(SysInfoLogLevel::None);
    whatever.insert();
    infolog.setInfoLogLevel(prevLevel); 
}
catch (Exception::DuplicateKeyException)
{
    infolog.setInfoLogLevel(prevLevel); 
}

#3


1  

Just check for the record by before calling the insert process.

只需在调用插入过程之前检查记录。

//Build query above
while (qr.next())
{
    SourceTable = qr.get(tablenum(SourceTable));

    select DestTable
        where DestTable.Field1 == SourceTable.Field1; //Replace with criteria that determines if records are the same

    if (!DestTable)
    {
        DestTable.Field1 = SourceTable.Field1;
        DestTable.Field2 = SourceTable.Field2;
        DestTable.Field3 = SourceTable.Field3;
        DestTable.Insert();
    }

}

//Once processing is finished
if (element.prompt())
{
    while select DestTable            
    {
        element.send(DestTable);
    }
}
else
{
    return false;
}

Basically, try to select the record that would match what would be inserted. If no records are returned, the insert it. Otherwise it just goes to the next record.

基本上,尝试选择与插入的匹配的记录。如果没有返回记录,则插入它。否则它只会进入下一条记录。