Changeset: 49697a4e087f for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/49697a4e087f
Modified Files:
sql/backends/monet5/sql.c
sql/backends/monet5/sql_cat.c
sql/server/rel_sequence.c
Branch: Jan2022
Log Message:
Added missing sequences properties checks and cleaned some code. We have yet to
look at no maxvalue and no minvalue because one test is failing
diffs (151 lines):
diff --git a/sql/backends/monet5/sql.c b/sql/backends/monet5/sql.c
--- a/sql/backends/monet5/sql.c
+++ b/sql/backends/monet5/sql.c
@@ -1064,9 +1064,9 @@ mvc_restart_seq(Client cntxt, MalBlkPtr
throw(SQL, "sql.restart", SQLSTATE(HY050) "Failed to fetch
sequence %s.%s", sname, seqname);
if (is_lng_nil(start))
throw(SQL, "sql.restart", SQLSTATE(HY050) "Cannot (re)start
sequence %s.%s with NULL", sname, seqname);
- if (seq->minvalue && start < seq->minvalue)
+ if (start < seq->minvalue)
throw(SQL, "sql.restart", SQLSTATE(HY050) "Cannot set sequence
%s.%s start to a value lesser than the minimum ("LLFMT" < "LLFMT")", sname,
seqname, start, seq->minvalue);
- if (seq->maxvalue && start > seq->maxvalue)
+ if (start > seq->maxvalue)
throw(SQL, "sql.restart", SQLSTATE(HY050) "Cannot set sequence
%s.%s start to a value higher than the maximum ("LLFMT" > "LLFMT")", sname,
seqname, start, seq->maxvalue);
switch (sql_trans_sequence_restart(m->session->tr, seq, start)) {
case -1:
diff --git a/sql/backends/monet5/sql_cat.c b/sql/backends/monet5/sql_cat.c
--- a/sql/backends/monet5/sql_cat.c
+++ b/sql/backends/monet5/sql_cat.c
@@ -793,12 +793,19 @@ create_seq(mvc *sql, char *sname, char *
if (is_lng_nil(seq->start) || is_lng_nil(seq->minvalue) ||
is_lng_nil(seq->maxvalue) ||
is_lng_nil(seq->increment) ||
is_lng_nil(seq->cacheinc) || is_bit_nil(seq->cycle))
throw(SQL,"sql.create_seq", SQLSTATE(42000) "CREATE SEQUENCE:
sequence properties must be non-NULL");
- if (seq->minvalue && seq->start < seq->minvalue)
+ if (seq->start < seq->minvalue)
throw(SQL,"sql.create_seq", SQLSTATE(42000) "CREATE SEQUENCE:
start value is lesser than the minimum ("LLFMT" < "LLFMT")", seq->start,
seq->minvalue);
- if (seq->maxvalue && seq->start > seq->maxvalue)
+ if (seq->start > seq->maxvalue)
throw(SQL,"sql.create_seq", SQLSTATE(42000) "CREATE SEQUENCE:
start value is higher than the maximum ("LLFMT" > "LLFMT")", seq->start,
seq->maxvalue);
- if (seq->minvalue && seq->maxvalue && seq->maxvalue < seq->minvalue)
+ if (seq->maxvalue < seq->minvalue)
throw(SQL,"sql.create_seq", SQLSTATE(42000) "CREATE SEQUENCE:
maximum value is lesser than the minimum ("LLFMT" < "LLFMT")", seq->maxvalue,
seq->minvalue);
+ if (seq->increment == 0)
+ throw(SQL,"sql.create_seq", SQLSTATE(42000) "CREATE SEQUENCE:
sequence increment cannot be 0");
+ if (seq->cacheinc <= 0)
+ throw(SQL,"sql.create_seq", SQLSTATE(42000) "CREATE SEQUENCE:
sequence cache must be positive");
+ lng calc = llabs(seq->increment) * seq->cacheinc;
+ if (calc < llabs(seq->increment) || calc < seq->cacheinc)
+ throw(SQL,"sql.create_seq", SQLSTATE(42000) "CREATE SEQUENCE:
The specified range of cached values cannot be set. Either reduce increment or
cache value");
switch (sql_trans_create_sequence(sql->session->tr, s, seq->base.name,
seq->start, seq->minvalue, seq->maxvalue, seq->increment, seq->cacheinc,
seq->cycle, seq->bedropped)) {
case -1:
throw(SQL,"sql.create_seq",SQLSTATE(HY013)
MAL_MALLOC_FAIL);
@@ -835,14 +842,21 @@ alter_seq(mvc *sql, char *sname, char *s
default:
break;
}
- if (nseq->minvalue && nseq->maxvalue && nseq->maxvalue < seq->minvalue)
- throw(SQL, "sql.alter_seq", SQLSTATE(42000) "ALTER SEQUENCE:
maximum value is lesser than the minimum ("LLFMT" < "LLFMT")", nseq->maxvalue,
nseq->minvalue);
+ if (nseq->maxvalue < nseq->minvalue)
+ throw(SQL,"sql.alter_seq", SQLSTATE(42000) "ALTER SEQUENCE:
maximum value is lesser than the minimum ("LLFMT" < "LLFMT")", nseq->maxvalue,
nseq->minvalue);
+ if (nseq->increment == 0)
+ throw(SQL,"sql.alter_seq", SQLSTATE(42000) "ALTER SEQUENCE:
sequence increment cannot be 0");
+ if (nseq->cacheinc <= 0)
+ throw(SQL,"sql.alter_seq", SQLSTATE(42000) "ALTER SEQUENCE:
sequence cache must be positive");
+ lng calc = llabs(nseq->increment) * nseq->cacheinc;
+ if (calc < llabs(nseq->increment) || calc < nseq->cacheinc)
+ throw(SQL,"sql.alter_seq", SQLSTATE(42000) "ALTER SEQUENCE: The
specified range of cached values cannot be set. Either reduce increment or
cache value");
if (val) {
if (is_lng_nil(*val))
throw(SQL,"sql.alter_seq", SQLSTATE(42000) "ALTER
SEQUENCE: sequence value must be non-NULL");
- if (nseq->minvalue && *val < nseq->minvalue)
+ if (*val < nseq->minvalue)
throw(SQL,"sql.alter_seq", SQLSTATE(42000) "ALTER
SEQUENCE: cannot set sequence start to a value lesser than the minimum ("LLFMT"
< "LLFMT")", *val, nseq->minvalue);
- if (nseq->maxvalue && *val > nseq->maxvalue)
+ if (*val > nseq->maxvalue)
throw(SQL,"sql.alter_seq", SQLSTATE(42000) "ALTER
SEQUENCE: cannot set sequence start to a value higher than the maximum ("LLFMT"
> "LLFMT")", *val, nseq->maxvalue);
switch (sql_trans_sequence_restart(sql->session->tr, nseq,
*val)) {
case -1:
diff --git a/sql/server/rel_sequence.c b/sql/server/rel_sequence.c
--- a/sql/server/rel_sequence.c
+++ b/sql/server/rel_sequence.c
@@ -102,12 +102,25 @@ rel_create_seq(
/* generate defaults */
if (is_lng_nil(inc)) inc = 1;
+ if (is_lng_nil(start)) start = !is_lng_nil(min) ? min : inc > 0 ? 1 :
-1; /* if start value not set, set it to the minimum if available */
if (is_lng_nil(min)) min = inc > 0 ? 0 : GDK_lng_min;
if (is_lng_nil(max)) max = inc > 0 ? GDK_lng_max : 0;
- if (is_lng_nil(start)) start = inc > 0 ? 1 : -1;
if (is_lng_nil(cache)) cache = 1;
+ if (is_bit_nil(cycle)) cycle = 1;
- // TODO: check that min < max and min <= start <= max and inc != 0 and
inc * cache > 0 does not overflow?
+ if (inc == 0)
+ return sql_error(sql, 02, SQLSTATE(42000) "CREATE SEQUENCE:
INCREMENT cannot be 0");
+ if (cache <= 0)
+ return sql_error(sql, 02, SQLSTATE(42000) "CREATE SEQUENCE:
CACHE must be positive");
+ lng calc = llabs(inc) * cache;
+ if (calc < llabs(inc) || calc < cache)
+ return sql_error(sql, 02, SQLSTATE(42000) "CREATE SEQUENCE: The
specified range of cached values cannot be set. Either reduce increment or
cache value");
+ if (max < min)
+ return sql_error(sql, 02, SQLSTATE(42000) "CREATE SEQUENCE:
MAXVALUE value is lesser than MINVALUE ("LLFMT" < "LLFMT")", max, min);
+ if (start < min)
+ return sql_error(sql, 02, SQLSTATE(42000) "CREATE SEQUENCE:
START value is lesser than MINVALUE ("LLFMT" < "LLFMT")", start, min);
+ if (start > max)
+ return sql_error(sql, 02, SQLSTATE(42000) "CREATE SEQUENCE:
START value is higher than MAXVALUE ("LLFMT" > "LLFMT")", start, max);
seq = create_sql_sequence(sql->store, sql->sa, s, name, start, min,
max, inc, cache, cycle);
seq->bedropped = bedropped;
@@ -216,17 +229,7 @@ list_create_seq(
assert(0);
}
}
- if (!is_lng_nil(start)) {
- if (!is_lng_nil(min) && start < min)
- return sql_error(sql, 02, SQLSTATE(42000)
"CREATE SEQUENCE: START value is lesser than MINVALUE ("LLFMT" < "LLFMT")",
start, min);
- if (!is_lng_nil(max) && start > max)
- return sql_error(sql, 02, SQLSTATE(42000)
"CREATE SEQUENCE: START value is higher than MAXVALUE ("LLFMT" > "LLFMT")",
start, max);
- }
- if (!is_lng_nil(min) && !is_lng_nil(max) && max < min)
- return sql_error(sql, 02, SQLSTATE(42000) "CREATE
SEQUENCE: MAXVALUE value is lesser than MINVALUE ("LLFMT" < "LLFMT")", max,
min);
}
- if (is_lng_nil(start) && !is_lng_nil(min) && min) /* if start value not
set, set it to the minimum if available */
- start = min;
return rel_create_seq(sql, qname, t, start, inc, min, max, cache,
cycle, bedropped);
}
@@ -258,8 +261,24 @@ rel_alter_seq(
return sql_error(sql, 02, SQLSTATE(42000) "ALTER SEQUENCE:
insufficient privileges "
"for '%s' in schema '%s'",
get_string_global_var(sql, "current_user"), seq->s->base.name);
+ /* if not being modified, use existing values */
+ if (is_lng_nil(inc)) inc = seq->increment;
+ if (is_lng_nil(min)) min = seq->minvalue;
+ if (is_lng_nil(max)) max = seq->maxvalue;
+ if (is_lng_nil(cache)) cache = seq->cacheinc;
+ if (is_bit_nil(cycle)) cycle = seq->cycle;
+
+ if (inc == 0)
+ return sql_error(sql, 02, SQLSTATE(42000) "ALTER SEQUENCE:
INCREMENT cannot be 0");
+ if (cache <= 0)
+ return sql_error(sql, 02, SQLSTATE(42000) "ALTER SEQUENCE:
CACHE must be positive");
+ lng calc = llabs(inc) * cache;
+ if (calc < llabs(inc) || calc < cache)
+ return sql_error(sql, 02, SQLSTATE(42000) "ALTER SEQUENCE: The
specified range of cached values cannot be set. Either reduce increment or
cache value");
+ if (max < min)
+ return sql_error(sql, 02, SQLSTATE(42000) "ALTER SEQUENCE:
MAXVALUE value is lesser than MINVALUE ("LLFMT" < "LLFMT")", max, min);
/* first alter the known values */
- seq = create_sql_sequence(sql->store, sql->sa, seq->s, name,
seq->start, min, max, inc, cache, (bit) cycle);
+ seq = create_sql_sequence(sql->store, sql->sa, seq->s, name,
seq->start, min, max, inc, cache, cycle);
/* restart may be a query, i.e. we create a statement
restart(ssname,seqname,value) */
@@ -363,8 +382,6 @@ list_alter_seq(
assert(0);
}
}
- if (!is_lng_nil(min) && !is_lng_nil(max) && max < min)
- return sql_error(sql, 02, SQLSTATE(42000) "ALTER SEQUENCE:
MAXVALUE value is lesser than MINVALUE ("LLFMT" < "LLFMT")", max, min);
return rel_alter_seq(query, qname, t, start, inc, min, max, cache,
cycle);
}
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list