aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordrh <>2023-10-13 13:49:46 +0000
committerdrh <>2023-10-13 13:49:46 +0000
commitaf527231c14206ec6ab9564c93e731cc7ea56001 (patch)
treef1fa2b1fc9b95d83d399b3bde70bdd2c89ac5618 /src
parent98170653405fc5f0aad29bf6a9513364c50b1191 (diff)
downloadsqlite-af527231c14206ec6ab9564c93e731cc7ea56001.tar.gz
sqlite-af527231c14206ec6ab9564c93e731cc7ea56001.zip
Immediately fail a CREATE TABLE statement that attempts to create a
table that has a generated column loop. Legacy allows the table to be created but the table would not be usable for anything. FossilOrigin-Name: 3237bf964117c1ef71143042837ef21872bb3d04bfd682075672e768953ec802
Diffstat (limited to 'src')
-rw-r--r--src/build.c7
-rw-r--r--src/vdbe.c11
2 files changed, 16 insertions, 2 deletions
diff --git a/src/build.c b/src/build.c
index 59e3e23f0..0920b0f22 100644
--- a/src/build.c
+++ b/src/build.c
@@ -2920,6 +2920,13 @@ void sqlite3EndTable(
/* Reparse everything to update our internal data structures */
sqlite3VdbeAddParseSchemaOp(v, iDb,
sqlite3MPrintf(db, "tbl_name='%q' AND type!='trigger'", p->zName),0);
+
+ /* Test for cycles in generated columns */
+ if( p->tabFlags & TF_HasGenerated ){
+ sqlite3VdbeAddOp4(v, OP_SqlExec, 0, 0, 0,
+ sqlite3MPrintf(db, "SELECT*FROM\"%w\".\"%s\"",
+ db->aDb[iDb].zDbSName, p->zName), P4_DYNAMIC);
+ }
}
/* Add the table to the in-memory representation of the database.
diff --git a/src/vdbe.c b/src/vdbe.c
index 646313650..00d365680 100644
--- a/src/vdbe.c
+++ b/src/vdbe.c
@@ -6908,11 +6908,18 @@ case OP_CreateBtree: { /* out2 */
** Run the SQL statement or statements specified in the P4 string.
*/
case OP_SqlExec: {
+ char *zErr;
+
sqlite3VdbeIncrWriteCounter(p, 0);
db->nSqlExec++;
- rc = sqlite3_exec(db, pOp->p4.z, 0, 0, 0);
+ zErr = 0;
+ rc = sqlite3_exec(db, pOp->p4.z, 0, 0, &zErr);
db->nSqlExec--;
- if( rc ) goto abort_due_to_error;
+ if( rc || zErr ){
+ sqlite3VdbeError(p, "%s", zErr);
+ sqlite3_free(zErr);
+ goto abort_due_to_error;
+ }
break;
}