Solved

_ in fieldname change to - underscore. How to solve?


Badge

Dear all, I having problems with writing an - character in a fieldname. If i chance it to - then FME will automaticaly change it to _ (underscore) do have have a idea?

I use the writer Spatialite. FME 2017.1. If i manualy change it to - then FME changes it to _....

icon

Best answer by hollyatsafe 29 August 2018, 19:50

View original

11 replies

Userlevel 4
Badge +30

Hi @tbaving

Try to use the transformer StringReplacer.

Thanks,

Danilo

Userlevel 4
Badge +30

Hi @tbaving

Try to use the transformer StringReplacer.

Thanks,

Danilo

 

Please, see it

 

Badge +2

Hi @tbaving,

If you want to change multiple attribute names you can use the BulkAttributeRenamer. Set the Action to String Replace, Text to Find to "-", and String (to replace) to "_".

I've attached an example workspace for you to test out for yourself.

-Chris

rename-attribute-name.fmwt

Badge

Dear all, with the inspecotor it works.... But if i add the spatialite writer it writes again an underscore instead of - . What im doing wrong? Many thanks guys.

Badge

Hi @tbaving,

If you want to change multiple attribute names you can use the BulkAttributeRenamer. Set the Action to String Replace, Text to Find to "-", and String (to replace) to "_".

I've attached an example workspace for you to test out for yourself.

-Chris

rename-attribute-name.fmwt

@ChrisAtSafe

Badge

Sorry i changed it. I mean _ to -.. change the topic tiltle.....

Badge +2

Hi @tbaving,

 

The answer provided by @ChrisAtSafe is the best way to do this. Since the correct formatting is showing in the Data Inspector it may be that spatialite doesn't except the hyphen character so FME automatically changes it to one it will.

This note: "SQL names cannot contain forbidden characters (such as spaces, brackets, colons, hyphens and so on" found here: https://www.gaia-gis.it/spatialite-3.0.0-BETA/spatialite-cookbook/html/basic-sql.html supports my suggestion.

There are some other articles online that suggest you can include forbidden characters in an SQLite field name if they are escaped in quotes or brackets, but sites contradict themselves on how this should be written:

https://stackoverflow.com/questions/23770480/sqlite-table-and-column-name-requirements?rq=1http://sqlite.1065341.n5.nabble.com/special-characters-as-column-names-td36677.html

Please consider voting for this idea to support special characters in writers and include a comment with details on the specific writer and your use case.

Badge +2

Dear all, with the inspecotor it works.... But if i add the spatialite writer it writes again an underscore instead of - . What im doing wrong? Many thanks guys.

Hi @tbaving,

 

It may be that the spatialite doesn't except the - character so FME automatically changes it to one it will.

 

This note: "SQL names cannot contain forbidden characters (such as spaces, brackets, colons, hyphens and so on" found here: https://www.gaia-gis.it/spatialite-3.0.0-BETA/spatialite-cookbook/html/basic-sql.html supports my suggestion.

 

Badge

Hi @tbaving,

 

The answer provided by @ChrisAtSafe is the best way to do this. Since the correct formatting is showing in the Data Inspector it may be that spatialite doesn't except the hyphen character so FME automatically changes it to one it will.

This note: "SQL names cannot contain forbidden characters (such as spaces, brackets, colons, hyphens and so on" found here: https://www.gaia-gis.it/spatialite-3.0.0-BETA/spatialite-cookbook/html/basic-sql.html supports my suggestion.

There are some other articles online that suggest you can include forbidden characters in an SQLite field name if they are escaped in quotes or brackets, but sites contradict themselves on how this should be written:

https://stackoverflow.com/questions/23770480/sqlite-table-and-column-name-requirements?rq=1http://sqlite.1065341.n5.nabble.com/special-characters-as-column-names-td36677.html

Please consider voting for this idea to support special characters in writers and include a comment with details on the specific writer and your use case.

 

And what about geopackage? Normally in qgis it accepts dashes. But in FME it automaticaly changes back to _ :(
Userlevel 4

Here's a workaround for the Geopackage format that probably isn't condoned by Safe at all ;-)

Open the file <FME Home>\metafile\geopackage.fmf in a text editor.

Modify lines 281 and 282 (or thereabouts, depending on your FME version) to remove the "-" character, the lines should read like this, notice the lack of the "-" character:

MACRO _FeatureTypeInvalidCharacters \\\"{}()',@&`~!#$%^*+=|[]:;<>?./
MACRO _AttributeInvalidCharacters \\\"{}()',@&`~!#$%^*+=|[]:;<>?./

Restart FME. You should now be able to create both feature types and attributes containing dashes:

0684Q00000ArKjqQAF.png

Tested with FME 2018.1 and QGIS 2.18.10, but no guarantees given whatsoever...

Userlevel 4

Hi @tbaving,

 

The answer provided by @ChrisAtSafe is the best way to do this. Since the correct formatting is showing in the Data Inspector it may be that spatialite doesn't except the hyphen character so FME automatically changes it to one it will.

This note: "SQL names cannot contain forbidden characters (such as spaces, brackets, colons, hyphens and so on" found here: https://www.gaia-gis.it/spatialite-3.0.0-BETA/spatialite-cookbook/html/basic-sql.html supports my suggestion.

There are some other articles online that suggest you can include forbidden characters in an SQLite field name if they are escaped in quotes or brackets, but sites contradict themselves on how this should be written:

https://stackoverflow.com/questions/23770480/sqlite-table-and-column-name-requirements?rq=1http://sqlite.1065341.n5.nabble.com/special-characters-as-column-names-td36677.html

Please consider voting for this idea to support special characters in writers and include a comment with details on the specific writer and your use case.

Actually, dashes seem to work just fine in GeoPackage, see my workaround below.

Reply