Passing text - should be easy

2552
9
01-12-2011 01:01 PM
JMcNeil
Occasional Contributor III
I'm hoping this is easy for someone else because it is giving me some trouble and I'm having a freeze and just can't seem to get it.

Really simple background I have a gp task that is taking a string from the user in the form of a TextBox.

 parameters.Add(new GPString("Expression", (AttQueryTextBox.Text)));


Here's my problem when the users enters a string like

"APN" = '999-999-999'
Fiddler is reporting the expression with Escape Sequences mixed with unicode value of Characters:p I think:confused:

So Fiddle is reporting something like:
\"APN\" = \u0027999-999-999\u0027

For the double quotation mark it is passing \" which maybe is the Escape Sequence

and for the single quotation mark it is passing \u0027 which might be the Unicode Value but I thought that was 0x0027 but that doesn't really matter.

I'm wondering how should I handle this??? I need the out put string to have the format of
"APN" = '999-999-999'
and if I give my endusers an example with direction they should be able to contruct the right statement.  I just don't know what that is:(

Another option I thought is I could clean the data before sending it to the GP but that could get messy because they could send use the 'OR' operator and string together muiltiple statements.

Thanks
J
0 Kudos
9 Replies
JenniferNery
Esri Regular Contributor
Thank you for reporting this. We'll try to get it fixed in future release.

As of now, I don't know if there is a workaround but I will let you know when I do.
0 Kudos
JMcNeil
Occasional Contributor III
Thanks Jennifer, Please let me know when/if you find a work-around.

At first I thought the problem was the textbox sending the text but I just tested that and now I know that is happen when GP parameter is sent so I guess I can't clean the statement somehow.

I'm sure there is something  I could do in the Model?  I'm using the select layer by attribute tool and I have a parameter (input type) that is my sql statement.  (this is population the "Expression (option)" Value in the Select Layer By Attribute tool.

My thought is maybe I could make a couple more steps in my model.  What if I drop the Expression Paramter and just created a new parameter that is populated by a text box in server and passing a straight text like 999-999-999 and maybe it would be muilple like 999-999-999 or 999-999-998.  This text would then feed to a paramater string in my model.  Then I would clean the string with maybe some python script in my model.  This script would add the necessary "APN" = '999-999-999' syntax and then that would be set as a input expression for the Select Layer By Attribute tool.

WOW that sounds like some work; just typing it was hard:eek:

I guess the trick would be looking for the OR operator and figuring out how many APNs were entered and then cleaning them and I'm not sure if the  "Expression (option)" Value in the Select Layer By Attribute tool can come from a script; I guess that is a question for the Model Builder team.

Umm Any thoughts?


Thanks
J.
0 Kudos
JenniferNery
Esri Regular Contributor
How about if you use GPMultiValue parameter that contains GPString?

Currently, our GPString parameter cannot take special characters. This is a bug that we have yet to fix in our API.

If you can avoid using (",'), you can use GPString. If you need to use these, you can use GPMultiValue and hopefully that will be a workaround.
0 Kudos
JMcNeil
Occasional Contributor III
Thanks Jennifer!  Sorry to hammer you but I just want to make sure I'm clear on this. 

Change this in my model right?


Currently, our GPString parameter cannot take special characters. This is a bug that we have yet to fix in our API.

If you can avoid using (",'), you can use GPString. If you need to use these, you can use GPMultiValue and hopefully that will be a workaround.


As I stated before I' using Select Layer by Attribute and using a Expression "From Parameter" right now the type is set to "SQL Expression."

The other options I see are "Any Value," "INFO Expression," "Interop Source Dataset," "SQL Expression," "String," and "Variant."

I don't see GPMultiValue but I'm guessing that might be "Any Value."  Should I use that?

Thanks
J
0 Kudos
JenniferNery
Esri Regular Contributor
To be honest, I don't know how you would update your Geoprocessor parameter from GPString to GPMultiValue. But I do know that the GPString in GPMultiValue will support special characters.

The following help document might be useful:
http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00150000000n000000.htm
0 Kudos
JMcNeil
Occasional Contributor III
To be honest, I don't know how you would update your Geoprocessor parameter from GPString to GPMultiValue. But I do know that the GPString in GPMultiValue will support special characters.

The following help document might be useful:
http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00150000000n000000.htm


Yea that seems like it is geared towards passing values to a script (either layers or fields names).  Also it mentions several times that it is used for a list of values rather than just one value and I want to be able to handle both.  Either way I don't think this will work in my case or I should say I don't have this option.

I've tired "Any Value" and "SQL Expression" and are looking for a GPString for input so I guess I will try"INFO Expression," "Interop Source Dataset," "String," and "Variant" and just make sure they will also expect a GPString.  Once I exhaust these options I will try to write something and maybe I will post something on the GP board.  Thanks for your help!

Hey maybe a heads up on when/if this bug is fix; not now but maybe before the API release.

Thanks
J
0 Kudos
JenniferNery
Esri Regular Contributor
I just happened to look back to this thread. The bug fix for GPString with special characters has been included in this release. Please try v2.2 Beta when it comes out. Thanks!
0 Kudos
JMcNeil
Occasional Contributor III
Jennifer,

Thanks for the follow up.  I actually just wrote a simple Python Script that handles the conversion.  The Python script is in my model so I accept plain text and add the double quotes, single quotes, dashes and special characters that my field query is expecting. 

If anyone need this python script (running a api that is not 2.2) I would be happy to provide it.

Side note....why are you not at the dev. summit??? I needed a good dodge ball player for my Silverlight team 😉
0 Kudos
JenniferNery
Esri Regular Contributor
Thanks for offering your Python script. I'll forward this link to someone I know who might need it.

Btw, I was at the Dev Summit Monday at the Code Challenge, Tuesday at the ArcGIS Mobile Island (Windows Phone 7) and Meet the Teams 🙂
0 Kudos