diff options
author | drh <> | 2021-12-24 20:22:13 +0000 |
---|---|---|
committer | drh <> | 2021-12-24 20:22:13 +0000 |
commit | f62641e91cc0aee1a24ea4a3c81289e4e821c4e5 (patch) | |
tree | 858ed6fcb6519dc309510e91b8da3979fec966cc /src/printf.c | |
parent | c320e062a3eaa4be3c8e7b50c63c43054decb441 (diff) | |
download | sqlite-f62641e91cc0aee1a24ea4a3c81289e4e821c4e5.tar.gz sqlite-f62641e91cc0aee1a24ea4a3c81289e4e821c4e5.zip |
Add the sqlite3_error_offset() interface. Use it in the CLI to provide
better context for error messages.
FossilOrigin-Name: b518ce77439852759bc0901071f36d622b1314c9bf3d29c279dfcc405188b975
Diffstat (limited to 'src/printf.c')
-rw-r--r-- | src/printf.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/printf.c b/src/printf.c index 6128e5cb4..9fea2d6ef 100644 --- a/src/printf.c +++ b/src/printf.c @@ -855,6 +855,7 @@ void sqlite3_str_vappendf( assert( bArgList==0 ); if( pToken && pToken->n ){ sqlite3_str_append(pAccum, (const char*)pToken->z, pToken->n); + sqlite3RecordErrorByteOffset(pAccum->db, pToken->z); } length = width = 0; break; @@ -909,6 +910,30 @@ void sqlite3_str_vappendf( }/* End for loop over the format string */ } /* End of function */ + +/* +** The z string points to the first character of a token that is +** associated with an error. If db does not already have an error +** byte offset recorded, try to compute the error byte offset for +** z and set the error byte offset in db. +*/ +void sqlite3RecordErrorByteOffset(sqlite3 *db, const char *z){ + const Parse *pParse; + const char *zText; + const char *zEnd; + assert( z!=0 ); + if( NEVER(db==0) ) return; + if( db->errByteOffset!=(-2) ) return; + pParse = db->pParse; + if( NEVER(pParse==0) ) return; + zText =pParse->zTail; + if( NEVER(zText==0) ) return; + zEnd = &zText[strlen(zText)]; + if( SQLITE_WITHIN(z,zText,zEnd) ){ + db->errByteOffset = (int)(z-zText); + } +} + /* ** Enlarge the memory allocation on a StrAccum object so that it is ** able to accept at least N more bytes of text. |