返回首页

gbase数据、南大通用产品文档:GBase8srtypmsize() 函数

更新日期:2024年09月11日

对于指定的 GBase 8s ESQL/C 或 SQL 数据类型,rtypmsize() 函数返回您必须在内
存中分配的字节数。

语法
mint rtypmsize(sqltype, sqllen)
mint sqltype;

GBase 8s ESQL/C 编程指南
南大通用数据技术股份有限公司
- 914 -

mint sqllen;
sqltype
GBase 8s ESQL/C 或 SQL 数据类型的整数代码。
sqllen
对于指定的数据类型,数据文件中的字节数。

用法
当您使用 sqlda 结构来动态地将数据访存至缓冲区时,rtypalign() 和 rtypmsize() 函
数是有用的。这些函数为列数据提供独立于机器的存储。

随同 DESCRIBE 语句初始化的 sqlda 结构,提供 rtypmsize() 函数来使用。在
DESCRIBE 语句确定列信息之后,sqltype 和 sqllen 组件的值在每一 sqlda.sqlvar 结构中
同名的组件中。

当 rtypmsize() 确定字符数据的大小时,请记住下列大小信息:
对于 CCHARTYPE(char)和 CSTRINGTYPE(string), GBase 8s ESQL/C 为空
终止符将字符的数目加一个字节。
对于 CFIXCHARTYPE(fixchar),GBase 8s ESQL/C 不添加空终止符。

在 unload.ec 演示程序中,您可看到 rtypmsize() 函数的应用。

返回代码
0
sqltype 不是有效的 SQL 类型。
>0
返回值是 sqltype 数据类型要求的字节数。

示例
此样例程序在 demo 目录中的 rtypmsize.ec 文件中。
/*
* rtypmsize.ec *

This program prepares a select statement on all columns of the catalog table. Then it

GBase 8s ESQL/C 编程指南
南大通用数据技术股份有限公司
- 915 -

displays the data type of each column and the number of bytes needed to store it in memory.
*/

#include

EXEC SQL include sqltypes;

#define WARNNOTIFY 1
#define NOWARNNOTIFY 0

EXEC SQL BEGIN DECLARE SECTION;
char db_name[20];
EXEC SQL END DECLARE SECTION;

main(argc, argv)
int argc;
char *argv[];
{
mint i;
char db_stmnt[50];
int4 exp_chk();
struct sqlda *sql_desc;
struct sqlvar_struct *col;

printf("RTYPMSIZE Sample ESQL Program running.\n\n");

if (argc > 2) /* correct no. of args? */
{
printf("\nUsage: %s [database]\nIncorrect no. of argument(s)\n",
argv[0]);
exit(1);
}
strcpy(db_name, "stores7");

GBase 8s ESQL/C 编程指南
南大通用数据技术股份有限公司
- 916 -

if (argc == 2)
strcpy(db_name, argv[1]);

EXEC SQL connect to :db_name;
sprintf(db_stmnt, "CONNECT TO %s", argv[1]);
exp_chk(db_stmnt, NOWARNNOTIFY);

printf("Connected to '%s' database.", db_name);

EXEC SQL prepare query_1 from 'select * from catalog';
/* prepare select */
if(exp_chk("Prepare", WARNNOTIFY) == 1)
exit(1);
EXEC SQL describe query_1 into sql_desc;
/* setup sqlda */
if(exp_chk("Describe", WARNNOTIFY) == 1)
exit(1);
/* column hdgs. */
printf("\n\tColumn Type Size\n\n");
/*
* For each column in the catalog table display the column name and the number of bytes
needed to store the column in memory.
*/
for(i = 0, col = sql_desc->sqlvar; i < sql_desc->sqld; i++, col++)
printf("\t%-20s%-8t%3d\n",
col->sqlname, rtypname(col->sqltype),
rtypmsize(col->sqltype, col->sqllen));

printf("\nRTYPMSIZE Sample Program over.\n\n");
}

/*
* The exp_chk() file contains the exception handling functions to check the

GBase 8s ESQL/C 编程指南
南大通用数据技术股份有限公司
- 917 -

SQLSTATE status variable to see if an error has occurred following an SQL statement. If a
warning or an error has occurred, exp_chk() executes the GET DIAGNOSTICS statement and
prints the detail for each exception that is returned.
*/
EXEC SQL include exp_chk.ec

输出
RTYPMSIZE Sample ESQL Program running.

Connected to stores7 database.

Column Type Size
catalog_num serial 4
stock_num smallint s
manu_code char 4
cat_descr text 64
cat_picture byte 64
cat_advert varchar 256

RTYPMSIZE Sample Program over.

biginttoifx_int8() 函数将 BIGINT 类型数值转换为 int8 类型数值。
语法

void biginttoifx_int8(bigintv, int8p)
const bigint bigintv
ifx_int8_t *int8p
bigintv
要转换为 int8 的 bigint 值。
int8p
指向包含转换的结果的 int8 结构的指针。

使用字符集和Unicode
JDBC 驱动发送给服务器的所有字符串都自动地从本地的Java
Unicode 转换
到客户端的字符编码,包括所有通过Statement.execute() 、
Statement.executeUpdate() 、
Statement.executeQuery()发送的查询以及所
有PreparedStatement 和CallableStatement 参数,但使用setBytes() 、
setBinaryStream() 、setAsiiStream() 、setUnicodeStream() 和 setBlob()
的参数集不包含在内。

GBase 8a 程序员手册JDBC 篇
南大通用数据技术股份有限公司

- 29 -
GBase 8a 使用JDBC 的ResultSets 在客户端与服务器之间传输数据支持单
一编码形式以及任意数目的编码形式。
在连接时会自动地检测客户端与服务器之间的字符编码。通过配置变量,
驱动使用的编码指定在服务器上,这个变量在GBase 8a server 中是
“character_set_server ”
。如果不想客户端自动识别编码,可以在用来连接
服务器的URL 中使用characterEncoding 属性,使用该属性的同时必须使用设
置“useUnicode”的值为true。
当在客户端指定字符编码时,
应该使用Java-style 名字。
下表列出了对于
GBase 字符集的Java-style 名字:
GBase Server 字符集名
Java 字符集名称
gbk
GBK
utf8
UTF-8
警告:在GBase JDBC 中,不要执行“set names”来设置字符集,因为驱
动不会发现字符集已经改变,而是会继续使用在初始化连接设置时使用的字符
集。
为了允许从客户端发来的各种字符集,应当使用“UTF-8”编码,或者把
“UTF-8”配置成缺省的服务器字符集,或者通过characterEncoding 属性配置
JDBC 驱动使用“UTF-8”


GBase 8a 程序员手册JDBC 篇


- 30 -

南大通用数据技术股份有限公司
3 GBase JDBC 高可用特性
GBase JDBC 高可用特性是针对GBase 数据库集群提供客户端高可用及负载
均衡相关功能功能。