All: I need to take the elements in the list ['1', '2', '3'] and make them separate SQL Statements: insert into table values ('1') insert into table values ('2') insert into table values ('3') how can i do this? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Todd Loomis SAIC - DMSO Support 1901 N. Beauregard Street, Suite 500 Alexandria, VA 22311 Office: 703.824.3407 Fax: 703.379.3778 tloomis@dmso.mil
Hi, I think that someone tell you before, but... sql_statement_list = [] for elem in ['1', '2', '3']: sql.append("insert into table values ('"+elem+"')") doing something like this, at the end, you have a list with the strings you want. Result: ["insert into table values ('1')", "insert into table values ('2')", "insert into table values ('3')"] I hop this help, Paula Mangas On Tue, 26 Feb 2002, Todd Loomis wrote:
All:
I need to take the elements in the list ['1', '2', '3'] and make them separate SQL Statements:
insert into table values ('1') insert into table values ('2') insert into table values ('3')
how can i do this?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Todd Loomis SAIC - DMSO Support 1901 N. Beauregard Street, Suite 500 Alexandria, VA 22311 Office: 703.824.3407 Fax: 703.379.3778 tloomis@dmso.mil
_______________________________________________ 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 )
-- ==================================================================== "Everything should be made as simple as possible, but not simpler" -- Albert Heinstein -------------------------------------------------------------------- Paula Mangas e-mail: pamm@students.fct.unl.pt URL: http://students.fct.unl.pt/~pamm/ TMV: (+351) 96 2559034 ====================================================================
Todd Loomis wrote:
All:
I need to take the elements in the list ['1', '2', '3'] and make them separate SQL Statements:
insert into table values ('1') insert into table values ('2') insert into table values ('3')
how can i do this?
Aha! Here's where the direct python experience can help; its actually easier to do in Python than it is in DTML. For database adapters which support positional binding, use (after having obtained a suitable cursor): cursor.executemany('INSERT INTO TABLE VALUES (:1)', (['1','2','3'],)) and the executemany statement will fire off the command once for each element in the list to be inserted. Note the extra set of parenthesis about the values; this is because the API says that this SINGLE argument is the LIST of ALL argument LISTS -- ie, if I wanted to insert two values, I would: cursor.executemany('INSERT INTO TABLE VALUES(:1, :2)', (['1','a'], ['2','b'], ['3','c'])) DCOracle2 processes them in row major order, not column major order (the spec is a bit ambiguous about this as I recall.) You can do this with Zope with a python script; but you have to play a game with the connection object to get an actual cursor you can program with. -- Matt Kromer Zope Corporation http://www.zope.com/
participants (3)
-
Matthew T. Kromer -
Paula Mangas -
Todd Loomis