Re: [Libdbi-drivers-devel] Postgres lastval for 8.1 and up (WAS Re: [libdbi-users] Finding inserted rows)
Mike Rylander writes: Well, like I said, I haven't had a chance to test it. Any confirmation that it works properly would be great. I'm about to be offline for about a week, and then I'll have work stuff piled up. I'll take another look as soon as I can, though ... :) I don't have a chance to test the patch right now (my PostgreSQL is still at 8.0) but it looks fine to me. I'll check it in if someone can confirm that it does work. I'll probably be able to install 8.1 next week, but I'd be glad if someone else can confirm the patch works. regards, Markus -- Markus Hoenicka [EMAIL PROTECTED] (Spam-protected email: replace the quadrupeds with mhoenicka) http://www.mhoenicka.de --- All the advantages of Linux Managed Hosting--Without the Cost and Risk! Fully trained technicians. The highest number of Red Hat certifications in the hosting industry. Fanatical Support. Click to learn more http://sel.as-us.falkag.net/sel?cmd=lnkkid=107521bid=248729dat=121642 ___ Libdbi-drivers-devel mailing list Libdbi-drivers-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/libdbi-drivers-devel
Re: [Libdbi-drivers-devel] Postgres lastval for 8.1 and up (WAS Re: [libdbi-users] Finding inserted rows)
On 27-May-06, at 7:34 PM, Mike Rylander wrote: I looked at using the Pg 8.1lastval() function and there was almost no work involved, so here's a patch. I haven't tested it, but I wanted to throw the code out there as I won't have time to look at this again for at least another week, maybe two. --- libdbi-drivers-0.8.1/drivers/pgsql/dbd_pgsql.c 2005-08-21 06:32:35.0 -0400 +++ libdbi-drivers-0.8.1-new/drivers/pgsql/dbd_pgsql.c 2006-05-27 20:08:16.0 -0400 @@ -497,7 +497,19 @@ unsigned long long dbd_get_seq_last(dbi_ char *rawdata; dbi_result_t *result; - asprintf(sql_cmd, SELECT currval('%s'), sequence); + char *version; + version = dbd_get_engine_version(conn, version); + + if (!sequence) { + if (atoi(version) = 8) { + if (atoi(version) == 8 atoi(version[2]) = 1) { + asprintf(sql_cmd, SELECT lastval ()); + } + } + } else { + asprintf(sql_cmd, SELECT currval('%s'), sequence); + } + if (!sql_cmd) return 0; result = dbd_query(conn, sql_cmd); free(sql_cmd); Hi, I like the idea behind this. What happens when sequence == NULL but the version is 8.1; maybe flag an error instead of falling through? --Toby --- All the advantages of Linux Managed Hosting--Without the Cost and Risk! Fully trained technicians. The highest number of Red Hat certifications in the hosting industry. Fanatical Support. Click to learn more http://sel.as-us.falkag.net/sel?cmd=lnkkid=107521bid=248729dat=121642 ___ Libdbi-drivers-devel mailing list Libdbi-drivers-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/libdbi-drivers-devel
Re: [Libdbi-drivers-devel] Postgres lastval for 8.1 and up (WAS Re: [libdbi-users] Finding inserted rows)
On 27-May-06, at 9:14 PM, Mike Rylander wrote: On 5/27/06, Toby Thain [EMAIL PROTECTED] wrote: On 27-May-06, at 7:34 PM, Mike Rylander wrote: I looked at using the Pg 8.1lastval() function and there was almost no work involved, so here's a patch. I haven't tested it, but I wanted to throw the code out there as I won't have time to look at this again for at least another week, maybe two. --- libdbi-drivers-0.8.1/drivers/pgsql/dbd_pgsql.c 2005-08-21 06:32:35.0 -0400 +++ libdbi-drivers-0.8.1-new/drivers/pgsql/dbd_pgsql.c 2006-05-27 20:08:16.0 -0400 @@ -497,7 +497,19 @@ unsigned long long dbd_get_seq_last(dbi_ char *rawdata; dbi_result_t *result; - asprintf(sql_cmd, SELECT currval('%s'), sequence); + char *version; + version = dbd_get_engine_version(conn, version); + + if (!sequence) { + if (atoi(version) = 8) { + if (atoi(version) == 8 atoi(version[2]) = 1) { + asprintf(sql_cmd, SELECT lastval ()); + } + } + } else { + asprintf(sql_cmd, SELECT currval('%s'), sequence); + } + if (!sql_cmd) return 0; result = dbd_query(conn, sql_cmd); free(sql_cmd); Hi, I like the idea behind this. What happens when sequence == NULL but the version is 8.1; maybe flag an error instead of falling through? The current code just returns 0 in that case, Right, I missed that. I guess everything's cool then :) --Toby but if there's a better error reporting mechanism I'm all for it. [looks at documentation] Hmm... According to the docs, 'return 0' is the current correct error value for the API. Changing that would break old apps, I'd think. Also, any apps written with Pg in mind to date will be using the sequence name, so I think it's easy to argue this as a new feature that requires a minimum Pg version in order to depend on it. If that dependancy can't be met, the sequence name is still required as in the past. Anyone else care to comment on a way to report (a potentially new class of) errors from dbd_get_seq_last()? --Toby -- Mike Rylander [EMAIL PROTECTED] GPLS -- PINES Development Database Developer http://open-ils.org --- All the advantages of Linux Managed Hosting--Without the Cost and Risk! Fully trained technicians. The highest number of Red Hat certifications in the hosting industry. Fanatical Support. Click to learn more http://sel.as-us.falkag.net/sel? cmd=lnkkid=107521bid=248729dat=121642 ___ Libdbi-drivers-devel mailing list Libdbi-drivers-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/libdbi-drivers-devel --- All the advantages of Linux Managed Hosting--Without the Cost and Risk! Fully trained technicians. The highest number of Red Hat certifications in the hosting industry. Fanatical Support. Click to learn more http://sel.as-us.falkag.net/sel?cmd=lnkkid=107521bid=248729dat=121642 ___ Libdbi-drivers-devel mailing list Libdbi-drivers-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/libdbi-drivers-devel
Re: [Libdbi-drivers-devel] Postgres lastval for 8.1 and up (WAS Re: [libdbi-users] Finding inserted rows)
On 5/27/06, Toby Thain [EMAIL PROTECTED] wrote: On 27-May-06, at 9:14 PM, Mike Rylander wrote: On 5/27/06, Toby Thain [EMAIL PROTECTED] wrote: On 27-May-06, at 7:34 PM, Mike Rylander wrote: I looked at using the Pg 8.1lastval() function and there was almost no work involved, so here's a patch. I haven't tested it, but I wanted to throw the code out there as I won't have time to look at this again for at least another week, maybe two. --- libdbi-drivers-0.8.1/drivers/pgsql/dbd_pgsql.c 2005-08-21 06:32:35.0 -0400 +++ libdbi-drivers-0.8.1-new/drivers/pgsql/dbd_pgsql.c 2006-05-27 20:08:16.0 -0400 @@ -497,7 +497,19 @@ unsigned long long dbd_get_seq_last(dbi_ char *rawdata; dbi_result_t *result; - asprintf(sql_cmd, SELECT currval('%s'), sequence); + char *version; + version = dbd_get_engine_version(conn, version); + + if (!sequence) { + if (atoi(version) = 8) { + if (atoi(version) == 8 atoi(version[2]) = 1) { + asprintf(sql_cmd, SELECT lastval ()); + } + } + } else { + asprintf(sql_cmd, SELECT currval('%s'), sequence); + } + if (!sql_cmd) return 0; result = dbd_query(conn, sql_cmd); free(sql_cmd); Hi, I like the idea behind this. What happens when sequence == NULL but the version is 8.1; maybe flag an error instead of falling through? The current code just returns 0 in that case, Right, I missed that. I guess everything's cool then :) Well, like I said, I haven't had a chance to test it. Any confirmation that it works properly would be great. I'm about to be offline for about a week, and then I'll have work stuff piled up. I'll take another look as soon as I can, though ... :) And thanks for taking a look so quickly! --Toby but if there's a better error reporting mechanism I'm all for it. [looks at documentation] Hmm... According to the docs, 'return 0' is the current correct error value for the API. Changing that would break old apps, I'd think. Also, any apps written with Pg in mind to date will be using the sequence name, so I think it's easy to argue this as a new feature that requires a minimum Pg version in order to depend on it. If that dependancy can't be met, the sequence name is still required as in the past. Anyone else care to comment on a way to report (a potentially new class of) errors from dbd_get_seq_last()? --Toby -- Mike Rylander [EMAIL PROTECTED] GPLS -- PINES Development Database Developer http://open-ils.org --- All the advantages of Linux Managed Hosting--Without the Cost and Risk! Fully trained technicians. The highest number of Red Hat certifications in the hosting industry. Fanatical Support. Click to learn more http://sel.as-us.falkag.net/sel? cmd=lnkkid=107521bid=248729dat=121642 ___ Libdbi-drivers-devel mailing list Libdbi-drivers-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/libdbi-drivers-devel -- Mike Rylander [EMAIL PROTECTED] GPLS -- PINES Development Database Developer http://open-ils.org --- All the advantages of Linux Managed Hosting--Without the Cost and Risk! Fully trained technicians. The highest number of Red Hat certifications in the hosting industry. Fanatical Support. Click to learn more http://sel.as-us.falkag.net/sel?cmd=lnkkid=107521bid=248729dat=121642 ___ Libdbi-drivers-devel mailing list Libdbi-drivers-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/libdbi-drivers-devel