Oleg Broytman | 1 Feb 18:05
X-Face
Picon
Favicon

Re: memcache

Hello. I have returned to investigate the issue. Are you still interested?

On Fri, Jul 31, 2009 at 01:10:34PM -0400, Stef Telford wrote:
>    Okay.. so.. assuming I can get a writeLock again after del'ing it..  
> we should be good there. If you can let me know exactly -what- in the  
> sqlmeta blows up, that may also help matters. The connection surely  
> explodes (And rightly so I think).

   The problem with sqlmeta is that it's a class generated on the fly. It
doesn't even have a module - and pickle protocol prefers stable classes,
with proper modules and names.
   But I think it's easy to deal with it anyway. We don't need to pickle
sqlmeta *class* - the class is in the corresponding SQLObject class. We
probably even don't need to pickle sqlmeta instance - we can just recreate
it on unpickling 'cause its only instance data is a reference to SQLObject
instance and we know the instance - at the time of unpickling it's 'self'
so we can reconstruct a sqlmeta instance using the known class and known
instance data. Just for the (rare) case a user would have put some data
into the instance I can save sqlmeta.__dict__ and restore it on unpickling.
   I am going to add the corresponding __getstate__ and __setstate__ to
SQLObject and test them a bit.

Oleg.
--

-- 
     Oleg Broytman            http://phd.pp.ru/            phd <at> phd.pp.ru
           Programmers don't die, they just GOSUB without RETURN.

------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
(Continue reading)

Stef Telford | 1 Feb 19:40

Re: memcache

Morning Oleg, Everyone,
     I found that to get memcache working, I had do two things;

     *) get rid of the cache writelocks inside main.py (eg; remark out 
any val._SO_writeLock.acquire()) mostly due to explosions whilst pickling
     *) subclass the SQLObject into another class (which I called 
CompassObject, since our reservation system is called Compass ;) and 
overloaded _SO_setValue to do a delete inside memcache on change and 
overloaded 'get' such that it looks up memcache. I have to del/create 
_SO_writeLock, sqlmeta and _connection on each object when it's returned.

     Note that if someone was calling a series of 'setValue' instead of 
one large 'set', this would cause a lot of cache deletes and then misses 
when it tries to set. Thankfully, we have already audited the codebase 
for that (it was about a 3-4% "win" for us to change it over).

     Also, in a totally random thought, you will probably hit the 1mb 
memcache limit when storing objects. Since we are storing objects 
without blobs, it works. The only real workaround if people start to 
complain about memcache 'not storing their objects' is to either go 
Tokyo Tyrant or Redis. If you go Redis, you also end up with more speed 
and m->s replication for free ;).

     I am more than willing to help and/or bounce ideas off if you want. 
The solution I have may not be 'perfect' but it's definitely performant 
enough for our needs :D

     Regards
     Stef

(Continue reading)

Petr Jakeš | 1 Feb 20:40
Picon

ForeignKey and MultipleJoin on legacy (existing) database

Hi,
I am trying to connect via SQLObject to the existing database (MySQL - Prestashop database)

The database has different naming style than SQLObject expect.

I know it is possible to use

class sqlmeta:       
        idName = 'id_order'

to get primary key working properly.

What I really can not figure out is how to get ForeignKey and MultipleJoin working.

Thanks for your comments

Petr Jakes


------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss
Oleg Broytman | 1 Feb 21:33
X-Face
Picon
Favicon

Re: ForeignKey and MultipleJoin on legacy (existing) database

On Mon, Feb 01, 2010 at 08:40:48PM +0100, Petr Jake?? wrote:
> I am trying to connect via SQLObject to the existing database

   You didn't mention fromDatabase but I am sure that what you meant,
right? Because it's certainly possible to connect to an existing database
without it.

> What I really can not figure out is how to get ForeignKey and MultipleJoin
> working.

   By declaring them yourself:

class MyTable(SQLObject):
    class sqlmeta:
        fromDatabase = True
    fk = ForeignKey('AnotherTable')
    mj = MultipleJoin('AnotherTable', joinColumn='at_id')

   Explicit declarations are compatible with fromDatabase. And of course
you are not obliged to use fromDatabase at all - just declare all you
columns and joins yourself.
   Of course IWBN if your patch fromDatabase machinery (methods
columnsFromSchema and guessClass in Connection class) to recognize at least
ForeignKeys.

Oleg.
--

-- 
     Oleg Broytman            http://phd.pp.ru/            phd <at> phd.pp.ru
           Programmers don't die, they just GOSUB without RETURN.

------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
Oleg Broytman | 1 Feb 21:43
X-Face
Picon
Favicon

Re: memcache

On Mon, Feb 01, 2010 at 01:40:51PM -0500, Stef Telford wrote:
>      *) subclass the SQLObject into another class (which I called 
> CompassObject, since our reservation system is called Compass ;) and 
> overloaded _SO_setValue to do a delete inside memcache on change and 

   To delete the instance from the cache to make the cache coherent?

> overloaded 'get' such that it looks up memcache. I have to del/create 

   I am going to do it in steps. The first step - to make SQLObject
