[sqlalchemy] Re: creating tables dynamically

2010-07-23 Thread Nebur
That shouldn't be too hard...
When creating a Table as shown in the tutorial, you can provide any
number of columns.
You can later modify an existing Table object; there's an
append_column method. See:
http://www.sqlalchemy.org/docs/reference/sqlalchemy/schema.html#tables-and-columns
 Nebur

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] SQLAlchemy+pymssql unicode problem

2010-07-23 Thread Massi
Hi everyone,

I'm trying to write a small script to get all the table names from
SQLServer database (with pymssql). Up to now the script is really
simple:

engine = create_engine(mssql+pymssql://user:passw...@db_host/
db_name, encoding=cp1252)
metadata = MetaData(engine, reflect=True)
tabs = metadata.tables.keys()
print tabs

When I try to run this script I get the following error:

Traceback (most recent call last):
  File DBScript.py, line 12, in module
metadata = MetaData(engine, reflect=True)
  File D:\Program Files\Python26\Lib\site-packages\sqlalchemy
\schema.py, line
1788, in __init__
self.reflect()
  File D:\Program Files\Python26\Lib\site-packages\sqlalchemy
\schema.py, line
1915, in reflect
Table(name, self, **reflect_opts)
  File D:\Program Files\Python26\Lib\site-packages\sqlalchemy
\schema.py, line
207, in __new__
table._init(name, metadata, *args, **kw)
  File D:\Program Files\Python26\Lib\site-packages\sqlalchemy
\schema.py, line
261, in _init
reflecttable(self, include_columns=include_columns)
  File D:\Program Files\Python26\Lib\site-packages\sqlalchemy\engine
\base.py,
line 1776, in reflecttable
self.dialect.reflecttable(conn, table, include_columns)
  File D:\Program Files\Python26\Lib\site-packages\sqlalchemy\engine
\default.py
, line 217, in reflecttable
return insp.reflecttable(table, include_columns)
  File D:\Program Files\Python26\lib\site-packages\sqlalchemy\engine
\reflection
.py, line 411, in reflecttable
raise exc.NoSuchTableError(table.name)
sqlalchemy.exc.NoSuchTableError

I found that this error is due to a table in my DB called Attività,
so I believe that it is related to a unicode issue. Does anyone have
any idea about this error? Thanks in advance for your help!

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



Re: [sqlalchemy] SQLAlchemy+pymssql unicode problem

2010-07-23 Thread Michael Bayer
The version of SQLAlchemy and pymssql is very significant here.Older 
pymssqls didn't really support unicode at all.  The current one, unclear, we 
have basic dialect support for the latest pymssql in 0.6 but it hasn't been 
strongly tested.

There is of course very good support for pyodbc which runs on all platforms.

On Jul 23, 2010, at 7:42 AM, Massi wrote:

 Hi everyone,
 
 I'm trying to write a small script to get all the table names from
 SQLServer database (with pymssql). Up to now the script is really
 simple:
 
 engine = create_engine(mssql+pymssql://user:passw...@db_host/
 db_name, encoding=cp1252)
 metadata = MetaData(engine, reflect=True)
 tabs = metadata.tables.keys()
 print tabs
 
 When I try to run this script I get the following error:
 
 Traceback (most recent call last):
  File DBScript.py, line 12, in module
metadata = MetaData(engine, reflect=True)
  File D:\Program Files\Python26\Lib\site-packages\sqlalchemy
 \schema.py, line
 1788, in __init__
self.reflect()
  File D:\Program Files\Python26\Lib\site-packages\sqlalchemy
 \schema.py, line
 1915, in reflect
Table(name, self, **reflect_opts)
  File D:\Program Files\Python26\Lib\site-packages\sqlalchemy
 \schema.py, line
 207, in __new__
table._init(name, metadata, *args, **kw)
  File D:\Program Files\Python26\Lib\site-packages\sqlalchemy
 \schema.py, line
 261, in _init
reflecttable(self, include_columns=include_columns)
  File D:\Program Files\Python26\Lib\site-packages\sqlalchemy\engine
 \base.py,
 line 1776, in reflecttable
self.dialect.reflecttable(conn, table, include_columns)
  File D:\Program Files\Python26\Lib\site-packages\sqlalchemy\engine
 \default.py
 , line 217, in reflecttable
return insp.reflecttable(table, include_columns)
  File D:\Program Files\Python26\lib\site-packages\sqlalchemy\engine
 \reflection
 .py, line 411, in reflecttable
