[sqlalchemy] Re: wx and SqlAlchemy
Mike, Mike wrote: I found the issue. For some reason, SqlAlchemy is passing a unicode string to a varchar field in SQL Server, which is causing an error to be raised. If I explicitly set the value to an integer or a string, it works fine. I'm not sure how it's getting cast to unicode, but I think I can work around this. How is your model defined? Maybe the column is incorrectly defined in the model or if you use autoload then maybe there is a problem with the autoload code. I would also work around it, but provide some more details here in a new thread as it might point to a problem in SA. Werner --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: Orphans not deleted using cascade parameter
Hi! Hi have a similar problem using table reflection a la sqlsoup. My DB Backend ist postgresql 8.3. I have a many to many relation: orms5=# \d project_programming_language Table public.project_programming_language Column | Type | Modifiers -+-+--- project_id | integer | not null programming_language_id | integer | not null Indexes: projprogpkconstraint PRIMARY KEY, btree (project_id, programming_language_id) Foreign-key constraints: programmierspracheconstraint FOREIGN KEY (programming_language_id) REFERENCES programming_language(programming_language_id) ON DELETE CASCADE projektconstraint FOREIGN KEY (project_id) REFERENCES project(project_id) ON DELETE CASCADE I got the same message, when delete an object of the table programming_language: Dependency rule tried to blank-out primary key column As you can see, the foreign key constraints in the db work fine: I can drop the row via a DELETE statement in sql. Michael --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] max(datetime) does not return a datetime. Bug or feature ?
Hello, consider the following (Elixir syntax sorry) class A(Entity): creation_date = Field(DateTime) ... A.query().max(A.creation_date) returns a unicode and not a datetime as max([a.creation_date for a in A.query()]) returns Is it a bug ? (sqlalchemy version 0.4.6) --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Replacement for query.mapper.class_
Hi, Hope everyone is well, not been around for a while. I've noticed one of my apps has broken with an SA upgrade. It was using query.mapper.class_ to determine the class from a query, but query.mapper no longer exists. What's the 0.5 way of doing this? Paul --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: Orphans not deleted using cascade parameter
I forgot to mention, that I use 0.5.0beta 3. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: Replacement for query.mapper.class_
see query._mapper_zero(), _only_mapper_zero(), _mapper_zero_or_none() On Friday 29 August 2008 11:32:30 Paul Johnston wrote: Hi, Hope everyone is well, not been around for a while. I've noticed one of my apps has broken with an SA upgrade. It was using query.mapper.class_ to determine the class from a query, but query.mapper no longer exists. What's the 0.5 way of doing this? --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: Orphans not deleted using cascade parameter
Hi Michael, I had the same problem for a while. I'm not exactly sure what I did in order to fix this (have 2 ideas in my mind, need to figure out which of it it was). As soon as I remember, I'll let you know. On Aug 29, 1:44 am, Michael Brickenstein [EMAIL PROTECTED] wrote: Hi! Hi have a similar problem using table reflection a la sqlsoup. My DB Backend ist postgresql 8.3. I have a many to many relation: orms5=# \d project_programming_language Table public.project_programming_language Column | Type | Modifiers -+-+--- project_id | integer | not null programming_language_id | integer | not null Indexes: projprogpkconstraint PRIMARY KEY, btree (project_id, programming_language_id) Foreign-key constraints: programmierspracheconstraint FOREIGN KEY (programming_language_id) REFERENCES programming_language(programming_language_id) ON DELETE CASCADE projektconstraint FOREIGN KEY (project_id) REFERENCES project(project_id) ON DELETE CASCADE I got the same message, when delete an object of the table programming_language: Dependency rule tried to blank-out primary key column As you can see, the foreign key constraints in the db work fine: I can drop the row via a DELETE statement in sql. Michael --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: wx and SqlAlchemy
Werner, On Aug 29, 2:21 am, Werner F. Bruhin [EMAIL PROTECTED] wrote: Mike, Mike wrote: I found the issue. For some reason, SqlAlchemy is passing a unicode string to a varchar field in SQL Server, which is causing an error to be raised. If I explicitly set the value to an integer or a string, it works fine. I'm not sure how it's getting cast to unicode, but I think I can work around this. How is your model defined? Maybe the column is incorrectly defined in the model or if you use autoload then maybe there is a problem with the autoload code. I would also work around it, but provide some more details here in a new thread as it might point to a problem in SA. Werner I'm not sure I really have a model. I created a separate Python file to hold my table classes, but in my wx.App, I import those classes and then map them to autoloaded tables. Then I bind my session object. This may not be the correct way to integrate SA into wx (or any other project), but I haven't seen any SA code in anything except for TurboGears examples. Mike --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: wx and SqlAlchemy
Werner, On Aug 29, 2:21 am, Werner F. Bruhin [EMAIL PROTECTED] wrote: Mike, Mike wrote: I found the issue. For some reason, SqlAlchemy is passing a unicode string to a varchar field in SQL Server, which is causing an error to be raised. If I explicitly set the value to an integer or a string, it works fine. I'm not sure how it's getting cast to unicode, but I think I can work around this. How is your model defined? Maybe the column is incorrectly defined in the model or if you use autoload then maybe there is a problem with the autoload code. I would also work around it, but provide some more details here in a new thread as it might point to a problem in SA. Werner As I was working on creating my new thread, I realized that it's more than likely that it's my fault. The value I am setting is derived from what pay period I am currently viewing in my application. I figure this out using a hack where I grab my frame's title. The title returns unicode which is something that SQL Server doesn't like since the field is set to varchar, not nvarchar. For some reason, this works using pymssql, but not with SqlAlchemy. I will write a separate post to that effect. Mike --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Unicode not getting translated to SQL Server?
Hi, I have a weird issue wherein I send a unicode string to SQL Server 2000 using SqlAlchemy in a wxPython program. A little history would probably help: I created a timesheet program last year using wxPython and connected to my databases using pymssql. In the hopes of making this program more flexible and efficient, I decided to switch to SqlAlchemy. In my program, I can view 26 separate time periods that show the user's time worked. To tell what period I am in, I grab the title of the wx frame. I store this in one of my tables so that the next time the user opens their timesheet, it will open to the last opened time period. Anyway, it appears that the wxPython returns the title as a unicode string. When I try to commit this string to my database, SqlAlchemy blows up and gives me this huge traceback: Traceback (most recent call last): File \\debianis\loginscript$\PythonPackages\Development \Timesheet_sa \ts_worksheet_MT.py, line 689, in onClose session.flush() File c:\python25\lib\site-packages\sqlalchemy-0.4.7-py2.5.egg \sqlalchemy\orm\session.py, line 789, in flush self.uow.flush(self, objects) File c:\python25\lib\site-packages\sqlalchemy-0.4.7-py2.5.egg \sqlalchemy\orm\unitofwork.py, line 233, in flush flush_context.execute() File c:\python25\lib\site-packages\sqlalchemy-0.4.7-py2.5.egg \sqlalchemy\orm\unitofwork.py, line 445, in execute UOWExecutor().execute(self, tasks) File c:\python25\lib\site-packages\sqlalchemy-0.4.7-py2.5.egg \sqlalchemy\orm\unitofwork.py, line 930, in execute self.execute_save_steps(trans, task) File c:\python25\lib\site-packages\sqlalchemy-0.4.7-py2.5.egg \sqlalchemy\orm\unitofwork.py, line 945, in execute_save_steps self.save_objects(trans, task) File c:\python25\lib\site-packages\sqlalchemy-0.4.7-py2.5.egg \sqlalchemy\orm\unitofwork.py, line 936, in save_objects task.mapper._save_obj(task.polymorphic_tosave_objects, trans) File c:\python25\lib\site-packages\sqlalchemy-0.4.7-py2.5.egg \sqlalchemy\orm\mapper.py, line 1144, in _save_obj c = connection.execute(statement.values(value_params), params) File c:\python25\lib\site-packages\sqlalchemy-0.4.7-py2.5.egg \sqlalchemy\engine\base.py, line 844, in execute return Connection.executors[c](self, object, multiparams, params) File c:\python25\lib\site-packages\sqlalchemy-0.4.7-py2.5.egg \sqlalchemy\engine\base.py, line 895, in execute_clauseelement return self._execute_compiled(elem.compile(dialect=self.dialect, column_keys=keys, inline=len(params) 1), distilled_params=params) File c:\python25\lib\site-packages\sqlalchemy-0.4.7-py2.5.egg \sqlalchemy\engine\base.py, line 907, in _execute_compiled self.__execute_raw(context) File c:\python25\lib\site-packages\sqlalchemy-0.4.7-py2.5.egg \sqlalchemy\engine\base.py, line 916, in __execute_raw self._cursor_execute(context.cursor, context.statement, context.parameters[0], context=context) File c:\python25\lib\site-packages\sqlalchemy-0.4.7-py2.5.egg \sqlalchemy\engine\base.py, line 960, in _cursor_execute self._handle_dbapi_exception(e, statement, parameters, cursor) File c:\python25\lib\site-packages\sqlalchemy-0.4.7-py2.5.egg \sqlalchemy\engine\base.py, line 942, in _handle_dbapi_exception raise exceptions.DBAPIError.instance(statement, parameters, e, connection_invalidated=is_disconnect) sqlalchemy.exceptions.DatabaseError: (DatabaseError) internal error: None 'UPDATE [tbl_Acct_Prefs] SET pref_value=%(pref_value)s WHERE [tbl_Acct_Prefs].[empID] = %(tbl_Acct_Prefs_empID)s AND [tbl_Acct_Prefs].pref_name = % (tbl_Acct_Prefs_pref_name)s' {'pref_value': u'4', 'tbl_Acct_Prefs_pref_name': 'last_payPeriod', 'tbl_Acct_Prefs_empID': 258} If I use pymssql instead, it works. As I understand it, SA should be using pymssql anyway, so I don't know why this is happening. I can cast the unicode to a string, so it's not a big deal. However, I thought someone might want to know that this is happening. Oh, and I use autoload to load my Table() objects. I'm not sure if that's significant or not though. I am also using a session.commit() to get the error above. I have upgraded to the 5.0beta3 too, but it gives the same error as above. I am using Python 2.5.2 on Windows XP. Let me know if you require additional information. Thanks, Mike --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: Orphans not deleted using cascade parameter
Unfortunately, without an illustration of your usage pattern, we can't assist with your issue.Here's the same test case again from earlier in the thread. Can you modify it to look like your failing condition ? rom sqlalchemy import * from sqlalchemy.orm import * from sqlalchemy.ext.declarative import declarative_base engine = create_engine('sqlite://', echo=True) Base = declarative_base() class PublicationElement(Base): __tablename__ = 'publication' publication_id = Column(Integer, primary_key=True) name = Column(Unicode(255)) class SectionElement(Base): __tablename__ = 'section' section_id = Column(Integer, primary_key=True) publication_id = Column(Integer, ForeignKey('publication.publication_id'), nullable=False) publication = relation('PublicationElement', cascade=all, delete- orphan, backref='sections') name = Column(Unicode(255)) Base.metadata.create_all(engine) Session = sessionmaker(bind=engine) sec1 = SectionElement(name='s1', publication=PublicationElement(name='p1')) sess = Session() sess.add(sec1) sess.commit() assert sess.query(SectionElement).one().publication.name == 'p1' sess.delete(sec1) sess.commit() assert engine.execute(select count(1) from publication).scalar() == 0 assert engine.execute(select count(1) from section).scalar() == 0 On Aug 29, 2008, at 1:44 AM, Michael Brickenstein wrote: Hi! Hi have a similar problem using table reflection a la sqlsoup. My DB Backend ist postgresql 8.3. I have a many to many relation: orms5=# \d project_programming_language Table public.project_programming_language Column | Type | Modifiers -+-+--- project_id | integer | not null programming_language_id | integer | not null Indexes: projprogpkconstraint PRIMARY KEY, btree (project_id, programming_language_id) Foreign-key constraints: programmierspracheconstraint FOREIGN KEY (programming_language_id) REFERENCES programming_language(programming_language_id) ON DELETE CASCADE projektconstraint FOREIGN KEY (project_id) REFERENCES project(project_id) ON DELETE CASCADE I got the same message, when delete an object of the table programming_language: Dependency rule tried to blank-out primary key column As you can see, the foreign key constraints in the db work fine: I can drop the row via a DELETE statement in sql. Michael --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: Unicode not getting translated to SQL Server?
On Aug 29, 2008, at 10:53 AM, Mike wrote: If I use pymssql instead, it works. As I understand it, SA should be using pymssql anyway, so I don't know why this is happening. I can cast the unicode to a string, so it's not a big deal. However, I thought someone might want to know that this is happening. without a sample of the code and schema in use, we can't say for sure what the issue is. Are you making usage of the Unicode type at least ? Oh, and I use autoload to load my Table() objects. I'm not sure if that's significant or not though. I am also using a session.commit() to get the error above. You might want to enable convert_unicode=True on your Engine, or override the specific columns requiring unicode compatibility with the Unicode type. String columns are reflected by default without unicode awareness. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Constructors not called?
Hi, Not sure if I'm misunderstanding what's happening, whether I have a bug, or whether this is normal behaviour, but as far as I can tell mapped objects that are returned from a query do not have their constructor called. Is that correct? In a bit more detail - I have a mapping defined to class Metric, and a query() returns a Metric instance, with the correct attributes, but if in the constructor I have something like: class Metric(object): def __init__(self): self.constructor_called = True then the instance returned by query does not have the constructor_called attribute (my actual code is more complex, but that's the general idea). Is this normal behaviour? Is there any way to get the constructor to be called? I can work around this if not, but would liek to be sure I am not ignoring an error of some kind. I've looked through the documentation, but couldn't find anything relevant. Apologies if I've missed the obvious. This is with version 0.4.7p1 Thanks, Andrew --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: Extension Mapper
You must be right. Of course, Turbogears2 already add an extension to the session, and it looks like it is not a list of extension anyway (or maybe in the latest trunk?). What the best way then? To subclass the tg2 extension with mine and continue to call overloaded method from mine? Anything better? On Aug 29, 3:57 am, Michael Bayer [EMAIL PROTECTED] wrote: On Aug 28, 2008, at 6:57 PM, GustaV wrote: Hi all. I'm currently working on a map (like in geography :) ) When a new tile in inserted in the DB, I'm using an extension mapper to update some neighbor's properties (like the neighbors count). The after_insert method helps a lot... but: When I modify another object than the one being inserted in the after_insert method, the modification happens in the python object, but doesn't occur is the DB. The commit at the end does not seem to have an effect. What should I do? modifications to objects inside of flush() aren't going to propigate the same way as when they're outside of the flush(). Within MapperExtension you should generally just do things with the connection (i.e., issue SQL directly). Otherwise, we have SessionExtension which has a before_flush() hook, and you can poke around inside the Session and change things freely before anything flush()-related occurs. The catch there is that you'd probably want to be using the latest 0.5 trunk for that (post beta3) since we've fixed it up a bit to work in a more useful way. I find that using before_flush() and after_flush() is generally a better way to go for dependent changes/SQL to be issued since you aren't doing things inside of the flush() itself, where its hard to predict when things will actually happen. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: Constructors not called?
On Aug 29, 2008, at 11:22 AM, andrew cooke wrote: Hi, Not sure if I'm misunderstanding what's happening, whether I have a bug, or whether this is normal behaviour, but as far as I can tell mapped objects that are returned from a query do not have their constructor called. Is that correct? yes. In a bit more detail - I have a mapping defined to class Metric, and a query() returns a Metric instance, with the correct attributes, but if in the constructor I have something like: class Metric(object): def __init__(self): self.constructor_called = True then the instance returned by query does not have the constructor_called attribute (my actual code is more complex, but that's the general idea). Is this normal behaviour? Is there any way to get the constructor to be called? I can work around this if not, but would liek to be sure I am not ignoring an error of some kind. an FAQ entry on this is here: http://www.sqlalchemy.org/trac/wiki/FAQ#whyisntmy__init__calledwhenIloadobjects --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: Unicode not getting translated to SQL Server?
Hi Mr. Bayer, On Aug 29, 10:10 am, Michael Bayer [EMAIL PROTECTED] wrote: On Aug 29, 2008, at 10:53 AM, Mike wrote: If I use pymssql instead, it works. As I understand it, SA should be using pymssql anyway, so I don't know why this is happening. I can cast the unicode to a string, so it's not a big deal. However, I thought someone might want to know that this is happening. without a sample of the code and schema in use, we can't say for sure what the issue is. Are you making usage of the Unicode type at least ? Since I am autoloading, I didn't know I could use the Unicode type to override what was reflected. How do I do that? There's only so much I can give being that I'm talking about accounting data, but here's a sample that should work: code from sqlalchemy import create_engine, Column, Float, Integer from sqlalchemy import MetaData, String, Table, Unicode from sqlalchemy.orm import mapper, sessionmaker class Acct_Prefs(object): ''' Table object for tbl_Acct_Prefs ''' def __init__(self, empID, pref_name, pref_value): self.empID = empID self.pref_name = pref_name self.pref_value = pref_value def __repr__(self): return Acct_Prefs ('%s', '%s', '%s') % (self.empID, self.pref_name, self.pref_value) class TimeEntries(object): ''' Table object for tbl_TimeEntries ''' def __init__(self, dateworked, empid, reg, ot, ce, hol, sklv, vac, ct, conv, misc, comments): self.dateworked = dateworked self.empid = empid self.reg = reg self.ot = ot self.ce = ce self.hol = hol self.sklv = sklv self.vac = vac self.ct = ct self.conv = conv self.misc = misc self.comments = comments def __repr__(self): return TimeEntries ('%s', '%s') % (self.dateworked, self.empid) # Connect to the database print 'connecting to MCISAccounting DB...' engine = create_engine('sqlite:///sample.db') metadata = MetaData(engine) # Load the tables print 'loading tables...' prefs_table = Table('tbl_Acct_Prefs', metadata, Column('empID', String(5), primary_key=True), Column('pref_name', String(50), primary_key=True, nullable=False), Column('pref_value', String(50), nullable=False) ) entry_table = Table('tbl_TimeEntries', metadata, Column('dateworked', String(10), primary_key=True), Column('empid', Integer, primary_key=True, autoincrement=False), Column('reg', Float), Column('ot', Float), Column('ce', Float), Column('hol', Float), Column('sklv', Float), Column('vac', Float), Column('ct', Float), Column('conv', Float), Column('misc', Float), Column('comments', Unicode(256)) ) metadata.create_all() # Map the tables print 'mapping tables...' mapper(TimeEntries, entry_table) mapper(Acct_Prefs, prefs_table) # Create a session object print 'creating session...' Session = sessionmaker(bind=engine) session = Session() prefOne = Acct_Prefs(258, 'last_payPeriod', 2) session.Add(prefOne) session.commit() /code That should get it to look as similar as possible to the state the SQL Server is in. Now here's where I get the issue. I do the following query pref = self.session.query(Acct_Prefs).filter_by(empID=258, pref_name='last_payPeriod').first() and then I do the following where someValue happens to be a unicode string: pref.pref_value = someValue session.commit() Oh, and I use autoload to load my Table() objects. I'm not sure if that's significant or not though. I am also using a session.commit() to get the error above. You might want to enable convert_unicode=True on your Engine, or override the specific columns requiring unicode compatibility with the Unicode type. String columns are reflected by default without unicode awareness. This might work. I'll give it a whirl anyway. I hope my code sample makes sense and isn't too ugly. I'm still pretty green with your cool ORM and SQL in general. Mike --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: Unicode not getting translated to SQL Server?
and then I do the following where someValue happens to be a unicode string: pref.pref_value = someValue session.commit() That's not going to work with pymssql as your DBAPI. Pymssql is based on Microsoft's DBLib (circa 1991 or so), which does not support unicode and never will: it's been unmaintained for something like 10 years now. You'll either need to convert everything to str() before it hits the DBAPI (which is what I do, I'm still using pymssql), or switch to pyodbc. I am using Python 2.5.2 on Windows XP. on windows, it should be easy to switch to pyodbc. Just install pyodbc, SQLAlchemy will look for it first, in preference over pymssql. Rick --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: Unicode not getting translated to SQL Server?
Hi Rick, On Aug 29, 11:02 am, Rick Morrison [EMAIL PROTECTED] wrote: and then I do the following where someValue happens to be a unicode string: pref.pref_value = someValue session.commit() That's not going to work with pymssql as your DBAPI. Pymssql is based on Microsoft's DBLib (circa 1991 or so), which does not support unicode and never will: it's been unmaintained for something like 10 years now. You'll either need to convert everything to str() before it hits the DBAPI (which is what I do, I'm still using pymssql), or switch to pyodbc. I am using Python 2.5.2 on Windows XP. on windows, it should be easy to switch to pyodbc. Just install pyodbc, SQLAlchemy will look for it first, in preference over pymssql. Rick That sounds like a plan. I think I used to have that installed, but I may be confusing it with adodb. Thanks for the tip! Mike --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: Extension Mapper
On Aug 29, 2008, at 11:36 AM, GustaV wrote: You must be right. Of course, Turbogears2 already add an extension to the session, and it looks like it is not a list of extension anyway (or maybe in the latest trunk?). What the best way then? To subclass the tg2 extension with mine and continue to call overloaded method from mine? Anything better? since I'm plugging SessionExtension quite a bit I'll look into turning that collection into a list. For now you can try monkeypatching or subclassing TG's extension. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] Re: Extension Mapper
in r5069, extension can be a list of SessionExtension objects. You can also append to session.extensions. On Aug 29, 2008, at 11:36 AM, GustaV wrote: You must be right. Of course, Turbogears2 already add an extension to the session, and it looks like it is not a list of extension anyway (or maybe in the latest trunk?). What the best way then? To subclass the tg2 extension with mine and continue to call overloaded method from mine? Anything better? On Aug 29, 3:57 am, Michael Bayer [EMAIL PROTECTED] wrote: On Aug 28, 2008, at 6:57 PM, GustaV wrote: Hi all. I'm currently working on a map (like in geography :) ) When a new tile in inserted in the DB, I'm using an extension mapper to update some neighbor's properties (like the neighbors count). The after_insert method helps a lot... but: When I modify another object than the one being inserted in the after_insert method, the modification happens in the python object, but doesn't occur is the DB. The commit at the end does not seem to have an effect. What should I do? modifications to objects inside of flush() aren't going to propigate the same way as when they're outside of the flush(). Within MapperExtension you should generally just do things with the connection (i.e., issue SQL directly). Otherwise, we have SessionExtension which has a before_flush() hook, and you can poke around inside the Session and change things freely before anything flush()-related occurs. The catch there is that you'd probably want to be using the latest 0.5 trunk for that (post beta3) since we've fixed it up a bit to work in a more useful way. I find that using before_flush() and after_flush() is generally a better way to go for dependent changes/SQL to be issued since you aren't doing things inside of the flush() itself, where its hard to predict when things will actually happen. --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---
[sqlalchemy] timing all queries
Is there a way to record the execution time for all queries issued by sqlalchemy? Thanks, Tvrtko --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~--~~~~--~~--~--~---