返回首页

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%-8s%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.

运行 CREATE SCHEMA 块之后,会将以下两行新信息添加到 systables 系统目录表中。
列名
第一行
第二行
tabname
customer
california
owner
maryl
maryl
partnum
16778361
0
tabid
101
102
rowsize
134
134
ncols
10
4
nindexes
2
0
nrows
0
0
created
01/26/2007
01/26/2007
version
1
0
tabtype
T
V
locklevel
P
B
npused
0
0
fextsize
16
0
nextsize
16
0
flags
0
0
site


dbname



对 systables 系统目录表中记录的每个表都指定一个 tabid(一个系统指定的顺序号,
它唯一地标识数据中的每个表)。
系统目录表接收 2 位的 tabid 号,
而用户创建的表接收
以 100 开头的顺序 tabid 号。

GBase 8s SQL 指南:参考
南大通用数据技术股份有限公司 - 10 -

数据加工用户:UserA,UserB;
查询用户:UserC,UserD,UserE;
其他用户按照数据加工用户方式处理。
资源分配需求:保障查询性能,控制加工消耗的性能。