SQLite

Check-in [348fa7aaf7]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Earlier detection of a host of errors in CREATE TABLE, such the CREATE TABLE statement itself fails, rather than generating an error on the first attempted use of the created table.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 348fa7aaf7958b3fb689ed023d946064ae8d92718a497a346e95114a2410cbf5
User & Date: drh 2023-10-13 22:19:23.580
References
2024-05-02
11:51
Omit the OP_SqlExec to "PRAGMA integrity_check" added by [348fa7aaf7958b3f] because it is a no-op. Even if the integrity_check failes, the CREATE TABLE is stull successful. The OP_SqlExec just burns CPU cycles for no reason. (check-in: 532795acd1 user: drh tags: faster-create)
Context
2023-10-14
10:54
Bug fix in sqlite3_analyzer: for databases larger than 1GiB, take into account the lock-byte page when calculating the number of freelist pages. (check-in: 26a909cdd3 user: drh tags: trunk)
2023-10-13
22:19
Earlier detection of a host of errors in CREATE TABLE, such the CREATE TABLE statement itself fails, rather than generating an error on the first attempted use of the created table. (check-in: 348fa7aaf7 user: drh tags: trunk)
19:41
Apply the correct affinity to DEFAULT values that are TRUE or FALSE. (check-in: 4958db70c8 user: drh tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/btree.c.
10704
10705
10706
10707
10708
10709
10710

10711
10712
10713
10714
10715
10716
10717
  if( iPage==0 ) return 0;
  if( checkRef(pCheck, iPage) ) return 0;
  pCheck->zPfx = "Tree %u page %u: ";
  pCheck->v1 = iPage;
  if( (rc = btreeGetPage(pBt, iPage, &pPage, 0))!=0 ){
    checkAppendMsg(pCheck,
       "unable to get the page. error code=%d", rc);

    goto end_of_check;
  }

  /* Clear MemPage.isInit to make sure the corruption detection code in
  ** btreeInitPage() is executed.  */
  savedIsInit = pPage->isInit;
  pPage->isInit = 0;







>







10704
10705
10706
10707
10708
10709
10710
10711
10712
10713
10714
10715
10716
10717
10718
  if( iPage==0 ) return 0;
  if( checkRef(pCheck, iPage) ) return 0;
  pCheck->zPfx = "Tree %u page %u: ";
  pCheck->v1 = iPage;
  if( (rc = btreeGetPage(pBt, iPage, &pPage, 0))!=0 ){
    checkAppendMsg(pCheck,
       "unable to get the page. error code=%d", rc);
    if( rc==SQLITE_IOERR_NOMEM ) pCheck->rc = SQLITE_NOMEM;
    goto end_of_check;
  }

  /* Clear MemPage.isInit to make sure the corruption detection code in
  ** btreeInitPage() is executed.  */
  savedIsInit = pPage->isInit;
  pPage->isInit = 0;
Changes to src/build.c.
2917
2918
2919
2920
2921
2922
2923
2924

2925
2926
2927
2928
2929



2930
2931
2932
2933
2934
2935
2936
    }
#endif

    /* 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.
  */
  if( db->init.busy ){
    Table *pOld;
    Schema *pSchema = p->pSchema;







|
>

|
|


>
>
>







2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
    }
#endif

    /* 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 and illegal expressions
    ** in CHECK constraints and in DEFAULT clauses. */
    if( p->tabFlags & TF_HasGenerated ){
      sqlite3VdbeAddOp4(v, OP_SqlExec, 1, 0, 0,
             sqlite3MPrintf(db, "SELECT*FROM\"%w\".\"%w\"",
                   db->aDb[iDb].zDbSName, p->zName), P4_DYNAMIC);
    }
    sqlite3VdbeAddOp4(v, OP_SqlExec, 1, 0, 0,
           sqlite3MPrintf(db, "PRAGMA \"%w\".integrity_check(%Q)",
                 db->aDb[iDb].zDbSName, p->zName), P4_DYNAMIC);
  }

  /* Add the table to the in-memory representation of the database.
  */
  if( db->init.busy ){
    Table *pOld;
    Schema *pSchema = p->pSchema;
Changes to src/vdbe.c.
6902
6903
6904
6905
6906
6907
6908


6909
6910
6911


6912
6913
6914
6915






6916
6917


6918
6919
6920

6921
6922
6923
6924
6925
6926
6927
  pOut->u.i = pgno;
  break;
}

/* Opcode: SqlExec * * * P4 *
**
** Run the SQL statement or statements specified in the P4 string.


*/
case OP_SqlExec: {
  char *zErr;



  sqlite3VdbeIncrWriteCounter(p, 0);
  db->nSqlExec++;
  zErr = 0;






  rc = sqlite3_exec(db, pOp->p4.z, 0, 0, &zErr);
  db->nSqlExec--;


  if( rc || zErr ){
    sqlite3VdbeError(p, "%s", zErr);
    sqlite3_free(zErr);

    goto abort_due_to_error;
  }
  break;
}

/* Opcode: ParseSchema P1 * * P4 *
**







>
>



>
>




>
>
>
>
>
>


>
>



>







6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6927
6928
6929
6930
6931
6932
6933
6934
6935
6936
6937
6938
6939
6940
  pOut->u.i = pgno;
  break;
}

/* Opcode: SqlExec * * * P4 *
**
** Run the SQL statement or statements specified in the P4 string.
** Disable Auth and Trace callbacks while those statements are running if
** P1 is true.
*/
case OP_SqlExec: {
  char *zErr;
  sqlite3_xauth xAuth;
  u8 mTrace;

  sqlite3VdbeIncrWriteCounter(p, 0);
  db->nSqlExec++;
  zErr = 0;
  xAuth = db->xAuth;
  mTrace = db->mTrace;
  if( pOp->p1 ){
    db->xAuth = 0;
    db->mTrace = 0;
  }
  rc = sqlite3_exec(db, pOp->p4.z, 0, 0, &zErr);
  db->nSqlExec--;
  db->xAuth = xAuth;
  db->mTrace = mTrace;
  if( rc || zErr ){
    sqlite3VdbeError(p, "%s", zErr);
    sqlite3_free(zErr);
    if( rc==SQLITE_NOMEM ) goto no_mem;
    goto abort_due_to_error;
  }
  break;
}

/* Opcode: ParseSchema P1 * * P4 *
**