354{
356
357 if (_rc == SQL_SUCCESS_WITH_INFO || _rc ==
SQL_ERROR) {
359 _htype == SQL_HANDLE_ENV
360 || _htype == SQL_HANDLE_DBC
361 || _htype == SQL_HANDLE_STMT
362 || _htype == SQL_HANDLE_DESC
363
364 );
366
367#if 0 && defined(__WINNT__)
368
369
370
371
372
373 StringBuilder sb;
374 SQLSMALLINT RecNumber = 0;
375 SQLINTEGER NativeError;
376 WCHAR SQLState[SQL_SQLSTATE_SIZE + 1];
377 WCHAR MessageText[1024];
378 SQLSMALLINT MessageTextLength;
379 SQLRETURN rc;
380 while ((rc = SQLGetDiagRecW(
381 _htype, _handle, ++RecNumber, SQLState, &NativeError,
382 MessageText,
__countof(MessageText, WCHAR), &MessageTextLength
383 )) == SQL_SUCCESS) {
384 if (sb.length() > 0) {
385 sb.append('\n');
386 }
387 sb.format(L"[%d][%ls]", RecNumber, SQLState);
388 sb.append(MessageText, (size_t) MessageTextLength);
389 }
390
391 String s = sb.toString();
392 #if __TRACE_THIS
393 if (_rc == SQL_SUCCESS_WITH_INFO) {
395 s.replace(L"\n", L"\n ").data());
396 }
397 #endif
398 try {
399 __lastErrorMessage = UTF8Encoder::encode(s);
400 }
401 catch (CharsetConvertException* _e) {
402 __DCL_TRACE1(L
"Fatal!! [%ls]\n", _e->toString().data());
404 }
405#else
406 ByteStringBuilder sb;
407 SQLSMALLINT RecNumber = 0;
408 SQLINTEGER NativeError;
409 SQLCHAR SQLState[SQL_SQLSTATE_SIZE + 1];
410 SQLCHAR ErrorMsg[1024];
411 SQLSMALLINT ErrorMsgLen;
412 SQLRETURN rc;
413 while ((rc = SQLGetDiagRecA(
414 _htype, _handle, ++RecNumber, SQLState, &NativeError,
415 ErrorMsg,
__countof(ErrorMsg, SQLCHAR), &ErrorMsgLen
416 )) == SQL_SUCCESS) {
417 if (sb.length() > 0) {
418 sb.append('\n');
419 }
420 sb.format("[%d][%hs]", RecNumber, SQLState);
421 sb.append((const char*)ErrorMsg, (size_t)ErrorMsgLen);
422 }
424 ByteString s;
425#ifdef __WINNT__
426
427
428
429
430 try {
431 String ws = LocaleDecoder::decode(sb.toByteString());
432 s = UTF8Encoder::encode(ws);
433 #if __TRACE_THIS
434 if (_rc == SQL_SUCCESS_WITH_INFO) {
436 ws.replace(L"\n", L"\n ").data());
437 }
438 #endif
439 }
440 catch (CharsetConvertException* _e) {
441 __DCL_TRACE1(L
"Fatal!! [%ls]\n", _e->toString().data());
443 }
444#else
445 s = sb.toByteString();
446 #if __TRACE_THIS
447 if (_rc == SQL_SUCCESS_WITH_INFO) {
449 s.replace("\n", "\n ").data());
450 }
451 #endif
452#endif
453 __lastErrorMessage = s;
454#endif
455 }
456 else {
457 #define CASE_STR(rc) case rc: __lastErrorMessage = #rc; break;
458 switch (_rc) {
464 default:
466 __lastErrorMessage = ByteString::format("SQLRETURN[%d] mabe bug!!", _rc);
467 }
468 }
469}
#define __DCL_TRACE1(fmt, arg1)
__DCL_BEGIN_NAMESPACE struct __SQL_ERROR SQL_ERROR
_PROTECTED const wchar_t * _filename
_PROTECTED const wchar_t int _line