Re: [Zope] Change ZSQLMethod connection id
Fabio schrieb: > Hi! > I solved (partially) my problem: very thanks. > > I studied acquisition and then I understood your example. > > I've another problem (the last, I hope): I call some ZSQLMethod from > Python scripts so I need to execute a command dynamically. > example > I need to execute > 'container.include.sql.%s.getX()' % container.REQUEST.SESSION['dbconn'] > > but 'exec' is not allowed. Does exist another way or I have to write: > if container.REQUEST.SESSION['dbconn'] == 'conn1': > container.include.sql.conn1.getX() > elif container.REQUEST.SESSION['dbconn'] == 'conn2': > container.include.sql.conn2.getX() > elif ... > > ? > > In ZPT pages I use python:path('python:container.%s.getX()' % var) without > problem but I don't knoe how do the same thing in a script python. > Well, thats just python - I'd suggest skimming thru the python tutorial at python.org at least. You reach objects by getattr(parent,attributename) And in Zope also via: parent[attributename] This should get you going I think. Regards Tino ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] Change ZSQLMethod connection id
Fabio schrieb: > >>No its not. Thats whe whole point. You can always >>look up >>context.somewhere[variable].yourzsqlmethods.yourzsqlmethod(params...) >> >>where variable holds the name of the connection folder. > > > I make an example. > > two user: > > pippo -> db connection: dbpluto (holds in session in dbname var) > pluto -> db connection: dbpippo (holds in session in dbname var) > > when pippo call /include/utils/getData I want to execute query using dbpippo > when pluto call /include/utils/getData I want to execute query using dbpluto > > how can I call getData? > in this way: > "here/context/SESSION/dbname/include/utils/getData" ? > > I think isn't right but I don't know how set "somewhere[variable]" of your > example. This example is completely wrong. First you need to read: http://www.plope.com/Books/2_7Edition/Acquisition.stx and: http://www.plope.com/Books/2_7Edition/BasicScripting.stx You would code your access to the zsql method in a python script. And I dont know why you mess with sessions anyway - if its a user, it has been logged in and you know his/her name via User API (also look into the book) I cant do it all for you :-) You will know how to read my example when your read the book chapters :-) My advice however is to stick to one connection and perhaps use the username as argument for housekeeping or whatever you do. HTH Tino ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] Change ZSQLMethod connection id
Fabio schrieb: > Thanks for your reply but... > I have to change ZSQLMethod's connection_id according to a variable in > session > (so every user has its own database) while your method (if I understand it) > is static. Isn't it? No its not. Thats whe whole point. You can always look up context.somewhere[variable].yourzsqlmethods.yourzsqlmethod(params...) where variable holds the name of the connection folder. However, your approach isnt recommended even with small number of users your connections to the database will explode to zopethreads x users There was a thread about "per user connection" on this list. Maybe you can join the group of promoters and help the people? Regards Tino ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] Change ZSQLMethod connection id
Fabio schrieb: > Hi! > in my zope application I call ZSQLMethods from python script. Is it possible > to set "connection id" property of a ZSQLMethod before call it? > > How? > ZSQLMethod.propertyItems() return only ('title','') If you set it only one time, you should be able to read it from ZMI page how to set it (just lookup the method call of the form and the variables it takes) If however you want to change it on every call, your ZODB is going to bloat badly - every change is saved. In this case you might want to create 2 folders and put both database connection objects with identical ID in each of them: somewhere/aconnectionfolder/dbconnection somewhere/bconnectionfolder/dbconnection and set in all your ZSQL methods "dbconnection" as connection (perhaps while you edit them, use this path: somewhere/aconnectionfolder/whereyourzsqlmethodis/yourzsqlmethod/manage_main where "whereyourzsqlmethodis" does not have to be physically there (read about Acquisition) Now, if you want to use one or the other connection, just use: context.somewhere.aconnection.pathtoyourzsqlmethods.yourzsqlmethod(params...) or context.somewhere.bconnection.pathtoyourzsqlmethods.yourzsqlmethod(params...) while you can even parametrize the path as usually. HTH Tino ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] Change ZSQLMethod connection id
Andreas Jung wrote: --On 23. Dezember 2005 13:33:08 +0100 Fabio <[EMAIL PROTECTED]> wrote: Hi! in my zope application I call ZSQLMethods from python script. Is it possible to set "connection id" property of a ZSQLMethod before call it? How? ZSQLMethod.propertyItems() return only ('title','') perhaps zsql_method.connection_id = '' might to the job. See DA.py -aj Fabio, This, I think, is something I found in ZopeLabs some time ago. - objs = container.ZopeFind(container, obj_metatypes=['Z SQL Method'], search_sub=1) # module: pyPsycopgPropertyChanges path_list = [] for path, method in objs: title = method.title conn_id = 'Psycopg_database_connection' args = method.arguments_src body = method.src method.manage_edit(title, conn_id, args, body,max_rows=5000) path_list.append(path) header = "Fixed up the following methods - %s out of total sql count of %s"%(str(len(path_list)), str(len(objs))) body="%s"%join(path_list, '') return header+body - HTH, David ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] Change ZSQLMethod connection id
--On 23. Dezember 2005 13:33:08 +0100 Fabio <[EMAIL PROTECTED]> wrote: Hi! in my zope application I call ZSQLMethods from python script. Is it possible to set "connection id" property of a ZSQLMethod before call it? How? ZSQLMethod.propertyItems() return only ('title','') perhaps zsql_method.connection_id = '' might to the job. See DA.py -aj pgpj19i0w6rY9.pgp Description: PGP signature ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
[Zope] Change ZSQLMethod connection id
Hi! in my zope application I call ZSQLMethods from python script. Is it possible to set "connection id" property of a ZSQLMethod before call it? How? ZSQLMethod.propertyItems() return only ('title','') Thanks, Fabio -- Dott. Fabio Marcone 2T srl Telefono+39 - 0871- 540154 Fax +39 - 0871- 571594 Email [EMAIL PROTECTED] Indirizzo Viale B. Croce 573, 66013 Chieti Scalo (CH) ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )