Christian Klinger | 5 Jan 11:20 2008
Picon

String Representation of keys

Hi,

first it´s hard for me to explain what i need. So i hope you can 
understand my problems.

I try to develope a "storm container" for zope.
I use the zalchemy product as a base for my work with storm.

I run into some Problems when i try to build a uri for my objects.

An example:

http://localhost/app/Person-(1,)

In uri consists of these relevant parts for me:

    app is the container
    Person is the classname of my Object
    (1,) these are the primary keys of my object

Currently i construct the primary key in this way:

     def _toStringIdentifier(self, obj):
         """ Construct the PrimaryKey"""
         store = getUtility(IZStorm).get(self.getStoreUtilityName())
         ident = self._getInstanceKey(obj)
         prefix = "%s-" %self._class.__name__
         return "%s%s" %(prefix, ident)

     def _getInstanceKey(self, obj):
(Continue reading)

Eduardo Willians | 7 Jan 18:29 2008
Picon

First time raises exception; Second works.

PyFriends,

Im finding problems on store. Someone could help me?

>>> result = store.find(Matriculas, Matriculas.MatriculaNum.like(6)).one()
Traceback (most recent call last):
  File "<pyshell#1>", line 1, in <module>
    result = store.find(Matriculas, Matriculas.MatriculaNum.like(6)).one()
  File "D:\LabSisTemporal\Routines\GeoSQL\storm\store.py", line 191, in find
    self.flush()
  File "D:\LabSisTemporal\Routines\GeoSQL\storm\store.py", line 438, in flush
    self._flush_one(obj_info)
  File "D:\LabSisTemporal\Routines\GeoSQL\storm\store.py", line 472,
in _flush_one
    result = self._connection.execute(expr)
  File "D:\LabSisTemporal\Routines\GeoSQL\storm\database.py", line
182, in execute
    raw_cursor = self.raw_execute(statement, params)
  File "D:\LabSisTemporal\Routines\GeoSQL\storm\database.py", line
242, in raw_execute
    raw_cursor.execute(statement)
  File "C:\Python25\lib\site-packages\MySQLdb\cursors.py", line 166, in execute
    self.errorhandler(self, exc, value)
  File "C:\Python25\lib\site-packages\MySQLdb\connections.py", line
35, in defaulterrorhandler
    raise errorclass, errorvalue
OperationalError: (1364, "Field 'Nome' doesn't have a default value")
>>>
>>> # Look. I'll try the same line but now it will work
>>> result = store.find(Matriculas, Matriculas.MatriculaNum.like(6)).one()
(Continue reading)

Hamilton Tran | 7 Jan 22:37 2008
Picon

error on mysql 5 with references and joins

I have a class that looks something like this

Class A:

m_id
b_id
m = reference(m_id, M.m_id)
m_value = Proxy(m, M.value)

when i try to do a

store.find((A,B), M.value == 'pie', B.b_id = A.b_id)

I get a mysql error 1054
http://www.delphifaq.com/faq/databases/mysql/f1110.shtml

Was wondering if there was a potential work around.

<div><p>I have a class that looks something like this<br><br>Class A:<br><br>m_id <br>b_id<br>m = reference(m_id, M.m_id)<br>m_value = Proxy(m, M.value)<br><br>when i try to do a<br><br>store.find((A,B), M.value == 'pie', 
B.b_id = A.b_id)<br><br>I get a mysql error 1054<br><a href="http://www.delphifaq.com/faq/databases/mysql/f1110.shtml">http://www.delphifaq.com/faq/databases/mysql/f1110.shtml</a><br><br>Was wondering if there was a potential work around.
<br><br></p></div>
Gustavo Niemeyer | 9 Jan 13:08 2008
Picon

Re: error on mysql 5 with references and joins

Hello Hamilton,

> when i try to do a
> 
> store.find((A,B), M.value == 'pie', B.b_id = A.b_id)
> 
> I get a mysql error 1054
> http://www.delphifaq.com/faq/databases/mysql/f1110.shtml
> 
> Was wondering if there was a potential work around.

Yes, this is a known problem (reported at [1]) which we'll certainly
fix for the upcoming version 0.12.  This version is taking a bit more
than we'd like because there are quite a few changes.  It's coming
soon nevertheless.

