Checkboxes/SQL data type problem
Hi, Please excuse a dumb newbie question. I've been trawling mailing list archives and documentation for clues and am getting nowhere. So far I've done most of what I need to do with DTML and relying on Znolk for working out basic code for handling external databases, so I'm probably missing something really obvious here. I'm using Zope 2.4.3 on NT4 connecting to Access databases via ZODBC DA. I'm having trouble updating a set of records in an external DB, selecting the records using checkboxes on a form. Code is below. The form appears to be producing the expected list of integers which are the record ids which need updating: if I get the results page to just display action_list it comes out as [15, 18] etc. ActionUpdateMethod works fine when I test it with a single record number. The results page should iterate over the list of record ids and update each record in turn. What actually happens is I get an error message: Error Type: sql.error Error Value: ('22005', -3030, '[Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression.') Which looks like it isn't an integer which is getting passed via the SQL. Yet as far as I can see, the list is a list of integers, the ZSQL argument tells it it's an integer and the sqlvar tag tells it it's an integer. What am I doing wrong? Relevant code: Form (DTML document - extraneous stuff cut): <form action="ActionUpdateResult" method="post"> <dtml-in ActionListMethod> <strong>Action:</strong> <input type="checkbox" name="action_list:int:list" value="<dtml-var ejournal_id>" checked> </dtml-in> <input type="submit" value="Action selected items"> </form> -------------------------------------------------------- ActionUpdateResult (DTML-document - results page): <dtml-in action_list> <dtml-call "ActionUpdateMethod(ejournal_id=_['sequence-item'])"> </dtml-in> -------------------------------------------------------- ActionUpdateMethod (ZSQL method): Arguments: ejournal_id:int actioned_date="<dtml-var ZopeTime fmt=%d/%m/%Y>" update new_ejournals set actioned_date=<dtml-sqlvar actioned_date type=string > where ejournal_id=<dtml-sqlvar ejournal_id type=int> -------------------------------------------------------- TIA for any light you can shed, John Whalley -- * John Whalley, Crewe Site Library, Manchester Metropolitan University * email: J.H.Whalley@mmu.ac.uk * Phone: (+44) 161 247 5220 (UK) * Usual disclaimer applies...........
when you use checkboxes with the same name or for that matter similar names <input name="..."> in a form, the item in the REQUEST variable is a list or in case of Zope a list-string of the form "['a','b','c']". Write a python script to convert it to a list. If you need one I can give it to you altho I must confess I am not an expert in Python. AM J.H.Whalley wrote:
Hi,
Please excuse a dumb newbie question. I've been trawling mailing list archives and documentation for clues and am getting nowhere. So far I've done most of what I need to do with DTML and relying on Znolk for working out basic code for handling external databases, so I'm probably missing something really obvious here.
I'm using Zope 2.4.3 on NT4 connecting to Access databases via ZODBC DA.
I'm having trouble updating a set of records in an external DB, selecting the records using checkboxes on a form. Code is below.
The form appears to be producing the expected list of integers which are the record ids which need updating: if I get the results page to just display action_list it comes out as [15, 18] etc.
ActionUpdateMethod works fine when I test it with a single record number.
The results page should iterate over the list of record ids and update each record in turn.
What actually happens is I get an error message:
Error Type: sql.error Error Value: ('22005', -3030, '[Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression.')
Which looks like it isn't an integer which is getting passed via the SQL. Yet as far as I can see, the list is a list of integers, the ZSQL argument tells it it's an integer and the sqlvar tag tells it it's an integer.
What am I doing wrong?
Relevant code:
Form (DTML document - extraneous stuff cut):
<form action="ActionUpdateResult" method="post">
<dtml-in ActionListMethod> <strong>Action:</strong> <input type="checkbox" name="action_list:int:list" value="<dtml-var ejournal_id>" checked> </dtml-in>
<input type="submit" value="Action selected items"> </form> --------------------------------------------------------
ActionUpdateResult (DTML-document - results page):
<dtml-in action_list> <dtml-call "ActionUpdateMethod(ejournal_id=_['sequence-item'])"> </dtml-in> --------------------------------------------------------
ActionUpdateMethod (ZSQL method):
Arguments: ejournal_id:int actioned_date="<dtml-var ZopeTime fmt=%d/%m/%Y>"
update new_ejournals set actioned_date=<dtml-sqlvar actioned_date type=string > where ejournal_id=<dtml-sqlvar ejournal_id type=int> --------------------------------------------------------
TIA for any light you can shed, John Whalley
-- * John Whalley, Crewe Site Library, Manchester Metropolitan University * email: J.H.Whalley@mmu.ac.uk * Phone: (+44) 161 247 5220 (UK) * Usual disclaimer applies...........
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
-- ================================================================== Aseem Mohanty Neurobehavioral Systems Inc, 828 San Pablo Ave, Albany, CA 94706 (R) 510 7696011 (M) 510 3014871 (O) 510 5279231 ================================================================== "I saw `cout' being shifted "Hello world" times to the left and stopped right there!!" -- Steve Gonedes ==================================================================
As a complete Python newbie an example would be really useful. I'd got the impression that using the form <input type="checkbox" name="action_list:int:list"... would make Zope realise it was dealing with a list of integers. It doesn't seem to, unfortunately. Thanks, John Whalley On 18 Jun 02, at 23:26, Aseem Mohanty wrote:
when you use checkboxes with the same name or for that matter similar names <input name="..."> in a form, the item in the REQUEST variable is a list or in case of Zope a list-string of the form "['a','b','c']". Write a python script to convert it to a list. If you need one I can give it to you altho I must confess I am not an expert in Python. AM
J.H.Whalley wrote:
Hi,
Please excuse a dumb newbie question. I've been trawling mailing list archives and documentation for clues and am getting nowhere. So far I've done most of what I need to do with DTML and relying on Znolk for working out basic code for handling external databases, so I'm probably missing something really obvious here.
I'm using Zope 2.4.3 on NT4 connecting to Access databases via ZODBC DA.
I'm having trouble updating a set of records in an external DB, selecting the records using checkboxes on a form. Code is below.
The form appears to be producing the expected list of integers which are the record ids which need updating: if I get the results page to just display action_list it comes out as [15, 18] etc.
ActionUpdateMethod works fine when I test it with a single record number.
The results page should iterate over the list of record ids and update each record in turn.
What actually happens is I get an error message:
Error Type: sql.error Error Value: ('22005', -3030, '[Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression.')
Which looks like it isn't an integer which is getting passed via the SQL. Yet as far as I can see, the list is a list of integers, the ZSQL argument tells it it's an integer and the sqlvar tag tells it it's an integer.
What am I doing wrong?
Relevant code:
Form (DTML document - extraneous stuff cut):
<form action="ActionUpdateResult" method="post">
<dtml-in ActionListMethod> <strong>Action:</strong> <input type="checkbox" name="action_list:int:list" value="<dtml-var ejournal_id>" checked> </dtml-in>
<input type="submit" value="Action selected items"> </form> --------------------------------------------------------
ActionUpdateResult (DTML-document - results page):
<dtml-in action_list> <dtml-call "ActionUpdateMethod(ejournal_id=_['sequence-item'])"> </dtml-in> --------------------------------------------------------
ActionUpdateMethod (ZSQL method):
Arguments: ejournal_id:int actioned_date="<dtml-var ZopeTime fmt=%d/%m/%Y>"
update new_ejournals set actioned_date=<dtml-sqlvar actioned_date type=string > where ejournal_id=<dtml-sqlvar ejournal_id type=int> --------------------------------------------------------
TIA for any light you can shed, John Whalley
-- * John Whalley, Crewe Site Library, Manchester Metropolitan University * email: J.H.Whalley@mmu.ac.uk * Phone: (+44) 161 247 5220 (UK) * Usual disclaimer applies...........
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
-- ================================================================== Aseem Mohanty Neurobehavioral Systems Inc, 828 San Pablo Ave, Albany, CA 94706 (R) 510 7696011 (M) 510 3014871 (O) 510 5279231 ==================================================================
"I saw `cout' being shifted "Hello world" times to the left and stopped right there!!" -- Steve Gonedes ==================================================================
-- * John Whalley, Crewe Site Library, Manchester Metropolitan University * email: J.H.Whalley@mmu.ac.uk * Phone: (+44) 161 247 5220 (UK) * Usual disclaimer applies...........
J.H.Whalley writes:
As a complete Python newbie an example would be really useful.
I'd got the impression that using the form <input type="checkbox" name="action_list:int:list"... would make Zope realise it was dealing with a list of integers. It doesn't seem to, unfortunately. It does!
Something else must be wrong. You already know the "<dtml-var REQUEST>" tip to analyse what you get from an HTTP summit? Use "showRequest" as the form action. "showRequest" is a DTML method with the following content: <dtml-var standard_html_header> <dtml-bar REQUEST> <dtml-var standard_html_footer> Dieter
Hi, You're right: something else was wrong! Thanks to Chris Withers for pointing me in the right direction: it was the ZSQL method which was the problem. Changing it to the following made everything work: --------------------------------------- Argument: ejournal_id:int update new_ejournals set actioned_date='<dtml-var ZopeTime fmt=%d/%m/%Y>' where ejournal_id=<dtml-sqlvar ejournal_id type=int> --------------------------------------- Thanks to everyone for your help, John Whalley On 20 Jun 02, at 21:53, Dieter Maurer wrote:
J.H.Whalley writes:
As a complete Python newbie an example would be really useful.
I'd got the impression that using the form <input type="checkbox" > name="action_list:int:list"... would make Zope realise it was dealing > with a list of integers. It doesn't seem to, unfortunately. It does!
Something else must be wrong.
You already know the "<dtml-var REQUEST>" tip to analyse what you get from an HTTP summit?
Use "showRequest" as the form action. "showRequest" is a DTML method with the following content:
<dtml-var standard_html_header> <dtml-bar REQUEST> <dtml-var standard_html_footer>
Dieter
-- * John Whalley, Crewe Site Library, Manchester Metropolitan University * email: J.H.Whalley@mmu.ac.uk * Phone: (+44) 161 247 5220 (UK) * Usual disclaimer applies...........
[Aseem Mohanty]
when you use checkboxes with the same name or for that matter similar names <input name="..."> in a form, the item in the REQUEST variable is a list or in case of Zope a list-string of the form "['a','b','c']". Write a python script to convert it to a list. If you need one I can give it to you altho I must confess I am not an expert in Python.
You really do get a real Python list, not a just string that looks like a list. Each element of the list is in fact a string. You don't need a script to convert it. Cheers, Tom P
Aseem Mohanty writes:
when you use checkboxes with the same name or for that matter similar names <input name="..."> in a form, the item in the REQUEST variable is a list or in case of Zope a list-string of the form "['a','b','c']". Write a python script to convert it to a list. Please do not follow this advice!
You will make your life much more difficult than necessary. First of all: If you have checkboxes with the same name, you will get: 1. no value for the name at all, when no checkbox is checked 2. a single string value with the checkbox "value", when a single checkbox if checked 3. a list of the checked checkbox values, when more than 1 checkbox is checked It is very nasty to handle these different types of behaviour. Fortunately, there is Zope (more precisely: ZPublisher) magic, to get a uniform behaviour: When you add ":list" to the name, you will always get a list when you get anything at all. This will unify cases 2 and 3 above. When you add an addition hidden variable with your basename suffixed with ":tokens:default" and an empty value, then you will get an empty list for the first case. This unifies case 1. Together, you will always get a list representing precisely the checked checkboxes. The hints above apply in the same way to multiple sections and lists coded as sequences of hidden variables in an HTML form. Read more about it on <http://www.dieter.handshake.de/pyprojects/zope/book/chap3.html> Dieter
Thanks for the link. I had actually seen it in an earlier mail of yours. The problem I had with that version, and the reason I had to go the roundabout way was that once I named it name=xxx:list ( <input type='hidden' name='deleted_users:list' value=''> ) I could no longer use it in a javascript on the page. If I tried to access it by just form_name.xxx ( <div onclick="document.manage_members.deleted_users.value='<dtml-var "member_data.user_id">';return true;"> ) I got a javascript error : "no object..." and if I accessed it using the name ( <div onclick="document.manage_members.deleted_users:list.value='<dtml-var "member_data.user_id">';return true;"> ) ... I got a expected ';' error. Hence I just decided to do it the dirty way. Any suggestions as to how to get around that problem. TIA AM ================================================================== Aseem Mohanty Neurobehavioral Systems Inc, 828 San Pablo Ave, Albany, CA 94706 (R) 510 7696011 (M) 510 3014871 (O) 510 5279231 ================================================================== "I saw `cout' being shifted "Hello world" times to the left and stopped right there!!" -- Steve Gonedes ==================================================================
[Aseem Mohanty]
The problem I had with that version, and the reason I had to go the roundabout way was that once I named it name=xxx:list ( <input type='hidden' name='deleted_users:list' value=''> ) I could no longer use it in a javascript on the page.
... Hence I just decided to do it the dirty way. Any suggestions as to how to get around that problem.
You can still use javascript to access these elements. If you know the position of the input element in the form, you can use this style of syntax to get to the exact element without needing its name: document.forms[2].elements[3] Also, you can still refer to these elements by name: document.forms[1].elements['input1:list'] If there are more than one form elements named "input1:list", then the expression will return a javascript array containing all the elements with that name. This works going back at least as far as Netscape 4.7, and probably farther but I can't test that. Works with IE and Mozilla as well. If you need to distinguish these form elements by some unique string, give them each a unique id attribute and use that to distinguish them. Cheers, Tom P
J.H.Whalley writes:
... I'm having trouble updating a set of records in an external DB, selecting the records using checkboxes on a form. Code is below.
The form appears to be producing the expected list of integers which are the record ids which need updating: if I get the results page to just display action_list it comes out as [15, 18] etc.
ActionUpdateMethod works fine when I test it with a single record number.
The results page should iterate over the list of record ids and update each record in turn.
What actually happens is I get an error message:
Error Type: sql.error Error Value: ('22005', -3030, '[Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression.')
Which looks like it isn't an integer which is getting passed via the SQL. Yet as far as I can see, the list is a list of integers, the ZSQL argument tells it it's an integer and the sqlvar tag tells it it's an integer.
What am I doing wrong? You know that all parameters passed from an HTML form are strings in the first place. Thus, what looks like a list of integers is probably a single string that just looks like a list.
You can use type suffixes in form variable names to tell Zope how to convert and pack HTML form data. For example, to get a list of integers, you can have: <input name="recno:int:list" ...> <input name="recno:int:list" ...> For details, see <http://www.dieter.handshake.de/pyprojects/zope/book/chap3.html> Dieter
I've already got the suffixes in place in the form: <input type="checkbox" name="action_list:int:list" value="<dtml-var ejournal_id>" checked> It looks like something is breaking somewhere else. Thanks for the URL, by the way: this is a resource I'd missed in my travels and I'm now working my way through it. Thanks, John Whalley On 19 Jun 02, at 20:27, Dieter Maurer wrote:
J.H.Whalley writes:
... I'm having trouble updating a set of records in an external DB, selecting the > records using checkboxes on a form. Code is below. > > The form appears to be producing the expected list of integers which are the > record ids which need updating: if I get the results page to just display > action_list it comes out as [15, 18] etc. > > ActionUpdateMethod works fine when I test it with a single record number.
The results page should iterate over the list of record ids and update each > record in turn. > > What actually happens is I get an error message: > > Error Type: sql.error > Error Value: ('22005', -3030, '[Microsoft][ODBC Microsoft Access Driver] Data > type mismatch in criteria expression.') > > Which looks like it isn't an integer which is getting passed via the SQL. Yet > as far as I can see, the list is a list of integers, the ZSQL argument tells > it it's an integer and the sqlvar tag tells it it's an integer. > > What am I doing wrong? You know that all parameters passed from an HTML form are strings in the first place. Thus, what looks like a list of integers is probably a single string that just looks like a list.
You can use type suffixes in form variable names to tell Zope how to convert and pack HTML form data. For example, to get a list of integers, you can have:
<input name="recno:int:list" ...> <input name="recno:int:list" ...>
For details, see
<http://www.dieter.handshake.de/pyprojects/zope/book/chap3.html>
Dieter
-- * John Whalley, Crewe Site Library, Manchester Metropolitan University * email: J.H.Whalley@mmu.ac.uk * Phone: (+44) 161 247 5220 (UK) * Usual disclaimer applies...........
[Dieter Maurer]
You know that all parameters passed from an HTML form are strings in the first place. Thus, what looks like a list of integers is probably a single string that just looks like a list.
No, it really is a list. You can use it in a dtml-in, for example. It is a list even if you don't use the ":list" syntax, as long as you have more than one input element with the same name. I just tried this to confirm my memory, and the following worked: In the form: <input name='p3' value='p3-1'><br> <input name='p3' value='p3-2'><br> In the dtml file that the form calls (i.e., the action attribute of the form): <dtml-in p3> &dtml-sequence-item;<br> </dtml-in> The result: p3-1 p3-2 You can also call a Python script with REQUEST as a parameter and use REQUEST.p3 as a list. Cheers, Tom P
participants (4)
-
Aseem Mohanty -
Dieter Maurer -
J.H.Whalley -
Thomas B. Passin