1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-16 23:02:26 +03:00

Improved error message formatting in the shell. Distinguish between

"Parse errors" and "Runtime errors".

FossilOrigin-Name: ae3e322a029952f575e49c73fb50b46bbea55be6792cc225cb94f5e0cbd046d9
This commit is contained in:
drh
2022-02-08 11:52:45 +00:00
parent e1c4743121
commit 3e46db21d4
5 changed files with 31 additions and 20 deletions

View File

@@ -11179,19 +11179,30 @@ static int runOneSqlLine(ShellState *p, char *zSql, FILE *in, int startline){
END_TIMER;
if( rc || zErrMsg ){
char zPrefix[100];
const char *zErrorTail;
const char *zErrorType;
if( zErrMsg==0 ){
zErrorType = "Error";
zErrorTail = sqlite3_errmsg(p->db);
}else if( strncmp(zErrMsg, "in prepare, ",12)==0 ){
zErrorType = "Parse error";
zErrorTail = &zErrMsg[12];
}else if( strncmp(zErrMsg, "stepping, ", 10)==0 ){
zErrorType = "Runtime error";
zErrorTail = &zErrMsg[10];
}else{
zErrorType = "Error";
zErrorTail = zErrMsg;
}
if( in!=0 || !stdin_is_interactive ){
sqlite3_snprintf(sizeof(zPrefix), zPrefix,
"Error: near line %d:", startline);
"%s near line %d:", zErrorType, startline);
}else{
sqlite3_snprintf(sizeof(zPrefix), zPrefix, "Error:");
}
if( zErrMsg!=0 ){
utf8_printf(stderr, "%s %s\n", zPrefix, zErrMsg);
sqlite3_free(zErrMsg);
zErrMsg = 0;
}else{
utf8_printf(stderr, "%s %s\n", zPrefix, sqlite3_errmsg(p->db));
sqlite3_snprintf(sizeof(zPrefix), zPrefix, "%s:", zErrorType);
}
utf8_printf(stderr, "%s %s\n", zPrefix, zErrorTail);
sqlite3_free(zErrMsg);
zErrMsg = 0;
return 1;
}else if( ShellHasFlag(p, SHFLG_CountChanges) ){
char zLineBuf[2000];