raise exc.NoSuchTableError(table.name)
 sqlalchemy.exc.NoSuchTableError
 
 I found that this error is due to a table in my DB called Attività,
 so I believe that it is related to a unicode issue. Does anyone have
 any idea about this error? Thanks in advance for your help!
 
 -- 
 You received this message because you are subscribed to the Google Groups 
 sqlalchemy group.
 To post to this group, send email to sqlalch...@googlegroups.com.
 To unsubscribe from this group, send email to 
 sqlalchemy+unsubscr...@googlegroups.com.
 For more options, visit this group at 
 http://groups.google.com/group/sqlalchemy?hl=en.
 

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] Adding a Column dynamically using a metaclass

2010-07-23 Thread cropr
I am trying to add a Column definition using a metaclass but things
aren't working as expected

I am using something like the code below

class MyMeta(DeclarativeMeta):
def __init__(cls, name, bases, attrdict):
setattr(cls, 'title', Column(types.String(80))
DeclarativeMeta.__init__(cls, name, bases, attrdict)

Base = declarative_base(metaclass=MyMeta)

class BasicModel(Base):
__tablename__ = 'basic'

id = Column(types.Integer, primary_key=True, autoincrement=True)
identifier = Column(types.String(40))

but the title Column does not seems to be included in the BasicModel
class.
Any idea what's wrong?

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



Re: [sqlalchemy] Adding a Column dynamically using a metaclass

2010-07-23 Thread Michael Bayer

On Jul 23, 2010, at 2:07 PM, cropr wrote:

 I am trying to add a Column definition using a metaclass but things
 aren't working as expected
 
 I am using something like the code below
 
 class MyMeta(DeclarativeMeta):
def __init__(cls, name, bases, attrdict):
setattr(cls, 'title', Column(types.String(80))
DeclarativeMeta.__init__(cls, name, bases, attrdict)
 
 Base = declarative_base(metaclass=MyMeta)
 
 class BasicModel(Base):
__tablename__ = 'basic'
 
id = Column(types.Integer, primary_key=True, autoincrement=True)
identifier = Column(types.String(40))
 
 but the title Column does not seems to be included in the BasicModel
 class.
 Any idea what's wrong?

Use regular mixins.  See 
http://www.sqlalchemy.org/docs/reference/ext/declarative.html#mixin-classes .

If for some reason you don't want to do that, using your recipe above, add the 
column to attrdict.  See 
http://www.sqlalchemy.org/trac/wiki/UsageRecipes/DeclarativeMixins for an 
example.


-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] Re: creating tables dynamically

2010-07-23 Thread Aref
Thank you for taking the time to reply.
The application I am writing takes input from the user to define the
table name, number of columns, types etc... I tried formatting the
inputs in a list and then passing the list elements to Table(). I kept
getting error messages. I abandoned this approach and simply used
basic SQL expression to get this done. It works.
Again thank you for the response.

On Jul 23, 3:47 am, Nebur g...@reifenberg.de wrote:
 That shouldn't be too hard...
 When creating a Table as shown in the tutorial, you can provide any
 number of columns.
 You can later modify an existing Table object; there's an
 append_column method. 
 See:http://www.sqlalchemy.org/docs/reference/sqlalchemy/schema.html#table...
  Nebur

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] sqlalchemy and desktop apps

2010-07-23 Thread Joel Mohler
Hello,

I'm a happy user of sqlalchemy on small personal projects of my own
(http://bitbucket.org/jbmohler/pyhacc is one of them which is not
ready for use yet).  At my day job we are in the process of evaluating
platforms for a rewrite of our small business accounting system.  We
expect this rewrite to have 200k-300k LOC and sqlalchemy stands up
well in many ways to some of the C# alternatives we are considering.
The notion of writing the entire project in python is quite daunting
to management who is new to opensource.

I'm wondering if anyone would be kind enough to give an example of a
large desktop app written in sqlalchemy (even better if it's using
PyQt for the gui).  We're pondering the viability of such a project in
python.  In particular, we do a fair bit of document logic client side
with several hundred line invoice documents which we wish to edit as a
whole locally and send back to the server on an explicit user save
command.  This is something which I wouldn't expect to typically be
needful in a web application.

I can certainly find examples of large websites on python via django,
but desktop business applications are a bit harder to come by.  I
believe that eric4 is a good example but I was hoping for a largish
project involving sqlalchemy as well.

Thanks,
Joel

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.