--- C:/Users/1134140140301/Documents/WorkingDir/work/API/psqlodbc-09.03.0400/convert.c Sun Oct 26 15:08:36 2014 +++ C:/Users/1134140140301/Documents/WorkingDir/work/psqlODBC/psqlodbc-09.03.0400/convert.c Tue Sep 15 17:30:23 2015 @@ -349,7 +349,9 @@ { char precstr[16], zonestr[16]; - int i; + int i, + len, + origlen; precstr[0] = '\0'; if (st->infinity > 0) @@ -402,10 +404,31 @@ snprintf(zonestr, sizeof(zonestr), "+%02d", -(int) zoneint / 3600); } #endif /* TIMEZONE_GLOBAL */ +#ifdef WIN32 + origlen = 19 + strlen(precstr) + strlen(zonestr); // "YYYY-MM-DD HH:MM:SS" + precision + timezone +#endif /* WIN32 */ if (st->y < 0) - return snprintf(str, bufsize, "%.4d-%.2d-%.2d %.2d:%.2d:%.2d%s%s BC", -st->y, st->m, st->d, st->hh, st->mm, st->ss, precstr, zonestr); + { +#ifdef WIN32 + origlen += 3; //add length of " BC" +#endif /* WIN32 */ + len = snprintf(str, bufsize, "%.4d-%.2d-%.2d %.2d:%.2d:%.2d%s%s BC", -st->y, st->m, st->d, st->hh, st->mm, st->ss, precstr, zonestr); + } else - return snprintf(str, bufsize, "%.4d-%.2d-%.2d %.2d:%.2d:%.2d%s%s", st->y, st->m, st->d, st->hh, st->mm, st->ss, precstr, zonestr); + { + len = snprintf(str, bufsize, "%.4d-%.2d-%.2d %.2d:%.2d:%.2d%s%s", st->y, st->m, st->d, st->hh, st->mm, st->ss, precstr, zonestr); + } +#ifdef WIN32 + if(len < 0 || len == origlen){ + /* + * In Windows, str may not include terminated string. + * so we need to add terminated string. + */ + str[bufsize-1] = '\0'; + len = origlen; + } +#endif /* WIN32 */ + return len; } #if (ODBCVER >= 0x0300) @@ -1175,12 +1198,24 @@ { case PG_TYPE_DATE: len = snprintf(rgbValueBindRow, cbValueMax, "%.4d-%.2d-%.2d", std_time.y, std_time.m, std_time.d); +#ifdef WIN32 + if(len < 0 || len == 10){ + rgbValueBindRow[cbValueMax-1]='\0'; + len = 10; + } +#endif /* WIN32 */ if (len + 1 > cbValueMax) result = COPY_RESULT_TRUNCATED; break; case PG_TYPE_TIME: len = snprintf(rgbValueBindRow, cbValueMax, "%.2d:%.2d:%.2d", std_time.hh, std_time.mm, std_time.ss); +#ifdef WIN32 + if(len < 0 || len == 8){ + rgbValueBindRow[cbValueMax-1]='\0'; + len = 8; + } +#endif /* WIN32 */ if (len + 1 > cbValueMax) result = COPY_RESULT_TRUNCATED; break; @@ -1192,13 +1227,19 @@ /* sprintf(rgbValueBindRow, "%.4d-%.2d-%.2d %.2d:%.2d:%.2d", std_time.y, std_time.m, std_time.d, std_time.hh, std_time.mm, std_time.ss); */ len = stime2timestamp(&std_time, rgbValueBindRow, cbValueMax, FALSE, - PG_VERSION_GE(conn, 7.2) ? (int) cbValueMax - len - 2 : 0); + PG_VERSION_GE(conn, 7.2) ? 6 : 0); if (len + 1 > cbValueMax) result = COPY_RESULT_TRUNCATED; break; case PG_TYPE_BOOL: len = snprintf(rgbValueBindRow, cbValueMax, "%s", neut_str); +#ifdef WIN32 + if(len < 0 || len == strlen(neut_str)){ + rgbValueBindRow[cbValueMax-1]='\0'; + len = strlen(neut_str); + } +#endif /* WIN32 */ if (len + 1 > cbValueMax) result = COPY_RESULT_TRUNCATED; mylog("PG_TYPE_BOOL: rgbValueBindRow = '%s'\n", rgbValueBindRow);