返回首页

gbase数据、南大通用产品文档:GBase8s关于本出版物

更新日期:2024年09月11日

本出版物描述了有关配置、管理和使用 GBase 8s 的概念与过程。

rsetnull() 函数将 C 变量设置为对应于数据库空值的值。

语法
mint rsetnull(type, ptrvar)
mint type;

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

char *ptrvar;
type
对应于 C 或 GBase 8s ESQL/C 变量的数据类型的 mint。此 type 可为除
了 var binary 或 lvarchar 指针变量之外的任何数据类型。
ptrvar
指向 C 或 GBase 8s ESQL/C 变量的指针。

用法

rsetnull() 函数将除了 var
binary 和 lvarchar 指针主变量之外的任何
数据类型的 GBase
8s
ESQL/C 变量设置为空。
要将 var
binary 或 lvarchar 指
针主变量设置为空,请使用 ifx_var_setnull() 宏。

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

This program fetches rows from the stock table for a chosen manufacturer and allows the
user to set the unit_price to NULL.
*/

#include
#include
EXEC SQL include decimal;
EXEC SQL include sqltypes;

#define WARNNOTIFY 1
#define NOWARNNOTIFY 0

#define LCASE(c) (isupper(c) ? tolower(c) : (c))

char format[] = "($$,$$$,$$$.&&)";

main()

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

