** Maybe construct two lines of text that point out the position of a ** syntax error. Return a pointer to the text, in memory obtained from ** sqlite3_malloc(). Or, if the most recent error does not involve a ** specific token that we can point to, return an empty string. ** ** In all cases, the memory returned is obtained from sqlite3_malloc64() ** and should be released by the caller invoking
| 22992 | ** and should be released by the caller invoking sqlite3_free(). |
| 22993 | */ |
| 22994 | static char *shell_error_context(const char *zSql, sqlite3 *db){ |
| 22995 | int iOffset; |
| 22996 | size_t len; |
| 22997 | char *zCode; |
| 22998 | char *zMsg; |
| 22999 | int i; |
| 23000 | if( db==0 |
| 23001 | || zSql==0 |
| 23002 | || (iOffset = sqlite3_error_offset(db))<0 |
| 23003 | || iOffset>=(int)strlen(zSql) |
| 23004 | ){ |
| 23005 | return sqlite3_mprintf(""); |
| 23006 | } |
| 23007 | while( iOffset>50 ){ |
| 23008 | iOffset--; |
| 23009 | zSql++; |
| 23010 | while( (zSql[0]&0xc0)==0x80 ){ zSql++; iOffset--; } |
| 23011 | } |
| 23012 | len = strlen(zSql); |
| 23013 | if( len>78 ){ |
| 23014 | len = 78; |
| 23015 | while( len>0 && (zSql[len]&0xc0)==0x80 ) len--; |
| 23016 | } |
| 23017 | zCode = sqlite3_mprintf("%.*s", len, zSql); |
| 23018 | shell_check_oom(zCode); |
| 23019 | for(i=0; zCode[i]; i++){ if( IsSpace(zSql[i]) ) zCode[i] = ' '; } |
| 23020 | if( iOffset<25 ){ |
| 23021 | zMsg = sqlite3_mprintf("\n %z\n %*s^--- error here", zCode,iOffset,""); |
| 23022 | }else{ |
| 23023 | zMsg = sqlite3_mprintf("\n %z\n %*serror here ---^", zCode,iOffset-14,""); |
| 23024 | } |
| 23025 | return zMsg; |
| 23026 | } |
| 23027 | |
| 23028 | |
| 23029 | /* |
no test coverage detected