MCPcopy Create free account
hub / github.com/GaijinEntertainment/daScript / shell_error_context

Function shell_error_context

modules/dasSQLITE/sqlite/shell.c:17918–17950  ·  view source on GitHub ↗

** 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

Source from the content-addressed store, hash-verified

17916** and should be released by the caller invoking sqlite3_free().
17917*/
17918static char *shell_error_context(const char *zSql, sqlite3 *db){
17919 int iOffset;
17920 size_t len;
17921 char *zCode;
17922 char *zMsg;
17923 int i;
17924 if( db==0
17925 || zSql==0
17926 || (iOffset = sqlite3_error_offset(db))<0
17927 || iOffset>=strlen(zSql)
17928 ){
17929 return sqlite3_mprintf("");
17930 }
17931 while( iOffset>50 ){
17932 iOffset--;
17933 zSql++;
17934 while( (zSql[0]&0xc0)==0x80 ){ zSql++; iOffset--; }
17935 }
17936 len = strlen(zSql);
17937 if( len>78 ){
17938 len = 78;
17939 while( (zSql[len]&0xc0)==0x80 ) len--;
17940 }
17941 zCode = sqlite3_mprintf("%.*s", len, zSql);
17942 shell_check_oom(zCode);
17943 for(i=0; zCode[i]; i++){ if( IsSpace(zSql[i]) ) zCode[i] = ' '; }
17944 if( iOffset<25 ){
17945 zMsg = sqlite3_mprintf("\n %z\n %*s^--- error here", zCode,iOffset,"");
17946 }else{
17947 zMsg = sqlite3_mprintf("\n %z\n %*serror here ---^", zCode,iOffset-14,"");
17948 }
17949 return zMsg;
17950}
17951
17952
17953/*

Callers 2

run_table_dump_queryFunction · 0.85
save_err_msgFunction · 0.85

Calls 2

shell_check_oomFunction · 0.85
IsSpaceFunction · 0.85

Tested by

no test coverage detected