返回首页

gbase数据、南大通用产品文档:GBase8sTEXT 和 CLOB 数据类型的代码集转换

更新日期:2024年09月11日

GBase 8s JDBC Driver 不会自动在 TEXT 、BYTE 、CLOB 和 BLOB 数据类型的代码集
之间进行转换。
可以使用以下方式在 TEXT 和 CLOB 数据类型的代码集之间进行转换:

可以通过使用 IFX_CODESETLOB 环境变量自动化客户端和数据库语言环境之间
的 TEXT 或 CLOB 数据的代码集转换。

可以使用 getBytes() 、
getString() 、
InputStreamReader() 和 OutputStreamWriter() 方法
在 TEXT 数据代码集之间进行转换。
使用 IFX_CODESETLOB 环境变量转换

GBase 8s JDBC Driver 程序员指南
南大通用数据技术股份有限公司
- 232
-
可以自动转换 TEXT 和 CLOB 数据类型的代码集对:

在将数据发送到数据库服务器之前从客户端语言环境转换到数据库语言环境。

在客户端检索数据之前,从数据库语言环境转换到客户端语言环境。
要自动化 TEXT 和 CLOB 数据类型的代码集之间的转换,请在连接 URL 中使
用 IFX_CODESETLOB 环境变量。例如:IFX_CODESETLOB = 4096。还可以使用以
下 IfxDataSource 类的方法来设置和获取 IFX_CODESETLOB 值:
public void setIfxIFX_CODESETLOB(int codesetlobFlag);
public int getIfxIFX_CODESETLOB();
IFX_CODESETLOB 可以具有以下值:
none
缺省值 不启用自动转换代码集。
0 在内部临时文件中发生自动转换代码集。
> 0 在客户端计算机的内存中发生自动转换代码集。该值指示分配给转换的字节数。

如果分配的字节数小于大对象的大小,则返回错误。
要在内存中执行转换,必须指定一个小于客户机的内存限制的量,并且大于任何已转换大
对象的可能大小。
当您使用以下 java.sql.Clob 接口方法或 Clob 接口的 GBase 8s 扩展中的任何一种时,即使
设置了 IFX_CODESETLOB 环境变量,也不会执行代码集转换。这些方法包括:
IfxCblob::setAsciiStream(long)
Clob::setAsciiStream(long position, InputStream fin, int length)
IFX_CODESETLOB 仅对来自 java.sql.PreparedStatement 接口的方法生效。
但是,在使用以下 java.sql.Clob 接口方法或 Clob 接口的 GBase 8s 扩展时,Unicode 字符
总是自动转换为数据库语言环境代码集。以下是这些方法的列表:
Clob::setCharacterStream(long) throws SQLException
Clob::setString(long, String) throws SQLException
Clob:: setString(long pos, String str, int offset, int len)
IfxCblob::setSubString(long position, String str, int length)
使用 JDK 方法转换
getBytes() 、getString() 、InputStreamReader() 和 OutputStreamWriter() 方法接受一个代码集
参数,该参数可以在 Unicode 与指定的代码集之间相互转换
以下样例代码显示了如何将客户端代码集中的文件转换为 Unicode,然后将其从 Unicode
转换为数据库代码集:
File infile = new File("data_jpn.dat");

GBase 8s JDBC Driver 程序员指南
南大通用数据技术股份有限公司
- 233
-
File outfile = new File ("data_conv.dat");..
.pstmt = conn.prepareStatement("insert into t_text values (?)");..
.// Convert data from client encoding to database encoding
System.out.println("Converting data ...\n");
try
{
String from = "SJIS";
String to = "8859_1";
convert(infile, outfile, from, to);
}
catch (Exception e)
{
System.out.println("Failed to convert file");
}

System.out.println("Inserting data ...\n");
try
{
int fileLength = (int) outfile.length();
fin = new FileInputStream(outfile);
pstmt.setAsciiStream(1 , fin, fileLength);
pstmt.executeUpdate();
}
catch (Exception e)
{
System.out.println("Failed to setAsciiStream");
}..
.public static void convert(File infile, File outfile, String from, String to)
throws IOException
{
InputStream in = new FileInputStream(infile);
OutputStream out = new FileOutputStream(outfile);

Reader r = new BufferedReader( new InputStreamReader( in, from));
Writer w = new BufferedWriter( new OutputStreamWriter( out, to));


GBase 8s JDBC Driver 程序员指南
南大通用数据技术股份有限公司
- 234
-
//Copy characters from input to output. The InputStreamReader
converts
// from the input encoding to Unicode, and the OutputStreamWriter
// converts from Unicode to the output encoding. Characters that can
// not be represented in the output encoding are output as '?'

char[] buffer = new char[4096];
int len;
while ((len = r.read(buffer)) != -1)
w.write(buffer, 0, len);
r.close();
w.flush();
w.close();
}
当从数据库检索数据时,
可以使用相同的方法将数据从数据库代码集转换为客户端代码集。

 摘要:
将完整的结果集检索到客户端。以便后续的gbase_stmt_fetch()调用能返
回缓冲数据。
 语法:
int gbase_stmt_store_result(GBASE_STMT *stmt);
 参数:
 返回值:
如果成功完成了对结果的缓冲处理,返回0。如果出现错误,返回非0 值。

 错误
CR_COMMANDS_OUT_OF_SYNC
以不恰当的顺序执行了命令。
CR_OUT_OF_MEMORY


内存溢出。
CR_SERVER_GONE_ERROR

GBase 服务器不可用。
CR_SERVER_LOST


在查询过程中,与服务器的连接丢失。
CR_UNKNOWN_ERROR


出现未知错误。


GBase 8a 程序员手册C API 篇


- 70 -

南大通用数据技术股份有限公司
5 GBase C API 应用示例

PG_STATIO_USER_INDEXES 视图显示命名空间中所有用户关系表索引的IO 状态信息。
名称
类型
描述
relid
oid
索引的表的OID。
indexrelid
oid
该索引的OID。
schemaname
name
该索引的模式名。
relname
name
该索引的表名。
indexrelname
name
索引名称。
idx_blks_read
bigint
从索引中读取的磁盘块数。
idx_blks_hit
bigint
索引命中缓存数。