I have just tested my script using sqlite instead of mysql and it works too.
However I need to run it with mysql...

Fabien.

2009/12/31 Glazner <[email protected]>

>
> > from elixir import *
> >
> > class tt(Entity):
> >     using_options(tablename = 'tt')
> >     d = Field(Integer, primary_key = True)
> >
> > setup_all()
> > metadata.bind = 'mysql://localhost/test'
> >
> > while True:
> >     a = tt.query.filter(None)
> >
> >     for x in a:
> >         print x.d
> >
> >     raw_input('')
> >     a = None
> >     session.expire_all()
> >
> > Once inserted new records in the table tt by using the command-line
> > mysql client (and committed), pressing return to loop once shows the
> > very same set of records, without the newly inserted ones.
> >
> > On the other hand, note that I found out that moving the metadata.bind
> > assignment into the while loop does the job. But that means to
> > reconnect to the engine over and over, which is quite ugly:
> >
> > from elixir import *
> >
> > class tt(Entity):
> >     using_options(tablename = 'tt')
> >     d = Field(Integer, primary_key = True)
> >
> > setup_all()
> >
> > while True:
> >     metadata.bind = 'mysql://localhost/test'
> >     a = tt.query.filter(None)
> >
> >     for x in a:
> >         print x.d
> >
> >     raw_input('')
> >
> > Does anyone have a cleaner solution?
> >
> > Fabien.
> >
> > On Dec 20, 5:12 pm, DavidG <[email protected]> wrote:
> >
> >
> >
> > > Thank you for your response. I am issuing a new query, that is not
> > > returning updated data.
> >
> > > Thanks, David
> >
> > > On Dec 20, 5:39 am, Gaetan de Menten <[email protected]> wrote:
> >
> > > > On Sat, Dec 19, 2009 at 16:17, DavidG <[email protected]> wrote:
> > > > > I am having a problem where I have an application that uses elixir
> on
> > > > > top of a database that can be updated by another application. If i
> > > > > don't do a full restart of the first application it does not seem
> to
> > > > > pickup the database changes.
> >
> > > > > I have tried all of the following:
> > > > >    session.remove()
> > > > >    session.expunge_all()
> > > > >    session.close_all()
> > > > >    session.expire_all()
> > > > >    session.clear()
> > > > >    session.flush()
> > > > >    session.close()
> >
> > > > > I have also tried to reload the module that is being called...
> >
> > > > Do you know that the in-memory objects (within the session or not)
> are
> > > > never automatically updated with the changes in the database? You
> have
> > > > to do session.query or session.merge.
> >
> > > > Other than that, does the other application commit its changes?
> >
> > > > Hope it helps,
> > > > --
> > > > Gaƫtan de Mentenhttp://openhex.org
>
> this works fine:
>
> write_and_commit.py:
>
> from elixir import *
> import time
> metadata.bind = "sqlite:///pop.db"
> metadata.bind.echo = True
> session.configure(autoflush=False)
>
> class Movie(Entity):
>    title = Field(Unicode(30),primary_key=True)
>
>    def __repr__(self):
>        return '<Movie "%s" (%d)>' % (self.title, self.year)
>
> setup_all(True)
>
> [m.delete() for m in Movie.query.all()]
>
> for i in range(1000):
>   m=Movie(title=u'pop%d'%i)
>   session.commit()
>   time.sleep(3)
>
> sniffer.py:
>
> from elixir import *
> import time
>
> metadata.bind = "sqlite:///pop.db"
> metadata.bind.echo = False
> session.configure(autoflush=False)
>
> class Movie(Entity):
>    title = Field(Unicode(30),primary_key=True)
>
>    def __repr__(self):
>        return '<Movie "%s">' % (self.title)
>
>
> setup_all(False)
>
> while True:
>    time.sleep(1)
>    print "\n".join(map(str,(Movie.query.all())))
>
>
> run write_and_commit.py first and then sniffer.py
> it works.
>
> --
>
> You received this message because you are subscribed to the Google Groups
> "SQLElixir" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<sqlelixir%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/sqlelixir?hl=en.
>
>
>

--

You received this message because you are subscribed to the Google Groups 
"SQLElixir" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sqlelixir?hl=en.


Reply via email to