返回首页

gbase数据、南大通用产品文档:GBase8s

更新日期:2024年09月11日

No serial, rowid, or primary key specified in the statement
可更新可滚动功能仅适用于在查询中指定了具有 SERIAL 列、主键或行 ID 的表。如果表
没有这些属性,则会创建一个可更新的可滚动的游标。

对于指定的 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.

GBase 8s ODBC Driver 提供可用于修改行和集合的函数。
下表提供了 GBase 8s ODBC Driver提供的用于修改行和集合的函数的概述。
函数
修改

集合
ifx_rc_delete()
删除元素


ifx_rc_insert()
插入元素

是(参阅下表。)
ifx_rc_setnull()
将行或集合设置为空


ifx_rc_update()
更改元素的值


下表描述了您可以插入元素的集合的位置。
只能在 SET 或 MULTISET 集合的末尾插入元
素,因为这些类型的集合中的元素的位置没有顺序。

开始
中间
末尾
List



Multiset 否


Set



提示: 如果您只需要插入或更新具有文字值的的行或集合,则不需要使用行或集合缓冲区。相反,您可
以在 INSERT 语句的 INTO 子句或 UPDATE 语句的 SET 子句中显式列出文字值。
每一行和集合都维护一个指向行或集合中的当前元素的查找位置。创建行或集合时,该查
找位置指向行或集合中的第一个元素。所有对客户端函数的调用都共享同一个行或集合缓
冲区的查找位置。
因此,
一个客户端函数会影响另一个使用相同缓冲区句柄的客户端函数。
下表描述了客户端函数如何更改查找位置。

GBase 8s ODBC Driver 程序员指南
南大通用数据技术股份有限公司
- 157 -
客户端函数
作用于
变更
ifx_rc_delete()
指定的位置。
将查找位置设置为删除后的位置。
ifx_rc_fetch()
指定的位置。
将查找位置设置到指定的位置。
ifx_rc_insert()
指定位置之前。
将查找位置设置到指定的位置。
ifx_rc_update()
指定的位置。
将查找位置设置到指定的位置。