Re: [Zope] ZPsycopg - Losing Connections

2005-07-27 Thread Thomas Olsen
On Wednesday den 27. July 2005 14:45, Peter Bengtsson wrote:
 On 7/27/05, Fernando Lujan [EMAIL PROTECTED] wrote:
  On 7/27/05, David [EMAIL PROTECTED] wrote:
   Python 2.3.5 - Zope 2.7.5 - PostgreSQL 7.3.4 - Psycopg 1.1.18 -
   Solaris 8 (Intel)
 
  The Psycopg version 1.1.19 solves this problem. :)

 The 1.1.19 version isn't in debian yet.
 $ apt-get show python-psycopg
 shows only 1.1.18 :(

#wget 
http://ftp.de.debian.org/debian/pool/main/p/psycopg/python-psycopg_1.1.19-1_i386.deb
#dpkg -i python-psycopg_1.1.19-1_i386.deb

-- 
Med venlig hilsen

Thomas Olsen
http://www.headnet.dk
___
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] ZSQLMethod conditional insert

2005-07-27 Thread Thomas Olsen
Hi

This is probably an FAQ but I haven't been able to find and answer.

I need a counter for a certain CMFType and want to store the hits in a MySQL 
database not to fill up the ZODB. I've checked to two suggestions below but 
they both use two ZSQLMethods first to check if the URL is already in the 
table, then to do the actual update or insert.

http://www.zope.org/Members/element/Simple_SQL_Page_Counter
http://zopelabs.com/cookbook/991116439

I'd like to be able to do that just in one ZSQLMethod for efficiency but I 
cant seem to figure out a way of doing it.

The table is very simple:

CREATE TABLE mostread (
  path varchar(255) NOT NULL default '',
  num bigint(20) NOT NULL default '0',
  dt datetime NOT NULL default '-00-00 00:00:00',
  PRIMARY KEY  (path)
)

For now my ZSQLMethod get the argument path which is a relative URL and it 
looks like this:

  select @lastval:=num from mostread where dtml-sqltest path type=string
  dtml-var sql_delimiter
  update mostread set [EMAIL PROTECTED], dt=now() where dtml-sqltest path 
type=string;
  /dtml-if

But that naturally only works if there is already a record containing path. 
What I want to do is something like this (pseudo-code):

  select @lastval:=num from mostread where dtml-sqltest path type=string
  dtml-var sql_delimiter
  dtml-if sequence-length  0
update mostread set [EMAIL PROTECTED], dt=now() where dtml-sqltest path 
type=string;
  dtml-else
insert into mostread(path, num, dt)
  values(dtml-sqlvar path type=string, 1, now())
  /dtml-if

Is there a way of doing this or should I just create that extra ZSQLMethod?

-- 
Med venlig hilsen

Thomas Olsen
http://www.headnet.dk
___
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] ZSQLMethod conditional insert

2005-07-27 Thread Thomas Olsen
Hi David

On Wednesday den 27. July 2005 23:50, David Pratt wrote:
 Hi Thomas. I would say postgres is better for this sort of thing.  In
 postgres, you can write a function in plpgsql or other function
 language (there is also a python function language) that you install in
 postgres. In any case once you write it and then call it - it is
 executed in a single transaction.  You are only left with selecting the
 function in your zsql from your script. 

I would prefer postgres too but it is decided to use MySQL in the project...

 It is hard to comment on the 
 method you have sketched out not knowing what arguments you are passing
 into the method. You have identified path but I see others that you
 haven't discussed so don't really know where you plan on getting them
 from.

Well path is actually the only argument passed to the method. select 
@lastval:=num is a (I think) MySQL specific way of assigning values to local 
variables. I could probably use a sub-select or something but my SQL is a bit 
rusty ;-)

 Regards,
 David

 On Wednesday, July 27, 2005, at 03:22 PM, Thomas Olsen wrote:
  Hi
 
  This is probably an FAQ but I haven't been able to find and answer.
 
  I need a counter for a certain CMFType and want to store the hits in a
  MySQL
  database not to fill up the ZODB. I've checked to two suggestions
  below but
  they both use two ZSQLMethods first to check if the URL is already in
  the
  table, then to do the actual update or insert.
 
  http://www.zope.org/Members/element/Simple_SQL_Page_Counter
  http://zopelabs.com/cookbook/991116439
 
  I'd like to be able to do that just in one ZSQLMethod for efficiency
  but I
  cant seem to figure out a way of doing it.
 
  The table is very simple:
 
  CREATE TABLE mostread (
path varchar(255) NOT NULL default '',
num bigint(20) NOT NULL default '0',
dt datetime NOT NULL default '-00-00 00:00:00',
PRIMARY KEY  (path)
  )
 
  For now my ZSQLMethod get the argument path which is a relative URL
  and it
  looks like this:
 
select @lastval:=num from mostread where dtml-sqltest path
  type=string
dtml-var sql_delimiter
update mostread set [EMAIL PROTECTED], dt=now() where dtml-sqltest path
  type=string;
/dtml-if
 
  But that naturally only works if there is already a record containing
  path.
  What I want to do is something like this (pseudo-code):
 
select @lastval:=num from mostread where dtml-sqltest path
  type=string
dtml-var sql_delimiter
dtml-if sequence-length  0
  update mostread set [EMAIL PROTECTED], dt=now() where dtml-sqltest
  path
  type=string;
dtml-else
  insert into mostread(path, num, dt)
values(dtml-sqlvar path type=string, 1, now())
/dtml-if
 
  Is there a way of doing this or should I just create that extra
  ZSQLMethod?
 
  --
  Med venlig hilsen
 
  Thomas Olsen
  http://www.headnet.dk
  ___
  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 )

-- 
Med venlig hilsen

Thomas Olsen
http://www.headnet.dk
___
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] Re: ZSQLMethod conditional insert

2005-07-27 Thread Thomas Olsen
On Thursday den 28. July 2005 00:23, Christian Scholz wrote:
 INSERT INTO table (a,b,c) VALUES (1,2,3)
        ON DUPLICATE KEY UPDATE c=c+1;

Thanks - that was exactly what I needed

-- 
Med venlig hilsen

Thomas Olsen
http://www.headnet.dk
___
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-dev] ZPT is young

2002-05-10 Thread Thomas Olsen

On Thursday 09 May 2002 09:47, Chris Withers wrote:
 Thomas Olsen wrote:
  DTML is great for style sheets, javascript and such where you cannot use
  ZPT and python scripts would be too ugly to use ;-)

 There's no reason to use DTML for these, as I've explained before ;-)


Must have missed that mail..?

-- 
Regards,
Thomas Olsen


___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists -
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )



Re: [Zope-dev] ZPT is young

2002-05-10 Thread Thomas Olsen

On Friday 10 May 2002 01:19, Adrian Hungate wrote:
 Yeah, for CSS I'd use ZStyleSheets, and for javascript I'd use a very large
 magnet... but that is another argument.

GRIN

-- 
Regards,
Thomas Olsen


___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists -
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )