Re: [sqlalchemy] [ANN] SQLTap - SQL profiling and introspection for SQLAlchemy applications
It's nice. On Wed, Mar 12, 2014 at 8:28 AM, Alan Shreve a...@inconshreveable.comwrote: Not out of the box, but it would be pretty easy to dump them all into sqllite or another other sql database and query them out when you want a report. And a little extra logic to not profile those queries so you don't recurse infinitely. Would love a patch! With sqlalchemy, it's pretty easy to make it database-agnostic too =) On Mar 10, 2014, at 6:29 AM, Thierry Florac tflo...@gmail.com wrote: That sounds really great. Simple question : is there any way to use SQLTap in a multi-processes WSGI environment ?? Best regards, Thierry 2014-03-10 5:28 GMT+01:00 Michael Bayer mike...@zzzcomputing.com: hey that looks pretty nice, ill give it a shoutout. On Mar 9, 2014, at 9:21 PM, Alan Shreve a...@inconshreveable.com wrote: A few years ago, I built SQLTap, a simple library to hook into SQLAlchemy and pull out statistics and information on the queries you ran. This last couple days I've overhauled it an updated it to make it more useful! You basically just start the profiler and then it can dump out nice browsable HTML reports like this: http://sqltap.inconshreveable.com/_images/sqltap-report-example.png SQLTap helps you answer questions like: What queries is my application running? How long do they take on average? At maximum? At minimum? At median? What sequences of function calls lead to each invocation of a query? Where in my source code is the query executed? The latest updates and improvements make up sqltap version 0.3 and include: - The report now has a sexy new HTML UI based on bootstrap3. - You can add sqltap to any WSGI application and get a live, updating dashboard of all the queries going through an application. - The WSGI integration has controls to enable/disable the profiling at any time so you can even include it in production applications for selective profiling. - The library's API is now greatly improved, allowing you to do your own real-time collection of statistics as well as allowing you to create individual profilers for different engines instead of forcing a global profiler. - Updated/improved documentation Install with: pip install sqltap And in your code: import sqltap profiler = sqltap.start() # sometime later after queries have been run sqltap.report(profiler.collect(), report.html) Links for reference: Code and some documentation (star it!): https://github.com/inconshreveable/sqltap Documentation: http://sqltap.inconshreveable.com/ On PyPI: https://pypi.python.org/pypi/sqltap Enjoy! - alan -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout. -- http://www.imagesdusport.com -- http://www.ztfy.org -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout. -- I like python! UliPad The Python Editor: http://code.google.com/p/ulipad/ UliWeb simple web framework: https://github.com/limodou/uliweb My Blog: http://my.oschina.net/limodou -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.
Re: [sqlalchemy] SQLAlchemy 0.9.1 released
“WHERE NULL” is not valid, that’s true; hence neither is select.where(None) anymore, which is what would happen above if “conditions” were empty (and if conditions is guaranteed not empty, you could say “cond = conditions[0]; for c in conditions[1:]:…” ) The change includes that it’s safe to use “true()” explicitly and it will be folded in (i.e. not rendered) when used with “AND”. Some people were doing the above pattern that way anyway, now that way works on all backends. in any case it’s better to use and_(): cond = and_(*conditions) it’s less code and way fewer method calls internally. Also when you have “cond = c cond”, you end up with a structure like a (b (c (d e)))” which eventually will cause a recursion overflow when parsed, if there’s too many conditions. I think there are two things here: 1. Should None be converted to NULL when deal with condition None or and_(condition, None) 2. How to combine multiple condition into one condition with and_ And I think the second question should be resolved by application itself, we just need to obey some good guide, that's ok. But for the first question, the old style I think None's behavior just like true(), but in 0.9.x, is not. So this makes the uncompatible process. Here is a test for 0.9.1: print and_('id=3', None) id=3 AND NULL print and_('id=3', '') id=3 print and_('id=3', true()) id=3 So empty string is the same as true(), and why empty string can be treated as true() but None is treated as NULL? Commonly, python will treat None, empty string are false boolean value, but here sqlalchemy does do like that obviousely. -- I like python! UliPad The Python Editor: http://code.google.com/p/ulipad/ UliWeb simple web framework: https://github.com/limodou/uliweb My Blog: http://my.oschina.net/limodou -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/groups/opt_out.
Re: [sqlalchemy] SQLAlchemy 0.9.1 released
On Thu, Jan 9, 2014 at 12:20 AM, Michael Bayer mike...@zzzcomputing.comwrote: On Jan 8, 2014, at 7:54 AM, limodou limo...@gmail.com wrote: I think there are two things here: 1. Should None be converted to NULL when deal with condition None or and_(condition, None) 2. How to combine multiple condition into one condition with and_ And I think the second question should be resolved by application itself, we just need to obey some good guide, that's ok. But for the first question, the old style I think None's behavior just like true(), but in 0.9.x, is not. So this makes the uncompatible process. Here is a test for 0.9.1: print and_('id=3', None) id=3 AND NULL print and_('id=3', '') id=3 print and_('id=3', true()) id=3 So empty string is the same as true(), and why empty string can be treated as true() but None is treated as NULL? Commonly, python will treat None, empty string are false boolean value, but here sqlalchemy does do like that obviously. Here is a sample script using the code you gave. Your code is equally broken in both 0.8 and 0.9, as if the list of conditions is empty, the same SELECT is produced on both versions both of which are invalid with “WHERE NULL”: from sqlalchemy.sql import select, column def my_select(conditions): cond = None for c in conditions: cond = c cond return select([column('x')]).where(cond) print my_select([]) 0.8.4: SELECT x WHERE NULL 0.9.1: SELECT x WHERE NULL But I'm not talking about empty condition, but condition None. In application, I can test if the condition is None and don't execute sql at all. Therefore, your script cannot work in either 0.8 or 0.9, unless you fix it as follows, in which case it works the same in both versions: def my_select(conditions): cond = conditions[0] for c in conditions[1:]: cond = c cond stmt = select([column(‘x’)]) if cond is not None: stmt = stmt.where(cond) return stmt or you assume that “conditions” is non-empty, in which case, as I mentioned earlier, do this: def my_select(conditions): cond = conditions[0] for c in conditions[1:]: cond = c cond return select([column('x')]).where(cond) or preferably, just say and_(*conditions). This thing is about how to deal with condition combination, if there is None value, above code is still not right. So the correct code maybe need add some test like if c is None:. And my point is not mainly about how to write correct condition combine, but the which the right way to convert None. as for interpreting None as NULL, None has always been treated as NULL in a SQL expression context - it is treated as NULL when used as a WHERE condition by itself and it is treated as NULL when used in a comparison. 0.8 is inconsistent that it is not treated as NULL when it happens to be part of an AND: Yes, I saw the code about 0.8.X and 0.9.1, the None convertion are the same. But difference between them is in AND process. So this inconsistent that you mean it's a bug in 0.8? from sqlalchemy.sql import select, column, literal c = column('x') print select([c]).where(c == 5) # 0.8 / 0.9: SELECT x WHERE x = :x_1 print select([c]).where(c == None) # 0.8 / 0.9: SELECT x WHERE x IS NULL print select([c]).where(5”) # 0.8 / 0.9: SELECT x WHERE 5 print select([c]).where(None) # 0.8 / 0.9: SELECT x WHERE NULL print select([c]).where((c == 5) 5”) # 0.8 / 0.9: SELECT x WHERE x = :x_1 AND 5 print select([c]).where((c == 5) None) # 0.8: SELECT x WHERE x = :x_1 # 0.9: SELECT x WHERE x = :x_1 AND NULL The only thing that might be more appropriate than coercing where(None) and where(x None) into NULL would be raising an error - because in fact where(x) and where(expr x) already throws an exception if x is not a SQL expression, string, or None/True/False (on both): I think raise exception maybe better, so that it'll let user to know what wrong with the condition. Otherwise some code like condition None can run in 0.8.X very well, but in 0.9 it'll only return nothing without any error thrown at all. It will break the old code. print select([c]).where(5) # 0.8 / 0.9 - raises exception print select([c]).where(c 5) # 0.8 / 0.9 - raises exception None also doesn’t act like true() in 0.8: print select([c]).where(true()) # 0.8: SELECT x WHERE true print select([c]).where(None) # 0.8: SELECT x WHERE NULL so overall, this change is mentioned in the “Migration Guide” exactly because it is in fact a behavioral change. You can argue it should be listed under “Core Behavioral Changes” instead of “Behavioral Improvements” and I wouldn’t have much issue with that, it is just listed under “Improvements” because it doesn’t change the behavior of code that’s written correctly in the first place. Or the doc add the inconsistant about condition None maybe the better. Thank you very much. -- I like python
Re: [sqlalchemy] Re: SQLAlchemy 0.9.1 released
I found a problem in 0.9.1 version: in 0.8.x : print (Blog.c.id==5) None blog.id = :id_1 But in 0.9.1: print (Blog.c.id==5) None blog.id = :id_1 AND NULL So I don't know if it's a bug? On Tue, Jan 7, 2014 at 2:25 AM, Jonathan Vanasco jonat...@findmeon.comwrote: automap sounds neat! thanks! -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/groups/opt_out. -- I like python! UliPad The Python Editor: http://code.google.com/p/ulipad/ UliWeb simple web framework: https://github.com/limodou/uliweb My Blog: http://my.oschina.net/limodou -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/groups/opt_out.
Re: [sqlalchemy] SQLAlchemy 0.9.1 released
But I don't know why make this decision. Because where NULL will get nothing. And in 0.8.X version, I need to combine multiple condition according user input to one condition, so my code just like: cond = None for c in conditions: cond = c cond So in 0.9.X, the result will be something like: WHERE todo.id = 1 AND NULL, so I got nothing. Above code is totally wrong in 0.9.X. And I think maybe the old way makes sence. On Tue, Jan 7, 2014 at 10:42 PM, Michael Bayer mike...@zzzcomputing.comwrote: that’s this: http://docs.sqlalchemy.org/en/rel_0_9/changelog/migration_09.html#improved-rendering-of-boolean-constants-null-constants-conjunctions On Jan 7, 2014, at 4:13 AM, limodou limo...@gmail.com wrote: I found a problem in 0.9.1 version: in 0.8.x : print (Blog.c.id http://blog.c.id/==5) None blog.id = :id_1 But in 0.9.1: print (Blog.c.id http://blog.c.id/==5) None blog.id = :id_1 AND NULL So I don't know if it's a bug? On Tue, Jan 7, 2014 at 2:25 AM, Jonathan Vanasco jonat...@findmeon.comwrote: automap sounds neat! thanks! -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/groups/opt_out. -- I like python! UliPad The Python Editor: http://code.google.com/p/ulipad/ UliWeb simple web framework: https://github.com/limodou/uliweb My Blog: http://my.oschina.net/limodou -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/groups/opt_out. -- I like python! UliPad The Python Editor: http://code.google.com/p/ulipad/ UliWeb simple web framework: https://github.com/limodou/uliweb My Blog: http://my.oschina.net/limodou -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/groups/opt_out.
Re: [sqlalchemy] SQLAlchemy 0.9.1 released
On Wed, Jan 8, 2014 at 3:31 PM, Wichert Akkerman wich...@wiggy.net wrote: On 08 Jan 2014, at 01:26, limodou limo...@gmail.com wrote: But I don't know why make this decision. Because where NULL will get nothing. And in 0.8.X version, I need to combine multiple condition according user input to one condition, so my code just like: cond = None for c in conditions: cond = c cond Why don’t you change the initial value to true() instead of None? If I read the documentation correctly that should work correctly in both SQLAlchemy versions. Even cond='' is correctly also, but I just think NULL is not a valid condition expression in SQL, so I think the old appoach maybe better. -- I like python! UliPad The Python Editor: http://code.google.com/p/ulipad/ UliWeb simple web framework: https://github.com/limodou/uliweb My Blog: http://my.oschina.net/limodou -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/groups/opt_out.
Re: [sqlalchemy] CreateTable display is not right for autoincrement in mysql
Thank you very much. This fixes my problem. So it's not a bug? On Sat, Oct 5, 2013 at 2:17 PM, Michael Bayer mike...@zzzcomputing.comwrote: On Oct 5, 2013, at 1:58 AM, limodou limo...@gmail.com wrote: Today I found if I have an id column in a table, and the autoincrement attribute is True, when I created the table it's right, but when I print the create statment is not right for autoincrement. The testing code is: from sqlalchemy import * from sqlalchemy.schema import CreateTable engine = create_engine('mysql://root:root@localhost/test', echo=True) metadata = MetaData() t = Table('mytable', metadata, Column('gid', Integer, primary_key=True, autoincrement=True), Column('id', Integer, primary_key=True) ) metadata.create_all(engine) print CreateTable(t) do the create table like this: print CreateTable(t).compile(dialect=engine.dialect) And the result is: 2013-10-05 12:59:54,523 INFO sqlalchemy.engine.base.Engine SELECT DATABASE() 2013-10-05 12:59:54,523 INFO sqlalchemy.engine.base.Engine () 2013-10-05 12:59:54,526 INFO sqlalchemy.engine.base.Engine SHOW VARIABLES LIKE 'character_set%%' 2013-10-05 12:59:54,526 INFO sqlalchemy.engine.base.Engine () 2013-10-05 12:59:54,526 INFO sqlalchemy.engine.base.Engine SHOW VARIABLES LIKE 'sql_mode' 2013-10-05 12:59:54,528 INFO sqlalchemy.engine.base.Engine () 2013-10-05 12:59:54,538 INFO sqlalchemy.engine.base.Engine DESCRIBE `mytable` 2013-10-05 12:59:54,538 INFO sqlalchemy.engine.base.Engine () 2013-10-05 12:59:54,552 INFO sqlalchemy.engine.base.Engine ROLLBACK 2013-10-05 12:59:54,575 INFO sqlalchemy.engine.base.Engine CREATE TABLE mytable ( gid INTEGER NOT NULL AUTO_INCREMENT, id INTEGER NOT NULL, PRIMARY KEY (gid, id) ) 2013-10-05 12:59:54,575 INFO sqlalchemy.engine.base.Engine () 2013-10-05 12:59:55,332 INFO sqlalchemy.engine.base.Engine COMMIT CREATE TABLE mytable ( gid INTEGER NOT NULL, id INTEGER NOT NULL, PRIMARY KEY (gid, id) ) So the above is right, and it's gid INTEGER NOT NULL AUTO_INCREMENT, but the next is not right, it losts AUTO_INCREMENT. I tried to check the code and I found the implementation of dialects/sql/mysql/base.py:get_column_specification(1408) is not like sql/compiler.py:get_column_specification(2021). I think maybe is a bug. BTW, my salalchemy version is 8.0. -- I like python! UliPad The Python Editor: http://code.google.com/p/ulipad/ UliWeb simple web framework: https://github.com/limodou/uliweb My Blog: http://my.oschina.net/limodou -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/groups/opt_out. -- I like python! UliPad The Python Editor: http://code.google.com/p/ulipad/ UliWeb simple web framework: https://github.com/limodou/uliweb My Blog: http://my.oschina.net/limodou -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/groups/opt_out.
[sqlalchemy] CreateTable display is not right for autoincrement in mysql
Today I found if I have an id column in a table, and the autoincrement attribute is True, when I created the table it's right, but when I print the create statment is not right for autoincrement. The testing code is: from sqlalchemy import * from sqlalchemy.schema import CreateTable engine = create_engine('mysql://root:root@localhost/test', echo=True) metadata = MetaData() t = Table('mytable', metadata, Column('gid', Integer, primary_key=True, autoincrement=True), Column('id', Integer, primary_key=True) ) metadata.create_all(engine) print CreateTable(t) And the result is: 2013-10-05 12:59:54,523 INFO sqlalchemy.engine.base.Engine SELECT DATABASE() 2013-10-05 12:59:54,523 INFO sqlalchemy.engine.base.Engine () 2013-10-05 12:59:54,526 INFO sqlalchemy.engine.base.Engine SHOW VARIABLES LIKE 'character_set%%' 2013-10-05 12:59:54,526 INFO sqlalchemy.engine.base.Engine () 2013-10-05 12:59:54,526 INFO sqlalchemy.engine.base.Engine SHOW VARIABLES LIKE 'sql_mode' 2013-10-05 12:59:54,528 INFO sqlalchemy.engine.base.Engine () 2013-10-05 12:59:54,538 INFO sqlalchemy.engine.base.Engine DESCRIBE `mytable` 2013-10-05 12:59:54,538 INFO sqlalchemy.engine.base.Engine () 2013-10-05 12:59:54,552 INFO sqlalchemy.engine.base.Engine ROLLBACK 2013-10-05 12:59:54,575 INFO sqlalchemy.engine.base.Engine CREATE TABLE mytable ( gid INTEGER NOT NULL AUTO_INCREMENT, id INTEGER NOT NULL, PRIMARY KEY (gid, id) ) 2013-10-05 12:59:54,575 INFO sqlalchemy.engine.base.Engine () 2013-10-05 12:59:55,332 INFO sqlalchemy.engine.base.Engine COMMIT CREATE TABLE mytable ( gid INTEGER NOT NULL, id INTEGER NOT NULL, PRIMARY KEY (gid, id) ) So the above is right, and it's gid INTEGER NOT NULL AUTO_INCREMENT, but the next is not right, it losts AUTO_INCREMENT. I tried to check the code and I found the implementation of dialects/sql/mysql/base.py:get_column_specification(1408) is not like sql/compiler.py:get_column_specification(2021). I think maybe is a bug. BTW, my salalchemy version is 8.0. -- I like python! UliPad The Python Editor: http://code.google.com/p/ulipad/ UliWeb simple web framework: https://github.com/limodou/uliweb My Blog: http://my.oschina.net/limodou -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/groups/opt_out.
[sqlalchemy] How to label const in select statement?
I have a select just like : select([User, 0]) and I don't know how to label 0 as real sql statement like this: select User.*, 0 as age; How to do that with label? Thanks. -- I like python! UliPad The Python Editor: http://code.google.com/p/ulipad/ UliWeb simple web framework: https://github.com/limodou/uliweb My Blog: http://my.oschina.net/limodou -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@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] Alembic 0.4.0 Released
On Tue, Oct 2, 2012 at 8:27 AM, Michael Bayer mike...@zzzcomputing.comwrote: Alembic 0.4.0 is now available. Alembic is the migrations tool for SQLAlchemy, including such features as minimalist script construction, autogeneration of candidate migrations, and offline script generation. Included in this release is a *big* change by Bruno Binet that adds full blown schema support to all migration operations, including autogenerate. This was a great effort on his part and I'm glad to have it in the release. Also thanks to Bryce Lohr for fixes to the multidb template which had fallen into disrepair, and Moriyoshi Koizumi for some nicely done MySQL related fixes. Alembic is available for download up on the cheeseshop at http://pypi.python.org/pypi/alembic/ 0.4.0 = - [feature] Support for tables in alternate schemas has been added fully to all operations, as well as to the autogenerate feature. When using autogenerate, specifying the flag include_schemas=True to Environment.configure() will also cause autogenerate to scan all schemas located by Inspector.get_schema_names(), which is supported by *some* (but not all) SQLAlchemy dialects including Postgresql. *Enormous* thanks to Bruno Binet for a huge effort in implementing as well as writing tests. #33. - [feature] The command line runner has been organized into a reusable CommandLine object, so that other front-ends can re-use the argument parsing built in. #70 - [feature] Added stdout option to Config, provides control over where the print output of commands like history, init, current etc. are sent. #43 - [bug] Fixed the multidb template which was badly out of date. It now generates revision files using the configuration to determine the different upgrade_xyz() methods needed as well, instead of needing to hardcode these. Huge thanks to BryceLohr for doing the heavy lifting here. #71 - [bug] Fixed the regexp that was checking for .py files in the version directory to allow any .py file through. Previously it was doing some kind of defensive checking, probably from some early notions of how this directory works, that was prohibiting various filename patterns such as those which begin with numbers. #72 - [bug] Fixed MySQL rendering for server_default which didn't work if the server_default was a generated SQL expression. Courtesy Moriyoshi Koizumi. - [feature] Added support for alteration of MySQL columns that have AUTO_INCREMENT, as well as enabling this flag. Courtesy Moriyoshi Koizumi. Thanks a lot, alembic is very useful for me. -- I like python! UliPad The Python Editor: http://code.google.com/p/ulipad/ UliWeb simple web framework: https://github.com/limodou/uliweb My Blog: http://my.oschina.net/limodou -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@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] Thread local connection garbage collection problem
On Wed, May 23, 2012 at 10:35 PM, Michael Bayer mike...@zzzcomputing.com wrote: There's some cleanup code inside of weakref callbacks which has been improved in 0.7 to not complain about unavoidable exceptions during Python's teardown of object state. Oh, I see. Thanks. -- I like python! UliPad The Python Editor: http://code.google.com/p/ulipad/ UliWeb simple web framework: http://code.google.com/p/uliweb/ My Blog: http://hi.baidu.com/limodou -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@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] Wired connection problem
On Thu, May 17, 2012 at 8:59 PM, Michael Bayer mike...@zzzcomputing.com wrote: On May 16, 2012, at 8:33 PM, limodou wrote: On Thu, May 17, 2012 at 8:03 AM, limodou limo...@gmail.com wrote: On Thu, May 17, 2012 at 7:46 AM, Michael Bayer mike...@zzzcomputing.com wrote: On May 16, 2012, at 7:32 PM, limodou wrote: OK you need to use two different connections here, for the read from one connection, persist on another in a short transaction pattern. Again the with engine.begin() thing, which is new as of 0.7...6? makes this pretty succinct: while True: with engine.begin() as conn: for row in conn.execute(select...): with engine.begin() as c2: c2.execute(update...) sleep(...) Ok, I see. And the last word, is there a way to disable the accumulation of transactional state? depending on backend and DBAPI there are ways to decrease the transaction isolation level. SQLA has a create_engine() parameter isolation_level understood by Postgresql, MySQL, and SQLite so far, for example. The docs seem to be partially missing at the moment, so accepted values are 'SERIALIZABLE', 'READ UNCOMMITTED', 'READ COMMITTED', 'REPEATABLE READ'. Different backends may interpret these differently - PG for example has ultimately only two effective isolation levels. These levels can also be affected per-connection using connection.execution_options(isolation_level='...'). So there's that, then there's just returning the connection to the pool/ rolling back as needed. Ok, I'll try it. Thanks a lot. I tried like this: engine = create_engine() conn = engine.connect() while True: conn.execution_options(isolation_level='REPEATABLE READ') for row in conn.execute(select(...)): conn.execute(update(...)) So I reset the conn isolation level each time. And it does the work if there is new changed records later after fetching empty result. But I can't find a way to display isolation level of a connection or engine, I just know how to set it. So how to display the exactly isolation level of each sql statement execution? Is there a function to do that? So I think I can reuse the same connection if I can reset the isolation level. uh yeah I don't know that there's a consistent way to do that, you'd need to execute() a statement against the database which shows the current isolation level. This varies depending on which DB you're using, I'd google their docs for that. might be worthwhile just to keep track of it. Thank you very much. -- I like python! UliPad The Python Editor: http://code.google.com/p/ulipad/ UliWeb simple web framework: http://code.google.com/p/uliweb/ My Blog: http://hi.baidu.com/limodou -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@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] Wired connection problem
On Wed, May 16, 2012 at 9:42 PM, Michael Bayer mike...@zzzcomputing.com wrote: On May 15, 2012, at 8:13 PM, limodou wrote: Recently I found a wired problem in my application, something like this: I have a long time deamon program, it'll be an infinite loop, just like: engine = create_engine('...') conn = engine.connect() while True: for row in select: update sleep(xxx) In the loop, I create conn at first, and then reuse it in the loop. If there is data in database, it'll fetch all matched records and update the flag, then do the next loop. So if there is no matched records, it'll just sleep and do nothing. The problem is, because I used the shared connection object, so if there is no matched records for a while, and even I changed the database to make some records, it'll not fetch the records at all. And if I restart the program it'll get them at the first time, then if I changed the database, it'll not fetch the records again. But If I put the conn creation in the loop, it seems everything is ok. And if I tried to use strategy='threadlocal', and get the conn like: conn = engine.contextual_connect(), even I put this line in the loop, the problem is still existed. So I don't know if someone else has faced the same problem like me? I don't know if I need to recreate connection every time in the loop? if you hold on to conn, transactional state will accumulate as you do things like SELECT on it, that is, if there is a high degree of transaction isolation in effect, a subsequent SELECT of the same criteria on the same connection may not indicate changes which have occurred in other concurrent transactions. When you say conn.close(), the underlying DBAPI resources are rolled back, which will revert transactional state, and the underlying DBAPI connection is returned to the connection pool for re-use. So you should be calling engine.connect() for each series of operations between the sleep. Awaking from the sleep you'd like to start with fresh transactional state. The easiest pattern here would be: while True: with engine.begin() as conn: for row in conn.execute(...): conn.execute(update...) sleep(...) also I'd avoid using the threadlocal strategy and also definitely don't share a connection with any other threads. connections are best used locally, quickly, and atomically across a group of related operations. Thank you for the detail explains. And I tried like this again: 1. if there are only select statements it will ok, and the select statements will fetch the new changed records. 2. select after update, if there is no record at some point, it'll not fetch the new changed records in the later loop, just like what you said the state is hold. So in my application, I need to do like: while True: for row in select(xxx): update() And I want to keep each update has seperate transaction, maybe like this: while True: conn = engine.connect() for row in conn.execute(select(xxx)): trans = conn.begin() conn.execute(update()) trans.commit() But above code is not right, I should put the transaction out of the loop just like what you written. So I want to know what is the suit appoach of keeping each update has seperate transaction? Should I use nested transaction? -- I like python! UliPad The Python Editor: http://code.google.com/p/ulipad/ UliWeb simple web framework: http://code.google.com/p/uliweb/ My Blog: http://hi.baidu.com/limodou -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@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] Wired connection problem
On Wed, May 16, 2012 at 11:27 PM, Michael Bayer mike...@zzzcomputing.com wrote: On May 16, 2012, at 11:11 AM, limodou wrote: Thank you for the detail explains. And I tried like this again: 1. if there are only select statements it will ok, and the select statements will fetch the new changed records. 2. select after update, if there is no record at some point, it'll not fetch the new changed records in the later loop, just like what you said the state is hold. So in my application, I need to do like: while True: for row in select(xxx): update() And I want to keep each update has seperate transaction, maybe like this: while True: conn = engine.connect() for row in conn.execute(select(xxx)): trans = conn.begin() conn.execute(update()) trans.commit() But above code is not right, I should put the transaction out of the loop just like what you written. So I want to know what is the suit appoach of keeping each update has seperate transaction? Should I use nested transaction? OK you need to use two different connections here, for the read from one connection, persist on another in a short transaction pattern. Again the with engine.begin() thing, which is new as of 0.7...6? makes this pretty succinct: while True: with engine.begin() as conn: for row in conn.execute(select...): with engine.begin() as c2: c2.execute(update...) sleep(...) Ok, I see. And the last word, is there a way to disable the accumulation of transactional state? Thank you very much. -- I like python! UliPad The Python Editor: http://code.google.com/p/ulipad/ UliWeb simple web framework: http://code.google.com/p/uliweb/ My Blog: http://hi.baidu.com/limodou -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@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] Wired connection problem
On Thu, May 17, 2012 at 7:46 AM, Michael Bayer mike...@zzzcomputing.com wrote: On May 16, 2012, at 7:32 PM, limodou wrote: OK you need to use two different connections here, for the read from one connection, persist on another in a short transaction pattern. Again the with engine.begin() thing, which is new as of 0.7...6? makes this pretty succinct: while True: with engine.begin() as conn: for row in conn.execute(select...): with engine.begin() as c2: c2.execute(update...) sleep(...) Ok, I see. And the last word, is there a way to disable the accumulation of transactional state? depending on backend and DBAPI there are ways to decrease the transaction isolation level. SQLA has a create_engine() parameter isolation_level understood by Postgresql, MySQL, and SQLite so far, for example. The docs seem to be partially missing at the moment, so accepted values are 'SERIALIZABLE', 'READ UNCOMMITTED', 'READ COMMITTED', 'REPEATABLE READ'. Different backends may interpret these differently - PG for example has ultimately only two effective isolation levels. These levels can also be affected per-connection using connection.execution_options(isolation_level='...'). So there's that, then there's just returning the connection to the pool/ rolling back as needed. Ok, I'll try it. Thanks a lot. -- I like python! UliPad The Python Editor: http://code.google.com/p/ulipad/ UliWeb simple web framework: http://code.google.com/p/uliweb/ My Blog: http://hi.baidu.com/limodou -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@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] Wired connection problem
On Thu, May 17, 2012 at 8:03 AM, limodou limo...@gmail.com wrote: On Thu, May 17, 2012 at 7:46 AM, Michael Bayer mike...@zzzcomputing.com wrote: On May 16, 2012, at 7:32 PM, limodou wrote: OK you need to use two different connections here, for the read from one connection, persist on another in a short transaction pattern. Again the with engine.begin() thing, which is new as of 0.7...6? makes this pretty succinct: while True: with engine.begin() as conn: for row in conn.execute(select...): with engine.begin() as c2: c2.execute(update...) sleep(...) Ok, I see. And the last word, is there a way to disable the accumulation of transactional state? depending on backend and DBAPI there are ways to decrease the transaction isolation level. SQLA has a create_engine() parameter isolation_level understood by Postgresql, MySQL, and SQLite so far, for example. The docs seem to be partially missing at the moment, so accepted values are 'SERIALIZABLE', 'READ UNCOMMITTED', 'READ COMMITTED', 'REPEATABLE READ'. Different backends may interpret these differently - PG for example has ultimately only two effective isolation levels. These levels can also be affected per-connection using connection.execution_options(isolation_level='...'). So there's that, then there's just returning the connection to the pool/ rolling back as needed. Ok, I'll try it. Thanks a lot. I tried like this: engine = create_engine() conn = engine.connect() while True: conn.execution_options(isolation_level='REPEATABLE READ') for row in conn.execute(select(...)): conn.execute(update(...)) So I reset the conn isolation level each time. And it does the work if there is new changed records later after fetching empty result. But I can't find a way to display isolation level of a connection or engine, I just know how to set it. So how to display the exactly isolation level of each sql statement execution? Is there a function to do that? So I think I can reuse the same connection if I can reset the isolation level. -- I like python! UliPad The Python Editor: http://code.google.com/p/ulipad/ UliWeb simple web framework: http://code.google.com/p/uliweb/ My Blog: http://hi.baidu.com/limodou -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@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] Wired connection problem
Recently I found a wired problem in my application, something like this: I have a long time deamon program, it'll be an infinite loop, just like: engine = create_engine('...') conn = engine.connect() while True: for row in select: update sleep(xxx) In the loop, I create conn at first, and then reuse it in the loop. If there is data in database, it'll fetch all matched records and update the flag, then do the next loop. So if there is no matched records, it'll just sleep and do nothing. The problem is, because I used the shared connection object, so if there is no matched records for a while, and even I changed the database to make some records, it'll not fetch the records at all. And if I restart the program it'll get them at the first time, then if I changed the database, it'll not fetch the records again. But If I put the conn creation in the loop, it seems everything is ok. And if I tried to use strategy='threadlocal', and get the conn like: conn = engine.contextual_connect(), even I put this line in the loop, the problem is still existed. So I don't know if someone else has faced the same problem like me? I don't know if I need to recreate connection every time in the loop? -- I like python! UliPad The Python Editor: http://code.google.com/p/ulipad/ UliWeb simple web framework: http://code.google.com/p/uliweb/ My Blog: http://hi.baidu.com/limodou -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@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] Does alembic support multiple databases?
I can't find how to enable alembic support multiple databases. -- I like python! UliPad The Python Editor: http://code.google.com/p/ulipad/ UliWeb simple web framework: http://code.google.com/p/uliweb/ My Blog: http://hi.baidu.com/limodou -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@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] Does alembic support multiple databases?
On Sun, Apr 29, 2012 at 10:42 PM, Michael Bayer mike...@zzzcomputing.com wrote: You would assemble a multi-database scheme of your choosing in env.py. If you do alembic init multidb you'll see an example of one. How env.py is organized depends greatly on the relationship of the databases to each other, that is, to what degree they are mirrors of each other versus storing different schemas. If I ran the command: alembic init multidb It'll create multidb folder and copy files in it. But I saw the alembic.ini will be the same one. So if I should change it myself? And how to let alembic know different database when executing commands like: revision, upgrade, etc. It seems that no database parameter existed. And if I can manage different databases in one directory or in one ini file? -- I like python! UliPad The Python Editor: http://code.google.com/p/ulipad/ UliWeb simple web framework: http://code.google.com/p/uliweb/ My Blog: http://hi.baidu.com/limodou -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@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] Does alembic support multiple databases?
On Sun, Apr 29, 2012 at 10:56 PM, limodou limo...@gmail.com wrote: On Sun, Apr 29, 2012 at 10:42 PM, Michael Bayer mike...@zzzcomputing.com wrote: You would assemble a multi-database scheme of your choosing in env.py. If you do alembic init multidb you'll see an example of one. How env.py is organized depends greatly on the relationship of the databases to each other, that is, to what degree they are mirrors of each other versus storing different schemas. If I ran the command: alembic init multidb It'll create multidb folder and copy files in it. But I saw the alembic.ini will be the same one. So if I should change it myself? And how to let alembic know different database when executing commands like: revision, upgrade, etc. It seems that no database parameter existed. And if I can manage different databases in one directory or in one ini file? BTW, I manage different databases in different directory now. -- I like python! UliPad The Python Editor: http://code.google.com/p/ulipad/ UliWeb simple web framework: http://code.google.com/p/uliweb/ My Blog: http://hi.baidu.com/limodou -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@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] Does alembic support multiple databases?
On Sun, Apr 29, 2012 at 11:13 PM, Michael Bayer mike...@zzzcomputing.com wrote: On Apr 29, 2012, at 10:56 AM, limodou wrote: On Sun, Apr 29, 2012 at 10:42 PM, Michael Bayer mike...@zzzcomputing.com wrote: You would assemble a multi-database scheme of your choosing in env.py. If you do alembic init multidb you'll see an example of one. How env.py is organized depends greatly on the relationship of the databases to each other, that is, to what degree they are mirrors of each other versus storing different schemas. If I ran the command: alembic init multidb It'll create multidb folder and copy files in it. But I saw the alembic.ini will be the same one. So if I should change it myself? And how to let alembic know different database when executing commands like: revision, upgrade, etc. It seems that no database parameter existed. And if I can manage different databases in one directory or in one ini file? multidb has a different alembic.ini as an example. If you already had an alembic.ini there it wouldn't overwrite it. if you really wanted two completely independent sets of migration scripts, then you'd run two migration environments. They can share the same alembic.ini like this: [my_db_one] sqlalchemy.url = [my_db_two] sqlalchemy.url = you then run alembic with alembic -n my_db_one or alembic -n my_db_two. The default config area is set by -n. A single env.py script can get multiple database URLs in any way it wants, as it determines how config is accessed. If you look in the multidb/env.py script, you'll see it's pulling multiple database urls from one section using config.get_section(name) - config file: [alembic] # path to migration scripts script_location = ${script_location} # template used to generate migration files # file_template = %%(rev)s_%%(slug)s databases = engine1, engine2 [engine1] sqlalchemy.url = driver://user:pass@localhost/dbname [engine2] sqlalchemy.url = driver://user:pass@localhost/dbname2 usage: config = context.config db_names = config.get_main_option('databases') for name in re.split(r',\s*', db_names): engines[name] = rec = {} rec['engine'] = engine_from_config( config.get_section(name), prefix='sqlalchemy.', poolclass=pool.NullPool) Over here I have both forms of multi db at the same time. There's two migration environments, and one migration environment does two databases that are largely mirrored, so three databases total. All three make use of a common env.py script that's in my application as a library, they then implement an env.py in the migration environment that draws upon the myapp/lib/env.py script for common features. You can pass instructions to a single env.py that may be controlling multiple databases using --tag: alembic --tag my_tag my_tag is available in env.py as context.get_tag_argument(). You can use that to conditionally run migrations on one database or the other. This is all DIY. Multi-database migrations can happen in many different ways so you'd need to build the approach that suits your situation best. thank you very much. -- I like python! UliPad The Python Editor: http://code.google.com/p/ulipad/ UliWeb simple web framework: http://code.google.com/p/uliweb/ My Blog: http://hi.baidu.com/limodou -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@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] About alembic alter column problem
I'm using alembic today, and I found a problem, if I changed the column, it'll automatically create add and drop statment, just like this: op.add_column('bas_grp_user', sa.Column('username', sa.Integer(), nullable=False)) op.drop_column('bas_grp_user', u'USERNAME') But when I ran the upgrade I got: sqlalchemy.exc.OperationalError: (OperationalError) (1060, Duplicate column name 'username') 'ALTER TABLE bas_grp_user ADD COLUMN username INTEGER NOT NULL' () so the problem is that the table is already exists in my database, so when it excute the first statement it'll be fail. So I think drop should be put in front of add. -- I like python! UliPad The Python Editor: http://code.google.com/p/ulipad/ UliWeb simple web framework: http://code.google.com/p/uliweb/ My Blog: http://hi.baidu.com/limodou -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@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: About alembic alter column problem
I also have other requirements: 1. if there is no changes should it can create nothing, not like this: def upgrade(): ### commands auto generated by Alembic - please adjust! ### pass ### end Alembic commands ### def downgrade(): ### commands auto generated by Alembic - please adjust! ### pass ### end Alembic commands ### 2. If I can merge the current changes into head revision, before I execute upgrade, so that I can combine several changes into one change. For me, I think just remove the head revision, and recreate new one that's ok. And only problem I think is that : if the user has manually changed the revision file, the changes will be lost. -- I like python! UliPad The Python Editor: http://code.google.com/p/ulipad/ UliWeb simple web framework: http://code.google.com/p/uliweb/ My Blog: http://hi.baidu.com/limodou -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@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] About alembic alter column problem
On Thu, Apr 12, 2012 at 10:37 PM, Michael Bayer mike...@zzzcomputing.com wrote: On Apr 12, 2012, at 4:07 AM, limodou wrote: I'm using alembic today, and I found a problem, if I changed the column, it'll automatically create add and drop statment, just like this: op.add_column('bas_grp_user', sa.Column('username', sa.Integer(), nullable=False)) op.drop_column('bas_grp_user', u'USERNAME') But when I ran the upgrade I got: sqlalchemy.exc.OperationalError: (OperationalError) (1060, Duplicate column name 'username') 'ALTER TABLE bas_grp_user ADD COLUMN username INTEGER NOT NULL' () this is a column name change - per the documentation, Alembic can't detect these and you need to manually change it to an alter_column(). In this case, there seems to be an odd casing change where the DB is reporting the name as USERNAME in all caps (usually this is oracle or firebird, though alembic should be normalizing these to lowercase) - but then the database can't distinguish between USERNAME and username. If this is happening for all your columns then there might be some dialect-related issue at play. Otherwise, if you just changed the name to USERNAME in the DB with quotes then this is what you'd get. I defined the column name as USERNAME“ at first, then I changed it to username, so it is the thing I want to change. I know the doc says it can't detect the column rename, but I think if alembic can put drop statement before add statement, it'll ok for this situation. What do you think? -- I like python! UliPad The Python Editor: http://code.google.com/p/ulipad/ UliWeb simple web framework: http://code.google.com/p/uliweb/ My Blog: http://hi.baidu.com/limodou -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@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] Re: About alembic alter column problem
On Thu, Apr 12, 2012 at 10:39 PM, Michael Bayer mike...@zzzcomputing.com wrote: On Apr 12, 2012, at 4:18 AM, limodou wrote: I also have other requirements: 1. if there is no changes should it can create nothing, not like this: def upgrade(): ### commands auto generated by Alembic - please adjust! ### pass ### end Alembic commands ### def downgrade(): ### commands auto generated by Alembic - please adjust! ### pass ### end Alembic commands ### that's what it should be doing what are you getting ? But if I changed the database later, and I want to run revision command, and it'll tell me the datebase is not up to date. So I must run upgrade even though that will no effect at all. So I think it's tedious. So I think if there is no change at all, why not just say The database is up to date, and don't create any revision file at all. If is this appoach better? 2. If I can merge the current changes into head revision, before I execute upgrade, so that I can combine several changes into one change. For me, I think just remove the head revision, and recreate new one that's ok. And only problem I think is that : if the user has manually changed the revision file, the changes will be lost. right, that's a problem, so easiest here is to just delete the head file yourself and re-run autogenerate. Alembic isn't going to delete files nor is it going to merge into an existing file - the first is too much of a surprise, the second is far too complicated for this kind of tool. KISS applies So if it can be an option to let user to decide if he want to remove the head revision will be handful. User knows what they want to do. I just don't want to delete the file manually. -- I like python! UliPad The Python Editor: http://code.google.com/p/ulipad/ UliWeb simple web framework: http://code.google.com/p/uliweb/ My Blog: http://hi.baidu.com/limodou -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@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] Re: About alembic alter column problem
2. If I can merge the current changes into head revision, before I execute upgrade, so that I can combine several changes into one change. For me, I think just remove the head revision, and recreate new one that's ok. And only problem I think is that : if the user has manually changed the revision file, the changes will be lost. right, that's a problem, so easiest here is to just delete the head file yourself and re-run autogenerate. Alembic isn't going to delete files nor is it going to merge into an existing file - the first is too much of a surprise, the second is far too complicated for this kind of tool. KISS applies So if it can be an option to let user to decide if he want to remove the head revision will be handful. User knows what they want to do. I just don't want to delete the file manually. BTW, the head I said just suit for those which have not be upgraded yet. So if the head revision is already upgraded, then it'll not be deleted. And If you like I can try to make some patches for these two demands. -- I like python! UliPad The Python Editor: http://code.google.com/p/ulipad/ UliWeb simple web framework: http://code.google.com/p/uliweb/ My Blog: http://hi.baidu.com/limodou -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@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] About alembic alter column problem
On Thu, Apr 12, 2012 at 11:38 PM, Michael Bayer mike...@zzzcomputing.com wrote: On Apr 12, 2012, at 10:42 AM, limodou wrote: On Thu, Apr 12, 2012 at 10:37 PM, Michael Bayer mike...@zzzcomputing.com wrote: On Apr 12, 2012, at 4:07 AM, limodou wrote: I'm using alembic today, and I found a problem, if I changed the column, it'll automatically create add and drop statment, just like this: op.add_column('bas_grp_user', sa.Column('username', sa.Integer(), nullable=False)) op.drop_column('bas_grp_user', u'USERNAME') But when I ran the upgrade I got: sqlalchemy.exc.OperationalError: (OperationalError) (1060, Duplicate column name 'username') 'ALTER TABLE bas_grp_user ADD COLUMN username INTEGER NOT NULL' () this is a column name change - per the documentation, Alembic can't detect these and you need to manually change it to an alter_column(). In this case, there seems to be an odd casing change where the DB is reporting the name as USERNAME in all caps (usually this is oracle or firebird, though alembic should be normalizing these to lowercase) - but then the database can't distinguish between USERNAME and username. If this is happening for all your columns then there might be some dialect-related issue at play. Otherwise, if you just changed the name to USERNAME in the DB with quotes then this is what you'd get. I defined the column name as USERNAME“ at first, then I changed it to username, so it is the thing I want to change. I know the doc says it can't detect the column rename, but I think if alembic can put drop statement before add statement, it'll ok for this situation. What do you think? dropping the column then recreating it with a new name IMHO is just wrong, whether or not it works - it needs to be changed to an alter_column regardless. The two Column objects have totally different names in any case - this is a rare edge case where the two different names happen to be the same in case insensitive - so there's quirky behavior on the part of the database at play (what database is this ? I'd love to know how you got this outcome). I'm using mysql. I also thought about it, and I think you are right. But I'm in developing stage, so I can drop the whole table at all, I just want to do is that I can run the upgrade script completely, but because the order of add and drop, I can't run the script directly, and I should modify the script so that it can run successfully. I just don't want to change them by hand. Maybe there is no a good solution. -- I like python! UliPad The Python Editor: http://code.google.com/p/ulipad/ UliWeb simple web framework: http://code.google.com/p/uliweb/ My Blog: http://hi.baidu.com/limodou -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@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] Re: About alembic alter column problem
On Thu, Apr 12, 2012 at 11:52 PM, Michael Bayer mike...@zzzcomputing.com wrote: On Apr 12, 2012, at 10:50 AM, limodou wrote: On Thu, Apr 12, 2012 at 10:39 PM, Michael Bayer mike...@zzzcomputing.com wrote: On Apr 12, 2012, at 4:18 AM, limodou wrote: I also have other requirements: 1. if there is no changes should it can create nothing, not like this: def upgrade(): ### commands auto generated by Alembic - please adjust! ### pass ### end Alembic commands ### def downgrade(): ### commands auto generated by Alembic - please adjust! ### pass ### end Alembic commands ### that's what it should be doing what are you getting ? But if I changed the database later, i dont understand, changed the database - do you mean, you changed your SQLAlchemy models? or you went into the database directly and manually added things ? I just changed sqlalchemy models, but not directly change the database. and I want to run revision command, and it'll tell me the datebase is not up to date. revision with --autogenerate is comparing the current state of the database to the current SQLAlchemy metadata, so the DB has to be on the latest revision for this to work, otherwise it will repeat other migrations that are already in previous version files that haven't been run. why not say alembic upgrade head each time before you say revision --autogenerate ? Because I think the script will do nothing at all (because the created script upgrade section is empty), why it'll always keep no use scripts? Why not just keep the last upgraded script and don't create new script if there is no changes? So I must run upgrade even though that will no effect at all. I'm really not following. How is the version number in alembic_version not the same number in your version files, except that you just need to run alembic upgrade head ? But if I don't run alembic upgrade head, I can't do other things. And for a revison control system, if there are no changes at all, it'll not create any patches at all, and I think maybe this is a good way. So I think it's tedious. So I think if there is no change at all, why not just say The database is up to date, and don't create any revision file at all. If is this appoach better? --autogenerate can't detect all changes, though. if you're using the revision command, it implies you want it to create a new revision file. It would be quite annoying if I wanted to use --autogenerate to catch things in general before I add my manual migration changes, which could include changes in column type or changes in server default that Alembic by default does not detect. I know, but sometimes user want to create new revision even there is no changes, but sometime they won't I think. And if there is an option to toggle the behavior is better. So if it can be an option to let user to decide if he want to remove the head revision will be handful. User knows what they want to do. I just don't want to delete the file manually. That's asking Alembic to guess, in a dangerous way, what revision files should be deleted. Suppose I check out the latest source tree. Revision files load in, say new files with (fake) numbers 7, 8, and 9 load in. My database is at version 6. For some reason, I'm not running alembic upgrade head (why??). For example, in my case, when I made some changes and I want to test them, so I can run revision --autogenerate and upgrade the database. And then I made other changes, and do the cycle again I can do this way. But sometimes I just change the model and run revision --autogenerate and don't upgrade the database, and I also made other changes, and I want to merge two changes into one piece, so I just want to delete the lastest revision, and re autogenerate the revision. So if the alembic can delete the head revision script for me, I don't need to delete it manually. That's what I think. I forget to do all that, then I change some of my app, and say alembic revision -m 'my changes' --autogenerate --delete-everything-not-there - according to this command, alembic would need to delete *three* revision files, for 7, 8 and 9, which I haven't even looked at. Since the request is really, delete all revision files down to the most recent revision that's in the database. I can't see people really wanting that behavior without them having to check things manually first. It's a manual operation, and there's no way to automate this - therefore might as well have the user just rm the file - that's what rm is for ! But in my case, I can't create 8, 9 before I run upgrade on 7, I'm using autogenerate option, so how to create 8, 9 without upgrade on previous rerison? I can only keep on un upgraded revision in my test. -- I like python! UliPad The Python Editor: http://code.google.com/p/ulipad/ UliWeb simple web framework: http://code.google.com/p/uliweb/ My Blog: http://hi.baidu.com
Re: [sqlalchemy] Re: About alembic alter column problem
On Thu, Apr 12, 2012 at 11:59 PM, Michael Bayer mike...@zzzcomputing.com wrote: On Apr 12, 2012, at 10:54 AM, limodou wrote: 2. If I can merge the current changes into head revision, before I execute upgrade, so that I can combine several changes into one change. For me, I think just remove the head revision, and recreate new one that's ok. And only problem I think is that : if the user has manually changed the revision file, the changes will be lost. right, that's a problem, so easiest here is to just delete the head file yourself and re-run autogenerate. Alembic isn't going to delete files nor is it going to merge into an existing file - the first is too much of a surprise, the second is far too complicated for this kind of tool. KISS applies So if it can be an option to let user to decide if he want to remove the head revision will be handful. User knows what they want to do. I just don't want to delete the file manually. BTW, the head I said just suit for those which have not be upgraded yet. So if the head revision is already upgraded, then it'll not be deleted. And If you like I can try to make some patches for these two demands. here's what I can do, since I will grant that rm is inconvenient in that you have to type the path to the file: alembic rm revision will delete revision files, including a range like alembic rm 5ea:head it must include an are you sure? dialog after it emits the pathnames of the files it will delete. great, This way maybe better. -- I like python! UliPad The Python Editor: http://code.google.com/p/ulipad/ UliWeb simple web framework: http://code.google.com/p/uliweb/ My Blog: http://hi.baidu.com/limodou -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@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] Re: About alembic alter column problem
On Fri, Apr 13, 2012 at 8:48 AM, Michael Bayer mike...@zzzcomputing.com wrote: On Apr 12, 2012, at 8:07 PM, limodou wrote: For example, in my case, when I made some changes and I want to test them, so I can run revision --autogenerate and upgrade the database. And then I made other changes, and do the cycle again I can do this way. But sometimes I just change the model and run revision --autogenerate and don't upgrade the database, and I also made other changes, and I want to merge two changes into one piece, so I just want to delete the lastest revision, and re autogenerate the revision. So if the alembic can delete the head revision script for me, I don't need to delete it manually. That's what I think. i think if people wanted anything, they'd want it to append to the file that's already thereor just add another new migration file. I'd never want it to delete So this thing I think is migrate, but I thought it's harder than just delete the un upgraded scripts and re autogenerate the revision. So I think deletion is just a simple way. If there is better appoach will be better. i know what you mean, you generate the rev, then keep doing other things before running upgrade. but for that to really do what I want, autogenerate would need to keep a list of what it already autogenerated, and is still pending, then add new migrations onto that. which implies it's keeping a datafile somewhere, or in the last migration file. which starts getting too complicated, and kind of redundant. I think really, just running upgrade is the answer - you can always downgrade again to test ! if more people start complaining about this issue maybe we'll come up with something else... So I think rm command will satisfy me now. And I think autogenerate is more handful, and for simple situation, I really know what I've made and don't need autogenerate to worry about for me. So that's what I need. And so I think rm can do the work. And if the rm command can remove all un upgraded revision is better, so I don't need to give rev:head parameter, because I need to check which is the first rev that un upgraded yet. -- I like python! UliPad The Python Editor: http://code.google.com/p/ulipad/ UliWeb simple web framework: http://code.google.com/p/uliweb/ My Blog: http://hi.baidu.com/limodou -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@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] Alembic 0.3.1 released
On Sun, Apr 8, 2012 at 9:53 PM, Michael Bayer mike...@zzzcomputing.comwrote: On Apr 7, 2012, at 8:50 PM, limodou wrote: I've tested today, and I felt very good. And I have a question, if I've autogenerated once, and havn't upgrade to the database, so if I rerun the autogenerate again, it'll say: Target database is not up to date. So I want to know if there is an option so that it can delete the revision which havenot upgrade to database(maybe I can set the revision number), and recreate new rivision, for now, I can delete last revision by hand, and run the autogenerate again it'll be ok. yeah I've been deleting it by hand. I guess a command prune or something like that ? I'd make it prompt you before deleting the files though. I'm not sure if i want to be in the business of erasing people's source code. And I want to know how to let alembic know other python web framework configuration when init. Or how to customize alembic init process? So the two integration paths are a. how to have the Alembic scripts know about your web framework when they run and b. how to have your web framework know about alembic when it runs. For a. we have the env.py script. I do this a lot now in env.py: from myapplication.model import Session # ... def run_migrations_online(): s = Session() if s.bind is not None: engine = s.bind else: engine = engine_from_config(...) so above, if I'm running Alembic from inside a script that has already loaded up my web framework (like in tests), Alembic uses the same engine that the web framework has already set up. for b. that was part of the focus for 0.3, to get more public API for alembic. I have an init() like this: def init_alembic(check_only): from alembic.config import Config from alembic.script import ScriptDirectory from alembic.migration import MigrationContext from alembic import command config = Config() config.set_main_option(script_location, myapp:migrations) if check_only: # check that the DB is up to date only script = ScriptDirectory.from_config(config) conn = DBSession().connection() ctx = MigrationContext.configure(conn) head = script.get_current_head() db_head = ctx.get_current_revision() if db_head != head: raise Exception(Current migration version %s does not match %s % (db_head, head)) else: # upgrade to head command.upgrade(config, head) so unit test fixtures that want to have a whole database available on a test node will run init_alembic() with False, the main app runner runs init_alembic() with True, so that the production app isn't trying to upgrade the database. Thank you very much. I'll test it more. -- I like python! UliPad The Python Editor: http://code.google.com/p/ulipad/ UliWeb simple web framework: http://code.google.com/p/uliweb/ My Blog: http://hi.baidu.com/limodou -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@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] Alembic 0.3.1 released
On Sun, Apr 8, 2012 at 6:05 AM, Michael Bayer mike...@zzzcomputing.comwrote: Alembic 0.3.1 is available at: http://pypi.python.org/pypi/alembic/ 0.3.1 = - [bug] bulk_insert() fixes: 1. bulk_insert() operation was not working most likely since the 0.2 series when used with an engine. #41 2. Repaired bulk_insert() to complete when used against a lower-case-t table and executing with only one set of parameters, working around SQLAlchemy bug #2461 in this regard. 3. bulk_insert() uses inline=True so that phrases like RETURNING and such don't get invoked for single-row bulk inserts. 4. bulk_insert() will check that you're passing a list of dictionaries in, raises TypeError if not detected. I've tested today, and I felt very good. And I have a question, if I've autogenerated once, and havn't upgrade to the database, so if I rerun the autogenerate again, it'll say: Target database is not up to date. So I want to know if there is an option so that it can delete the revision which havenot upgrade to database(maybe I can set the revision number), and recreate new rivision, for now, I can delete last revision by hand, and run the autogenerate again it'll be ok. And I want to know how to let alembic know other python web framework configuration when init. Or how to customize alembic init process? Thanks such a good tool. -- I like python! UliPad The Python Editor: http://code.google.com/p/ulipad/ UliWeb simple web framework: http://code.google.com/p/uliweb/ My Blog: http://hi.baidu.com/limodou -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@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] 'MySQL server has gone away' problem
On Wed, Aug 24, 2011 at 9:49 PM, Michael Bayer mike...@zzzcomputing.com wrote: On Aug 23, 2011, at 11:21 PM, limodou wrote: On Sat, Oct 23, 2010 at 9:22 PM, Michael Bayer mike...@zzzcomputing.com wrote: pool recycle means a connnection that is 3600 seconds old will be thrown away. does not help with reconnects. When a server gone away error is detected, the entire connection pool is thrown away and rebuilt. So assuming one engine, you'd get this error once for each connection that is still checked out and attempts a new operation. Subsequent transactions will proceed since the pool has been rebuilt. There was also a Mysql-reconnect bug fixed in 0.6.3 where previous versions might have impacted this. I want to know if this means that the first transaction will still be failed, and others will be successful? When the error is received, whatever transactional state has occurred on that connection is gone - however, if you're getting this error on the very first moment the connection is used, there's no state on the connection in any case. And sqlalchemy can automatically rebuild at the time the error occured but not the next time? Not sure what the question is here. You can call engine.dispose() at any time to rebuild the connection pool completely, if you were building an approach to ping the connection ahead of time perhaps. finally I found the problem. In my case I build my own ORM based on sqlalchemy, I call it uliorm. And it only use base select, update, insert, delete statements. And in order to keep the whole process can share the same connection object, I used the engin.contextual_connect() to get the default connection, and my logic same like this: db = create_engine(xxx, pool_recycle=7200) conn = db.contextual_connect() db.begin() try: try: db.execute() db.commit() except: db.rollback() finally: conn.close() But it seems that the conn is not close correctly, so the pool will not recycle it. And I changed my underliying connection process code, I built the connection object in a Begin() function, and stored it to a threading.local() object. And I also provide Commit() and Rollback() functions. So I gave up the contextual_connect(). And the result seems right now. -- I like python! UliPad The Python Editor: http://code.google.com/p/ulipad/ UliWeb simple web framework: http://code.google.com/p/uliweb/ My Blog: http://hi.baidu.com/limodou -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@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] 'MySQL server has gone away' problem
On Sat, Oct 23, 2010 at 9:22 PM, Michael Bayer mike...@zzzcomputing.com wrote: pool recycle means a connnection that is 3600 seconds old will be thrown away. does not help with reconnects. When a server gone away error is detected, the entire connection pool is thrown away and rebuilt. So assuming one engine, you'd get this error once for each connection that is still checked out and attempts a new operation. Subsequent transactions will proceed since the pool has been rebuilt. There was also a Mysql-reconnect bug fixed in 0.6.3 where previous versions might have impacted this. I want to know if this means that the first transaction will still be failed, and others will be successful? And sqlalchemy can automatically rebuild at the time the error occured but not the next time? -- I like python! UliPad The Python Editor: http://code.google.com/p/ulipad/ UliWeb simple web framework: http://code.google.com/p/uliweb/ My Blog: http://hi.baidu.com/limodou -- You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@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: Bypass checking to database structure (metadata.create_all)
On Thu, Oct 1, 2009 at 6:25 PM, Christian Démolis christiandemo...@gmail.com wrote: Thx Simon, I tried Base.metadata.create_all(engine, checkfirst=False) but it throws an error. When checkfirst is True, the declaration works. I don t understand... Maybe orm needs additional information in declarative classes when checkfirst=False because orm doesn t look in database in this case? These is the error : Z:\python Declaration.py Le temps de chargement des modules SQL ALCHEMY 0.25 Le temps de dÚclaration SQL ALCHEMY 0.156000137329 Traceback (most recent call last): File Declaration.py, line 1435, in module Base.metadata.create_all(engine, checkfirst=False) File c:\python25\lib\site-packages\SQLAlchemy-0.5.6-py2.5.egg\sqlalchemy\sche ma.py, line 1796, in create_all bind.create(self, checkfirst=checkfirst, tables=tables) File c:\python25\lib\site-packages\SQLAlchemy-0.5.6-py2.5.egg\sqlalchemy\engi ne\base.py, line 1129, in create self._run_visitor(self.dialect.schemagenerator, entity, connection=connectio n, **kwargs) File c:\python25\lib\site-packages\SQLAlchemy-0.5.6-py2.5.egg\sqlalchemy\engi ne\base.py, line 1158, in _run_visitor visitorcallable(self.dialect, conn, **kwargs).traverse(element) File c:\python25\lib\site-packages\SQLAlchemy-0.5.6-py2.5.egg\sqlalchemy\sql\ visitors.py, line 89, in traverse return traverse(obj, self.__traverse_options__, self._visitor_dict) File c:\python25\lib\site-packages\SQLAlchemy-0.5.6-py2.5.egg\sqlalchemy\sql\ visitors.py, line 200, in traverse return traverse_using(iterate(obj, opts), obj, visitors) File c:\python25\lib\site-packages\SQLAlchemy-0.5.6-py2.5.egg\sqlalchemy\sql\ visitors.py, line 194, in traverse_using meth(target) File c:\python25\lib\site-packages\SQLAlchemy-0.5.6-py2.5.egg\sqlalchemy\sql\ compiler.py, line 831, in visit_metadata self.traverse_single(table) File c:\python25\lib\site-packages\SQLAlchemy-0.5.6-py2.5.egg\sqlalchemy\sql\ visitors.py, line 79, in traverse_single return meth(obj) File c:\python25\lib\site-packages\SQLAlchemy-0.5.6-py2.5.egg\sqlalchemy\sql\ compiler.py, line 870, in visit_table self.execute() File c:\python25\lib\site-packages\SQLAlchemy-0.5.6-py2.5.egg\sqlalchemy\engi ne\base.py, line 1812, in execute return self.connection.execute(self.buffer.getvalue()) File c:\python25\lib\site-packages\SQLAlchemy-0.5.6-py2.5.egg\sqlalchemy\engi ne\base.py, line 824, in execute return Connection.executors[c](self, object, multiparams, params) File c:\python25\lib\site-packages\SQLAlchemy-0.5.6-py2.5.egg\sqlalchemy\engi ne\base.py, line 888, in _execute_text return self.__execute_context(context) File c:\python25\lib\site-packages\SQLAlchemy-0.5.6-py2.5.egg\sqlalchemy\engi ne\base.py, line 896, in __execute_context self._cursor_execute(context.cursor, context.statement, context.parameters[0 ], context=context) File c:\python25\lib\site-packages\SQLAlchemy-0.5.6-py2.5.egg\sqlalchemy\engi ne\base.py, line 950, in _cursor_execute self._handle_dbapi_exception(e, statement, parameters, cursor, context) File c:\python25\lib\site-packages\SQLAlchemy-0.5.6-py2.5.egg\sqlalchemy\engi ne\base.py, line 931, in _handle_dbapi_exception raise exc.DBAPIError.instance(statement, parameters, e, connection_invalidat ed=is_disconnect) sqlalchemy.exc.ProgrammingError: (ProgrammingError) (1064, Erreur de syntaxe pr \xe8s de ' \n\tcp VARCHAR, \n\tlatitude VARCHAR, \n\tlongitude VARCHAR, \n\teloi gn' \xe0 la ligne 3) '\nCREATE TABLE maps_ville (\n\t`IdVille` INTEGER NOT NULL AUTO_INCREMENT, \n\tnom VARCHAR, \n\tcp VARCHAR, \n\tlatitude VARCHAR, \n\tlong itude VARCHAR, \n\teloignement VARCHAR, \n\turl VARCHAR, \n\tPRIMARY KEY (`IdVil le`)\n)\n\n' () It seems that there is no length for VARCHAR, the right syntax should be VARCHAR(length), and I also need this problem when I testing in Mysql, but there is no problem in Sqlite. -- I like python! UliPad The Python Editor: http://code.google.com/p/ulipad/ UliWeb simple web framework: http://uliwebproject.appspot.com My Blog: http://hi.baidu.com/limodou --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@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: How to display table creation sql statement?
2009/2/3 Sergei Beilin sbei...@narod.ru: On 3 фев, 09:31, limodou limo...@gmail.com wrote: Thanks and I want to know if I must call meta.create_all(engine), because this code will create the tables, but I just want to see the SQL statements, but not create the tables. Note the additional properties: strategy='mock', executor=lambda s, p='': buf.write(s + p) As far as I understand, they will prevent creating the tables and would just write the create statements to 'buf'. Thank you very much, I'll test it. -- I like python! UliPad The Python Editor: http://code.google.com/p/ulipad/ UliWeb simple web framework: http://uliwebproject.appspot.com My Blog: (new)http://http://hi.baidu.com/limodou (old)http://www.donews.net/limodou --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@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] How to display table creation sql statement?
I want to know if there is a simple way to show the table creation sql statement, and I don't want to display them in debug mode. I just want to show sql statement via table definition. -- I like python! UliPad The Python Editor: http://code.google.com/p/ulipad/ UliWeb simple web framework: http://uliwebproject.appspot.com My Blog: (new)http://http://hi.baidu.com/limodou (old)http://www.donews.net/limodou --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@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: How to display table creation sql statement?
On Tue, Feb 3, 2009 at 11:40 AM, Michael Bayer mike...@zzzcomputing.com wrote: current method is http://www.sqlalchemy.org/trac/wiki/FAQ#HowcanIgettheCREATETABLEDROPTABLEoutputasastring . 0.6 has something more general purpose. Thanks and I want to know if I must call meta.create_all(engine), because this code will create the tables, but I just want to see the SQL statements, but not create the tables. -- I like python! UliPad The Python Editor: http://code.google.com/p/ulipad/ UliWeb simple web framework: http://uliwebproject.appspot.com My Blog: (new)http://http://hi.baidu.com/limodou (old)http://www.donews.net/limodou --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups sqlalchemy group. To post to this group, send email to sqlalchemy@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 -~--~~~~--~~--~--~---