From orm-devel@mailman.tux4web.de Sat Mar 1 11:13:38 2003 From: orm-devel@mailman.tux4web.de (Werner F. Bruhin) Date: Sat, 01 Mar 2003 12:13:38 +0100 Subject: [orm-devel] select problem In-Reply-To: <3E5F69A2.9070508@free.fr> References: <3E5F5C1D.3020409@free.fr> <15967.25217.226664.238413@lisa.tux4web.de> <3E5F69A2.9070508@free.fr> Message-ID: <3E6095E2.2040407@free.fr> Hi Diedrich, I figured out the cause of the select problem. - Column names in the db are in capital letters. - Column names in the class definition are in lower case During the select ORM compares the column description returned by kinterbasdb to the class definition and fails and fills the value with None (see around line 175 of orm.dbclass. I see in the code that there is a column name and an attribute name - does this mean I can define column name as "WINENAME" and attribute as "winename" to solve this problem? If yes, can you give me a sample class definition to do this, so I can update fbgen. If no, what do you suggest to get over this (using lower case in db does not work, as somewhere along the line they get converted to upper). BTW - just noticed, looking for doc on the class def format, the spell error on the web page - Sing up .... mailinglist should be "Sign up". See you Werner Werner F. Bruhin wrote: > Hi Diedrich, > > I checked if I get the correct result using kinterbasdb directly with > the following little script. > import kinterbasdb > > con = > kinterbasdb.connect(dsn="c:\\dev\mywinecb\\data\\mywinecb.gdb",user="sysdba",password="masterkey",charset="ISO8859_1") > > > cur = con.cursor() > > cur.execute("SELECT test.id,test.winename FROM test WHERE id=45") > #cur.execute("SELECT* FROM test") > print cur.fetchall() > > The select with the where clause returns the right column. > > Debugging ORM I do not see when the fetchxxx (one or all is called). > > Will go and make myself a tea, maybe that will clear up my vision! > > Have fun with Firebird on Linux. > > See you > Werner > > Diedrich Vorberg wrote: > >> Hi Werner, >> >> >> >>> debug output is: SELECT test.id,test.winename FROM test WHERE id=45 >>> Any hints/help would be appreciated. >>> >> >> >> Try running the query on a plain cursor to see if it returns the >> dataset you'd expect. Use the selectone() method of the cursor and >> check the tuple that's returned. That's exactly what orm does just a >> couple more functioncalls involved..:-) >> >> I'll set up firebird on Linux today and try it myself. Untill than I >> can't say much more. >> >> Diedrich >> >> >> > > > _______________________________________________ > orm-devel mailing list > orm-devel@mailman.tux4web.de > http://mailman.tux4web.de/mailman/listinfo/orm-devel > > From orm-devel@mailman.tux4web.de Sat Mar 1 11:32:39 2003 From: orm-devel@mailman.tux4web.de (Diedrich Vorberg) Date: Sat, 1 Mar 2003 12:32:39 +0100 Subject: [orm-devel] select problem In-Reply-To: <3E6095E2.2040407@free.fr> References: <3E5F5C1D.3020409@free.fr> <15967.25217.226664.238413@lisa.tux4web.de> <3E5F69A2.9070508@free.fr> <3E6095E2.2040407@free.fr> Message-ID: <15968.39511.164035.988214@lisa.tux4web.de> Hi Werner, >- Column names in the db are in capital letters. >- Column names in the class definition are in lower case this is odd: as I remember SQL requires case*in*sensitivity. But I don't know for sure to be honest. >I see in the code that there is a column name and an attribute name - >does this mean I can define column name as "WINENAME" and attribute as >"winename" to solve this problem? Yes, that's the way to go. >If yes, can you give me a sample class definition to do this, so I can >update fbgen. class test(dbclass): columns = { "id": gen(), "winename": varchar(columnName="WINENAME") } orm.columns.varchar is an alias for orm.columns._string which is a descendant of datatype so it inherits datatype's __init__. That's where the columnName argument is defined (ref: orm/columns.py:269). >If no, what do you suggest to get over this (using lower case in db does >not work, as somewhere along the line they get converted to upper). If upper case columns names are a rule of the RDBMs it should be put into the adapter's datasource module. The datasource_base class has a method selectColumns() which returns a string as "col1, col2, col3" for any SQL SELECT query generated by orm. The firebird datasource should probably overload it like this: def selectColumns(self, dbclass): """ Firebird expects columns names to be upper case in general. """ return string.upper(datasource_base.dbclass.selectColumns(self)) As a sidenote: That's the same method that's adding the infamous "oid," to the pgsql's adapter's SELECT queries. >BTW - just noticed, looking for doc on the class def format, the spell >error on the web page - Sing up .... mailinglist should be "Sign up". Fixed. Thanks! Diedrich -- _..._ Diedrich Vorberg .' '. / _ _ \ http://www.tux4web.de | (o)_(o) | info@tux4web.de \( ) / .---. //'._.'\ \ / \ Internet Dienstleistungen // . \ \ \.@-@./ und 'Consulting'. || . \ \ /`\_/`\ |\ : / | // _ \\ Linux Rules! \ `) ' (` /_ | \ )|_ _)``".____,.'"` (_ /`\_`> <_/ \ ) )'--'( ( \__/'---'\__/ '---` `---` From orm-devel@mailman.tux4web.de Sat Mar 1 13:03:37 2003 From: orm-devel@mailman.tux4web.de (Werner F. Bruhin) Date: Sat, 01 Mar 2003 14:03:37 +0100 Subject: [orm-devel] Dir structure for DOC Message-ID: <3E60AFA9.6010107@free.fr> Diedrich, I would like to create some samples/test stuff for Firebird. Instead of having it all in a directory mixed in with code which DOES not work for Firebird, I would prefer to setup a directory, e.g. doc/firebird, which then would contain a dir adbase with a version of adbase for Firebird etc etc. Let me know if you are fine with this or how else you would like to handle it. See you Werner From orm-devel@mailman.tux4web.de Sat Mar 1 13:49:08 2003 From: orm-devel@mailman.tux4web.de (Diedrich Vorberg) Date: Sat, 1 Mar 2003 14:49:08 +0100 Subject: [orm-devel] Dir structure for DOC In-Reply-To: <3E60AFA9.6010107@free.fr> References: <3E60AFA9.6010107@free.fr> Message-ID: <15968.47700.966628.357850@lisa.tux4web.de> Hi Werner, >Let me know if you are fine with this or how else you would like to >handle it. I'd prefer doc/examples/firebird. Could you perhaps modify doc/examples/examples.py so it also supports firebird? This way the basic sanity test (test_*) will work, too. I'll start working on examples.py's MySQL support, which is currently broken. I'll let you know, when I'm done. Diedrich -- _..._ Diedrich Vorberg .' '. / _ _ \ http://www.tux4web.de | (o)_(o) | info@tux4web.de \( ) / .---. //'._.'\ \ / \ Internet Dienstleistungen // . \ \ \.@-@./ und 'Consulting'. || . \ \ /`\_/`\ |\ : / | // _ \\ Linux Rules! \ `) ' (` /_ | \ )|_ _)``".____,.'"` (_ /`\_`> <_/ \ ) )'--'( ( \__/'---'\__/ '---` `---` From orm-devel@mailman.tux4web.de Sat Mar 1 14:53:45 2003 From: orm-devel@mailman.tux4web.de (Werner F. Bruhin) Date: Sat, 01 Mar 2003 15:53:45 +0100 Subject: [orm-devel] Dir structure for DOC In-Reply-To: <15968.47700.966628.357850@lisa.tux4web.de> References: <3E60AFA9.6010107@free.fr> <15968.47700.966628.357850@lisa.tux4web.de> Message-ID: <3E60C979.1050709@free.fr> Hi Diedrich, Sounds good. See you Werner Diedrich Vorberg wrote: >Hi Werner, > > > >>Let me know if you are fine with this or how else you would like to >>handle it. >> >> >I'd prefer doc/examples/firebird. > >Could you perhaps modify doc/examples/examples.py so it also supports >firebird? This way the basic sanity test (test_*) will work, too. >I'll start working on examples.py's MySQL support, which is currently >broken. I'll let you know, when I'm done. > >Diedrich > > > From orm-devel@mailman.tux4web.de Sun Mar 2 10:34:01 2003 From: orm-devel@mailman.tux4web.de (Werner F. Bruhin) Date: Sun, 02 Mar 2003 11:34:01 +0100 Subject: [orm-devel] SelectByPrimaryKey problem Message-ID: <3E61DE19.8040300@free.fr> Hi Diedrich, I am back to trying to solve this problem. My current test script does this: result = ds.select(test, ID=45) w2 = result.fetchone() print w2 - no problem up to here w2 = ds.selectByPrimaryKey(test, 45) print w2 On the selectByPrimaryKey I get Illegal Primary key - see line 334 of orm.datasource. When I debug "result" from line 332 it is always empty. The code runs through: selectByClause - I think no problem here runSelect - I think no problem here selectResult - here we do have a problem, this returns none (we only touch __init__, which does not provide a return value), which returns to runSelect and it sets result to the return value of none. If I comment 334 to 336 the code works, but obviously no check is done. My question: what are you trying to check at that moment? Is there something returned by the other DB's at that point, if yes what? See you Werner From orm-devel@mailman.tux4web.de Sun Mar 2 15:44:42 2003 From: orm-devel@mailman.tux4web.de (Diedrich Vorberg) Date: Sun, 2 Mar 2003 16:44:42 +0100 Subject: [orm-devel] SelectByPrimaryKey problem In-Reply-To: <3E61DE19.8040300@free.fr> References: <3E61DE19.8040300@free.fr> Message-ID: <15970.9962.489225.511148@lisa.local.> Hi Werner, >If I comment 334 to 336 the code works, but obviously no check is done. > >My question: what are you trying to check at that moment? Is there >something returned by the other DB's at that point, if yes what? the problem might be the queryResult.__len__() method called by the len() function in selectByPrimaryKey(). It returns the cursor's rowcount attribute. Could you verify, that this attribute is set correctly be the DB API? If it isn't I'd have to rephrase the selectByPrimaryKey() method to skip the len() test and check the returnvalue of fetchone() instead. Diedrich -- _..._ Diedrich Vorberg .' '. / _ _ \ http://www.tux4web.de | (o)_(o) | info@tux4web.de \( ) / .---. //'._.'\ \ / \ Internet Dienstleistungen // . \ \ \.@-@./ und 'Consulting'. || . \ \ /`\_/`\ |\ : / | // _ \\ Linux Rules! \ `) ' (` /_ | \ )|_ _)``".____,.'"` (_ /`\_`> <_/ \ ) )'--'( ( \__/'---'\__/ '---` `---` From orm-devel@mailman.tux4web.de Sun Mar 2 17:59:12 2003 From: orm-devel@mailman.tux4web.de (Ross J. Reedstrom) Date: Sun, 2 Mar 2003 11:59:12 -0600 Subject: [orm-devel] select problem In-Reply-To: <15968.39511.164035.988214@lisa.tux4web.de> References: <3E5F5C1D.3020409@free.fr> <15967.25217.226664.238413@lisa.tux4web.de> <3E5F69A2.9070508@free.fr> <3E6095E2.2040407@free.fr> <15968.39511.164035.988214@lisa.tux4web.de> Message-ID: <20030302175912.GC9340@wallace.ece.rice.edu> On Sat, Mar 01, 2003 at 12:32:39PM +0100, Diedrich Vorberg wrote: > Hi Werner, > > >- Column names in the db are in capital letters. > >- Column names in the class definition are in lower case > this is odd: as I remember SQL requires case*in*sensitivity. But I > don't know for sure to be honest. Yup, all identifiers (table, column, function names, etc.) are case insensitive, unless quoted (with "). The part that's catching you here is that theat's usually implemented by them not being case-preserving, either: Oracle (and FB, apparently) upcase all unquoted identifiers. PostgreSQL, on the other hand, downcases everything, the way C programmers like it. ;-) The problem arised, then, when the case-altered value is returned, and compared in python (which, of course, is case sensitive) > >If no, what do you suggest to get over this (using lower case in db does > >not work, as somewhere along the line they get converted to upper). You can probably quote everythngi, but it's a pain: I did a whole DB schema with MixedCase once, and I almost went mad with things like: select "Table1Name"."Column1Name", "Table2Name".* from "Table1", "Table2" where ... You get the idea. > If upper case columns names are a rule of the RDBMs it should be put > into the adapter's datasource module. The datasource_base class has a > method selectColumns() which returns a string as "col1, col2, col3" > for any SQL SELECT query generated by orm. The firebird datasource > should probably overload it like this: > > def selectColumns(self, dbclass): > """ > Firebird expects columns names to be upper case in general. > """ > return string.upper(datasource_base.dbclass.selectColumns(self)) > Hmm, it's not FireBird that's having the problem with column names, I think: it's orm. Be careful about up/down casing, since the SQL spec says these names can be _anything_ if quoted properly: SELECT "#" from "My Really silly-tablename" is perfectly valid SQL. Ross From orm-devel@mailman.tux4web.de Sun Mar 2 18:00:19 2003 From: orm-devel@mailman.tux4web.de (Werner F. Bruhin) Date: Sun, 02 Mar 2003 19:00:19 +0100 Subject: [orm-devel] Some questions Message-ID: <3E6246B3.2070203@free.fr> Hi Diedrich, Will move firebird/adbase up in a moment. While trying to get it to work (nearly there) I "found" some questions. - Is there a way to define the foreign key columns - i.e. override the default parenttable_id format to e.g. FK_whatever? - BTW - the second address append uses the wrong object (home again instead of atwork) - Will you fix this for msql and postgre or should I? I am actually surprised that the append issues an Update, should we not have to do the append first, and it only inserts the person id into the address object and then do the insert for the address (no update). The current approach will NOT work if the DB enforces integrity or just does not allow null in person_id. - Is storing the height and width of the picture some db requirement? - Where do I get the PIL/image module from? - the import throws an error that it can't find it. See you Werner From orm-devel@mailman.tux4web.de Sun Mar 2 18:14:56 2003 From: orm-devel@mailman.tux4web.de (Werner F. Bruhin) Date: Sun, 02 Mar 2003 19:14:56 +0100 Subject: [orm-devel] select problem In-Reply-To: <20030302175912.GC9340@wallace.ece.rice.edu> References: <3E5F5C1D.3020409@free.fr> <15967.25217.226664.238413@lisa.tux4web.de> <3E5F69A2.9070508@free.fr> <3E6095E2.2040407@free.fr> <15968.39511.164035.988214@lisa.tux4web.de> <20030302175912.GC9340@wallace.ece.rice.edu> Message-ID: <3E624A20.1000201@free.fr> Ross, Thanks for your comments. For the moment I went with specifying columnName in the orm class definition - as they are generated (by fbgen) this is an easy way around the problem - at least for the moment. See you Werner Ross J. Reedstrom wrote: >On Sat, Mar 01, 2003 at 12:32:39PM +0100, Diedrich Vorberg wrote: > > >>Hi Werner, >> >> >> >>>- Column names in the db are in capital letters. >>>- Column names in the class definition are in lower case >>> >>> >>this is odd: as I remember SQL requires case*in*sensitivity. But I >>don't know for sure to be honest. >> >> > >Yup, all identifiers (table, column, function names, etc.) are case >insensitive, unless quoted (with "). The part that's catching you here is >that theat's usually implemented by them not being case-preserving, either: >Oracle (and FB, apparently) upcase all unquoted identifiers. PostgreSQL, >on the other hand, downcases everything, the way C programmers like it. ;-) > >The problem arised, then, when the case-altered value is returned, and >compared in python (which, of course, is case sensitive) > > > >>>If no, what do you suggest to get over this (using lower case in db does >>>not work, as somewhere along the line they get converted to upper). >>> >>> > >You can probably quote everythngi, but it's a pain: I did a whole DB schema >with MixedCase once, and I almost went mad with things like: > >select "Table1Name"."Column1Name", "Table2Name".* from "Table1", "Table2" >where ... > >You get the idea. > > > >>If upper case columns names are a rule of the RDBMs it should be put >>into the adapter's datasource module. The datasource_base class has a >>method selectColumns() which returns a string as "col1, col2, col3" >>for any SQL SELECT query generated by orm. The firebird datasource >>should probably overload it like this: >> >> def selectColumns(self, dbclass): >> """ >> Firebird expects columns names to be upper case in general. >> """ >> return string.upper(datasource_base.dbclass.selectColumns(self)) >> >> >> > >Hmm, it's not FireBird that's having the problem with column names, I think: >it's orm. Be careful about up/down casing, since the SQL spec says these >names can be _anything_ if quoted properly: > >SELECT "#" from "My Really silly-tablename" > >is perfectly valid SQL. > >Ross >_______________________________________________ >orm-devel mailing list >orm-devel@mailman.tux4web.de >http://mailman.tux4web.de/mailman/listinfo/orm-devel > > > > From orm-devel@mailman.tux4web.de Sun Mar 2 18:16:59 2003 From: orm-devel@mailman.tux4web.de (Werner F. Bruhin) Date: Sun, 02 Mar 2003 19:16:59 +0100 Subject: [orm-devel] SelectByPrimaryKey problem In-Reply-To: <15970.9962.489225.511148@lisa.local.> References: <3E61DE19.8040300@free.fr> <15970.9962.489225.511148@lisa.local.> Message-ID: <3E624A9B.9000802@free.fr> Hi Diedrich, Will look into it. If it does not do and the db-api spec defines it I am quit sure that David Rushby (kinterbasdb) will fix it. See you Werner Diedrich Vorberg wrote: >Hi Werner, > > > >>If I comment 334 to 336 the code works, but obviously no check is done. >> >>My question: what are you trying to check at that moment? Is there >>something returned by the other DB's at that point, if yes what? >> >> > >the problem might be the queryResult.__len__() method called by the >len() function in selectByPrimaryKey(). It returns the cursor's >rowcount attribute. Could you verify, that this attribute is set >correctly be the DB API? > >If it isn't I'd have to rephrase the selectByPrimaryKey() method to >skip the len() test and check the returnvalue of fetchone() instead. > >Diedrich > > > From orm-devel@mailman.tux4web.de Sun Mar 2 18:27:58 2003 From: orm-devel@mailman.tux4web.de (Werner F. Bruhin) Date: Sun, 02 Mar 2003 19:27:58 +0100 Subject: [orm-devel] SelectByPrimaryKey problem In-Reply-To: <15970.9962.489225.511148@lisa.local.> References: <3E61DE19.8040300@free.fr> <15970.9962.489225.511148@lisa.local.> Message-ID: <3E624D2E.6060409@free.fr> Hi Diedrich, Unlike me I checked the documentation for kinterbasdb before anything else, and it clearly states that rowcount is NOT supported due to Interbase and Firebird limition (see below). Checked the Firebird 1.5 beta change notes and it does not look like anything changed to this affect. *Unsupported Features* * |Cursor| class o |nextset| method This method is not implemented because the database engine does not support opening multiple result sets simultaneously with a single cursor. o |rowcount| attribute The value of this attribute is initially |-1|, and it never changes, because the Interbase/Firebird C API does not support the determination of the number of rows affected by an executed statement. See you Werner Diedrich Vorberg wrote: >Hi Werner, > > > >>If I comment 334 to 336 the code works, but obviously no check is done. >> >>My question: what are you trying to check at that moment? Is there >>something returned by the other DB's at that point, if yes what? >> >> > >the problem might be the queryResult.__len__() method called by the >len() function in selectByPrimaryKey(). It returns the cursor's >rowcount attribute. Could you verify, that this attribute is set >correctly be the DB API? > >If it isn't I'd have to rephrase the selectByPrimaryKey() method to >skip the len() test and check the returnvalue of fetchone() instead. > >Diedrich > > > From orm-devel@mailman.tux4web.de Sun Mar 2 19:44:35 2003 From: orm-devel@mailman.tux4web.de (Diedrich Vorberg) Date: Sun, 2 Mar 2003 20:44:35 +0100 Subject: [orm-devel] select problem In-Reply-To: <20030302175912.GC9340@wallace.ece.rice.edu> References: <3E5F5C1D.3020409@free.fr> <15967.25217.226664.238413@lisa.tux4web.de> <3E5F69A2.9070508@free.fr> <3E6095E2.2040407@free.fr> <15968.39511.164035.988214@lisa.tux4web.de> <20030302175912.GC9340@wallace.ece.rice.edu> Message-ID: <15970.24355.437528.452929@lisa.local.> Hi Ross, >PostgreSQL, >on the other hand, downcases everything, the way C programmers like it. ;-) That's why it never showed up, I stuck to lower case identifiers. >The problem arised, then, when the case-altered value is returned, and >compared in python (which, of course, is case sensitive) Agreed. >Hmm, it's not FireBird that's having the problem with column names, I think: >it's orm. Be careful about up/down casing, since the SQL spec says these >names can be _anything_ if quoted properly: > >SELECT "#" from "My Really silly-tablename" > >is perfectly valid SQL. ORM aims at making SQL identifiers independent from SQL identifiers. You can use a columnName attribute with every datatype in your columns dict and you can set the tableName attribute in each of your dbclasses. The problem is, that cases in which these are anything else but valid lowercase Python identifiers is not tested very well. That's why the comparison issue never showed up. Also, the SQL syntax using quotes is never used so you'd end up having the same problem. As you pointed out above it does not make a great deal of sense to use anything but "Python like" identifiers in SQL. How desireble is it for ORM to consider this case and modify the procedures that create SQL statements accordingly? >Ross Thanks for pointing this our Ross! Diedrich -- _..._ Diedrich Vorberg .' '. / _ _ \ http://www.tux4web.de | (o)_(o) | info@tux4web.de \( ) / .---. //'._.'\ \ / \ Internet Dienstleistungen // . \ \ \.@-@./ und 'Consulting'. || . \ \ /`\_/`\ |\ : / | // _ \\ Linux Rules! \ `) ' (` /_ | \ )|_ _)``".____,.'"` (_ /`\_`> <_/ \ ) )'--'( ( \__/'---'\__/ '---` `---` From orm-devel@mailman.tux4web.de Sun Mar 2 19:59:34 2003 From: orm-devel@mailman.tux4web.de (Diedrich Vorberg) Date: Sun, 2 Mar 2003 20:59:34 +0100 Subject: [orm-devel] Some questions In-Reply-To: <3E6246B3.2070203@free.fr> References: <3E6246B3.2070203@free.fr> Message-ID: <15970.25254.41024.261371@lisa.local.> Hi Werner, >- Is there a way to define the foreign key columns - i.e. override the >default parenttable_id format to e.g. FK_whatever? you can pass the columnName, foreignKeyColumn or one of the other attributes to the relationship classes when defining your columns dict. See the constructor of one2one, one2many, etc >- BTW - the second address append uses the wrong object (home again >instead of atwork) - Will you fix this for msql and postgre or should I? Done. Thanks! >I am actually surprised that the append issues an Update, should we not >have to do the append first, and it only inserts the person id into the >address object and then do the insert for the address (no update). The >current approach will NOT work if the DB enforces integrity or just does >not allow null in person_id. Correct. There is a silly reason this is coded that way: I hadn't heard about SQL constrains at the time. I'll bring this up in a more general eMail shortly. >- Is storing the height and width of the picture some db requirement? Nope. Just a slightly younger me trying to show off with my knowlage of PIL and Python's unpack syntax. Also I wondered if the unpacking would work well with my __setattr__() methods. Storing image data in the RDMBS was a reqirement of the project ORM grew up with though. >- Where do I get the PIL/image module from? - the import throws an >error that it can't find it. For PIL checkout http://www.pythonware.com/products/pil/ If you ever have to work with images PIL's absolutely cool. Diedrich -- _..._ Diedrich Vorberg .' '. / _ _ \ http://www.tux4web.de | (o)_(o) | info@tux4web.de \( ) / .---. //'._.'\ \ / \ Internet Dienstleistungen // . \ \ \.@-@./ und 'Consulting'. || . \ \ /`\_/`\ |\ : / | // _ \\ Linux Rules! \ `) ' (` /_ | \ )|_ _)``".____,.'"` (_ /`\_`> <_/ \ ) )'--'( ( \__/'---'\__/ '---` `---` From orm-devel@mailman.tux4web.de Sun Mar 2 20:11:40 2003 From: orm-devel@mailman.tux4web.de (Diedrich Vorberg) Date: Sun, 2 Mar 2003 21:11:40 +0100 Subject: [orm-devel] SelectByPrimaryKey problem In-Reply-To: <3E624D2E.6060409@free.fr> References: <3E61DE19.8040300@free.fr> <15970.9962.489225.511148@lisa.local.> <3E624D2E.6060409@free.fr> Message-ID: <15970.25980.558164.336261@lisa.local.> I've modified the selectByPrimaryKey() method to check the value returned by fetchone() to determine whether the key is valid. Diedrich -- _..._ Diedrich Vorberg .' '. / _ _ \ http://www.tux4web.de | (o)_(o) | info@tux4web.de \( ) / .---. //'._.'\ \ / \ Internet Dienstleistungen // . \ \ \.@-@./ und 'Consulting'. || . \ \ /`\_/`\ |\ : / | // _ \\ Linux Rules! \ `) ' (` /_ | \ )|_ _)``".____,.'"` (_ /`\_`> <_/ \ ) )'--'( ( \__/'---'\__/ '---` `---` From orm-devel@mailman.tux4web.de Sun Mar 2 20:45:31 2003 From: orm-devel@mailman.tux4web.de (Diedrich Vorberg) Date: Sun, 2 Mar 2003 21:45:31 +0100 Subject: [orm-devel] When to execute INSERT statements Message-ID: <15970.28011.139313.657027@lisa.local.> Hello everybody, Werner's work on the Firebird adapter and his thinking-through of ORM brought up a point I was thinking about ago some time back: should ORM automatically create INSERT statements of dependant objects? Answer: H=E4=E4=E4=E4... (Anohter free German lesson: it means: "What the heck are'ya=20 talking about?" ;-) Ok, let me illustrate my point with an example: Let's say I've got the old one2many relationship of authors and books. Storing the information of "'A Farewell To Arms' and 'The Old Man And The Sea' are writen by Hemingway" would look like: ernest =3D author(name=3D"Hemingway") ds.insert(ernest) book1 =3D book(title=3D"A Farewall To Arms") ds.insert(book1) ernest.books.append(book1) book2 =3D book(title=3D"The Old Man And The Sea") ds.insert(book2) ernest.books.append(book2) ds.commit() This will result in one INSERT for Ernest and one INSERT plus one=20 UPDATE statement for the books. As Werner correctly pointed out, this=20= will fail if the backend enforces constrains to ensure table=20 integrity: the books are INSERTed with empty book_id columns. Also=20 there are five statements where three would do. My argument for implementing this the way I did was, that I wanted=20 the programmer to knowingly insert things in the database so he knows=20= exactly what's going on. There is another, simmilar case I was thinking about: ernest =3D author(name=3D"Steinbeck", books=3D[book(title=3D"Tortilla Flat"), book(title=3D"Cannery Row")]) Here dbclass' constructor would have to automatically issue three INSERT statements. This get's sort of complicated if book had another relationship as one of it's attributes. Of course ds.insert() could recursively travers the resulting object tree and create appropriate INSERTs but if something goes wrong inside ORM or the data model has a subtlety this can be very hard to look-through and debug. My idea for this would be to extend the UPDATE statement cache to=20 also include CREATEs and this way avoid redundant SQL queries and the=20= problem with constrains. (As a reminder: the update cache keeps track of all UPDATE statements=20= and joins consecutive UPDATEs on the same object into a single=20 statement.) Do you think this a good idea? What kind of drawbacks would you expect (increased complexity aside)? Do you think the subtlety of one ds.insert() or append() call=20 creating several SQL statements can be lived with? Diedrich --=20 _..._ Diedrich Vorberg .' '. / _ _ \ http://www.tux4web.de | (o)_(o) | info@tux4web.de \( ) / .---. //'._.'\ \ / \ Internet Dienstleistungen // . \ \ \.@-@./ und 'Consulting'. || . \ \ /`\_/`\ |\ : / | // _ \\ Linux Rules! \ `) ' (` /_ | \ )|_ _)``".____,.'"` (_ /`\_`> <_/ \ ) )'--'( ( \__/'---'\__/ '---` `---` From orm-devel@mailman.tux4web.de Mon Mar 3 09:37:18 2003 From: orm-devel@mailman.tux4web.de (Werner F. Bruhin) Date: Mon, 03 Mar 2003 10:37:18 +0100 Subject: [orm-devel] Update problem - string quoting Message-ID: <3E63224E.50809@free.fr> Hi Diedrich, kinterbasdb throws an error Token unknown "some" when doing ds.update(w, 'winename', 'some really new stuff') When escaping a set of quotes it works. ds.update(w, 'winename', '\'some really new stuff\'') See you Werner From orm-devel@mailman.tux4web.de Mon Mar 3 09:38:36 2003 From: orm-devel@mailman.tux4web.de (Werner F. Bruhin) Date: Mon, 03 Mar 2003 10:38:36 +0100 Subject: [orm-devel] SelectByPrimaryKey problem In-Reply-To: <15970.25980.558164.336261@lisa.local.> References: <3E61DE19.8040300@free.fr> <15970.9962.489225.511148@lisa.local.> <3E624D2E.6060409@free.fr> <15970.25980.558164.336261@lisa.local.> Message-ID: <3E63229C.9000004@free.fr> Hi Diedrich, First, you give me too much credit! Don't think I am thinking ORM through, it is more a plowing through. Overall ORM is still too complex for me to grasp all the intricacies. Got the latest version for this, sorry, but I don't think it works. I think (no I guess) that the problem comes from returning "result.fetchone()" instead of just returning "ret". However if I use the following code. ret = result.fetchone() if ret is None: raise IllegalPrimaryKey("%s in %s" % (fmt, dbclass.__name__)) else: return ret It works, BUT we never get IllegalPrimaryKey, instead result.fetchone() already raises an exception (if key is illegal) for an empty result (see below), as the stack shows were we are coming from isn't that already good enough. w2 = ds.selectByPrimaryKey(test, 450) File "C:\Python22\lib\site-packages\orm\datasource.py", line 338, in selectByPrimaryKey ret = result.fetchone() File "C:\Python22\lib\site-packages\orm\datasource.py", line 625, in fetchone queryResult.fetchone(self)) File "C:\Python22\lib\site-packages\orm\dbclass.py", line 158, in _fromTuple if tpl == None: raise EmptyResultError() orm.errors.EmptyResultError See you Werner Diedrich Vorberg wrote: >I've modified the selectByPrimaryKey() method to check the value >returned by fetchone() to determine whether the key is valid. > >Diedrich > > From orm-devel@mailman.tux4web.de Mon Mar 3 10:27:16 2003 From: orm-devel@mailman.tux4web.de (Diedrich Vorberg) Date: Mon, 3 Mar 2003 11:27:16 +0100 Subject: [orm-devel] SelectByPrimaryKey problem In-Reply-To: <3E63229C.9000004@free.fr> References: <3E61DE19.8040300@free.fr> <15970.9962.489225.511148@lisa.local.> <3E624D2E.6060409@free.fr> <15970.25980.558164.336261@lisa.local.> <3E63229C.9000004@free.fr> Message-ID: <15971.11780.949533.880580@lisa.tux4web.de> Mea culpa. Should have run a test... update from CVS, please. -- _..._ Diedrich Vorberg .' '. / _ _ \ http://www.tux4web.de | (o)_(o) | info@tux4web.de \( ) / .---. //'._.'\ \ / \ Internet Dienstleistungen // . \ \ \.@-@./ und 'Consulting'. || . \ \ /`\_/`\ |\ : / | // _ \\ Linux Rules! \ `) ' (` /_ | \ )|_ _)``".____,.'"` (_ /`\_`> <_/ \ ) )'--'( ( \__/'---'\__/ '---` `---` From orm-devel@mailman.tux4web.de Mon Mar 3 10:28:05 2003 From: orm-devel@mailman.tux4web.de (Diedrich Vorberg) Date: Mon, 3 Mar 2003 11:28:05 +0100 Subject: [orm-devel] Update problem - string quoting In-Reply-To: <3E63224E.50809@free.fr> References: <3E63224E.50809@free.fr> Message-ID: <15971.11829.909865.277845@lisa.tux4web.de> Hi Werner, >ds.update(w, 'winename', 'some really new stuff') > >When escaping a set of quotes it works. > >ds.update(w, 'winename', '\'some really new stuff\'') this is the desired behaviour, the 2nd argument is ment to be an SQL literal to go in the UPDATE statement. Diedrich -- _..._ Diedrich Vorberg .' '. / _ _ \ http://www.tux4web.de | (o)_(o) | info@tux4web.de \( ) / .---. //'._.'\ \ / \ Internet Dienstleistungen // . \ \ \.@-@./ und 'Consulting'. || . \ \ /`\_/`\ |\ : / | // _ \\ Linux Rules! \ `) ' (` /_ | \ )|_ _)``".____,.'"` (_ /`\_`> <_/ \ ) )'--'( ( \__/'---'\__/ '---` `---` From orm-devel@mailman.tux4web.de Mon Mar 3 11:20:35 2003 From: orm-devel@mailman.tux4web.de (Werner F. Bruhin) Date: Mon, 03 Mar 2003 12:20:35 +0100 Subject: [orm-devel] Update problem - string quoting In-Reply-To: <15971.11829.909865.277845@lisa.tux4web.de> References: <3E63224E.50809@free.fr> <15971.11829.909865.277845@lisa.tux4web.de> Message-ID: <3E633A83.9060708@free.fr> Hi Diedrich, Isn't this a bit confusion, in insert we do this: w = test(WINENAME='some new ORM stuff') but in update I have to think of putting in the escaped quotes, or is just me? See you Werner Diedrich Vorberg wrote: >Hi Werner, > > > >>ds.update(w, 'winename', 'some really new stuff') >> >>When escaping a set of quotes it works. >> >>ds.update(w, 'winename', '\'some really new stuff\'') >> >> > >this is the desired behaviour, the 2nd argument is ment to be an SQL >literal to go in the UPDATE statement. > >Diedrich > > > From orm-devel@mailman.tux4web.de Mon Mar 3 11:27:21 2003 From: orm-devel@mailman.tux4web.de (Werner F. Bruhin) Date: Mon, 03 Mar 2003 12:27:21 +0100 Subject: [orm-devel] SelectByPrimaryKey problem In-Reply-To: <15971.11780.949533.880580@lisa.tux4web.de> References: <3E61DE19.8040300@free.fr> <15970.9962.489225.511148@lisa.local.> <3E624D2E.6060409@free.fr> <15970.25980.558164.336261@lisa.local.> <3E63229C.9000004@free.fr> <15971.11780.949533.880580@lisa.tux4web.de> Message-ID: <3E633C19.6070109@free.fr> Hi Diedrich, No problem, BUT why bother with the IllegalPrimaryKey exception, I don't think we will ever get this, as fetchone will complain. See you Werner Diedrich Vorberg wrote: >Mea culpa. Should have run a test... update from CVS, please. > > From orm-devel@mailman.tux4web.de Mon Mar 3 12:57:57 2003 From: orm-devel@mailman.tux4web.de (Diedrich Vorberg) Date: Mon, 3 Mar 2003 13:57:57 +0100 Subject: [orm-devel] Update problem - string quoting In-Reply-To: <3E633A83.9060708@free.fr> References: <3E63224E.50809@free.fr> <15971.11829.909865.277845@lisa.tux4web.de> <3E633A83.9060708@free.fr> Message-ID: <15971.20821.860363.558522@lisa.tux4web.de> >w = test(WINENAME='some new ORM stuff') > >but in update I have to think of putting in the escaped quotes, or is >just me? the update() method is not ment to be used directly. It is called by dbclass.__setattr__(). It should be protected, but all classes derived from dbclass would need their own update() method in each datasource class than. Python's attribute access mechanism is not as sophisticated as e.g. C++'s. Diedrich -- _..._ Diedrich Vorberg .' '. / _ _ \ http://www.tux4web.de | (o)_(o) | info@tux4web.de \( ) / .---. //'._.'\ \ / \ Internet Dienstleistungen // . \ \ \.@-@./ und 'Consulting'. || . \ \ /`\_/`\ |\ : / | // _ \\ Linux Rules! \ `) ' (` /_ | \ )|_ _)``".____,.'"` (_ /`\_`> <_/ \ ) )'--'( ( \__/'---'\__/ '---` `---` From orm-devel@mailman.tux4web.de Mon Mar 3 13:01:41 2003 From: orm-devel@mailman.tux4web.de (Diedrich Vorberg) Date: Mon, 3 Mar 2003 14:01:41 +0100 Subject: [orm-devel] SelectByPrimaryKey problem In-Reply-To: <3E633C19.6070109@free.fr> References: <3E61DE19.8040300@free.fr> <15970.9962.489225.511148@lisa.local.> <3E624D2E.6060409@free.fr> <15970.25980.558164.336261@lisa.local.> <3E63229C.9000004@free.fr> <15971.11780.949533.880580@lisa.tux4web.de> <3E633C19.6070109@free.fr> Message-ID: <15971.21045.540563.969434@lisa.tux4web.de> >No problem, BUT why bother with the IllegalPrimaryKey exception, I don't >think we will ever get this, as fetchone will complain. fetchone() will return None. I've decided to create the exception instead of returning None to the caller, because imho passing an illegal key should be considered an error condition and that's represented better by an exception than by an if x is None: clause. Diedrich -- _..._ Diedrich Vorberg .' '. / _ _ \ http://www.tux4web.de | (o)_(o) | info@tux4web.de \( ) / .---. //'._.'\ \ / \ Internet Dienstleistungen // . \ \ \.@-@./ und 'Consulting'. || . \ \ /`\_/`\ |\ : / | // _ \\ Linux Rules! \ `) ' (` /_ | \ )|_ _)``".____,.'"` (_ /`\_`> <_/ \ ) )'--'( ( \__/'---'\__/ '---` `---` From orm-devel@mailman.tux4web.de Mon Mar 3 16:23:57 2003 From: orm-devel@mailman.tux4web.de (Werner F. Bruhin) Date: Mon, 03 Mar 2003 17:23:57 +0100 Subject: [orm-devel] one2one test - problem Message-ID: <3E63819D.8020904@free.fr> Hi Diedrich, I am just about uploading some example stuff. I am getting: File "test_one2one.py", line 142, in ? print p.child.child_data AttributeError: 'NoneType' object has no attribute 'child_data' I tried this: "child": one2one(child) or this: "child": one2one(child()) First example is how the code was originally. Keep in mind that python and oo are new to me. So, I can deal with examples, but I getting very confused by looking at a constructor and trying to figure out what I have to fee to it. Another question on the directory structure: - I created a Firebird specific example dir with all the test stuff in it. This is easier for me to deal with then trying to worry about what I do to other adapter test code. Is this fine with you? See you Werner BTW - the SSH works fine with putty and tortoisecvs since you converted the key for me. From orm-devel@mailman.tux4web.de Mon Mar 3 16:59:25 2003 From: orm-devel@mailman.tux4web.de (Werner F. Bruhin) Date: Mon, 03 Mar 2003 17:59:25 +0100 Subject: [orm-devel] one2one - second Message-ID: <3E6389ED.6080400@free.fr> Hi Diedrich, Just tried something else. p = ds.selectByPrimaryKey(parent, 1) print p print p.parent_data print p.child #print p.child.child_data print The p.child.child_data gives the error. child2 = child(id=3, child_data="child2 data") ds.insert(child2) ds.commit() p.child = child2 print p.child.child_data This one works, so problem is not with the class definition (i.e. original code "child": one2one(child), is therefore correct, but problem is related to selectByPrimaryKey. I think it is tea time again (don't think I am English, I am actually Swiss German), as I obviously am missing something. See you Werner From orm-devel@mailman.tux4web.de Tue Mar 4 14:02:16 2003 From: orm-devel@mailman.tux4web.de (Diedrich Vorberg) Date: Tue, 4 Mar 2003 15:02:16 +0100 Subject: [orm-devel] one2one test - problem In-Reply-To: <3E63819D.8020904@free.fr> References: <3E63819D.8020904@free.fr> Message-ID: <15972.45544.291967.933617@lisa.tux4web.de> Hi, >- I created a Firebird specific example dir with all the test stuff in >it. This is easier for me to deal with then trying to worry about what >I do to other adapter test code. Is this fine with you? yes, it is. I thought I already said so. I'll answer the other stuff some other time, I need a break... sorry. Diedrich -- _..._ Diedrich Vorberg .' '. / _ _ \ http://www.tux4web.de | (o)_(o) | info@tux4web.de \( ) / .---. //'._.'\ \ / \ Internet Dienstleistungen // . \ \ \.@-@./ und 'Consulting'. || . \ \ /`\_/`\ |\ : / | // _ \\ Linux Rules! \ `) ' (` /_ | \ )|_ _)``".____,.'"` (_ /`\_`> <_/ \ ) )'--'( ( \__/'---'\__/ '---` `---` From orm-devel@mailman.tux4web.de Tue Mar 4 16:52:41 2003 From: orm-devel@mailman.tux4web.de (Werner F. Bruhin) Date: Tue, 04 Mar 2003 17:52:41 +0100 Subject: [orm-devel] A short update Message-ID: <3E64D9D9.8060101@free.fr> Hi Diedrich, I can understand that you need a break, no problem , I know that I bugged you a lot these days, just ignore the outstanding mails. Let me know when you have some time again and I ask the questions which are at that point still open. Update: - test_one2one is running without error - but this does not mean that it works yet. Some sql updates don't happen yet e.g. doing "p.child = child2" never updates the DB - figured out how to pass the foreign key, which solved some of the problems (as it had to be in caps). See you Werner From orm-devel@mailman.tux4web.de Tue Mar 4 16:51:15 2003 From: orm-devel@mailman.tux4web.de (Werner F. Bruhin) Date: Tue, 04 Mar 2003 17:51:15 +0100 Subject: [orm-devel] Python book recommendation? Message-ID: <3E64D983.80305@free.fr> TRYING to do this Firebird adapter shows that I need a better grasp of Python and OO. Any recommendations for a good Python book would be appreciated. See you Werner From orm-devel@mailman.tux4web.de Tue Mar 4 17:45:27 2003 From: orm-devel@mailman.tux4web.de (Diedrich Vorberg) Date: Tue, 4 Mar 2003 18:45:27 +0100 Subject: [orm-devel] Python book recommendation? In-Reply-To: <3E64D983.80305@free.fr> References: <3E64D983.80305@free.fr> Message-ID: <15972.58935.938828.400299@lisa.tux4web.de> >TRYING to do this Firebird adapter shows that I need a better grasp of >Python and OO. >Any recommendations for a good Python book would be appreciated. Personally I've stuck with the documentation on python.org, so I can't make any particular recomnendation. One thing I kept realizing about the Python crowd: they expect you to read the sourcecode. Unlike Java and C++ programmers who tend to document more (if you're lucky :-). That's why I tried to write rather eleborate source code comments in ORM. If you have any questions you can email me off-list if you want to, I'd be happy to be of help. German or English. Diedrich -- _..._ Diedrich Vorberg .' '. / _ _ \ http://www.tux4web.de | (o)_(o) | info@tux4web.de \( ) / .---. //'._.'\ \ / \ Internet Dienstleistungen // . \ \ \.@-@./ und 'Consulting'. || . \ \ /`\_/`\ |\ : / | // _ \\ Linux Rules! \ `) ' (` /_ | \ )|_ _)``".____,.'"` (_ /`\_`> <_/ \ ) )'--'( ( \__/'---'\__/ '---` `---` From orm-devel@mailman.tux4web.de Tue Mar 4 20:48:02 2003 From: orm-devel@mailman.tux4web.de (Mathieu Fenniak) Date: Tue, 4 Mar 2003 13:48:02 -0700 Subject: [orm-devel] Python book recommendation? In-Reply-To: <3E64D983.80305@free.fr> Message-ID: <97C6B5A8-4E82-11D7-BE39-000393903B64@pobox.com> On Tuesday, March 4, 2003, at 09:51 AM, Werner F. Bruhin wrote: > TRYING to do this Firebird adapter shows that I need a better grasp of > Python and OO. > > Any recommendations for a good Python book would be appreciated. I picked up O'Reilly's Python Cookbook on the weekend. It is targetted towards people who know Python already. I wasn't sure I would get much out of it, but I thought my bookshelf looked bad without a single Python book. I've found many interesting tidbits of information in the Python Cookbook which I've never picked up anywhere else, especially with regard to new features in Python 2.2. I also recommend reading documents on Python.org such as the 'What's New in Python 2.2' (http://python.org/doc/2.2.1/whatsnew/), and various PEPs (http://python.org/peps), as they will occasionally reveal secrets which don't seem to be part of the main documentation package. -- Random words of the day: For a crowd is not company; and faces are but a gallery of pictures; and talk but a tinkling cymbal, where there is no love. Francis Bacon Mathieu Fenniak PGP Key ID 0x2459092A http://www.stompstompstomp.com/ From orm-devel@mailman.tux4web.de Wed Mar 5 00:28:18 2003 From: orm-devel@mailman.tux4web.de (Ross J. Reedstrom) Date: Tue, 4 Mar 2003 18:28:18 -0600 Subject: [orm-devel] Python book recommendation? In-Reply-To: <97C6B5A8-4E82-11D7-BE39-000393903B64@pobox.com> References: <3E64D983.80305@free.fr> <97C6B5A8-4E82-11D7-BE39-000393903B64@pobox.com> Message-ID: <20030305002818.GA20778@wallace.ece.rice.edu> On Tue, Mar 04, 2003 at 01:48:02PM -0700, Mathieu Fenniak wrote: > On Tuesday, March 4, 2003, at 09:51 AM, Werner F. Bruhin wrote: > >TRYING to do this Firebird adapter shows that I need a better grasp of > >Python and OO. > > > >Any recommendations for a good Python book would be appreciated. > > I picked up O'Reilly's Python Cookbook on the weekend. It is targetted > towards people who know Python already. I wasn't sure I would get much > out of it, but I thought my bookshelf looked bad without a single > Python book. I've found many interesting tidbits of information in the > Python Cookbook which I've never picked up anywhere else, especially > with regard to new features in Python 2.2. +1 on the Python Cookbook: I can never have too many examples. O'Reilly's Programming Python is pretty good, too. I'd not recommend 'Learning Python' unless what you're really doing is learning to program, using python. > > I also recommend reading documents on Python.org such as the 'What's > New in Python 2.2' (http://python.org/doc/2.2.1/whatsnew/), and various > PEPs (http://python.org/peps), as they will occasionally reveal secrets > which don't seem to be part of the main documentation package. Yup, can't beat the docs for what's really supposed to happen. Ross From orm-devel@mailman.tux4web.de Wed Mar 5 17:45:40 2003 From: orm-devel@mailman.tux4web.de (Werner F. Bruhin) Date: Wed, 05 Mar 2003 18:45:40 +0100 Subject: [orm-devel] FB adapter update - tests Message-ID: <3E6637C4.7030203@free.fr> The following tests are working: - one2many - many2one - many2many - test1 Had to add explicit commits in the appropriate places. While Firebird has an autocommit feature, I am not using it. I am right in assuming that your test db's have "autocommit" set? NOT working: - one2one Problem is that changing a child object does not get updated in the db, e.g. p.child = child2 ds.commit() This should cause a SQL update for the parent record, but none happens. See you Werner From orm-devel@mailman.tux4web.de Wed Mar 5 17:52:11 2003 From: orm-devel@mailman.tux4web.de (Werner F. Bruhin) Date: Wed, 05 Mar 2003 18:52:11 +0100 Subject: [orm-devel] Python book recommendation? In-Reply-To: <20030305002818.GA20778@wallace.ece.rice.edu> References: <3E64D983.80305@free.fr> <97C6B5A8-4E82-11D7-BE39-000393903B64@pobox.com> <20030305002818.GA20778@wallace.ece.rice.edu> Message-ID: <3E66394B.90309@free.fr> Mathieu and Ross, Thanks for the book tips. See you Werner Ross J. Reedstrom wrote: >On Tue, Mar 04, 2003 at 01:48:02PM -0700, Mathieu Fenniak wrote: > > >>On Tuesday, March 4, 2003, at 09:51 AM, Werner F. Bruhin wrote: >> >> >>>TRYING to do this Firebird adapter shows that I need a better grasp of >>>Python and OO. >>> >>>Any recommendations for a good Python book would be appreciated. >>> >>> >>I picked up O'Reilly's Python Cookbook on the weekend. It is targetted >>towards people who know Python already. I wasn't sure I would get much >>out of it, but I thought my bookshelf looked bad without a single >>Python book. I've found many interesting tidbits of information in the >>Python Cookbook which I've never picked up anywhere else, especially >>with regard to new features in Python 2.2. >> >> > >+1 on the Python Cookbook: I can never have too many examples. O'Reilly's >Programming Python is pretty good, too. I'd not recommend 'Learning Python' >unless what you're really doing is learning to program, using python. > > > >>I also recommend reading documents on Python.org such as the 'What's >>New in Python 2.2' (http://python.org/doc/2.2.1/whatsnew/), and various >>PEPs (http://python.org/peps), as they will occasionally reveal secrets >>which don't seem to be part of the main documentation package. >> >> > >Yup, can't beat the docs for what's really supposed to happen. > >Ross >_______________________________________________ >orm-devel mailing list >orm-devel@mailman.tux4web.de >http://mailman.tux4web.de/mailman/listinfo/orm-devel > > > > From orm-devel@mailman.tux4web.de Thu Mar 6 13:50:03 2003 From: orm-devel@mailman.tux4web.de (Diedrich Vorberg) Date: Thu, 6 Mar 2003 14:50:03 +0100 Subject: [orm-devel] FB adapter update - tests In-Reply-To: <3E6637C4.7030203@free.fr> References: <3E6637C4.7030203@free.fr> Message-ID: <15975.21003.706607.773056@lisa.tux4web.de> Hi, >p.child = child2 >ds.commit() >This should cause a SQL update for the parent record, but none happens. updates are not executed immediately; they are queued and executed on commit(). I've added a call to debug() to clerify the output. Diedrich -- _..._ Diedrich Vorberg .' '. / _ _ \ http://www.tux4web.de | (o)_(o) | info@tux4web.de \( ) / .---. //'._.'\ \ / \ Internet Dienstleistungen // . \ \ \.@-@./ und 'Consulting'. || . \ \ /`\_/`\ |\ : / | // _ \\ Linux Rules! \ `) ' (` /_ | \ )|_ _)``".____,.'"` (_ /`\_`> <_/ \ ) )'--'( ( \__/'---'\__/ '---` `---` From orm-devel@mailman.tux4web.de Thu Mar 6 16:12:06 2003 From: orm-devel@mailman.tux4web.de (Werner F. Bruhin) Date: Thu, 06 Mar 2003 17:12:06 +0100 Subject: [orm-devel] When to execute INSERT statements In-Reply-To: <15970.28011.139313.657027@lisa.local.> References: <15970.28011.139313.657027@lisa.local.> Message-ID: <3E677356.7030306@free.fr> Diedrich, I hope/wish that you will update ORM's insert behavior so the database can enforce data integrity (DI). One of the main reason for me to implement an application using a DB like Firebird is that it provides DI. Presently I am not concerned that multiple statements are used, but I guess in a high volume application this might be another reason to have a hang up with the present implementation of ORM. Should you decide NOT to make any change I think you should at least explain the situation in the documentation, so people (at least the once who read documentation) are aware of it. See you Werner Diedrich Vorberg wrote: >Hello everybody, > >Werner's work on the Firebird adapter and his thinking-through of ORM >brought up a point I was thinking about ago some time back: should ORM >automatically create INSERT statements of dependant objects? > >Answer: Hääää... >(Anohter free German lesson: it means: "What the heck are'ya >talking about?" ;-) > >Ok, let me illustrate my point with an example: > >Let's say I've got the old one2many relationship of authors and >books. Storing the information of "'A Farewell To Arms' and 'The Old >Man And The Sea' are writen by Hemingway" would look like: > > ernest = author(name="Hemingway") > ds.insert(ernest) > > book1 = book(title="A Farewall To Arms") > ds.insert(book1) > ernest.books.append(book1) > > book2 = book(title="The Old Man And The Sea") > ds.insert(book2) > ernest.books.append(book2) > > ds.commit() > >This will result in one INSERT for Ernest and one INSERT plus one >UPDATE statement for the books. As Werner correctly pointed out, this >will fail if the backend enforces constrains to ensure table >integrity: the books are INSERTed with empty book_id columns. Also >there are five statements where three would do. > >My argument for implementing this the way I did was, that I wanted >the programmer to knowingly insert things in the database so he knows >exactly what's going on. > >There is another, simmilar case I was thinking about: > > ernest = author(name="Steinbeck", > books=[book(title="Tortilla Flat"), > book(title="Cannery Row")]) > >Here dbclass' constructor would have to automatically issue three >INSERT statements. > >This get's sort of complicated if book had another relationship as one >of it's attributes. Of course ds.insert() could recursively travers >the resulting object tree and create appropriate INSERTs but if >something goes wrong inside ORM or the data model has a subtlety this >can be very hard to look-through and debug. > >My idea for this would be to extend the UPDATE statement cache to >also include CREATEs and this way avoid redundant SQL queries and the >problem with constrains. > >(As a reminder: the update cache keeps track of all UPDATE statements >and joins consecutive UPDATEs on the same object into a single >statement.) > >Do you think this a good idea? >What kind of drawbacks would you expect (increased complexity aside)? >Do you think the subtlety of one ds.insert() or append() call >creating several SQL statements can be lived with? > >Diedrich > > > From orm-devel@mailman.tux4web.de Fri Mar 7 17:05:27 2003 From: orm-devel@mailman.tux4web.de (Diedrich Vorberg) Date: Fri, 7 Mar 2003 18:05:27 +0100 Subject: [orm-devel] One week off (sort of) Message-ID: <15976.53591.569811.306961@lisa.tux4web.de> Hello folks, I've been drafted by the army to participate in a one week maneuver so I won't be online for some time, just in case you wonder... Diedrich -- _..._ Diedrich Vorberg .' '. / _ _ \ http://www.tux4web.de | (o)_(o) | info@tux4web.de \( ) / .---. //'._.'\ \ / \ Internet Dienstleistungen // . \ \ \.@-@./ und 'Consulting'. || . \ \ /`\_/`\ |\ : / | // _ \\ Linux Rules! \ `) ' (` /_ | \ )|_ _)``".____,.'"` (_ /`\_`> <_/ \ ) )'--'( ( \__/'---'\__/ '---` `---` From orm-devel@mailman.tux4web.de Fri Mar 7 19:24:26 2003 From: orm-devel@mailman.tux4web.de (Werner F. Bruhin) Date: Fri, 07 Mar 2003 20:24:26 +0100 Subject: [orm-devel] Debug - request for enhancement Message-ID: <3E68F1EA.8080802@free.fr> Hi Diedrich, Whenever you get around to change/update the debug stuff can you keep this in mind. 1. Allow to activate/deactive debug during startup. 2. Add an optional name parameter to debug, this helps to figure which debug one looks at, something along these lines. def debug(s, name='============='): print "====" + name +"=======================================" print s See you Werner From orm-devel@mailman.tux4web.de Fri Mar 7 19:50:48 2003 From: orm-devel@mailman.tux4web.de (Michael Watkins) Date: Fri, 07 Mar 2003 11:50:48 -0800 Subject: [orm-devel] Debug - request for enhancement In-Reply-To: <3E68F1EA.8080802@free.fr> Message-ID: <5.2.0.9.0.20030307114824.00afd7b0@mail.mikewatkins.net> I second this - debug should check a datasource property _debug that defaults to False and can be set perhaps as an optional parameter debug=False First thing I do whenever looking at a new version of ORM is overwrite debug() such that it does nothing... At 08:24 PM 3/7/2003 +0100, you wrote: >Hi Diedrich, > >Whenever you get around to change/update the debug stuff can you keep this >in mind. > >1. Allow to activate/deactive debug during startup. > >2. Add an optional name parameter to debug, this helps to figure which >debug one looks at, something along these lines. > > def debug(s, name='============='): > print "====" + name > +"=======================================" > print s > >See you >Werner > > > >_______________________________________________ >orm-devel mailing list >orm-devel@mailman.tux4web.de >http://mailman.tux4web.de/mailman/listinfo/orm-devel From orm-devel@mailman.tux4web.de Sat Mar 15 21:30:33 2003 From: orm-devel@mailman.tux4web.de (Diedrich Vorberg) Date: Sat, 15 Mar 2003 22:30:33 +0100 Subject: [orm-devel] Re: one2many In-Reply-To: <3E6A17C0.8090307@free.fr> References: <3E6A17C0.8090307@free.fr> Message-ID: <15987.39801.402142.614447@lisa.tux4web.de> >The UPDATE did not work (parentid was not updated) until I made the >changes to two lines in relationship (around line 351 - lines marked WFB) > > updateCommand = "UPDATE %s SET %s=%s WHERE %s IN (%s)" % \ > (self._childClass.relation(), > self._foreignKeyColumn, > self._dbObj.primaryKeyValue().format(), # WFB >changed > self._childClass.primaryKey, # WFB changed > join(newKeys, ", ")) Yes, this is correct. Diedrich -- _..._ Diedrich Vorberg .' '. / _ _ \ http://www.tux4web.de | (o)_(o) | info@tux4web.de \( ) / .---. //'._.'\ \ / \ Internet Dienstleistungen // . \ \ \.@-@./ und 'Consulting'. || . \ \ /`\_/`\ |\ : / | // _ \\ Linux Rules! \ `) ' (` /_ | \ )|_ _)``".____,.'"` (_ /`\_`> <_/ \ ) )'--'( ( \__/'---'\__/ '---` `---`