{
char decdsply[20];
char ans;
int4 ret, exp_chk();

EXEC SQL BEGIN DECLARE SECTION;
short stock_num;
char description[16];
dec_t unit_price;
char manu_code[4];
EXEC SQL END DECLARE SECTION;

printf("RSETNULL Sample ESQL Program running.\n\n");
EXEC SQL connect to 'stores7'; /* connect to stores7 */
exp_chk("Connect to stores7", NOWARNNOTIFY);

printf("This program selects all rows for a given manufacturer\n");
printf("from the stock table and allows you to set the unit_price\n");
printf("\nTo begin, enter a manufacturer code - for example: 'HSK'\n");
printf("\nEnter Manufacturer code: ");
/* prompt for mfr. code */
gets(manu_code); /* get mfr. code */
EXEC SQL declare upcurs cursor for /* declare cursor */
select stock_num, description, unit_price from stock
where manu_code = :manu_code
for update of unit_price;
rupshift(manu_code); /* Make mfr code upper case */
EXEC SQL open upcurs; /* open select cursor */
if(exp_chk("Open cursor", WARNNOTIFY) == 1)
exit(1);

/*
* Display Column Headings

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

*/
printf("\nStock # \tDescription \t\tUnit Price");
while(1)
{
/* get a row */
EXEC SQL fetch upcurs into :stock_num, :description, :unit_price;
if ((ret = exp_chk("fetch", WARNNOTIFY)) == 100)
/* if end of rows */
break;
if(ret == 1)
exit(1);
if(risnull(CDECIMALTYPE, (char *) &unit_price))
/* unit_price NULL? */
continue; /* skip to next row */
rfmtdec(&unit_price, format, decdsply);
/* format unit_price */
/* display item */
printf("\n\t%d\t%15s\t%s", stock_num, description, decdsply);
ans = ' ';
/* Set unit_price to NULL? y(es) or n(o) */
while((ans = LCASE(ans)) != 'y' && ans != 'n')
{
printf("\n. . . Set unit_price to NULL ? (y/n) ");
scanf("%1s", &ans);
}
if (ans == 'y') /* if yes, NULL to unit_price */
{
rsetnull(CDECIMALTYPE, (char *) &unit_price);
EXEC SQL update stock set unit_price = :unit_price
where current of upcurs; /* and update current row */
if(exp_chk("UPDATE", WARNNOTIFY) == 1)
exit(1);
}

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

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

/*
* The exp_chk() file contains the exception handling functions to check the
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

输出
RSETNULL Sample ESQL Program running.

This program selects all rows for a given manufacturer
from the stock table and allows you to set the unit_price
to NULL.

To begin, enter a manufacturer code - for example: 'HSK'

Enter Manufacturer code: HSK

Stock # Description Unit Price
1 baseball gloves $800.00
. . . Set unit_price to NULL ? (y/n) n

3 baseball bat $240.00
. . . Set unit_price to NULL ? (y/n) y

4 football $960.00
. . . Set unit_price to NULL ? (y/n) n

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


110 helmet $600.00
. . . Set unit_price to NULL ? (y/n) y

RSETNULL Sample Program over.

SQLExtendedFetch 扩展 SQLFetch 的功能。
SQLExtendedFetch 通过以下方式扩展功能:

GBase 8s ODBC Driver 程序员指南
南大通用数据技术股份有限公司
- 223 -

l 为每个绑定列返回数组形式的行集数据(一行或多行)。
l 根据滚动类型参数的设置滚动结果。
SQLExtendedFetch 与 SQLSetStmtOption 一起使用。
要一次向前获取一行数据,应用程序会调用 SQLFetch。
下表描述了 SQLExtendedFetch 的 SQLSTATE 和错误值。
SQLSTATE
错误值
错误消息
01000
-11001
General warning
01004
-11003
Data truncated
01S01
-11006
Error in row
07006
-11013
Restricted data type attribute violation
08S01
-11020
Communication-link failure
22002
-11024
Indicator value required but not supplied
22003
-11025
Numeric value out of range
22005
-11026
Error in assignment
22008
-11027
Datetime field overflow
22012
-11028
Division by zero
24000
-11031
Invalid cursor state
40001
-11037
Serialization failure
S1000
-11060
General error
S1001
-11061
Memory-allocation failure
S1002
-11062
Invalid column number
S1008
-11065
Operation canceled
S1010
-11067
Function-sequence error
S1106
-11086
Fetch type out of range
S1107
-11087
Row value out of range
S1C00
-11092
Driver not capable
S1T00
-11094
Time-out expired
08S01
-11301
A protocol error has been detected. Current connection is
closed.
S1000
-11307
In SQLExtendedFetch, only SQL_FETCH_NEXT is
supported for SQL_SCROLL_Forward_only cursors

如果发生与整个行集相关的错误,例如 SQLSTATE S1T00 (超时),则驱动程序返回
SQL_ERROR 和适当的 SQLSTATE。行集缓冲区的的内容未定义,游标位置不变。

GBase 8s ODBC Driver 程序员指南
南大通用数据技术股份有限公司
- 224 -

如果发生与单个行相关的错误,则驱动程序执行以下操作:
l
将行 rgfRowStatus 数组中的元素设置为 SQL_ROW_ERROR
l
在错误队列中发布 SQLSTATE 01S01(行中的错误)
l
在错误队列中的 SQLSTATE 01S01(行中的错误)之后,发布零个或多个附加的
SQLSTATE 值
驱动程序处理错误或警告之后,它继续行集中剩余的操作,并返回
SQL_SUCCESS_WITH_INFO。因此,对于与单个行相关的每个错误,错误队列包含
SQLSTATE 01S01(行中的错误),后跟零个或多个附加的 SQLSTATE 值。
驱动程序处理该错误之后,
它访存行集中的剩余的行,
并返回 SQL_SUCCESS_WITH_INFO。
因此,对于返回错误的每一行,错误队列包含 SQLSTATE 01S01(行中的错误),后跟零
个或多个附加的 SQLSTATE 值。
如果行集包含已经访存的行,则当首次访存行时,驱动程序不需要返回错误的 SQLSTATE
值。但是,对于最初返回错误的每一行,它需要返回 SQLSTATE 01S01(行中的错误),
和 SQL_SUCCESS_WITH_INFO。例如,维护高速缓存的静态游标可能会缓存行状态信息
(因此,它可以确定哪一行包含错误),但是不能缓存与错误相关的 SQLSTATE。
错误行不会影响相关游标的移动。例如,假定结果集大小为 100,行集大小为 10。如果当
前行集是从 11 到 20 的行,并且 11 行的 rgfRowStatus 数组中的元素是
SQL_ROW_ERROR,则使用 SQL_FETCH_NEXT 访存类型调用 SQLExtendedFetch 仍然
返回 21 到 30 行。
如果驱动程序返回任何警告,例如 SQLSTATE 01004(数据截断),则在返回适用于整个
行或行集中位置行的警告,然后返回特定行的错误信息。它返回关于这些行的任何其它错
误信息的特定行的警告。