RWWString
Class RWWString from the Essential Tools Module is used for wide character strings in SourcePro DB. While RWWString can hold values from any wide character set, your operating system determines significantly how the values are interpreted. If an instance of this class is used for print or screen output, the output device must understand the character set. For more details on RWWString, please see the SourcePro API Reference Guide.
NOTE: You are encouraged to use RWBasicUString rather than RWWString for handling Unicode data. Platform-dependent definitions of the wide character type will decrease the portability of your applications.
Note that wide character strings are rarely serialized; multibyte strings are used for serialization. To send a wide character string to a database, it must be translated into multibyte form. The operating system provides calls that translate a wide string into a multibyte string. The DB Interface Module automatically employs the translation system calls to send a wide string to a server. This applies only when serializing literal values and does not apply to bound data.
Class RWWString may be used both for sending data to a database client and for receiving the data that is fetched. When using a wide string with an RWDBInserter, the destination column must be able to handle characters from a national character set. Usually this would be NCHAR or NVARCHAR, but for some databases it could be other CHAR or VARCHAR variants. Similarly, when an RWWString is used in an expression with class RWDBExpr, it should be used where a national string makes sense semantically.
The following example demonstrates the use of RWWString with both RWDBInserter and RWDBSelector. Assume that the table, t1, consists of one column of type NVARCHAR.
NOTE: Applications using RWWString are not portable. If a system defines a wchar_t as 4 bytes and a database client defines an NVARCHAR type as 2 bytes, the database client may reject the wchar_t as invalid input and give a binding or type conversion error.
void
showSQLUsingWideStrings RWDBDatabase& aDB)
{
RWWString wstring("\346\202\250\345\245\275",
RWWString::multiByte);
 
RWDBTable t1 = aDB.table("t1");
RWDBInserter ins = t1.inserter();
ins << wstring;
cout << ins.asString(true) << endl;
 
RWDBSelector sel = aDB.selector();
sel << t1;
sel.where (t1["a"] == wstring);
cout << sel.asString(true) << endl;
}
The output of this demonstration routine is two SQL statements. They represent a SELECT statement and an INSERT statement of the form:
INSERT INTO t1 VALUES (‘’)
SELECT * FROM t1 WHERE t1.a = ‘
In both cases, the actual strings reflect the dialect of SQL understood by the server, which is represented by aDB. When sending a literal value, the quoting technique required by that server for multibyte strings is placed around the multibyte string.
The use of RWWStrings with cursors is a little more restrictive. The originating column must be of a type appropriate for national character strings. The NCHAR and NVARCHAR data types are always acceptable; however, for many databases CHAR and VARCHAR variants also work. The next example demonstrates how to use an RWWString to fetch data from a database with an RWDBCursor and RWDBReader:
 
void
getWideStrings(RWDBDatabase& aDB)
{
RWDBTable t1 = aDB.table("t1");
 
RWWString wstring;
 
{
cout << "t1 using a cursor" << endl;
RWDBCursor cur = t1.cursor();
cur << &wstring;
while (cur.fetchRow().isValid())
cout << wstring << endl;
}
 
{
cout << "t1 using a reader" << endl;
RWDBReader rdr = t1.reader();
while (rdr()) {
rdr >> wstring;
cout << wstring << endl;
}
}
}
If the display device used understands the character sets involved and the table t1 contains the single row of our Chinese hello example, the output of this sample program should look something like this:
t1 using a cursor
t1 using a reader
Finally, RWWString can be used with RWDBStoredProc the same way as with other data types. You should check your Access Module Guide to see if there are any specific restrictions that apply to your database.