Hi everyone, I have a script that loops thru' formulator and creates the insert sql string (with a view to creating the sqlMethod on the fly). When I come to multicheckbox fields I want enter the selected values into my db column by separating them with a semi-colon. However when I want to do this part of the script : if field.meta_type=='MultiCheckBoxField': sql=sql+"<dtml-in " + field.id + ">\n" sql=sql+"<dtml-var sequence-item>;" sql=sql+"</dtml-in>," the '/' of the </dtml-in> prevents the string from being rendered properly and results in the following (and none of the line breaks appear): .... values (, , , , , , , , , , , , , , , , ;,, ;,, , , , , ;, ;,, , , , , , , ;,, , , , , ) However if I remove the '<' of the </dtml-in> and leave it '/dtml-in>, the string renders ok: .... values (<dtml-sqlvar nom type=string >, <dtml-in prestataire> <dtml-var sequence-item>;/dtml-in>, I don't understand at all since all I am doing is concatenating strings. Thanks in advance for your help (full script below) Marie Robichon ________________________________________________________ sql="insert into microtomo\n " sql=sql+"(" for field in context.Formulator.get_fields(): if field.meta_type!='LabelField': sql= sql+ field.id + ", \n" sql=sql[:-3] sql=sql+") \n values \n(" for field in context.Formulator.get_fields(): if field.meta_type!='LabelField': if field.meta_type=='IntegerField': type='int' else: type='string' if field.is_required(): constraint="" else: constraint="optional" if field.meta_type=='MultiCheckBoxField': sql=sql+"<dtml-in " + field.id + ">\n" sql=sql+"<dtml-var sequence-item>;" sql=sql+"</dtml-in>," else: sql=sql + "<dtml-sqlvar "+ field.id + " type="+type + " " + constraint + ">,\n" sql=sql[:-3] sql=sql+">)" return sql
Marie Robichon wrote:
Hi everyone,
I have a script that loops thru' formulator and creates the insert sql string (with a view to creating the sqlMethod on the fly). When I come to multicheckbox fields I want enter the selected values into my db column by separating them with a semi-colon. However when I want to do this part of the script :
if field.meta_type=='MultiCheckBoxField': sql=sql+"<dtml-in " + field.id + ">\n" sql=sql+"<dtml-var sequence-item>;" sql=sql+"</dtml-in>,"
the '/' of the </dtml-in> prevents the string from being rendered properly and results in the following (and none of the line breaks appear):
.... values (, , , , , , , , , , , , , , , , ;,, ;,, , , , , ;, ;,, , , , , , , ;,, , , , , )
However if I remove the '<' of the </dtml-in> and leave it '/dtml-in>, the string renders ok:
.... values (<dtml-sqlvar nom type=string >, <dtml-in prestataire> <dtml-var sequence-item>;/dtml-in>,
I don't understand at all since all I am doing is concatenating strings.
Are you viewing it in a browser only? It's possible that the browser is seeing HTML-ish code and (properly) ignoring all the tags, as they mean nothing to it. Try a "view source" and see if it's really being rendered properly or not. Otherwise, maybe you ran afoul of Python escaping rules (though I don't see where.) Do some tests at the Python console to find out. --jcc -- "My point and period will be throughly wrought, Or well or ill, as this day's battle's fought."
Are you viewing it in a browser only? It's possible that the browser is seeing HTML-ish code and (properly) ignoring all the tags, as they mean nothing to it. Try a "view source" and see if it's really being rendered properly or not.
Otherwise, maybe you ran afoul of Python escaping rules (though I don't see where.) Do some tests at the Python console to find out.
Hi, Thanks a lot this was exactly the problem. Now I have another one ;-). When I run my script (see below) the 'manage_addZSQLMethod' raises an attribute error, but I can't see why. My arg string and my sql string are correct, my connection_id also. Any ideas ? TIA Marie ## Script (Python) "insertSQL" ##bind container=container ##bind context=context ##bind namespace= ##bind script=script ##bind subpath=traverse_subpath ##parameters=tableName ##title= ## arg="" for field in context.Formulator.get_fields(): if field.meta_type!='LabelField': arg= arg+ field.id + "\n" sql="insert into "+ tableName + "\n " sql=sql+"(" for field in context.Formulator.get_fields(): if field.meta_type!='LabelField': sql= sql+ field.id + ", \n" sql=sql[:-3] sql=sql+") \n values \n(" for field in context.Formulator.get_fields(): if field.meta_type!='LabelField': if field.meta_type=='IntegerField': type='int' else: type='string' if field.is_required(): constraint="" else: constraint="optional" if field.meta_type=='MultiCheckBoxField': sql=sql+"<dtml-in " + field.id + ">\n" sql=sql+"<dtml-var sequence-item>;" sql = sql + "< /dtml-in>,\n" else: sql=sql + "<dtml-sqlvar "+ field.id + " type="+type + " " + constraint + ">, \n" sql=sql[:-4] sql=sql+">)" folder=getattr(context,'id') folder.manage_addZSQLMethod('insert'+tableName,'Insert into '+tableName,'Oracle_database_connection',arg,sql)
Marie Robichon wrote:
Are you viewing it in a browser only? It's possible that the browser is seeing HTML-ish code and (properly) ignoring all the tags, as they mean nothing to it. Try a "view source" and see if it's really being rendered properly or not.
Otherwise, maybe you ran afoul of Python escaping rules (though I don't see where.) Do some tests at the Python console to find out.
Thanks a lot this was exactly the problem.
Now I have another one ;-). When I run my script (see below) the 'manage_addZSQLMethod' raises an attribute error, but I can't see why. My arg string and my sql string are correct, my connection_id also. ... folder=getattr(context,'id')
folder.manage_addZSQLMethod('insert'+tableName,'Insert into '+tableName,'Oracle_database_connection',arg,sql)
The syntax for adding products is:: context.manage_addProduct['Product'].manage_addProduct(id='new_id2', ...) and see http://www.zopelabs.com/cookbook/1012279676 You must look up the module via 'manage_addProduct' in order to get the constructor. In your case:: folder.manage_addProduct['ZSQLMethods'].manage_addZSQLMethod('insert'+tableName,'Insert into '+tableName,'Oracle_database_connection',arg,sql) You may also be interested in http://zope.org/Members/karpati/books/create_files --jcc -- "Code generators follow the 80/20 rule. They solve most of the problems, but not all of the problems. There are always features and edge cases that will need hand-coding. Even if code generation could build 100 percent of the application, there will still be an endless supply of boring meetings about feature design." (http://www.devx.com/java/editorial/15511)
participants (3)
-
J Cameron Cooper -
J. Cameron Cooper -
Marie Robichon