<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Emulating nextval() function to get sequence in MySQL</title>
	<atom:link href="http://www.microshell.com/database/mysql/emulating-nextval-function-to-get-sequence-in-mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.microshell.com/database/mysql/emulating-nextval-function-to-get-sequence-in-mysql/</link>
	<description>Learn something share something</description>
	<lastBuildDate>Mon, 23 Jan 2012 10:40:22 -0800</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: christophe</title>
		<link>http://www.microshell.com/database/mysql/emulating-nextval-function-to-get-sequence-in-mysql/comment-page-1/#comment-15227</link>
		<dc:creator>christophe</dc:creator>
		<pubDate>Fri, 18 Nov 2011 09:46:35 +0000</pubDate>
		<guid isPermaLink="false">http://www.microshell.com/?p=777#comment-15227</guid>
		<description>Hi there ! 
I have the same error as Jagpreet Singh. Have you fixed it ? Please help</description>
		<content:encoded><![CDATA[<p>Hi there !<br />
I have the same error as Jagpreet Singh. Have you fixed it ? Please help</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jagpreet Singh</title>
		<link>http://www.microshell.com/database/mysql/emulating-nextval-function-to-get-sequence-in-mysql/comment-page-1/#comment-13483</link>
		<dc:creator>Jagpreet Singh</dc:creator>
		<pubDate>Wed, 05 Oct 2011 08:13:16 +0000</pubDate>
		<guid isPermaLink="false">http://www.microshell.com/?p=777#comment-13483</guid>
		<description>Great help!! But i could not succeed. I am facing following problem -
Error Code: 1418. This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its declaration and binary logging is enabled (you *might* want to use the less safe log_bin_trust_function_creators variable)</description>
		<content:encoded><![CDATA[<p>Great help!! But i could not succeed. I am facing following problem -<br />
Error Code: 1418. This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its declaration and binary logging is enabled (you *might* want to use the less safe log_bin_trust_function_creators variable)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rajesh</title>
		<link>http://www.microshell.com/database/mysql/emulating-nextval-function-to-get-sequence-in-mysql/comment-page-1/#comment-13359</link>
		<dc:creator>Rajesh</dc:creator>
		<pubDate>Wed, 28 Sep 2011 06:56:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.microshell.com/?p=777#comment-13359</guid>
		<description>Thanks!
Very useful solution</description>
		<content:encoded><![CDATA[<p>Thanks!<br />
Very useful solution</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jan</title>
		<link>http://www.microshell.com/database/mysql/emulating-nextval-function-to-get-sequence-in-mysql/comment-page-1/#comment-13207</link>
		<dc:creator>Jan</dc:creator>
		<pubDate>Mon, 19 Sep 2011 15:37:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.microshell.com/?p=777#comment-13207</guid>
		<description>Thanks for the post, very clever idea. For the latecomers it would be nice if you could update your original post with the code from CesarDraw. Your original function code does not work as is.

Best regards,
Jan</description>
		<content:encoded><![CDATA[<p>Thanks for the post, very clever idea. For the latecomers it would be nice if you could update your original post with the code from CesarDraw. Your original function code does not work as is.</p>
<p>Best regards,<br />
Jan</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Zeljko</title>
		<link>http://www.microshell.com/database/mysql/emulating-nextval-function-to-get-sequence-in-mysql/comment-page-1/#comment-7389</link>
		<dc:creator>Zeljko</dc:creator>
		<pubDate>Sun, 06 Feb 2011 13:39:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.microshell.com/?p=777#comment-7389</guid>
		<description>Great post! Thanks</description>
		<content:encoded><![CDATA[<p>Great post! Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vishal</title>
		<link>http://www.microshell.com/database/mysql/emulating-nextval-function-to-get-sequence-in-mysql/comment-page-1/#comment-4836</link>
		<dc:creator>Vishal</dc:creator>
		<pubDate>Thu, 23 Sep 2010 07:56:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.microshell.com/?p=777#comment-4836</guid>
		<description>Thanks Maresa, 
But i was thinking writing function in DB, which will take care all commit operation as well (i.e. inside Function - nextval). So user of function would not bother about any commit operation. 

But here in function we cannot fire commit as - it is not allowed in mysql (explicit implicit commit). 
So i was wondering any other way to do same ?</description>
		<content:encoded><![CDATA[<p>Thanks Maresa,<br />
But i was thinking writing function in DB, which will take care all commit operation as well (i.e. inside Function &#8211; nextval). So user of function would not bother about any commit operation. </p>
<p>But here in function we cannot fire commit as &#8211; it is not allowed in mysql (explicit implicit commit).<br />
So i was wondering any other way to do same ?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Maresa</title>
		<link>http://www.microshell.com/database/mysql/emulating-nextval-function-to-get-sequence-in-mysql/comment-page-1/#comment-4834</link>
		<dc:creator>Maresa</dc:creator>
		<pubDate>Thu, 23 Sep 2010 04:55:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.microshell.com/?p=777#comment-4834</guid>
		<description>@Vishal: I&#039;m trying to guess what you mean.

START TRANSACTION;
SELECT @myid := nextval(&#039;sq_my_sequence&#039;) as next_sequence;
INSERT INTO some_table (id, name) VALUES (@myid, &#039;My Name&#039;);
COMMIT;</description>
		<content:encoded><![CDATA[<p>@Vishal: I&#8217;m trying to guess what you mean.</p>
<p>START TRANSACTION;<br />
SELECT @myid := nextval(&#8217;sq_my_sequence&#8217;) as next_sequence;<br />
INSERT INTO some_table (id, name) VALUES (@myid, &#8216;My Name&#8217;);<br />
COMMIT;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vishal</title>
		<link>http://www.microshell.com/database/mysql/emulating-nextval-function-to-get-sequence-in-mysql/comment-page-1/#comment-4815</link>
		<dc:creator>Vishal</dc:creator>
		<pubDate>Tue, 21 Sep 2010 16:07:02 +0000</pubDate>
		<guid isPermaLink="false">http://www.microshell.com/?p=777#comment-4815</guid>
		<description>Hi, 

please advice. 
if i have connection with auto commit false, 
then this function when will commit the operation. 

Thanks</description>
		<content:encoded><![CDATA[<p>Hi, </p>
<p>please advice.<br />
if i have connection with auto commit false,<br />
then this function when will commit the operation. </p>
<p>Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Maresa</title>
		<link>http://www.microshell.com/database/mysql/emulating-nextval-function-to-get-sequence-in-mysql/comment-page-1/#comment-3647</link>
		<dc:creator>Maresa</dc:creator>
		<pubDate>Fri, 30 Apr 2010 07:47:57 +0000</pubDate>
		<guid isPermaLink="false">http://www.microshell.com/?p=777#comment-3647</guid>
		<description>@CaesarDraw Thank you. Mind letting me know what lines wasn&#039;t working? I see one that I didn&#039;t realize that somehow grater than ( &gt; ) is being printed as &gt;. It is fixed.</description>
		<content:encoded><![CDATA[<p>@CaesarDraw Thank you. Mind letting me know what lines wasn&#8217;t working? I see one that I didn&#8217;t realize that somehow grater than ( > ) is being printed as &gt;. It is fixed.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: CesarDraw</title>
		<link>http://www.microshell.com/database/mysql/emulating-nextval-function-to-get-sequence-in-mysql/comment-page-1/#comment-3594</link>
		<dc:creator>CesarDraw</dc:creator>
		<pubDate>Sat, 24 Apr 2010 21:53:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.microshell.com/?p=777#comment-3594</guid>
		<description>congrats! I corrected some lines that were causing errors and thus worked:

DELIMITER $$

DROP FUNCTION IF EXISTS `fac201001`.`nextval` $$
CREATE FUNCTION `sequence`.`nextval` (`seq_name` varchar(100)) RETURNS bigint(20) NOT DETERMINISTIC
BEGIN
  DECLARE cur_val bigint(20);


SELECT
        sequence_cur_value INTO cur_val
    FROM
        `sequence`.`sequence_data`
    WHERE
        sequence_name = seq_name;

    IF cur_val IS NOT NULL THEN
        UPDATE
            `sequence`.`sequence_data`
        SET
            sequence_cur_value = IF (
                (sequence_cur_value + sequence_increment) &gt; sequence_max_value,
                IF (
                    sequence_cycle = TRUE,
                    sequence_min_value,
                    NULL
                ),
                sequence_cur_value + sequence_increment
            )
        WHERE
            sequence_name = seq_name;
    END IF;

    RETURN cur_val;


END $$

DELIMITER ;</description>
		<content:encoded><![CDATA[<p>congrats! I corrected some lines that were causing errors and thus worked:</p>
<p>DELIMITER $$</p>
<p>DROP FUNCTION IF EXISTS `fac201001`.`nextval` $$<br />
CREATE FUNCTION `sequence`.`nextval` (`seq_name` varchar(100)) RETURNS bigint(20) NOT DETERMINISTIC<br />
BEGIN<br />
  DECLARE cur_val bigint(20);</p>
<p>SELECT<br />
        sequence_cur_value INTO cur_val<br />
    FROM<br />
        `sequence`.`sequence_data`<br />
    WHERE<br />
        sequence_name = seq_name;</p>
<p>    IF cur_val IS NOT NULL THEN<br />
        UPDATE<br />
            `sequence`.`sequence_data`<br />
        SET<br />
            sequence_cur_value = IF (<br />
                (sequence_cur_value + sequence_increment) &gt; sequence_max_value,<br />
                IF (<br />
                    sequence_cycle = TRUE,<br />
                    sequence_min_value,<br />
                    NULL<br />
                ),<br />
                sequence_cur_value + sequence_increment<br />
            )<br />
        WHERE<br />
            sequence_name = seq_name;<br />
    END IF;</p>
<p>    RETURN cur_val;</p>
<p>END $$</p>
<p>DELIMITER ;</p>
]]></content:encoded>
	</item>
</channel>
</rss>

