Variable as record type or dictionary
Hi Zopists! I need to copy a record from into a <dtml-in> tag to use it later. Suppose: "Client" is a select ZSQL method (select * from Client where <dtml-sqltest client_num type=string>). ---- <dtml-in "Client(client_num='2345')"> copy the retrieved record in a variable </dtml-in> ---- "OrderLine" is a insert ZSQL method: insert into OrderLine (order_num,client_num,client_name,client_address,...,product_num,...) values (<dtml-sqlvar order_num type=string>, insert the column "client_num" from the previous retrieved Client record, insert the column "client_name" from the previous retrieved Client record, insert the column "client_address" from the previous retrieved Client record, ..., <dtml-sqlvar product_num type=string>, ...) ---- Registering the order lines... <dtml-call "OrderLine(order_num='OR4567',product_num='PENCIL-0067')"> <dtml-call "OrderLine(order_num='OR4568',product_num='PEN-BLUE-8')"> <dtml-call "OrderLine(order_num='OR4569',product_num='PENCIL-0045')"> <dtml-call "OrderLine(order_num='OR4570',product_num='PENCIL-0023')"> <dtml-call "OrderLine(order_num='OR4571',product_num='PEN-BLCK-1')"> <dtml-call "OrderLine(order_num='OR4572',product_num='PEN-031')"> ---- Take in mind that I can't put the ZSQL method "Client" inside the ZSQL method "OrderLine" because the Client method needs about 10 seconds to execute and if every "OrderLine" method needs his time plus 10 seconds (from the "Client" method) this can take over one minute for the above example order. This is not viable! Awaiting 15 seconds to place the order is acceptable but over one minute isn't. The solution is to execute the "Client" method only one time. Any ideas how can I copy the Client record? Juan Carlos Coruña.
Hi Juan, ZSQL methods are cached. So you need not copy them to a variable. Siply call it first: <dtml-call "Client(client_num='2345')"> and use it later with <dtml-in "Client(client_num='2345')"> ... </dtml-in> Or did I miss something obvious? HTH Tino Wildenhain Juan Carlos Coruña wrote:
Hi Zopists!
I need to copy a record from into a <dtml-in> tag to use it later.
Suppose:
"Client" is a select ZSQL method (select * from Client where <dtml-sqltest client_num type=string>). ---- <dtml-in "Client(client_num='2345')"> copy the retrieved record in a variable </dtml-in> ---- "OrderLine" is a insert ZSQL method:
insert into OrderLine (order_num,client_num,client_name,client_address,...,product_num,...) values (<dtml-sqlvar order_num type=string>, insert the column "client_num" from the previous retrieved Client record, insert the column "client_name" from the previous retrieved Client record, insert the column "client_address" from the previous retrieved Client record, ..., <dtml-sqlvar product_num type=string>, ...) ---- Registering the order lines... <dtml-call "OrderLine(order_num='OR4567',product_num='PENCIL-0067')"> <dtml-call "OrderLine(order_num='OR4568',product_num='PEN-BLUE-8')"> <dtml-call "OrderLine(order_num='OR4569',product_num='PENCIL-0045')"> <dtml-call "OrderLine(order_num='OR4570',product_num='PENCIL-0023')"> <dtml-call "OrderLine(order_num='OR4571',product_num='PEN-BLCK-1')"> <dtml-call "OrderLine(order_num='OR4572',product_num='PEN-031')">
----
Take in mind that I can't put the ZSQL method "Client" inside the ZSQL method "OrderLine" because the Client method needs about 10 seconds to execute and if every "OrderLine" method needs his time plus 10 seconds (from the "Client" method) this can take over one minute for the above example order. This is not viable! Awaiting 15 seconds to place the order is acceptable but over one minute isn't.
The solution is to execute the "Client" method only one time. Any ideas how can I copy the Client record?
Juan Carlos Coruña.
_______________________________________________ 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 )
Hi Tino and Zopist, Maybe me example was not the best. I will try to expose a better example: (The real case is too complicated to expose here.) Suppose: "OrderHeader" is a insert ZSQL method: insert into OrderHeader order_num,paymethod,client_num,client_name,client_address,... (over 40 columns) values (<dtml-sqlvar order_num type=string>, copy the column "order_num" in a variable <dtml-in "getPaymethods(code='TR')"> <dtml-sqlvar paymethod type=string>, copy the column "paymethod" in a variable ... </dtml-in> <dtml-in getClient(client_num='SD4998')"> <dtml-sqlvar client_num type=string>, copy the column "client_num" <dtml-sqlvar client_name type=string>, copy the column "Client_name" ... </dtml-in> ...) Each column to insert is obtained by a diferent ZSQL methods, REQUEST variable or External Method. ---- "OrderLine" is a insert ZSQL method: insert into OrderLine (order_num,paymethod,client_num,client_name,client_address,...,product_num,. .. (over 40 columns)) values (insert the column "order_num" from the variable, insert the column "client_num" from the variable, insert the column "client_name" from the variable, insert the column "client_address" from the variable, ..., <dtml-sqlvar product_num type=string>, ...) ---- Registering the order lines... <dtml-call "OrderHeader(order_num='OR4567')"> <dtml-call "OrderLine(product_num='PENCIL-0067')"> <dtml-call "OrderLine(product_num='PEN-BLUE-8')"> <dtml-call "OrderLine(product_num='PENCIL-0045')"> <dtml-call "OrderLine(product_num='PENCIL-0023')"> <dtml-call "OrderLine(product_num='PEN-BLCK-1')"> <dtml-call "OrderLine(product_num='PEN-031')"> ---- I don't like to put: <dtml-call "getOrderHeader(order_num='OR4567')"> after the line <dtml-call "OrderHeader... because I think its superfluous as I processed all the columns in a previous method. Storing each column in a REQUEST variable its a mess, I have a lot of REQUEST variables and the variable name of them can match some column names, so I can't mix the variables. The best solution were a python dictionary type variable, or variables in a diferent namespace,... Any Ideas? Juan Carlos Coruña.
participants (2)
-
Juan Carlos Coruña -
Tino Wildenhain