[Zope] arrays in sql methods and dtml-in

Dennis Moore rainking@feeding.frenzy.com
Wed, 24 Nov 1999 13:42:52 -0600


I have a document with a checkbox group in it.  This group corresponds to
an array in my Postgres database.  So, for example, the user does this:

Letters:
[ ] A
[x] B
[ ] C
[x] D

Then my dtml method gets: ['B', 'D']
which i would like to insert into my database.  In Postgres, a normal array
insertion looks like:

insert into foo (letters) values ('{"B", "D"}');

so i tried this:

<dtml-with REQUEST>
	INSERT INTO foo (
		letters
	) VALUES (
		<dtml-in letters>
			<dtml-if sequence-start>
				'{
			</dtml-if>
			"<dtml-sqlvar sequence-item type=string>"
			<dtml-if sequence-end>
				'}
			</dtml-if>
		<dtml-else>
			null
		</dtml-in>
	)
</dtml-with>

This gives me the error:
Error Type: InError
Error Value: Strings are not allowed as input to the in tag.
Traceback (innermost last):
  File /local/zope/lib/python/ZPublisher/Publish.py, line 214, in publish_module
  File /local/zope/lib/python/ZPublisher/Publish.py, line 179, in publish
  File /local/zope/lib/python/Zope/__init__.py, line 201, in zpublisher_exception_hook
    (Object: ElementWithAttributes)
  File /local/zope/lib/python/ZPublisher/Publish.py, line 165, in publish
  File /local/zope/lib/python/ZPublisher/mapply.py, line 160, in mapply
    (Object: PerformSignup)
  File /local/zope/lib/python/ZPublisher/Publish.py, line 102, in call_object
    (Object: PerformSignup)
  File /local/zope/lib/python/OFS/DTMLMethod.py, line 145, in __call__
    (Object: PerformSignup)
  File /local/zope/lib/python/DocumentTemplate/DT_String.py, line 502, in __call__
    (Object: PerformSignup)
  File /local/zope/lib/python/DocumentTemplate/DT_In.py, line 691, in renderwob
    (Object: getuser)
  File /local/zope/lib/python/Shared/DC/ZRDB/DA.py, line 395, in __call__
    (Object: sqlUserInsert)
  File /local/zope/lib/python/DocumentTemplate/DT_String.py, line 502, in __call__
    (Object: <string>)
  File /local/zope/lib/python/DocumentTemplate/DT_With.py, line 148, in render
    (Object: REQUEST)
  File /local/zope/lib/python/DocumentTemplate/DT_In.py, line 641, in renderwob
    (Object: software)
InError: (see above)


When I initially had just 
<dtml-sqlvar letters type=string>
I got the content of letters, but it wasn't in the proper format for
Postgres.  Now it seems like I can't get the elements of 'letters' or
something.  Has anyone used Postgres arrays with Zope and has a better way
of doing this?  Or at least one works? (=

-- 
pity this busy monster, manunkind,         |    Dennis  Moore    |       Sarah
not. Progress is a comfortable disease.    | rainking@frenzy.com |   McLachlan
   -e.e. cummings: One Times One           |  archon on the irc  |     "Black"
If I cried me a river of all my confessions would I drown in my shallow regret?