tag:blogger.com,1999:blog-11683713.post113624132655854248..comments2024-01-12T21:16:50.520-08:00Comments on Spyced: ORM design part 2Jonathan Ellishttp://www.blogger.com/profile/11003648392946638242noreply@blogger.comBlogger18125tag:blogger.com,1999:blog-11683713.post-1141512621911541212006-03-04T14:50:00.000-08:002006-03-04T14:50:00.000-08:00I think the problem is in th following: ORM is abo...I think the problem is in th following: ORM is about mapping object model to relational model. While object is a good enough structural element to be mapped to the database, there is not good enough thing to be mapped to query language. We have imperative language, but SQL is declarative and though better to do operations with large amount of data. <BR/><BR/>We need a declarative model to operate with objects. <BR/>And <A HREF="http://www.artima.com/weblogs/viewpost.jsp?thread=150834" REL="nofollow">Bruce Eckel agree with me</A> :).<BR/><BR/>And once it would be created we get object advantages from these queries so for example querying<BR/>[x for x in employee if x.age>25]<BR/>will not depend on whether age is a stored field or a property (today()-self.birthdate)<BR/><BR/>SQL in ORM is a kind of embedded assembler in the high level languages: the current compromise between comfort and performanceMax Beluginhttps://www.blogger.com/profile/03910001890342930950noreply@blogger.comtag:blogger.com,1999:blog-11683713.post-1136690275370898542006-01-07T19:17:00.000-08:002006-01-07T19:17:00.000-08:00Ian: I don't think I'm comfortable with this idea ...Ian: I don't think I'm comfortable with this idea that "if a database conforms to schema A, and my code expects schema B, then the right thing to do is to automatically change A to B." Because A is different for a reason. Sometimes that reason is just that A is an older version but not always.<BR/><BR/>But you are right that this can be a useful tool.Jonathan Ellishttps://www.blogger.com/profile/11003648392946638242noreply@blogger.comtag:blogger.com,1999:blog-11683713.post-1136527561976913342006-01-05T22:06:00.000-08:002006-01-05T22:06:00.000-08:00Actually, I would go so far as to say that Axiom u...Actually, I would go so far as to say that Axiom uses SQL in a few ways that exposing SQL would make impractical.<BR/><BR/>First, any ORM must be able to know what it can cache, what it can't, and how everything stands in the face of transactions. Exposing SQL can make this difficult.<BR/><BR/>Second, Axiom does a lot of automatic table munging on the fly (schema upgrades, entity references, List objects) that would be almost impossible with exposing of SQL.<BR/><BR/>In the end, I think that Glyph probably missed the mark a bit. There are interesting objecty things that can be done with Axiom. There is enough of an interface to the relational model in the Axiom's queries and references that you can still take advantage of the underlying SQLs speed.<BR/><BR/>That said, implementing something in Axiom generally would make it almost impossible to properly munge directly through SQL because of how complex its data management is (especially across versions).<BR/><BR/>There is also serious responsibility that comes with keeping both the coding API and SQL storage implementation solid across versions. This is because Axiom uses SQL very differently from most ORMs. Look at powerups, for example. Nobody else does this as elegantly.<BR/><BR/>This is not a problem with Axiom, its a strength of it. It implements a ODB with some of the speed and power of a RDB. It couldn't do it if you were mucking about with the internals.<BR/><BR/>One other nicety of not exposing SQL is that it makes it fairly simple to port to another database. If someone dropped the right amount of money, I bet you could see Axiom running on MySQL, PostgreSQL, or Oracle in a matter of days. Interestingly, not a single Axiom derived application would break.<BR/><BR/>Anyone who has watched the efforts to port any large SQL-based system to another database knows the trouble this saves. I, for one, believe that anything that can be expressed in vanilla SQL can be represented with an appropriate API under any database system. SQL is really too simple to make this difficult. It's one of SQL's strengths.<BR/><BR/>Axiom doesn't much expose SQL for a these very good reasons. Preventing the underskilled from creating SQL injection attacks is a useful as a side effect. Tts focus of this discussion is likely an unnecessary distraction. The real reason that Axiom doesn't expose it is simply because it makes Axiom too complex to be usefully maintained and it makes a number of very useful things far too difficult.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-11683713.post-1136389769799147132006-01-04T07:49:00.000-08:002006-01-04T07:49:00.000-08:00Anonymous said... Real-life SQL Injection vulne...<I> Anonymous said...<BR/><BR/> Real-life SQL Injection vulnerabilities:<BR/> http://www.securityfocus.com/bid/15912<BR/> http://www.securityfocus.com/bid/13620<BR/> http://www.securityfocus.com/bid/13513<BR/>...<BR/>Solved problem? No. No it isn't.<BR/></I> <BR/>OK, now paste one that isnt solved by using bind parameters properly.<BR/><BR/>Solved problem ? Yes. Yes it is.mike bayerhttps://www.blogger.com/profile/01417862951114999907noreply@blogger.comtag:blogger.com,1999:blog-11683713.post-1136387334342719802006-01-04T07:08:00.000-08:002006-01-04T07:08:00.000-08:00Real-life SQL Injection vulnerabilities:http://www...Real-life SQL Injection vulnerabilities:<BR/><BR/>http://www.securityfocus.com/bid/15912<BR/>http://www.securityfocus.com/bid/13620<BR/>http://www.securityfocus.com/bid/13513<BR/>http://www.securityfocus.com/bid/16020<BR/>http://www.securityfocus.com/bid/16039<BR/>http://www.securityfocus.com/bid/13030<BR/>http://www.securityfocus.com/bid/16038<BR/>http://www.securityfocus.com/bid/16097 <BR/>http://www.securityfocus.com/bid/15088<BR/>http://www.securityfocus.com/bid/15676<BR/>http://www.securityfocus.com/bid/14618<BR/>http://www.securityfocus.com/bid/15598<BR/>http://www.securityfocus.com/bid/13649<BR/>http://www.securityfocus.com/bid/13643<BR/>http://www.securityfocus.com/bid/15330<BR/>http://www.securityfocus.com/bid/13355<BR/>http://www.securityfocus.com/bid/15787 <BR/><BR/>Mostly from 2005. There's lots more. I got tired of pasting links.<BR/><BR/>Solved problem? No. No it isn't.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-11683713.post-1136368381805372782006-01-04T01:53:00.000-08:002006-01-04T01:53:00.000-08:00I do know SQL fairly enough and yet I do not wish ...I do know SQL fairly enough and yet I do not wish to use it directly, since ORM semantics may not yield the full expressiveness of SQL, but they tie nicely in with my code, which SQL simply doesn't.<BR/><BR/>I like sqlobject-admin for beeing an easy tool to make me worry less about how to setup the correct database from my ORM modell, +1.<BR/><BR/>One of a the nice things to have would be a tool that helps you convert one schema of a database to another mostly automated. Would quite take a bit of the edge out of changing schemas.Florianhttps://www.blogger.com/profile/06798512674087485252noreply@blogger.comtag:blogger.com,1999:blog-11683713.post-1136343380974984352006-01-03T18:56:00.000-08:002006-01-03T18:56:00.000-08:00Python cannot beat domain specific languages, spec...Python cannot beat domain specific languages, specially <I>good</I> domain specific languages such as SQL, in expressivity. That is why most people familiar with SQL will always feel constrained with any wrapper/mapper in Python. It doesn't matter if an SQL 'feature' is provided, the fact that it's in Python not SQL has already taken it away from the relational model. Unless you have a relational wrapper in Python (which is different from an OR mapper, btw).<BR/><BR/>From the little I've seen SQLAlchemy does a good job of exposing both - a relational wrapper as well as an OR mapper. Otherwise if you have a pure OR mapper, the users will always have to compromise on control, expressivity and/or performance. Of course, the benefit of gaining persistent objects may justify the use in many cases.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-11683713.post-1136329493572571412006-01-03T15:04:00.000-08:002006-01-03T15:04:00.000-08:00I just wanted to note that the notional link to "...I just wanted to note that the notional link to "Why Axiom Doesn't Expose SQL" actually points to the front page of blogger.comAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-11683713.post-1136298695820279332006-01-03T06:31:00.000-08:002006-01-03T06:31:00.000-08:00Well, I'm happy to have gotten such a lively discu...Well, I'm happy to have gotten such a lively discussion going :-).<BR/><BR/>I'll stop trolling for just a moment here to point out another vector of agreement that's probably non-obvious from the way I've been talking about this. Of course your ORM should <I>let you</I> get at SQL, just like Python should let you get at C.<BR/><BR/>If you've written a crappy ORM that needs patching up, the last thing your users are going to want to do is to crack open your source code to start diddling things around so they can get to the SQL, already. As the python community motto goes, "we're all adults here". Axiom <I>does</I> have a way to get at your SQL, "Store.executeSQL". (And by the way, that method will actually raise an exception if you attempt to insert SQL strings by hand rather than using bind parameters ;-))<BR/><BR/>My main point here is that every time a user has to go and call that method, I should recognize it as a failure of my code and attempt to fix it (as I believe other ORM authors should), rather than just accepting "Oh, all my users should know SQL, so if you want to access feature XYZ of course you have to generate some SQL strings yourself".glyphhttps://www.blogger.com/profile/07021175796928101086noreply@blogger.comtag:blogger.com,1999:blog-11683713.post-1136281036519687242006-01-03T01:37:00.000-08:002006-01-03T01:37:00.000-08:00I think you misunderstand the role of sqlobject-ad...I think you misunderstand the role of sqlobject-admin. Code almost always expects a certain schema. In SQLObject that is made explicit, because the class definition also is (generally) sufficient to determine exactly what schema you expect. But whether the expectation is explicit or implicit, it is always there.<BR/><BR/>sqlobject-admin manages the differences between the code's expectations and the actual database. So you can record versions, upgrade a database (via hand-written SQL), create a database from scratch, and see some of the differences between the database and the expected schema.<BR/><BR/>This isn't reinventing the database DDL, but simply a tool that addresses fairly universal issues. You could write the same thing with DDL parsers and whatnot, or the databases could build these sorts of tools in. But DDL parsers are hard and uncommon, and AFAIK databases don't include these kinds of tools.<BR/><BR/>As for SQL injection, the blame lays heavy on the shoulders of PHP. They just got it horribly wrong, so that doing the right thing looks *almost* like doing the very wrong thing, and so that the wrong thing is easier. That's just dumb design, I don't think it really implies much about larger concepts in SQL and database abstraction. It does imply a lot about what your failure cases should be, but that's a different discussion.Ian Bickinghttps://www.blogger.com/profile/10921115783730718101noreply@blogger.comtag:blogger.com,1999:blog-11683713.post-1136255938300428162006-01-02T18:38:00.000-08:002006-01-02T18:38:00.000-08:00Using an ORM primarily to prevent sql-injection at...Using an ORM <I>primarily</I> to prevent sql-injection attacks is, to say the least, overkill. SQL injection attacks are quite rare in Python because the DBAPI gives you such a great interface for escaping values.<BR/><BR/>That said, I've found the most compelling reason for using an ORM is to automate tasks where you need don't know ahead of time what your query will look like.<BR/><BR/>I've found that in many of those instances, simple methods that map dictionaries to queries and back are quite sufficient, like dict2insert or dict2update.<BR/><BR/>But I still love SQLObject. :)Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-11683713.post-1136255362806139852006-01-02T18:29:00.000-08:002006-01-02T18:29:00.000-08:00(troll)"everything the user could possibly want, o...(troll)<BR/>"everything the user could possibly want, or at least everything we think he should want" should be part of the Twisted motto. The rest could be:<BR/><BR/> * in the core package (serial line support)<BR/> * with some bizzare, non-standard-compliant implementation (https)<BR/> * while reimplementing half the Python standard library b/c it's synchronous and we're smarter (logging)<BR/><BR/>What did you expect from Glyph?<BR/>(/troll)<BR/><BR/>That said, Twisted's a great library.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-11683713.post-1136253310166750292006-01-02T17:55:00.000-08:002006-01-02T17:55:00.000-08:00Briefly, the criticism of sqlobject-admin is, it's...Briefly, the criticism of sqlobject-admin is, it's a solution in search of a problem. There already exists a well-defined, standard, supported-by-many-tools method of interacting with your database in DDL, and sqlobject-admin wants to discourage in favor of more verbose, nonstandard, unsupported-by-other-tools sqlobject class definitions... why?Jonathan Ellishttps://www.blogger.com/profile/11003648392946638242noreply@blogger.comtag:blogger.com,1999:blog-11683713.post-1136250888684580702006-01-02T17:14:00.000-08:002006-01-02T17:14:00.000-08:00I'm unclear what the criticism of sqlobject-admin ...I'm unclear what the criticism of sqlobject-admin is. That it doesn't generate any ALTER statements for you, forcing you to write them by hand?Ian Bickinghttps://www.blogger.com/profile/10921115783730718101noreply@blogger.comtag:blogger.com,1999:blog-11683713.post-1136250792223359282006-01-02T17:13:00.000-08:002006-01-02T17:13:00.000-08:00Different ORMs try to play quite different roles. ...Different ORMs try to play quite different roles. Everyone agrees that it is ideal for an application to provide a high-level interface to its database layer which conceals its implementation, and to which one sends very simple messages rather than querying directly with SQL. An ORM library may aim to be a complete wrapper and enforce this separation itself, possibly at the cost of forcing you to use the database in particular way, whether good or bad, or it may merely facilitate your (the software developer's) enforcement of that separation in the creation of your own abstraction layer. The choice here is a matter of taste, probably; PyDO for one prefers the second approach. No matter how pure your ORM is, you can write impure code with it; this being the case, I'd personally rather have a good compromise between convenience and flexibility. Simplicity is nice, too.<BR/><BR/>The comparison with C and memory management isn't entirely apropos, I think. With C, you are forced to manage memory everywhere; it pervades everything you do, and is usually irrelevant to everything you really want to be thinking about while writing an application. An ORM that permits you to use SQL directly doesn't force you to use it everywhere; and when you do use it, the reason for doing so is likely to be relevant to your purpose in writing the application, so you'll think about it as carefully as you know how.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-11683713.post-1136246701122551362006-01-02T16:05:00.000-08:002006-01-02T16:05:00.000-08:00... I should perhaps note that picking on code gen...... I should perhaps note that picking on code generation is something of a straw man. The main point of that earlier post was, as I quoted Sion, <BR/><BR/>"[D]enying derived classes full access to your inner workings just leads to clumsier (less readable and more bug-prone) implementations derivations... [I]t's based on the hubris that you are a better programmer than anyone who might want to extend your class and can forsee all circumstances in which it might be subclassed."<BR/><BR/>The application to ORM tools that try to keep you away from SQL is, I think, clear.Jonathan Ellishttps://www.blogger.com/profile/11003648392946638242noreply@blogger.comtag:blogger.com,1999:blog-11683713.post-1136246469241977072006-01-02T16:01:00.000-08:002006-01-02T16:01:00.000-08:00There are significantly more ways to shoot yoursel...There are significantly more ways to shoot yourself in the foot with buffer overflows in C than there are to expose yourself to an SQL injection, and the defense mechanisms require much more state to be kept in a programmer's head. Equating the two is just silly. Frankly it sounds like you're saying "I got burned by sql injection so it must be a Hard Problem." It's okay to screw up; now you know better. But it's a solved problem for the majority of the world!<BR/><BR/>As to code generation, you're conflating two issues:<BR/><BR/>1) runtime generation is much less fragile than compile-time for some areas, such, as, well, database introspection<BR/><BR/>2) generation of code that doesn't need to be hand-modified afterwards (most SQL) is inherently more robust than generation of code that does (most Python or C#)<BR/><BR/>Finally, for C modules, we did indeed have to write our own wrapper for some POSIX pthread functions in order to get decent condition variable performance. Sometimes that 1% of code you leave out of your tool that does 99% of what users need is the dealbreaker... but every user will have a different 1%.Jonathan Ellishttps://www.blogger.com/profile/11003648392946638242noreply@blogger.comtag:blogger.com,1999:blog-11683713.post-1136245501107993302006-01-02T15:45:00.000-08:002006-01-02T15:45:00.000-08:00Hi, Jonathan :)As far as it's "ridiculously easy" ...Hi, Jonathan :)<BR/><BR/>As far as it's "ridiculously easy" to write injection-proof SQL - it's almost as easy to write buffer-overflow-proof C. Yet, here we are, it's 2006 now, and otherwise bright people are still writing C code with buffer overflows in it and web-based relational database access code with tons of SQL injection vulnerabilities.<BR/><BR/>In the article you cite about "we-know-better-than-you thinking", you say that code generation is "fragile at best". Why is SQL code generation less fragile than Python or C# code generation? If you were writing a program that would generate Python code (however strict its quoting rules), I <I>would</I>, rightly, object that it opened the door to shutil.rmtree attacks. Similarly, if you are actually writing your code in SQL, rather than generating SQL from some other language, I suspect it would not be so vulnerable to attacks.<BR/><BR/>All I'm saying is that you should anticipate the unexpected by writing a non-crappy ORM, not writing a crappy one and letting your users patch it up by executing their own SQL. The C modules that you're using, I assume, aren't interfaces to POSIX functionality, but new functionality in their own right. The equivalent in an ORM is providing graceful access to stored procedures. That <I>doesn't</I> mean that you should be generating the stored procedures (or for that matter, C functions) from your application code.glyphhttps://www.blogger.com/profile/07021175796928101086noreply@blogger.com