On Wed, Nov 11, 2009 at 03:03, Kevin Ar18 <[email protected]> wrote:
>> Hope it helps,
> Try as I may, I can't get it to work....  Let me show you the real code:
>
> planet_names = ["Janus","Planet2"]
>
> from elixir import *
> metadata.bind = "sqlite:///citiesxl.db"
> class Base_Planet(Entity):
>  date = Field(String)
>  cities = Field(Integer)
> for planet_name in planet_names:
>  exec(str(planet_name)+" = Base_Planet")
> setup_all()
> create_all()
> for i in range(len(planet_names)):
>  exec(str(planet_names[i])+"(date=url_date, cities=planet_numbers[i])")
> session.commit()
> print Janus.query.all()
>
> -----
> the key point is that I want to dynamically create the tables, meaning I
> can't hard-code the table name. So far, all of this code works.
> ----
> Now, when I try to view the data separately, it doesn't work:
>
> from elixir import *
> metadata.bind = "sqlite:///citiesxl.db"

You are missing the declaration of your classes here. What people
usually do is have that in a seperate module and simply import the
module at this point. If you don't do that, how is the program
supposed to know what is that Janus class that you refer to? There is
one way to do approximately what I think you want, you need to use the
Sqlsoup SQLAlchemy extension, instead of Elixir.

> setup_all()
> print metadata.sorted_tables
> print Janus.query.all()

-- 
Gaëtan de Menten
http://openhex.org

--~--~---------~--~----~------------~-------~--~----~
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