无法使用c++将128以上的ascii字符插入到oracle数据库中程序
我正在尝试使用 C++ 程序插入高于 ascii 范围 128 的字符(字符为 Ø、Å)。对于小于 128 的 ascii 字符,它工作正常
数据库中使用的数据类型是 VARCHAR2
这些字符作为问号 (????) 插入到 DB 如果我通过 Toad 在数据库中设置带有这些字符的字段值,并尝试使用应用程序读取它们,它们会被读取为问号(???)
有人能给我一个示例代码,说明如何插入包含这些字符的字符串(ascii 值) 128 以上)。
我认为数据类型转换有问题。 (因为在插入到数据库之前的应用程序级别,这些字符显示正确。另外,如果我通过 Toad 设置字段值并从数据库读取,它们将被读取为问号。我可以在数据库中设置字段值意味着数据库列可以保存这些字符)
我'我在我的应用程序中使用以下定义和绑定方法
OCIDefineByPos(p_sql, &p_dfn, p_DBCon->p_err, iPos, (dvoid*)p->un_DataArray.pzValue, (sword)iSize, SQLT_STR, (dvoid*)p->un_FlagArray.pssValue, 0, 0, OCI_默认);
OCIBindByName(p_sql, &p_bnd, p_DBCon->p_err, (text *) zName, -1, (dvoid *) zValue, iSize, SQLT_STR, 0, 0, 0, 0, 0, OCI_DEFAULT);
有人可以帮助我吗 或者如果您有一些可以插入最多 256 个 ASCII 值的示例程序,请与我分享
I'm trying to insert characters above ascii range 128 using a C++ program(characters are Ø, Å). It's working fine for ascii characters less than 128
Data type used in database is VARCHAR2
Those characters are inserted as question marks (????) to DB
If I set field value in DB with those characters through Toad and try to read using application they were read as question marks(????)
Can someone please give me an example code to how to insert strings which contains those characters(ascii value above 128).
I think problem with data type conversion. (Because in application level before insert to DB those characters display correctly.Also If I set field value through Toad and read from DB they are read as Question Marks. I can set field value in DB means DB column can hold those characters)
I'm using following to Define and Bind methods in my application
OCIDefineByPos(p_sql, &p_dfn, p_DBCon->p_err, iPos,
(dvoid*)p->un_DataArray.pzValue, (sword)iSize, SQLT_STR, (dvoid*)p->un_FlagArray.pssValue, 0, 0,
OCI_DEFAULT);
OCIBindByName(p_sql, &p_bnd, p_DBCon->p_err, (text *) zName,
-1, (dvoid *) zValue, iSize, SQLT_STR, 0, 0, 0, 0, 0, OCI_DEFAULT);
Can someone help me
Or If you have some sample program that can insert ascii values up to 256 please share it with me
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
WE8MSWIN1252 对应于“MS Windows 代码页 1252 8 位西欧”。
在将字符串插入数据库之前,您必须将它们转换为 Windows 代码页 1252。
例如,在 Windows 上,如果您的字符串采用 utf8 格式,则使用 MultiByteToWideChar 将它们转换为 utf16,然后使用 WideCharToMultiByte 将其转换回 CodePage1252
WE8MSWIN1252 correspond to "MS Windows Code Page 1252 8-bit West European".
You have to convert your strings to the Windows Code Page 1252 before inserting them in the db.
For instance, on Windows, if your strings are in utf8 then convert them to utf16 with MultiByteToWideChar and then back to CodePage1252 using WideCharToMultiByte
这可能是因为,没有 128 以上的 ASCII 字符。ASCII 是 7 位编码。
为了添加非 ascii 字符(ASCII 中没有 Ø、Å),您需要使用不同的编码来放入它们。现在大多数正常的应用程序都使用 utf8。
This may be because, there ARE no ascii characters above 128. ASCII is a 7-bit encoding.
In order to add non-ascii characters (there are no Ø, Å in ASCII), you'll need to use a different encoding to put them in. Most sane applications nowadays use utf8.