Date: Thursday, January 19, 2006 @ 18:34:08
Author: marc
Path: /cvsroot/carob/odbsequoia/src
Modified: util.cpp (1.2 -> 1.3)
Replaced non-portable #ifdef SQL_WCHART_CONVERT conditional compilation by
a real C++ check: "if (sizeof(SQLWCHAR) == sizeof(wchar_t)"
----------+
util.cpp | 38 +++++++++++++++++++++++++-------------
1 files changed, 25 insertions(+), 13 deletions(-)
Index: odbsequoia/src/util.cpp
diff -u odbsequoia/src/util.cpp:1.2 odbsequoia/src/util.cpp:1.3
--- odbsequoia/src/util.cpp:1.2 Wed Jan 11 17:11:08 2006
+++ odbsequoia/src/util.cpp Thu Jan 19 18:34:08 2006
@@ -39,18 +39,25 @@
{
bool isNTS = (SQL_NTS == inLen);
-// this macro belongs to unixodbc. TODO: check about iodbc, windows etc.
-// also check for __STDC_ISO_10646__
-#ifdef SQL_WCHART_CONVERT
-#warning SQLWCHAR == wchar_t: optimized but untested code!
+ if (sizeof(wchar_t) == sizeof(SQLWCHAR)) // compiler should optimize this
away
+ {
+ // - we can have sizeof = 4, like for instance when:
+ // SQL_WCHART_CONVERT (from unixodbc) + __STDC_ISO_10646__
+ // - or we can have sizeof = 2, for instance on Windows
+
+ // #warning SQLWCHAR == wchar_t: optimized but untested code!
std::wstring objres;
if (isNTS)
- objres = std::wstring(in);
+ objres = std::wstring((const wchar_t *)in);
else
- objres = std::wstring(in, inLen);
+ objres = std::wstring((const wchar_t *)in, inLen);
+
+ return objres;
-#else // sizeof(SQLWCHAR) != sizeof(wchar_t)
+ } else {
+ // here we assume:
+ // 2 == sizeof(SQLWCHAR) < 4 == sizeof(wchar_t)
if (isNTS)
inLen = sqlwcstrlen(in); // TODO: we could walk the string only once
@@ -61,9 +68,10 @@
std::wstring objres(res, inLen);
delete[] res;
-#endif
-
return objres;
+
+ }
+
}
@@ -83,10 +91,14 @@
toSQLW(const std::wstring& in,
SQLWCHAR * const outbuf, const SQLLEN bufsize, SQLLEN * outsize)
{
-#ifdef SQL_WCHART_CONVERT
-#error TODO not implemented yet (SQLWCHAR == wchar_t: optimized but untested
code!)
+
+ // See explanations in fromSQLW(...) above
+ if (sizeof(wchar_t) == sizeof(SQLWCHAR))
+ {
+ exit(432); // TODO not implemented yet
+
+ } else {
-#else
// minus one for the trailing zero. We want enough room for a
// SQLWCHAR zero, not just for a byte zero.
SQLWCHAR * const outbuf_end = outbuf + bufsize - 1;
@@ -107,8 +119,8 @@
return true;
else
return false;
-#endif // SQL_WCHART_CONVERT
+ }
}
/*
_______________________________________________
Carob-commits mailing list
[email protected]
https://forge.continuent.org/mailman/listinfo/carob-commits