Date: Wednesday, January 11, 2006 @ 17:11:08
Author: marc
Path: /cvsroot/carob/odbsequoia/src
Modified: util.cpp (1.1 -> 1.2) util.hpp (1.1 -> 1.2)
Added toSQLW() std::wstring -> SQLWCHAR * conversion functions.
----------+
util.cpp | 45 ++++++++++++++++++++++++++++++++++++++++++++-
util.hpp | 15 +++++++++++++++
2 files changed, 59 insertions(+), 1 deletion(-)
Index: odbsequoia/src/util.cpp
diff -u odbsequoia/src/util.cpp:1.1 odbsequoia/src/util.cpp:1.2
--- odbsequoia/src/util.cpp:1.1 Thu Jan 5 21:34:11 2006
+++ odbsequoia/src/util.cpp Wed Jan 11 17:11:08 2006
@@ -53,7 +53,7 @@
#else // sizeof(SQLWCHAR) != sizeof(wchar_t)
if (isNTS)
- inLen = sqlwcstrlen(in);
+ inLen = sqlwcstrlen(in); // TODO: we could walk the string only once
wchar_t *res = new wchar_t[inLen];
for (int i=0; i<inLen ; i++)
res[i] = in[i]; // FIXME: this is poor man's UCS-4/UTF-16 converter
indeed!
@@ -67,6 +67,49 @@
}
+bool
+toSQLW(const std::wstring& in,
+ SQLWCHAR * const outbuf, const SQLSMALLINT bufsize, SQLSMALLINT *
outsize)
+{
+ SQLLEN biggeroutsize;
+
+ bool truncated = toSQLW(in, outbuf, bufsize, &biggeroutsize);
+ *outsize = biggeroutsize; // will not overflow since < SMALLINT bufsize
+ return truncated;
+}
+
+
+bool
+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!)
+
+#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;
+
+ std::wstring::const_iterator src = in.begin();
+ SQLWCHAR * dst = outbuf;
+
+ while (dst < outbuf_end && src != in.end())
+ {
+ *dst = *src; // FIXME: this is poor man's UCS-4/UTF-16 converter
indeed!
+ dst++; src++;
+ }
+
+ *dst = 0;
+ *outsize = dst - outbuf;
+
+ if (src != in.end())
+ return true;
+ else
+ return false;
+#endif // SQL_WCHART_CONVERT
+
+}
/*
* Local Variables:
Index: odbsequoia/src/util.hpp
diff -u odbsequoia/src/util.hpp:1.1 odbsequoia/src/util.hpp:1.2
--- odbsequoia/src/util.hpp:1.1 Thu Jan 5 21:34:11 2006
+++ odbsequoia/src/util.hpp Wed Jan 11 17:11:08 2006
@@ -20,6 +20,8 @@
*/
#include <sql.h>
+#include <sqlucode.h>
+
#include <string>
std::wstring
@@ -27,6 +29,19 @@
/*
+ * Converts wstring into a NTS SQLWCHAR array. Caller provides the
+ * buffer. Returns true if truncated. All sizes counted in SQLWCHAR
+ * (NOT in bytes!). SQL_NTS not accepted (yet?) as bufsize.
+ */
+bool
+toSQLW(const std::wstring& in,
+ SQLWCHAR * const outbuf, const SQLLEN bufsize, SQLLEN * outsize);
+/* Same thing but for kids */
+bool
+toSQLW(const std::wstring& in,
+ SQLWCHAR * const outbuf, const SQLSMALLINT bufsize, SQLSMALLINT *
outsize);
+
+/*
* Local Variables:
* c-file-style: "bsd"
* c-basic-offset: 4
_______________________________________________
Carob-commits mailing list
[email protected]
https://forge.continuent.org/mailman/listinfo/carob-commits