From vamlists at gmail.com Sat Jun 16 23:27:48 2007 From: vamlists at gmail.com (Vamsee Kanakala) Date: Sun, 17 Jun 2007 04:57:48 +0530 Subject: [postmodern-devel] Defer creation of sequence ids? Message-ID: <467471F4.9050201@gmail.com> Hi, I think, create-instance should defer the creation of an id (from sequence-next), because, there are some times when an object is created, but is not saved. For example, in a web application, I would need to create an object so that I can fill in the slots from the form values, but I might not save it, as it might have some validation errors. It would save some sequence ids (a lot actually, as there might be multiple rounds of validation errors) if I don't have to assign an id unless it is being saved to the database. I think we could have insert-dao/save-dao to retrieve a new sequence id if the column "id" is not filled/nil/zero, and use an existing id if it's value is greater than zero. If this sounds ok, I can create a patch. Regards, Vamsee. From marijnh at gmail.com Sun Jun 17 08:15:11 2007 From: marijnh at gmail.com (Marijn Haverbeke) Date: Sun, 17 Jun 2007 10:15:11 +0200 Subject: [postmodern-devel] Defer creation of sequence ids? In-Reply-To: <467471F4.9050201@gmail.com> References: <467471F4.9050201@gmail.com> Message-ID: Hello Vamsee, You make a good point. However, sometimes it is useful to have the id of your new object before saving it. The next-id function can be used for that, of course. But deferring the creation of ids for all DAO objects might break some existing code. How moving the initialization of the auto-id field to an initialize-instance method, which only does it if no :defer-id (or something similar) keyword arg is given? Then, save/insert-dao could check whether the id field has a value, and initialize it when it does not. Regards, Marijn From vamlists at gmail.com Sun Jun 17 17:58:11 2007 From: vamlists at gmail.com (Vamsee Kanakala) Date: Sun, 17 Jun 2007 23:28:11 +0530 Subject: [postmodern-devel] Defer creation of sequence ids? In-Reply-To: References: <467471F4.9050201@gmail.com> Message-ID: <46757633.2070907@gmail.com> Marijn Haverbeke wrote: > How moving the initialization > of the auto-id field to an initialize-instance method, which only does > it if no :defer-id (or something similar) keyword arg is given? Then, > save/insert-dao could check whether the id field has a value, and > initialize it when it does not. > Sounds good to me. I've been trying to hack something into the set-fields method of deftable, haven't entirely succeeded yet, but your approach seems more elegant to me. I don't think I know the code well enough to do this design change, I'll be grateful if you can check in a solution, I'll test it out. Thanks, Vamsee. From marijnh at gmail.com Sun Jun 17 19:18:52 2007 From: marijnh at gmail.com (Marijn Haverbeke) Date: Sun, 17 Jun 2007 21:18:52 +0200 Subject: [postmodern-devel] Defer creation of sequence ids? In-Reply-To: <46757633.2070907@gmail.com> References: <467471F4.9050201@gmail.com> <46757633.2070907@gmail.com> Message-ID: I have pushed a patch implementing the change I described. The deftable macro is slowly becoming a multi-headed monster, but hey, that only adds to its charm. Take a look and see whether this works for you. Regards, Marijn From vamlists at gmail.com Thu Jun 21 14:19:15 2007 From: vamlists at gmail.com (Vamsee Kanakala) Date: Thu, 21 Jun 2007 19:49:15 +0530 Subject: [postmodern-devel] Defer creation of sequence ids? In-Reply-To: References: <467471F4.9050201@gmail.com> <46757633.2070907@gmail.com> Message-ID: <467A88E3.6000004@gmail.com> Marijn Haverbeke wrote: > I have pushed a patch implementing the change I described. The > deftable macro is slowly becoming a multi-headed monster, but hey, > that only adds to its charm. Take a look and see whether this works > for you. > Thank you, works great - do you think the attached change to save-dao would be ok? Regards, Vamsee. -------------- next part -------------- A non-text attachment was scrubbed... Name: save-dao-patch.diff Type: text/x-patch Size: 490 bytes Desc: not available URL: From marijnh at gmail.com Thu Jun 21 15:58:35 2007 From: marijnh at gmail.com (Marijn Haverbeke) Date: Thu, 21 Jun 2007 17:58:35 +0200 Subject: [postmodern-devel] Defer creation of sequence ids? In-Reply-To: <467A88E3.6000004@gmail.com> References: <467471F4.9050201@gmail.com> <46757633.2070907@gmail.com> <467A88E3.6000004@gmail.com> Message-ID: > Thank you, works great - do you think the attached change to save-dao > would be ok? Definitely. It has been applied to the repository. (By the way, I prefer patches created with 'darcs send' to plain diffs.) Marijn From marijnh at gmail.com Fri Jun 22 07:18:37 2007 From: marijnh at gmail.com (Marijn Haverbeke) Date: Fri, 22 Jun 2007 09:18:37 +0200 Subject: [postmodern-devel] Defer creation of sequence ids? In-Reply-To: References: <467471F4.9050201@gmail.com> <46757633.2070907@gmail.com> <467A88E3.6000004@gmail.com> Message-ID: Oh, I just realized your patch does not work when the auto-id slot is called something other than 'id', I pushed another patch to fix this. Cheers, Marijn From osei.poku at gmail.com Wed Jun 27 18:29:46 2007 From: osei.poku at gmail.com (Osei Poku) Date: Wed, 27 Jun 2007 14:29:46 -0400 Subject: [postmodern-devel] Query generation Message-ID: <20070627182946.GA30854@pokut60> Hi, I want to generate the following query: "UPDATE table1 SET col1 = NULL, col2 = NULL" from the following list: ("col1" "col2") my attempt is: (sql (append '(:update :table1 :set) (loop for a in '("col1" "col2") collect a collect :NULL))) but that apparently doesnt work. this can probably be attributed to my newness to lisp. Any ideas? thanks -- Osei Poku PhD Student, ECE Carnegie Mellon University From rm at seid-online.de Wed Jun 27 19:22:14 2007 From: rm at seid-online.de (Ralf Mattes) Date: Wed, 27 Jun 2007 21:22:14 +0200 Subject: [postmodern-devel] Query generation In-Reply-To: <20070627182946.GA30854@pokut60> References: <20070627182946.GA30854@pokut60> Message-ID: <1182972134.6227.2.camel@localhost.localdomain> On Wed, 2007-06-27 at 14:29 -0400, Osei Poku wrote: > Hi, > > I want to generate the following query: > > "UPDATE table1 SET col1 = NULL, col2 = NULL" > > from the following list: ("col1" "col2") > > my attempt is: > > (sql > (append > '(:update :table1 :set) > (loop for a in '("col1" "col2") > collect a collect :NULL))) > > but that apparently doesnt work. this can probably be attributed to > my newness to lisp. > > Any ideas? 'postmodern:sql' is a macro, not a function and hence will not evaluate its argument. When your code really looks like above you could fix it like this: (sql #.(append '(:update :table1 :set) (loop for a in '("col1" "col2") collect a collect :NULL))) HTH Ralf Mattes > thanks > From rm at seid-online.de Wed Jun 27 19:24:44 2007 From: rm at seid-online.de (Ralf Mattes) Date: Wed, 27 Jun 2007 21:24:44 +0200 Subject: [postmodern-devel] Query generation In-Reply-To: <1182972134.6227.2.camel@localhost.localdomain> References: <20070627182946.GA30854@pokut60> <1182972134.6227.2.camel@localhost.localdomain> Message-ID: <1182972284.6227.5.camel@localhost.localdomain> On Wed, 2007-06-27 at 21:22 +0200, Ralf Mattes wrote: > On Wed, 2007-06-27 at 14:29 -0400, Osei Poku wrote: > > Hi, > > > > I want to generate the following query: > > > > "UPDATE table1 SET col1 = NULL, col2 = NULL" > > > > from the following list: ("col1" "col2") > > > > my attempt is: > > > > (sql > > (append > > '(:update :table1 :set) > > (loop for a in '("col1" "col2") > > collect a collect :NULL))) > > > > but that apparently doesnt work. this can probably be attributed to > > my newness to lisp. > > > > Any ideas? > > 'postmodern:sql' is a macro, not a function and hence will not evaluate > its argument. When your code really looks like above you could fix it > like this: > > (sql #.(append > '(:update :table1 :set) > (loop for a in '("col1" "col2") > collect a collect :NULL))) > Sorry for following up my own post: if you really need to build up your SQL at runtime you could also use the functional pendant to 'sql': (sql-compile(append '(:update :table1 :set) (loop for a in '("col1" "col2") collect a collect :NULL))) Cheers, RalfD > > > > > thanks > > > > _______________________________________________ > postmodern-devel mailing list > postmodern-devel at common-lisp.net > http://common-lisp.net/cgi-bin/mailman/listinfo/postmodern-devel From opoku at ece.cmu.edu Wed Jun 27 19:50:40 2007 From: opoku at ece.cmu.edu (Osei Poku) Date: Wed, 27 Jun 2007 15:50:40 -0400 Subject: [postmodern-devel] Query generation In-Reply-To: <1182972284.6227.5.camel@localhost.localdomain> References: <20070627182946.GA30854@pokut60> <1182972134.6227.2.camel@localhost.localdomain> <1182972284.6227.5.camel@localhost.localdomain> Message-ID: <20070627195040.GA30116@pokut60> On Wed, Jun 27, 2007 at 09:24:44PM +0200, Ralf Mattes wrote: > On Wed, 2007-06-27 at 21:22 +0200, Ralf Mattes wrote: > > On Wed, 2007-06-27 at 14:29 -0400, Osei Poku wrote: > > > Hi, > > > > > > I want to generate the following query: > > > > > > "UPDATE table1 SET col1 = NULL, col2 = NULL" > > > > > > from the following list: ("col1" "col2") > > > > > > my attempt is: > > > > > > (sql > > > (append > > > '(:update :table1 :set) > > > (loop for a in '("col1" "col2") > > > collect a collect :NULL))) > > > > > > but that apparently doesnt work. this can probably be attributed to > > > my newness to lisp. > > > > > > Any ideas? > > > > 'postmodern:sql' is a macro, not a function and hence will not evaluate > > its argument. When your code really looks like above you could fix it > > like this: > > > > (sql #.(append > > '(:update :table1 :set) > > (loop for a in '("col1" "col2") > > collect a collect :NULL))) > > > Aah, the beauty of the obscure and powerful reader macro :) This is pretty much what I thought I needed until ... > > Sorry for following up my own post: if you really need to build up your > SQL at runtime you could also use the functional pendant to 'sql': > > (sql-compile(append > '(:update :table1 :set) > (loop for a in '("col1" "col2") > collect a collect :NULL))) > > Yes. This is what I really want: the ability to freely insert arbitrary s-exps in the s-sql syntax. The two solutions are probably equivalent anyway. Thanks a bunch. > Cheers, RalfD > > > > > > > > > > thanks > > > > > > > _______________________________________________ > > postmodern-devel mailing list > > postmodern-devel at common-lisp.net > > http://common-lisp.net/cgi-bin/mailman/listinfo/postmodern-devel > > _______________________________________________ > postmodern-devel mailing list > postmodern-devel at common-lisp.net > http://common-lisp.net/cgi-bin/mailman/listinfo/postmodern-devel -- Osei Poku PhD Student, ECE Carnegie Mellon University