instances pickleable. MemcachedCache would be the next. But I am going to
develop a separate cache class, not hack into .get machinery.

> _SO_writeLock, sqlmeta and _connection on each object when it's returned.

   _connection? Do you mean per-instance connection? In general, the
connection is stored in the SQLObject table class and it doesn't need to be
pickled or restored. But how do you restore per-instance connection?

>      Also, in a totally random thought, you will probably hit the 1mb 
> memcache limit when storing objects.

   What's the limit?

Oleg.
--

-- 
     Oleg Broytman            http://phd.pp.ru/            phd <at> phd.pp.ru
           Programmers don't die, they just GOSUB without RETURN.

------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
Petr Jakeš | 1 Feb 22:09
Picon

Re: ForeignKey and MultipleJoin on legacy (existing) database


> I am trying to connect via SQLObject to the existing database

  You didn't mention fromDatabase but I am sure that what you meant,
right? Because it's certainly possible to connect to an existing database
without it.

> What I really can not figure out is how to get ForeignKey and MultipleJoin
> working.

  By declaring them yourself:

class MyTable(SQLObject):
   class sqlmeta:
       fromDatabase = True
   fk = ForeignKey('AnotherTable')
   mj = MultipleJoin('AnotherTable', joinColumn='at_id')
 
Thanks for the syntax, it works great.

  Explicit declarations are compatible with fromDatabase. And of course
you are not obliged to use fromDatabase at all - just declare all you
columns and joins yourself.

I have used fromDatabase  because my lazybones only.

  Of course IWBN if your patch fromDatabase machinery (methods
columnsFromSchema and guessClass in Connection class) to recognize at least
ForeignKeys.

IWBN, I would like to. But, to be honest, I think my Pythonic skills are to low for this task (it is REALLY not about the time or laziness).

Thanks and Best Regards

Petr
------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss
John Bresnahan | 4 Feb 00:37
Favicon

setConnection()

I am trying to change the connection with which a given object is associate for some needed 
transactional behavior.  In an API function a user hands me an SQLObject called xfer.  I want to 
update a value in that object and automically update the value of a row in another table.

To achieve this I created a transaction with

trans = sqlhub.processConnection.transaction()

and then i call xfer.setConnection(trans).

This does not seem to have the effects I assumed so I have a few questions:

1) Is there a better way to achieve the results I am looking for?

2) at what point is an object associated with a DB connection?

3) is it at all possible to change the DB connection associated with a given object?

Any help is greatly appreciated.

Thanks,

John

------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
Oleg Broytman | 4 Feb 14:53
X-Face
Picon
Favicon

Re: per-instance connection (was: setConnection)

On Wed, Feb 03, 2010 at 01:37:08PM -1000, John Bresnahan wrote:
> 2) at what point is an object associated with a DB connection?
> 3) is it at all possible to change the DB connection associated with a given object?

   Objects (SQLObject instances that correspond to rows in a table) are
seldom associated with a connection (though it is certainly possible).
   SQLObject classes (that correspond to tables) are usually associated with
a connection; .setConnection() is a class method.
   To associate an object with a connection you have to SELECT it via that
connection:

> trans = sqlhub.processConnection.transaction()

and now do

   xfer = XferTable.get(id, connection=trans)
or XferTable.select(condition, connection=trans).
   Most SQLObject methods accept 'connection' parameter.

Oleg.
--

-- 
     Oleg Broytman            http://phd.pp.ru/            phd <at> phd.pp.ru
           Programmers don't die, they just GOSUB without RETURN.

------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
John Bresnahan | 4 Feb 21:45
Favicon

Re: per-instance connection

> On Wed, Feb 03, 2010 at 01:37:08PM -1000, John Bresnahan wrote:
>> 2) at what point is an object associated with a DB connection?
>> 3) is it at all possible to change the DB connection associated with a given object?
> 
>    Objects (SQLObject instances that correspond to rows in a table) are
> seldom associated with a connection (though it is certainly possible).
>    SQLObject classes (that correspond to tables) are usually associated with
> a connection; .setConnection() is a class method.
>    To associate an object with a connection you have to SELECT it via that
> connection:
> 
>> trans = sqlhub.processConnection.transaction()
> 
> and now do
> 
>    xfer = XferTable.get(id, connection=trans)
> or XferTable.select(condition, connection=trans).
>    Most SQLObject methods accept 'connection' parameter.

Thanks much!  Is there a way to change the connection associated with an object you have already 
acquired via select?

------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
Petr Jakeš | 4 Feb 21:46
Picon

how to set dbEncoding for the whole table/database, not for the row?

Hi,
I know below code example works. I would like to know, if it is possible to set the encoding for the whole table at once (or for the connection/database) instead to define it for each column.

Petr

====== code example ============

class Customer(SQLObject):
    _connection = connection
    class sqlmeta:       
        idName = 'id_customer'
#        fromDatabase = True
    orders = MultipleJoin('Orders', joinColumn = "id_customer")
    lastname = UnicodeCol(dbEncoding = "1250")
    firstname = UnicodeCol(dbEncoding = "1250")

------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss

Gmane