返回首页

gbase数据、南大通用产品文档:GBase8a使用jdbc 获取HH:MM:SSxxxxxx 格式的时间

更新日期:2024年09月11日

Jdbc 规范对与Time 类型的定义并没有处理微妙的部分,当实际情况真的需要处理
如下类似语句时time(now() + interval 1 microsecond) 结果集的getTime 方法是报格
式错误的,针对此做了一个增强,通过getTime 方法可以获取HH:MM:SS 的time
类型,如果确实需要获取完整值,可以通过getObject 获取,然后转成String 型。

10:26.25 TrackStmtWo+
5145 gbase
20
0 7600388

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.