Commit 5b5c83f9 authored by Vadim B. Mikheev's avatar Vadim B. Mikheev

Oracle like currval behaviour.

parent 465047d6
...@@ -204,6 +204,7 @@ nextval (struct varlena * seqin) ...@@ -204,6 +204,7 @@ nextval (struct varlena * seqin)
/* open and WIntentLock sequence */ /* open and WIntentLock sequence */
elm = init_sequence ("nextval", seqname); elm = init_sequence ("nextval", seqname);
pfree (seqname);
if ( elm->last != elm->cached ) /* some numbers were cached */ if ( elm->last != elm->cached ) /* some numbers were cached */
{ {
...@@ -237,7 +238,7 @@ nextval (struct varlena * seqin) ...@@ -237,7 +238,7 @@ nextval (struct varlena * seqin)
break; /* stop caching */ break; /* stop caching */
if ( seq->is_cycled != 't' ) if ( seq->is_cycled != 't' )
elog (WARN, "%s.nextval: got MAXVALUE (%d)", elog (WARN, "%s.nextval: got MAXVALUE (%d)",
seqname, maxv); elm->name, maxv);
next = minv; next = minv;
} }
else else
...@@ -252,7 +253,7 @@ nextval (struct varlena * seqin) ...@@ -252,7 +253,7 @@ nextval (struct varlena * seqin)
break; /* stop caching */ break; /* stop caching */
if ( seq->is_cycled != 't' ) if ( seq->is_cycled != 't' )
elog (WARN, "%s.nextval: got MINVALUE (%d)", elog (WARN, "%s.nextval: got MINVALUE (%d)",
seqname, minv); elm->name, minv);
next = maxv; next = maxv;
} }
else else
...@@ -287,33 +288,18 @@ currval (struct varlena * seqin) ...@@ -287,33 +288,18 @@ currval (struct varlena * seqin)
{ {
char *seqname = textout(seqin); char *seqname = textout(seqin);
SeqTable elm; SeqTable elm;
Buffer buf;
SequenceTupleForm seq;
ItemPointerData iptr;
int4 result; int4 result;
/* open and WIntentLock sequence */ /* open and WIntentLock sequence */
elm = init_sequence ("currval", seqname); elm = init_sequence ("currval", seqname);
pfree (seqname);
if ( elm->last != elm->cached ) /* some numbers were cached */ if ( elm->increment == 0 ) /* nextval/read_info were not called */
{
return (elm->last); /* return last returned by nextval */
}
seq = read_info ("currval", elm, &buf);
if ( seq->is_called != 't' )
{ {
elog (WARN, "%s.currval: yet undefined (%s.nextval never called)", elog (WARN, "%s.currval is not yet defined in this session", elm->name);
seqname, seqname);
} }
result = seq->last_value;
if ( ReleaseBuffer (buf) == STATUS_ERROR ) result = elm->last;
elog (WARN, "%s.currval: ReleaseBuffer failed", seqname);
ItemPointerSet(&iptr, 0, FirstOffsetNumber);
RelationUnsetSingleWLockPage (elm->rel, &iptr);
return (result); return (result);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment