RE: [Zope] How to check type of variable in DTML
From what I have seen, Zope does not do this. The link you sent has nothing relating to this issue.
If I send in a string to a ZSQL method and the first block below is in the WHERE clause, then it strips off the first and last letters. If I send in a list like ['Ford','Toyota',''] then is takes the [ and ] off and gives me the correct IN syntax. I need to see if the variable coming in is a list or just a string and branch accordingly. Maybe I am going about it all wrong but this is what I am trying to do now. Thanks -Allen -----Original Message----- From: hans [mailto:hans@beehive.de] Sent: Wednesday, May 08, 2002 10:22 AM To: Schmidt, Allen J. Cc: zope@zope.org Subject: Re: [Zope] How to check type of variable in DTML "Schmidt, Allen J." wrote:
I am passing a variable to a ZSQL method and I need to check whether its a string or a list before it is part of a WHERE statement. How can I check this?
you dont need to. Zope can do this for you. especially <dtml-sqlvar ...> and <dtml-sqltest> see http://www.zope.org/Members/jshell/ZSQLMethods-InsertingData
<dtml-if mk> CMAKE IN ( <dtml-var "mk[1:-1}"> ) </dtml-if>
This works well if its a list but blows up if just a string. Needs to be like this:
<dtml-if mk is_A_list> CMAKE IN ( <dtml-var "mk[1:-1}"> ) <dtml-else> <dtml-var sqltest mk column=CMAKE type=nb optional> </dtml-if>
-- ------------------------------------------------------------- Who's got only a hammer sees the world as a nail hans augustin (software developer) hans@beehive.de beehive elektronische medien GmbH http://www.beehive.de phone: +49 30 847-82 0 fax: +49 30 847-82 299
"Schmidt, Allen J." wrote:
From what I have seen, Zope does not do this. The link you sent has nothing relating to this issue.
sorry. ive seem it somewhere. try "multiple"
If I send in a string to a ZSQL method and the first block below is in the WHERE clause, then it strips off the first and last letters.
If I send in a list like ['Ford','Toyota',''] then is takes the [ and ] off and gives me the correct IN syntax.
I need to see if the variable coming in is a list or just a string and branch accordingly. Maybe I am going about it all wrong but this is what I am trying to do now. Subject: Re: [Zope] How to check type of variable in DTML
"Schmidt, Allen J." wrote:
I am passing a variable to a ZSQL method and I need to check whether its a string or a list before it is part of a WHERE statement. How can I check this?
you dont need to. Zope can do this for you. especially <dtml-sqlvar ...> and <dtml-sqltest> see http://www.zope.org/Members/jshell/ZSQLMethods-InsertingData
<dtml-if mk> CMAKE IN ( <dtml-var "mk[1:-1}"> ) </dtml-if>
This works well if its a list but blows up if just a string. Needs to be like this:
<dtml-if mk is_A_list> CMAKE IN ( <dtml-var "mk[1:-1}"> ) <dtml-else> <dtml-var sqltest mk column=CMAKE type=nb optional> </dtml-if>
-- ------------------------------------------------------------- Who's got only a hammer sees the world as a nail hans augustin (software developer) hans@beehive.de beehive elektronische medien GmbH http://www.beehive.de phone: +49 30 847-82 0 fax: +49 30 847-82 299
there was a question abt howto handle (in a ZSQL Method) a variable, that is sometimes a string, sometimes a list of strings. the suggestion of "multiple" was not satisfying. maybe it was an unfit zope version. fixed in 2.4.4 and 2.5.1 http://www.zope.org/Products/Zope/2.5.1/CHANGES.txt says: - Caused sqltest implementation to match help system docs Expression tags now work. "multiple" attribute now works. type="nb" attr now works. (thanks to Christian Theune for the patch) ------------------------------------------------------------- Who's got only a hammer sees the world as a nail hans augustin (software developer) hans@beehive.de beehive elektronische medien GmbH http://www.beehive.de phone: +49 30 847-82 0 fax: +49 30 847-82 299
On Wednesday, May 8, 2002, at 11:30 PM, Schmidt, Allen J. wrote:
If I send in a string to a ZSQL method and the first block below is in the WHERE clause, then it strips off the first and last letters.
If I send in a list like ['Ford','Toyota',''] then is takes the [ and ] off and gives me the correct IN syntax.
I need to see if the variable coming in is a list or just a string and branch accordingly. Maybe I am going about it all wrong but this is what I am trying to do now.
SELECT * FROM foo_table WHERE <dtml-sqltest some_parameter column=some_column_name type=nb multiple=true> If I pass a string as the some_parameter parameter, the following SQL is generated: SELECT * FROM foo_table WHERE some_column_name = 'The string I passed, quoted nicely for me by Zope' If I pass a list or strings, the following SQL is generated: SELECT * FROM foo_table WHERE some_column_name IN ('First string','Second string') -- Stuart Bishop <zen@shangri-la.dropbear.id.au> http://shangri-la.dropbear.id.au/
participants (3)
-
hans -
Schmidt, Allen J. -
Stuart Bishop