Update of /cvsroot/monetdb/sql/src/storage/bat
In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv6798/src/storage/bat

Modified Files:
        bat_sequence.mx 
Log Message:
propagated changes of Sunday Feb 11 2007 - Tuesday Feb 20 2007
from the SQL_2-16 branch to the development trunk


Index: bat_sequence.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/storage/bat/bat_sequence.mx,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- bat_sequence.mx     24 Jan 2007 23:54:50 -0000      1.18
+++ bat_sequence.mx     20 Feb 2007 11:50:47 -0000      1.19
@@ -23,6 +23,7 @@
 extern void sequences_exit(void);
 
 extern int seq_next_value(sql_sequence *seq, lng *val);
+extern int seq_get_value(sql_sequence *seq, lng *val);
 extern int seq_restart(sql_sequence *seq, lng start);
 
 #endif /* BAT_SEQ_H */
@@ -108,7 +109,7 @@
        }
        s->called = 0;
        s->cur = start;
-       s->cached = start + seq->cacheinc;
+       s->cached = start;
        /* handle min/max and cycle */
        if ((seq->maxvalue && s->cur > seq->maxvalue) ||
            (seq->minvalue && s->cur < seq->minvalue))
@@ -155,8 +156,8 @@
            (seq->minvalue && s->cur < seq->minvalue))
        {
                if (seq->cycle) {
-                       /* cycle to the start value again */
-                       s->cur = seq->start;
+                       /* cycle to the min value again */
+                       s->cur = seq->minvalue;
                        save = 1;
                } else { /* we're out of numbers */
                        store_unlock();
@@ -167,7 +168,7 @@
        nr = s->cur;
        *val = nr;
        if (save || nr == s->cached) {
-               s->cached = nr + seq->cacheinc;
+               s->cached = nr + seq->cacheinc*seq->increment;
                sql_update_sequence_cache(seq, s->cached);
                store_unlock(); 
                return 1;
@@ -176,3 +177,45 @@
        store_unlock(); 
        return 1;
 }
+
+int
+seq_get_value(sql_sequence *seq, lng *val)
+{
+       node *n = NULL;
+       bat_sequence *s;
+
+       *val = 0;
+       store_lock();
+       for ( n = sql_seqs->h; n; n = n ->next ) {
+               s = n->data;
+               if (s->seqid == seq->base.id)
+                       break;
+       }
+       if (!n) {
+               s = sql_create_sequence(seq);
+               if (!s) {
+                       store_unlock();
+                       return 0;
+               }
+               list_append(sql_seqs, s);
+       } else {
+               s = n->data;
+       }
+       *val = s->cur;
+       if (s->called)
+               *val += seq->increment;
+       /* handle min/max and cycle */
+       if ((seq->maxvalue && *val > seq->maxvalue) ||
+           (seq->minvalue && *val < seq->minvalue))
+       {
+               if (seq->cycle) {
+                       /* cycle to the min value again */
+                       *val = seq->minvalue;
+               } else { /* we're out of numbers */
+                       store_unlock();
+                       return(0);
+               }
+       }
+       store_unlock();
+       return 1;
+}


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Monetdb-sql-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-sql-checkins

Reply via email to