add the trim function and optimize error print
Project: http://git-wip-us.apache.org/repos/asf/trafodion/repo Commit: http://git-wip-us.apache.org/repos/asf/trafodion/commit/3c9cc942 Tree: http://git-wip-us.apache.org/repos/asf/trafodion/tree/3c9cc942 Diff: http://git-wip-us.apache.org/repos/asf/trafodion/diff/3c9cc942 Branch: refs/heads/master Commit: 3c9cc94218014e951377ea53b7d47f08ef678268 Parents: 5161f7b Author: SuJinpei <[email protected]> Authored: Mon Aug 13 11:26:06 2018 +0800 Committer: SuJinpei <[email protected]> Committed: Tue Nov 20 12:55:38 2018 +0800 ---------------------------------------------------------------------- core/conn/odb/src/odb.c | 54 +++++++++++++++++++++++++++++++++----------- 1 file changed, 41 insertions(+), 13 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/trafodion/blob/3c9cc942/core/conn/odb/src/odb.c ---------------------------------------------------------------------- diff --git a/core/conn/odb/src/odb.c b/core/conn/odb/src/odb.c index d008d82..8e2593f 100755 --- a/core/conn/odb/src/odb.c +++ b/core/conn/odb/src/odb.c @@ -720,6 +720,7 @@ static void setan ( int eid, int tid, int nrag, char *rag[], char *ql ); static int Omexec(int tid, int eid, int ten, int scn, SQLCHAR *Ocmd, char *label, char *dcat, char *dsch); static char *strup ( char *s ); static char *strlo ( char *s ); +static char *strtrim(char *str); int mrinit ( void ); void mrend ( void ); char *mreadline ( char *prompt, unsigned int *length ); @@ -6979,6 +6980,8 @@ static void Oload(int eid) fprintf(stderr, "odb [Oload(%d)] - DIV error for %s\n", __LINE__, (char *)etab[eid].td[j].Oname); goto oload_exit; } + } else if (!strmicmp("trim", bp, 4)) { + map[j].op = 17; } else { map[j].op = 0; @@ -7378,6 +7381,7 @@ static void Oload(int eid) } if ( fg & 0062 ) { /* field/record ready or nofile */ oload_lastrow: + str[ifl] = '\0'; if ( rmap && rmap[k] >= 0 ) { Odp = &etab[eid].Orowsetl[m*etab[eid].s + etab[eid].td[rmap[k]].start]; if ( fg & 0200 ) { /* embed file reading mode */ @@ -7542,6 +7546,10 @@ static void Oload(int eid) } } break; + case 17: // trim + str = strtrim(str); + ifl = strlen(str); + break; } if ( ifl > (int)etab[eid].td[rmap[k]].Osize ) { /* prevent Orowsetl[] overflow */ str[ifl]='\0'; @@ -10106,6 +10114,7 @@ static int Oloadbuff(int eid) clock_gettime(CLOCK_MONOTONIC, &tsp1); #endif Or = SQLExecute(thps[tid].Os) ; /* Execute INSERT (load/copy) or tgt command */ + SQLLEN tLastRow = -1; /* this is special solution for China Union Pay, print only first error message for state 22003 */ #ifdef ODB_PROFILE clock_gettime(CLOCK_MONOTONIC, &tsp2); ti += tspdiff ( &tsp1 , &tsp2 ) ; @@ -10189,20 +10198,24 @@ static int Oloadbuff(int eid) /* Ok, now we have an error message (Otxt), a five char SQLState (Ostate), * a native error code (Onative) and the rowset row number (Orown). Let's * print everything to stderr. */ - fprintf(stderr, "[%d] odb [Oloadbuff(%d)] - Error loading row %lu (State: %s, Native %ld)\n%s\n", - tid, __LINE__, (unsigned long)Orown + etab[eid].nbs, (char *)Ostate, (long)Onative, (char *)Otxt); - if ( type == 'C' ) { /* 'C' thread */ - if ( etab[eid].fdmp ) { /* dump ODBC buffer */ - MutexLock(&etab[gpar].pmutex); - fprintf(etab[eid].fdmp, "[%d] odb [Oloadbuff(%d)] - Error loading row %lu (State: %s, Native %ld)\n%s\n", - tid, __LINE__, (unsigned long)Orown + etab[eid].nbs, (char *)Ostate, (long)Onative, (char *)Otxt); - fprintf(etab[eid].fdmp, "[%d] Dumping row %lu in a block of %zu rows. ODBC row length = %zu\n", - tid, (unsigned long) Orown, etab[eid].ar, etab[par].s ) ; - dumpbuff(etab[eid].fdmp, tid, (unsigned char *)(etab[eid].Orowsetl + (Orown - 1) * etab[par].s), etab[par].s, 0 ); - MutexUnlock(&etab[gpar].pmutex); + if (tLastRow != Orown) { + tLastRow = Orown; + fprintf(stderr, "[%d] odb [Oloadbuff(%d)] - Error loading row %lu (State: %s, Native %ld)\n%s\n", + tid, __LINE__, (unsigned long)Orown + etab[eid].nbs, (char *)Ostate, (long)Onative, (char *)Otxt); + if (type == 'C') { /* 'C' thread */ + if (etab[eid].fdmp) { /* dump ODBC buffer */ + MutexLock(&etab[gpar].pmutex); + fprintf(etab[eid].fdmp, "[%d] odb [Oloadbuff(%d)] - Error loading row %lu (State: %s, Native %ld)\n%s\n", + tid, __LINE__, (unsigned long)Orown + etab[eid].nbs, (char *)Ostate, (long)Onative, (char *)Otxt); + fprintf(etab[eid].fdmp, "[%d] Dumping row %lu in a block of %zu rows. ODBC row length = %zu\n", + tid, (unsigned long)Orown, etab[eid].ar, etab[par].s); + dumpbuff(etab[eid].fdmp, tid, (unsigned char *)(etab[eid].Orowsetl + (Orown - 1) * etab[par].s), etab[par].s, 0); + MutexUnlock(&etab[gpar].pmutex); + } + } + else { /* either multi ('L') or single ('l') threaded loaders */ + prec('L', (unsigned char *)(etab[eid].Orowsetl + etab[par].s*(Orown - 1)), eid); } - } else { /* either multi ('L') or single ('l') threaded loaders */ - prec('L', (unsigned char *)(etab[eid].Orowsetl + etab[par].s*(Orown-1)), eid); } break; } @@ -13299,6 +13312,21 @@ static char *strlo ( char *s ) return(save); } +static char *strtrim(char *str) +{ + // trim tailing space + size_t i = strlen(str) - 1; + while (str[i] == ' ') --i; + str[i + 1] = '\0'; + + // trim heading space + for (i = 0; str[i] == ' '; ++i); + if (i > 0) + strcpy(str, str + i); + + return str; +} + /* expandtype: * return SQL type string associated with a given data type *
