Skip to main content
Hello all,

 

 

I'm trying to update an Access table of mine using generated GUIDs, lets say I have the following:

 

Table_one

 

PARENT_GUID,FIELD_GUID

 

ABC123-EFT1,TEST23

 

ABC123-EFT1,TEST24

 

ABC123-EFT2,TEST23

 

ABC123-EFT2,TEST25

 

 

Also:

 

Table_two

 

PARENT_GUID,MEMO_FILLED_WITH_GUIDS

 

ABC123-EFT1,#IF##AND##CONDITION#{TEST23}ISNULL#ENDCONDITION##THEN##DO#{TEST24}ISMANDATORY

 

ABC123-EFT2,#IF##AND##CONDITION#{TEST23}ISNULL#ENDCONDITION##THEN##DO#{TEST25}ISMANDATORY

 

 

Now, due to some reasons, as you can see the FIELD_GUID is non-unique. I want to make it unique, and replace the FIELD_GUIDs with freshly replaced ones. However, seeing Table_two.MEMO_FILLED_WITH_GUIDS is a memo field filled with guids, I'd thought of using the replace function, within a SQLExecutor, like this:

 

 

UPDATE Table_two SET MEMO_FILLED_WITH_GUIDS= replace(MEMO_FILLED_WITH_GUIDS, @Value(FIELD_GUID, @Value(NEW_GUID_GENERATED)) WHERE PARENT_GUID = @Value(PARENT_GUID)

 

 

Where NEW_GUID_GENERATED is a GUID generated using FME.

 

 

However, this results in the following:

 

ERROR |MS Access Reader: Query failed. (-2147217900) Undefined function 'replace' in expression.'

 

 

Is there a way I can still use replace? Or is there a FME transformer which I can use to replace a value in a string based on another column, and use the PARENT_GUID in a where kinda clause?

 

 

Thanks in advance!
Hi,

 

 

I'm not sure why the replace function cannot be used in the SQLExecutor, but this way could be a workaround.

 

1) Use an SQLExecutor to merge MEMO_FILLED_WITH_GUIDS to the initiator features.

 

SQL Statement:

 

-----

 

SELECT MEMO_FILLED_WITH_GUIDS

 

FROM Table_two WHERE PARENT_GUID = '@Value(PARENT_GUID)'

 

-----

 

Attributes to Expose: MEMO_FILLED_WITH_GUIDS

 

Combine Attributes: Keep Initiator (or Result) Attributes if Conflict

 

Note: Maybe the Joiner can be also used instead of the SQLExecutor.

 

 

2) Send Result features into a StringReplacer transformer to replace FIELD_GUID with NEW_GUID_GENERATED.

 

Attributes: MEMO_FILLED_WITH_GUIDS

 

Text to Match: FIELD_GUID (Attribute Value)

 

Replacement Text: NEW_GUID_GENERATED (Attribute Value)

 

 

3) Send Output features into 2nd SQLExecutor

 

SQL Statement:

 

-----

 

UPDATE Table_two

 

SET MEMO_FILLED_WITH_GUIDS = '@Value(MEMO_FILLED_WITH_GUIDS)'

 

WHERE PARENT_GUID = '@Value(PARENT_GUID)'

 

-----

 

 

Hope this helps,

 

Takashi
Hey Takashi,

 

 

That would nearly work! The thing is, MEMO_FILLED_WITH _GUIDS could theoretically contain an infinite amount of unique GUIDs (Well, up to max memo field length / GUID length, but that doesn't matter).

 

 

For the example above, I'd have to run the Workbench twice, seeing it once would replace the value:

 

#IF##AND##CONDITION#{TEST23}ISNULL#ENDCONDITION##THEN##DO#{TEST25}ISMANDATORY

 

to:

 

#IF##AND##CONDITION#{N3W-TEST23}ISNULL#ENDCONDITION##THEN##DO#{TEST25}ISMANDATORY

 

but in the same run:

 

#IF##AND##CONDITION#{TEST23}ISNULL#ENDCONDITION##THEN##DO#{N3W-TEST25}ISMANDATORY

 

 

And on second run:

 

#IF##AND##CONDITION#{TEST23}ISNULL#ENDCONDITION##THEN##DO#{N3W-TEST25}ISMANDATORY

 

 

to:

 

#IF##AND##CONDITION#{N3W-TEST23}ISNULL#ENDCONDITION##THEN##DO#{N3W-TEST25}ISMANDATORY

 

 

So the best way would be a replace function, to just replace the string that needs replacing, instead of the whole attributevalue... But how...

 


Hi,

 

 

rather than using the FME Replace function, you should probably be using the MS Access Replace() function in stead.

 

 

See the documentation here (http://www.techonthenet.com/access/functions/string/replace.php).

 

 

David
Hey David,

 

 

I'm afraid that is the Replace() function from Acces ;) 

 

 

However, Access doesn't support batch query running, and I found out Replace() function isn't usable anywhere outside of Access... And I don't want to run 1200 queries (Rows in Table_one) by hand.

 

 

I've used a workaround for now, exporting Table_two to SQLite, then using Replace(), then importing it back to Access.

 

 

To be honest, I'll be happy when I finally won't have to use Access anymore.

 

 

For me this is solved for now, if anyone knows a better solution, that would be awesome.

 

 

Thanks to you both!
It might be that your Access database is too old to support the Replace function in the API calls.

 

 

There is a nice workaround here (http://www.access-programmers.co.uk/forums/showthread.php?t=142513). Might be worth a try.

 

 

David

Reply