Subject Re: {Spam?} [firebird-support] Replacing substrings...
Author munster77054
Paul:

Thanks!

Now, there is more of a problem. I hope I can explain it sufficiently here.

I worked on this almost all evening, and for about an hour this morning, and I can't get it to work. Hope you or someone can help and kick me in the head on this!

I have these two tables, and the data shown in it (discussion continues below):

===============================
CREATE TABLE CHANGEPARAMS
(
FIELD01 VARCHAR(30) NOT NULL,
FIELD02 VARCHAR(30),
PRIMARY KEY (FIELD01)
);

CREATE TABLE CHANGEME
(
FIELD01 VARCHAR(30) NOT NULL,
PRIMARY KEY (FIELD01)
);

INSERT INTO CHANGEPARAMS (FIELD01, FIELD02) VALUES ('Fpdd', '@@');

INSERT INTO CHANGEME (FIELD01) VALUES ('AjlMxjyqbeTI');
INSERT INTO CHANGEME (FIELD01) VALUES ('hMhFWDTxqSZr');
INSERT INTO CHANGEME (FIELD01) VALUES ('cJdDpOUAIDNw');
INSERT INTO CHANGEME (FIELD01) VALUES ('HchGWSxOWepN');
INSERT INTO CHANGEME (FIELD01) VALUES ('bGLSQGqLFpdd');
INSERT INTO CHANGEME (FIELD01) VALUES ('hVftrnMCcPLh');
INSERT INTO CHANGEME (FIELD01) VALUES ('BhXbtmAdeJNk');
INSERT INTO CHANGEME (FIELD01) VALUES ('BljxEwpIGgEA');
INSERT INTO CHANGEME (FIELD01) VALUES ('MLwDxkUDNqeA');
INSERT INTO CHANGEME (FIELD01) VALUES ('MlkoBuTsfwEB');
INSERT INTO CHANGEME (FIELD01) VALUES ('KIaFpddQAsTW');
INSERT INTO CHANGEME (FIELD01) VALUES ('KBNNdlRXvXXv');
INSERT INTO CHANGEME (FIELD01) VALUES ('iVmKJkHLWLxw');
INSERT INTO CHANGEME (FIELD01) VALUES ('FpdddZNYpFEW');
INSERT INTO CHANGEME (FIELD01) VALUES ('XfgJQRoyNVwp');
INSERT INTO CHANGEME (FIELD01) VALUES ('iJysbwSBnBfy');
INSERT INTO CHANGEME (FIELD01) VALUES ('nJobAfmJWnac');
INSERT INTO CHANGEME (FIELD01) VALUES ('MndCJUsAvglg');
INSERT INTO CHANGEME (FIELD01) VALUES ('nPlOyjyYGUFA');
INSERT INTO CHANGEME (FIELD01) VALUES ('vjxADNrovKwS');
INSERT INTO CHANGEME (FIELD01) VALUES ('OBbTkjfrRMtA');
INSERT INTO CHANGEME (FIELD01) VALUES ('sjwfTdWwcWmx');
INSERT INTO CHANGEME (FIELD01) VALUES ('rUNZPCsRaqRY');
INSERT INTO CHANGEME (FIELD01) VALUES ('pbSjvshyRAIU');
INSERT INTO CHANGEME (FIELD01) VALUES ('QRdJrtFDRrep');
INSERT INTO CHANGEME (FIELD01) VALUES ('XtnfdZsQVeiP');
INSERT INTO CHANGEME (FIELD01) VALUES ('XCbYDwMAiBIr');
INSERT INTO CHANGEME (FIELD01) VALUES ('uZhRIyDKMUgA');
INSERT INTO CHANGEME (FIELD01) VALUES ('xjOHJAcjAYNY');
INSERT INTO CHANGEME (FIELD01) VALUES ('qWXNbcLKbTJU');
===============================

What I'm trying to do is to replace all occurrences of the data in changeme (field01), with the value in changeparams field02 if the values in changeparams (field01) is contained in changeme (field01). So the execution would come out to be:

bGLSQGqLFpdd would become bGLSQGqL@@ (record 5)
KIaFpddQAsTW would become KIa@@QAsTW (record 11)
FpdddZNYpFEW would become @@dZNYpFEW (record 14)
MLwDxkUDNqeA would become $$xkUDNqeA (record 9)

I'm working on this to integrate it into a program that I wrote to update fields with bad values.

I always do a "PROOF OF CONCEPT" within firebird first, then implement it into the program.

The program current works fine, using native C++ calls, but when it gets to this area, it slows down, and as I add things to the changeparams table, it gets slower and slower. I want to implement that part in SQL, because I know the execution will be dramatically faster.

Several years ago, I wrote a program, that did something completely different from this, that with native C++ calls, took 12+ hours to run. I rewrote it using SQL, and it finished in 30-45 seconds, and it was processing around 100K of records, if I recall correctly.

Here is the most recent attempt:

UPDATE CHANGEME
SET CHANGEME.FIELD01 = REPLACE (CHANGEME.FIELD01,CHANGEPARAMS.FIELD01, CHANGEPARAMS.FIELD02)
WHERE CHANGEME.FIELD01 CONTAINING CHANGEPARAMS.FIELD01

This is the error I've been getting:

Column does not belong to referenced table.
Dynamic SQL Error.
SQL error code = -206.
Column unknown.
CHANGEPARAMS.FIELD01.
At line 3, column 49.

At one point, I even tried just a join within a the visual query builder of EMS Interbase/Firebord Manager AND sql Maestro and got the exact same thing, although in all circumstances, the field was there.

Oh yea, I forgot to say, I'm using the most current version of FB 2.5.0.26074.

I hope you kind folks can help this brain locked person!

THANKS LOADS!

<rest deleted for brevity>