We apologize for the issue.

--

-- 
Gustavo Niemeyer
http://niemeyer.net

Gustavo Niemeyer | 9 Jan 13:08 2008
Picon

Re: error on mysql 5 with references and joins


> Yes, this is a known problem (reported at [1]) which we'll certainly

Oops.. missing reference:

[1] https://bugs.edge.launchpad.net/storm/+bug/162528

--

-- 
Gustavo Niemeyer
http://niemeyer.net

Gustavo Niemeyer | 9 Jan 13:13 2008
Picon

Re: String Representation of keys

Hey Christian,

(...)
> I run into some Problems when i try to build a uri for my objects.
(...)
> I know this is very ugly but i don´t find a better way for doing this
> maybe someone of you has an better idea of doing this.

As we discussed online, building a string representation of composed keys
for using on a URI certainly means some kind of encoding.  If the service
is public it's important to keep an eye on how securely the
encoding/decoding procedure is done.  With that in mind, I don't see many
choices besides defining such an encoding/decoding scheme for keys, which
is pretty much what you have done.

-- 
Gustavo Niemeyer
http://niemeyer.net

--

-- 
storm mailing list
storm <at> lists.canonical.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/storm
Gustavo Niemeyer | 9 Jan 13:19 2008
Picon

Re: First time raises exception; Second works.

Hi Eduardo,

> Im finding problems on store. Someone could help me?
> 
>>>> result = store.find(Matriculas, Matriculas.MatriculaNum.like(6)).one()
> Traceback (most recent call last):
>   File "<pyshell#1>", line 1, in <module>
>     result = store.find(Matriculas, Matriculas.MatriculaNum.like(6)).one()
>   File "D:\LabSisTemporal\Routines\GeoSQL\storm\store.py", line 191, in find
>     self.flush()

Notice that the error is related to *flushing* of previous changes, not to
your statement above.

> To solve the problem I have to use this:

This is a pretty bad workaround for a problem that is happening somewhere
else, perhaps related to schema (e.g. does your "name" column in the
database have no default value, and you're trying to create a Matricula
without one?)

To help you further, we'd need a self-contained test case.  IOW, a
test case in a single file showing the problem once executed.

> Sorry for my poor english.

Your english is pretty good.

--

-- 
Gustavo Niemeyer
http://niemeyer.net

Gustavo Niemeyer | 9 Jan 16:15 2008
Picon

3 to go before 0.12

Hello Stormers,

Here is a suggested list of branches for reviewing and merging
before 0.12 is out:

  https://bugs.launchpad.net/storm/+bug/162528
  https://bugs.launchpad.net/storm/+bug/163565
  https://bugs.launchpad.net/storm/+bug/174388

--

-- 
Gustavo Niemeyer
http://niemeyer.net

Gerdus van Zyl | 11 Jan 15:02 2008
Picon

Calculated attributes

Hi,

Is there an easy way to get SQL calculated attributes using storm?

my class:
class Account(object):
    __storm_table__ = "account"
    id = Int(primary=True)
    name = Unicode()

    def getBalance(self):
        balance = SQL("SELECT sum(amount) FROM entry")
        r = store.execute(balance).get_one()[0]
        return r

I want to turn getBalance into balance property.
e.g: balance = SQLvalue("SELECT sum(amount) FROM entry")
I know it can be done using balance = property(getBalance) etc, but a
convenience function would be great.

Also is there a method that is called on an Entity when it is retrieve
from the store?  __init__ does not seem to be called.

Thank you,
Gerdus van Zyl

Gerdus van Zyl | 11 Jan 16:27 2008
Picon

Threading question

How can I move an object between stores?
I am getting:
WrongStoreError: [<class 'model.Entry'> : 22 - Stationary - A - 10] is
part of another store

my code looks like this:
        db = getStore() #thread local store

        for b in self.biz:
            oldstore = Store.of(b)
            oldstore.remove(b)
            db.add(b)
        db.flush()
        db.commit()

In my GUI application it retrieves a list of items on the main thread
and calls the above code in another thread in reaction to a click
event.

Thanks,
Gerdus


Gmane