From: Michel A. <ex...@wi...> - 2006-09-23 11:35:39
|
Recently I had a thought on database exceptions. I am too lazy to repeat, so here is the transcript: 13:21 < exhuma> hmmm... I wonder.... When using turbogears, you generally also use SQLObject or SQLAlchemy. 13:21 < exhuma> Which is good abstractionwise. 13:22 < exhuma> however.... The database exceptions get still raised "into" the controllers files. 13:23 < exhuma> But if you want to be DBMS-agnostic, you should not be required to import the different database's exceptions for intercepting them 13:23 < exhuma> I mean, right now I ran into an exception in my app which comes from psycopg. 13:24 < exhuma> So I need to do something like "from psycopg import ...". If I then wanted to port to a different DBMS I needed to rewrite those statements. 13:24 < exhuma> hummm... actually that's more an SQLObject issue I suppose ;) But let me clarify ;) I like the simplicity of SQLObject. It's beautiful to work with. Main reason for that is that you can be really ignorant about the underlying database system. But one thing slipped through I guess. Let's say you run into an IntegrityError exception. For example if you want to insert something that violates a unique-key constraint in the database. The exception that get's raised from the application is actually the exception from the database module itself (be it MySQLdb, psycopg, or something else). So to catch those exceptions properly you have to either write something like "except MySQLdb.IntegrityError" or somewhere else "from MySQLdb import IntegrityError".But that means you would need to change the code every time you change the DBMS. I beleive that for an abstraction framework like SQLObject it would be much better to have it raise it's own exceptions. So you could do "... except sqlobject.IntegrityError ..." and only make it raise other exceptions if it's not supported or known by SQLObject. What do you think? Best regards, Mich |