RE : RE : [Zope-DB] How lunch SQL request from python script ?

2007-01-19 Thread CERETTO Thierry

Sorry for my mistake when I sent my emails.

THANK YOU to everybody for your precious help.

Thierry 
(A guy a little less desperate!)  


-Message d'origine-
De : [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] De la part de Ed Leafe
Envoyé : vendredi 19 janvier 2007 14:11
À : zope-db@zope.org
Objet : Re: RE : [Zope-DB] How lunch SQL request from python script ?

On Jan 19, 2007, at 7:31 AM, Charlie Clark wrote:

> keep replies on the mailing list so that others can learn from them.



This is repeated so often that you'd think that the list  
administrators would get a clue and set the default Reply-to: header  
to include the list address. I run several technical lists, and  
except on announcement lists, set the Reply-to: to the list address,  
and these sorts of problems never happen. And despite the dire  
warnings of the email purists, nothing bad has ever happened; the  
world continues to turn just fine.

If it is important that replies go to the list, then the default  
behavior should be just that. Send your complaints to the list  
admins, not to the posters who expect things to work intelligently.



-- Ed Leafe
-- http://leafe.com
-- http://dabodev.com


___
Zope-DB mailing list
Zope-DB@zope.org
http://mail.zope.org/mailman/listinfo/zope-db
___
Zope-DB mailing list
Zope-DB@zope.org
http://mail.zope.org/mailman/listinfo/zope-db


Re: RE : [Zope-DB] How lunch SQL request from python script ?

2007-01-19 Thread Ed Leafe

On Jan 19, 2007, at 7:31 AM, Charlie Clark wrote:


keep replies on the mailing list so that others can learn from them.




	This is repeated so often that you'd think that the list  
administrators would get a clue and set the default Reply-to: header  
to include the list address. I run several technical lists, and  
except on announcement lists, set the Reply-to: to the list address,  
and these sorts of problems never happen. And despite the dire  
warnings of the email purists, nothing bad has ever happened; the  
world continues to turn just fine.


	If it is important that replies go to the list, then the default  
behavior should be just that. Send your complaints to the list  
admins, not to the posters who expect things to work intelligently.




-- Ed Leafe
-- http://leafe.com
-- http://dabodev.com


___
Zope-DB mailing list
Zope-DB@zope.org
http://mail.zope.org/mailman/listinfo/zope-db


Re: RE : [Zope-DB] How lunch SQL request from python script ?

2007-01-19 Thread Maciej Wisniowski

>
> The only thing that's missing for me is using this idiom with existing
> ZSQL methods and that's because I've forgotten how to get them to
> render the query rather than execute it. Anyone care to enlighten me! ;-)
Not sure if I understand you, but do you think about
src__=1 parameter when calling ZSQLMethod?

-- 
Maciej Wisniowski
___
Zope-DB mailing list
Zope-DB@zope.org
http://mail.zope.org/mailman/listinfo/zope-db


Re: RE : [Zope-DB] How lunch SQL request from python script ?

2007-01-19 Thread Charlie Clark
Am 19.01.2007, 13:27 Uhr, schrieb Maciej Wisniowski  
<[EMAIL PROTECTED]>:



Please, stay on the list
First, isn't Charlie Clark solution good for you? It seems to be
reasonable.


Thanks! ;-)

I have try to use external method but without success... (I have read  
some post as you suggested it)



Create database connection object called 'myconnection' in ZMI and
connect it to your database.
Create external method like:
def callSQL(self, statement):
 conn = self.myconnection()
 return conn.query(statement)


The only thing that's missing for me is using this idiom with existing  
ZSQL methods and that's because I've forgotten how to get them to render  
the query rather than execute it. Anyone care to enlighten me! ;-)


Charlie
___
Zope-DB mailing list
Zope-DB@zope.org
http://mail.zope.org/mailman/listinfo/zope-db


Re: RE : [Zope-DB] How lunch SQL request from python script ?

2007-01-19 Thread Charlie Clark

Am 19.01.2007, 12:22 Uhr, schrieb CERETTO Thierry <[EMAIL PROTECTED]>:

Thierry,

keep replies on the mailing list so that others can learn from them.


Hi,
Thanks Charlie, your method works well (after some hours of labor...)
My code below (not finalized, but, for Zope/Python/MySsql newbies, can  
be useful for to start...)


Yes, except that it's not really very Pythonic and we're the number of  
script kiddies out there picking up the language we need to try and  
encourage the good stuff.



from Products.PythonScripts.standard import html_quote
from string import split


No! strings have got the split() method (since Python 1.6)


request = container.REQUEST
RESPONSE =  request.RESPONSE
# Get argument(s)
criteres = mot_MAJ
# Test


Assuming the criteria are coming from some web form there should be no  
need to split a string, they should already be available as a list.



#for cc in criteres.split(' '):
  #print cc.upper()
# Counter
countResults = 0
# Loop through arguments
for c in criteres.split(' '):
  # Lecture_mots iS "Z SQL method" in Zope (ZMI) which use a "Z MySQL  
database connection"

  results = context.lecture_mots(critere='%'+c.upper()+'%')


I'd actually use upper() in the DB query but it doesn't make much  
difference



  if len(results) == 0:  # if not results is a nicer way to write this
  print 'No results for ' + c
  else:
  countResults = len(results)
  print str(countResults) + ' results for ' + c
  for ligne in results:
  print '' + ligne[1] + ''
  # Test
  #for colonne in ligne:
  #print colonne
return results


Do not use a PythonScript to generate user readable output! Use it simply  
to control your SQL query and pass the results to a template to display  
which look something like this.






As you actually wish to list the results by criteria then you should pass  
the criteria to the script in a template loop but I'll leave that to you.


Charlie
___
Zope-DB mailing list
Zope-DB@zope.org
http://mail.zope.org/mailman/listinfo/zope-db


Re: RE : [Zope-DB] How lunch SQL request from python script ?

2007-01-19 Thread Maciej Wisniowski
Please, stay on the list :)


First, isn't Charlie Clark solution good for you? It seems to be
reasonable.
> I have try to use external method but without success... (I have read some 
> post as you suggested it)
>   
Create database connection object called 'myconnection' in ZMI and
connect it to your database.
Create external method like:

def callSQL(self, statement):
 conn = self.myconnection()
 return conn.query(statement)

-- 
Maciej Wisniowski
___
Zope-DB mailing list
Zope-DB@zope.org
http://mail.zope.org/mailman/listinfo/zope-db