ASCII CHECK - change value in primary key

boompumpboompump Member Posts: 3
Hi,

I've some trouble in checking ASCII with 10 or 13 in database.
When I find out there are data with ASCII 13 or 10, i will detele it then replace back to original data.
it seems work in regular fields except primary key fields.
My thought was delete the field value before I insert new value into it.
I can't use RENAME, it will occur another modify problem.
Then here's the problem that I met, not sure if my code are correct or not, need your help.When the Fields are Key Column, I will DELETE it first then INSERT the new value to Field
but it shows me a massage like (I've searched the table 'Item') : The Item does not exist,
Identification fields and values: No.='A-I000001'

But If I didn't delete it first , it will show me : the Item already exists.

What should I do to change the primary key value?

Really need your help.
Windows.OPEN(Text000+
             Text001+
             Text002);
IF g_intTableNo >0 THEN
  g_recField.SETRANGE(TableNo,g_intTableNo);

IF g_recField.FIND('-') THEN
  IF g_recField.Enabled = TRUE THEN
  REPEAT
    CLEAR(g_rrfRecordRef);
    CLEAR(g_krfKeyRecordRef);
    g_rrfRecordRef.OPEN(g_recField.TableNo);
    g_krfKeyRecordRef.OPEN(g_recField.TableNo);
    Windows.UPDATE(1,g_recField.TableName);  //
    g_krfKeyRef := g_rrfRecordRef.KEYINDEX(1);
    g_intKeyCount := g_krfKeyRef.FIELDCOUNT;
    FOR i:= 1 TO g_intKeyCount DO BEGIN
      g_frfFieldIndex[i] := g_krfKeyRef.FIELDINDEX(i);
    END;
    IF g_rrfRecordRef.FIND('-') THEN BEGIN
      g_frfFieldRef := g_rrfRecordRef.FIELD(g_recField."No.");
      Windows.UPDATE(2,g_recField.FieldName);                     //
      IF (g_recField.Type = g_recField.Type::Code) OR
         (g_recField.Type = g_recField.Type::Text) THEN
        REPEAT
          CLEAR(l_txtNewValue);
          CLEAR(l_txtOldValue);
          CLEAR(l_txtKeyValue);
          CLEAR(l_booKeyColumn);
          l_txtOldValue := g_frfFieldRef.VALUE;
          Windows.UPDATE(3,l_txtOldValue); //
          FOR i:= 1 TO STRLEN(l_txtOldValue) DO BEGIN
            cSTR := l_txtOldValue[i];
            IF (cSTR <> 13) AND (cSTR <> 10) THEN
              l_txtNewValue += FORMAT(l_txtOldValue[i]);
          END;
          g_txtNewValue := l_txtNewValue;
          FOR i:= 1 TO g_intKeyCount DO BEGIN
            IF g_frfFieldRef.NAME = g_frfFieldIndex[i].NAME THEN BEGIN
              l_intKeyIndex := i;
              l_booKeyColumn := TRUE;
              g_frfFieldIndex[i].VALUE := l_txtNewValue

            END;
            IF l_booKeyColumn THEN BEGIN
              //f_booRenameKeyField(g_intKeyCount);
              f_inserKeyField(g_intKeyCount);
            END ELSE BEGIN
              g_frfFieldRef.VALUE := l_txtNewValue;
                //IF NOT g_rrfRecordRef.MODIFY THEN
               // ERROR('Modify failure Column: %1 Value: %2',g_frfFieldRef.NAME,l_txtNewValue);
            END;
           END;
        UNTIL g_rrfRecordRef.NEXT = 0;
      g_rrfRecordRef.CLOSE;
    END;
  UNTIL g_recField.NEXT = 0;

MESSAGE('Finished!');
Windows.CLOSE;
---------------------------------------------------
[Function:f_booRenameKeyField(p_intKeyCount : Integer)]

CASE p_intKeyCount OF
  1: 
   BEGIN
      g_rrfRecordRef.DELETE;
      g_frfFieldRef.VALUE := g_frfFieldIndex[1].VALUE;
      g_rrfRecordRef.INSERT;

   END;
END;

Comments

  • rdebathrdebath Member Posts: 383
    You might try this:

    http://www.mibuso.com/dlinfo.asp?FileID=1149

    It's "Remove TAB CR and LF from Text Fields" option will do what you want.

    If the item without the CRLF already exists in the database it'll fail to rename the item, but that's okay because all the postings attached to the item will be renamed. So you can delete it.
  • boompumpboompump Member Posts: 3
    rdebath wrote:
    You might try this:

    http://www.mibuso.com/dlinfo.asp?FileID=1149

    It's "Remove TAB CR and LF from Text Fields" option will do what you want.

    If the item without the CRLF already exists in the database it'll fail to rename the item, but that's okay because all the postings attached to the item will be renamed. So you can delete it.

    OOHHH~~thank you so very much.
    its really help me a lot.
    i'm will go research the code.
    really a big help
    Thank you.
Sign In or Register to comment.