Created
April 27, 2012 06:12
-
-
Save Stiivi/2506388 to your computer and use it in GitHub Desktop.
SQLAlchemy bug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sqlalchemy import * | |
from sqlalchemy import sql | |
def create_table(url, schema=None): | |
engine = create_engine(url) | |
metadata = MetaData(engine, reflect=True) | |
table = Table("test_table", metadata, schema=schema) | |
if table.exists(): | |
table.drop() | |
table = Table("test_table", metadata, schema=schema) | |
table.append_column(Column("name", String)) | |
table.create() | |
table.insert(("foo", )).execute() | |
def get_key(url,schema=None): | |
print "URL : %s" % url | |
print "schema : %s" % schema | |
create_table(url, schema) | |
engine = create_engine(url) | |
metadata = MetaData(engine, reflect=True) | |
table = Table("test_table", metadata, schema=schema, autoload=True) | |
if not table.exists(): | |
print "table does not exist" | |
print "table : %s" % (table, ) | |
print "columns : %s" % (table.columns, ) | |
column = table.c["name"].label("foo.bar") | |
cursor = sql.expression.select([column]) | |
row = cursor.execute().fetchone() | |
print "keys are: %s" % (row.keys(), ) | |
print "" | |
# Each should print keys as "foo.bar" | |
get_key("postgres://localhost/sandbox") | |
get_key("postgres://localhost/sandbox", "test") | |
get_key("sqlite:////tmp/test.sqlite") | |
# The sqlite prints just "bar" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment