[sqlalchemy] Re: Is there a way to replace object in DB?
On Jan 15, 2008 6:54 PM, Michael Bayer [EMAIL PROTECTED] wrote: The last commit fails with: sqlalchemy.exceptions.IntegrityError: (IntegrityError) Referers.objectId may not be NULL u'UPDATE Referers SET objectId=? WHERE Referers.id = ?' [None, 1] right thats because the instance doesnt exist yet. its better for you to just use the straight ahead query.get(), if None then save() approach. Do you mean obj2 (id of which should go to objectId column in this UPDATE)? If so, why it doesn't exist? It's saved (updated in fact) just several lines above, so it must be both in DB and in session. The last lines of the original test case for convenience: [...] obj2 = replace(session, ModelObject(1, u'title2')) session.commit() ref2 = ModelReferer(1, obj2) replace(session, ref2) session.commit() --~--~-~--~~~---~--~~ 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: two scoped sessions in one app?
I had a Session.configure() statement which was called for both sessions and this was making setup unusable. Duh. On Jan 16, 2008 2:12 PM, Max Ischenko [EMAIL PROTECTED] wrote: On Jan 15, 2008 6:14 PM, Michael Bayer [EMAIL PROTECTED] wrote: if you are using multiple scoped sessions you won't be able to use Session.mapper - the idea of Session.mapper is that all instances get tied to a single contextual session. OK, so how do I set it up. I'm reading http://www.sqlalchemy.org/docs/04/session.html but answer isn't clear. Should I use set up one scope session and another with create_session? -- Max http://maxischenko.in.ua // http://www.linkedin.com/in/maksim --~--~-~--~~~---~--~~ 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: two scoped sessions in one app?
On Jan 15, 2008 6:14 PM, Michael Bayer [EMAIL PROTECTED] wrote: if you are using multiple scoped sessions you won't be able to use Session.mapper - the idea of Session.mapper is that all instances get tied to a single contextual session. OK, so how do I set it up. I'm reading http://www.sqlalchemy.org/docs/04/session.html but answer isn't clear. Should I use set up one scope session and another with create_session? --~--~-~--~~~---~--~~ 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: two scoped sessions in one app?
Hello, Sorry for reply to myself; just want to tell that the problem is solved. Here is how my setup looks like: Session = scoped_session(sessionmaker(autoflush=True, transactional=False)) SessionCDB = scoped_session(sessionmaker(autoflush=True, transactional=False)) ... # application startup sqlalchemy_configure(blog, Session, init_blog_meta) sqlalchemy_configure(cdb, SessionCDB, init_companydb_meta) ... def sqlalchemy_configure(dbname, session, callback): global metadata_cache from sqlalchemy import engine_from_config from pylons import config engine = engine_from_config(config, 'sqlalchemy.%s.' % dbname) session.configure(bind=engine) meta = sqlalchemy.MetaData(engine) metadata_cache[dbname] = meta callback(session.mapper, meta) Max. --~--~-~--~~~---~--~~ 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] DBMS
Hi, Send me some study material on DBMS. -- Regards, Manish Soni M. Phil.(Computer Science),MCA(Hons.) Master of Science (Computer Science) B.Sc.(Mathematics, Physics, Computer Application) MCPDEA, MCSD(.Net), MCDBA(SQL Server 2000), MCAD(.Net), A Level, OCA(9i) MCP(VB6 Desktop, VB6 Distributed, Windows 2000 Server), SCJP, PGDCA, MCSA(Messaging), MCSE(2003), CCNA, Hardware and Networking Diploma of Six Months MCP(Microsoft CRM) [EMAIL PROTECTED] Winning Horse doesn't know why it runs in race; it runs because of beats and pains…. Life is a race; God is your rider; if you are in pain then think, God wants You to win… --~--~-~--~~~---~--~~ 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: eagerloading polymorphic mapper
On Jan 16, 2008, at 2:24 AM, [EMAIL PROTECTED] wrote: yeahhh i know i dont see the wider sql picture... i may put all this as a ticket to remind.. maybe one day you'll be in better mood (;-) it can certainly be done but id like to at least first get eager loads from the *base* polymorphic mapper working...query has been steadily heading towards a more sophisticated and singular notion (such as, now you can do your query.select_from(any selectable).filter() which you wanted months ago) and i think theres a certain order things need to be done. --~--~-~--~~~---~--~~ 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] postgresql truncate table
someone know why when I execute a session.execute(truncate table some_table cascade) in a postgresql database nothing happens? I need to put some extra parameter? -- Alexandre da Silva Analista de Sistemas - Bacharel em Sistemas de Informação (2003-2007) --~--~-~--~~~---~--~~ 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: Is there a way to replace object in DB?
On Jan 16, 2008, at 4:43 AM, Denis S. Otkidach wrote: On Jan 15, 2008 6:54 PM, Michael Bayer [EMAIL PROTECTED] wrote: The last commit fails with: sqlalchemy.exceptions.IntegrityError: (IntegrityError) Referers.objectId may not be NULL u'UPDATE Referers SET objectId=? WHERE Referers.id = ?' [None, 1] right thats because the instance doesnt exist yet. its better for you to just use the straight ahead query.get(), if None then save() approach. Do you mean obj2 (id of which should go to objectId column in this UPDATE)? If so, why it doesn't exist? It's saved (updated in fact) just several lines above, so it must be both in DB and in session. The last lines of the original test case for convenience: [...] obj2 = replace(session, ModelObject(1, u'title2')) session.commit() ref2 = ModelReferer(1, obj2) replace(session, ref2) session.commit() I cant tell what your issue is there without the backing data showing the full picture. We dont support manipulating _instance_key manually as a supported use case, so issues are not surprising. heres an example using public APIs: def replace(session, cls, id, **kwargs): obj = session.query(cls).get(id) if obj is None: obj = cls(id=id, **kwargs) session.save(obj) else: for key in kwargs: setattr(obj, key, kwargs[key]) return obj obj2 = replace(session, ModelObject, 1, title=u'title2') session.commit() ref2 = replace(session, ModelReferer, 1, object=obj2) session.commit() the above will also use less SQL than how you were doing it. if that function is producing the same issue, provide a test case that includes the supporting data and runs fully since from your example I dont know if ModelReferer(1) is supposed to be present or not. --~--~-~--~~~---~--~~ 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] Connecting to MSSQL with a System DSN on Windows
I have a Windows setup in which I need to use Integrated Authentication with pyodbc and MSSQL. I have set up a System DSN using the Control Panel and pyodbc connects OK using this DSN - I can run queries etc. without problems. I use the connection string 'DSN=MyDSN' for pyodbc, where MyDSN is the System DSN I have set up. However, this doesn't work if I pass it to create_engine() - e.g. 'mssql://DSN=MyDSN'. How can I get this to work without specifying username, password or database in the URL? Sorry if this has come up before. I saw an earlier (Sep 2007) thread which seems to imply that you have to the username password in the URL, and an earlier (June 2007) thread about using Driver={} on Unix. Is there an easy way to just pass the pyodbc connection to SQLAlchemy? I couldn't spot anything obvious in the docs. Thanks in advance, Vinay Sajip --~--~-~--~~~---~--~~ 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: Connecting to MSSQL with a System DSN on Windows [Solved]
On 16 Jan, 18:10, Vinay Sajip [EMAIL PROTECTED] wrote: I have a Windows setup in which I need to use Integrated Authentication with pyodbc and MSSQL. I have set up a System DSN using the Control Panel and pyodbc connects OK using this DSN - I can run queries etc. without problems. I use the connection string 'DSN=MyDSN' for pyodbc, where MyDSN is the System DSN I have set up. However, this doesn't work if I pass it to create_engine() - e.g. 'mssql://DSN=MyDSN'. How can I get this to work without specifying username, password or database in the URL? Sorry if this has come up before. I saw an earlier (Sep 2007) thread which seems to imply that you have to the username password in the URL, and an earlier (June 2007) thread about using Driver={} on Unix. Is there an easy way to just pass the pyodbc connection to SQLAlchemy? I couldn't spot anything obvious in the docs. Problem solved. I had to use r'machinename\sqlexpress' as the host because it's an embedded version of MSSQL. Sorry for the noise. Vinay Sajip --~--~-~--~~~---~--~~ 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: DBMS
On Wed, Jan 16, 2008 at 02:33:53PM +0530, Manish Soni wrote: Send me some study material on DBMS. -- Regards, Manish Soni M. Phil.(Computer Science),MCA(Hons.) Master of Science (Computer Science) B.Sc.(Mathematics, Physics, Computer Application) MCPDEA, MCSD(.Net), MCDBA(SQL Server 2000), MCAD(.Net), A Level, OCA(9i) MCP(VB6 Desktop, VB6 Distributed, Windows 2000 Server), SCJP, PGDCA, MCSA(Messaging), MCSE(2003), CCNA, Hardware and Networking Diploma of Six Months MCP(Microsoft CRM) Pardon me... you have all these degrees but still just order the mailing list of an open-source database toolkit to send you some material on DBMS? We must be having a serious language interface problem here. Back when I made my Master of Informatics I learned a whole lot about DBMSs. Christoph --~--~-~--~~~---~--~~ 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: Connecting to MSSQL with a System DSN on Windows
Hi, 'mssql://DSN=MyDSN'. How can I get this to work without specifying You were nearly there... mssql://?dsn=mydsn 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: Doing a dynamic Update
Rick, On Jan 15, 1:34 pm, Rick Morrison [EMAIL PROTECTED] wrote: Two issues: a) You need to give SA a table definition for the table you're trying to update. b) You need to specify the name of the column to update in the dict(), not the string 'key' I've updated the script to work by passing in both the column name to update and the update value to use. I've made my changes in bold below: def main(*key, val*): engine = create_engine('mssql://dbName:[EMAIL PROTECTED]') * # No table name in URI !! /%s' % tblName)* I actually had this right in my code, but I posted it incorrectly when sanitizing it for the newsgroup. conn = engine.connect() # create MetaData meta = MetaData() # bind to an engine meta.bind = engine * # specify table definition tbl = Table('tbl_Acct_prefs', meta, Column('netname', VARCHAR(20)), Column('pref_name', VARCHAR(40)), Column('pref_value', VARCHAR(40)) )* # create metadata *#* meta.create_all() * # === you need this only if you're creating the table with your program* I was following the docs on the website for this one...I guess I misunderstood since their example was using a sqlite database in memory. Oh well... tbl.update(tbl.c.netname=='saw').execute(*{key:val}*) This worked. Thank you for your patience and for sharing your knowledge. 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: postgresql truncate table
you probably need to begin/commit a transaction since the PG dialect doesnt pick up truncate as an autocommit keyword. exactly, thank you for reply Att -- Alexandre da Silva Analista de Sistemas - Bacharel em Sistemas de Informação (2003-2007) --~--~-~--~~~---~--~~ 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] access the fields in a record as a dict
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 hi friends, in older sa i could cast a record to a dict, in order to access their fields by their name, especially if the field name is not a valid python identifier, like a calculated or fixed numeric column. how could i do it again please? tia, alex -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.6 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iQCVAwUBR46TPdpwN1sq38njAQKv7wQArF0nV0WRTZVI/3qdLC5+7yZDspw1bGhT 6H8vPFQKDZCsJNNP98nbV1zKjMC/OfypPOqJvS7T9SpD2XZ9G7LOYeAQpSakzNOO DiJE/vY4SzX83cwfFj218EfzqtOeg0L010sIrkj9IG9ZETkXQjAG9iZIF/i3hujq CoOV31EiB4k= =bBud -END PGP SIGNATURE- --~--~-~--~~~---~--~~ 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: Large eager fetches not so eager?
I still have no answer as to what this might be, but I am starting to see it more often. It's now biting me a bit harder as it's beginning to happen on items that I cache on startup and then .expunge(). When I later go to access a relation on the expunged item, the trigger of the lazy loader fails. Looks like it may be becoming a bad idea to rely on eager fetches On Jan 14, 2008 10:06 PM, Rick Morrison [EMAIL PROTECTED] wrote: I had already put together a short test case which as usual is of course working fine, but it's greatly simpler than the in-application use and uses sqlite instead of MSSQL, so I'll bang on it from time to time as I've got a few seconds and I'll see where it goes. I did notice some behavior that might give a clue. Whenever an eagerly loaded item is missing in the list of results, so are all the values that follow. For example, if I shorten my original list to fifty items, 0-43 might be ok. After item 43, then *every* remaining item is missing, so I would think that it's something that traverses the list of results and once it breaks, it stops the traverse. as far as I know, none of the otherwise eagerly loaded items are already mapped, and the joins are not self-referential. It's a three-way join of three different tables as outlined in the orig post. So it might be something new. --~--~-~--~~~---~--~~ 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: DBMS
On Thursday, January 17, 2008, 2:11:56 AM, Christoph Haas wrote: Send me some study material on DBMS. Pardon me... you have all these degrees but still just order the mailing list of an open-source database toolkit to send you some material on DBMS? We must be having a serious language interface problem here. Back when I made my Master of Informatics I learned a whole lot about DBMSs. probably virus? -- Salam, -Jaimy Azle Train yourselft to let go of everything you fear to loose. -- Master Yoda --~--~-~--~~~---~--~~ 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: access the fields in a record as a dict
what, like dict(row) ? that should workno ? On Jan 16, 2008, at 6:29 PM, alex bodnaru wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 hi friends, in older sa i could cast a record to a dict, in order to access their fields by their name, especially if the field name is not a valid python identifier, like a calculated or fixed numeric column. how could i do it again please? tia, alex -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.6 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iQCVAwUBR46TPdpwN1sq38njAQKv7wQArF0nV0WRTZVI/3qdLC5+7yZDspw1bGhT 6H8vPFQKDZCsJNNP98nbV1zKjMC/OfypPOqJvS7T9SpD2XZ9G7LOYeAQpSakzNOO DiJE/vY4SzX83cwfFj218EfzqtOeg0L010sIrkj9IG9ZETkXQjAG9iZIF/i3hujq CoOV31EiB4k= =bBud -END PGP SIGNATURE- --~--~-~--~~~---~--~~ 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: Large eager fetches not so eager?
On Jan 16, 2008, at 7:32 PM, Rick Morrison wrote: I still have no answer as to what this might be, but I am starting to see it more often. It's now biting me a bit harder as it's beginning to happen on items that I cache on startup and then .expunge(). When I later go to access a relation on the expunged item, the trigger of the lazy loader fails. Looks like it may be becoming a bad idea to rely on eager fetches start adding a layer of assertion to your app. try ensuring that none of the desired objects are present in the session beforehand, and that afterwards they are all there and the __dict__ contains the full collections. since it seems like you have very specific areas where you know eager loading is to occur you should start trying to narrow down where its happening. also try putting exception throws in sqlalchemy itself - like inside of mapper._instance(), at the point where it loads an object thats already present and skips loading its attributeshardcode some assertions there specific to your application, possibly relying upon some globals that you set before and after the load operation. do the same inside of strategies.py at the point wehre it says degrading to lazy loader, etc. --~--~-~--~~~---~--~~ 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: Large eager fetches not so eager?
Thanks for the tips. I am sure that none of the objects are loaded beforehand: I've got it localized to a run of unit tests that I can start afresh each time. So far it's intermittent, seems to happen only one of say 10 runs. Happens more frequently on a fresh build of sample data for the test runs. The sample data build takes 45mins, so it's painful to run repeatedly. I'll see if I can wire up something that will loop on it overnight. --~--~-~--~~~---~--~~ 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: access the fields in a record as a dict
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 hi mike, thanks for your prompt answer. it doesn't work anymore, indeed :( alex Michael Bayer wrote: what, like dict(row) ? that should workno ? On Jan 16, 2008, at 6:29 PM, alex bodnaru wrote: hi friends, in older sa i could cast a record to a dict, in order to access their fields by their name, especially if the field name is not a valid python identifier, like a calculated or fixed numeric column. how could i do it again please? tia, alex -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.6 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iQCVAwUBR47GONpwN1sq38njAQKiKwP7BhcGfQIbqXRdoJRSyELSsuDlc8JCoa2W qAsWBARQ8uRdmO/EhDglRN/K/60sMVVUWDbarLH8F/qerC4pwTOrZwQcKyRG/LPL zIftKU9uNg/yS2Q6kmPSPsXbbA1Kjwe/JwbHm0LXPk15fB5vzwXk76F6ae1oDRAO kgb7oQTIbOw= =jmyV -END PGP SIGNATURE- --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---