返回首页

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

更新日期:2024年09月11日

rfmtlong() 函数使用格式化掩码来将 C long 值转换为字符串。

语法
mint rfmtlong(lng_val, fmtstring, outbuf)
int4 lng_val;
char *fmtstring;
char *outbuf;
lng_val
rfmtlong() 将其转换为字符值的 int4 整数。
fmtstring
指向包含 lng_val 中的值的格式化掩码的字符缓冲区的指针。
outbuf
指向接收 lng_val 中的值的格式化的字符串的字符缓冲区的指针。

用法
rfmtlong() 函数的 fmtstring 参数指向数值的格式化掩码,其包含描述
如何格式化 long integer 值的字符。

当您使用 rfmtlong() 来格式化 MONEY 值时,该函数使用 DBMONEY 环境变量指
定的货币符号。如果您未设置此环境变量,则 rfmtlong() 使用客户机语言环境定义的货币
符号。缺省的语言环境 US English 定义货币符号如同您将 DBMONEY 设置为 “$,.” 一
样。

当您使用有多字节字符集的非缺省的语言环境时,rfmtlong() 支持格式字符串中的多
字节字符。

返回代码

GBase 8s ESQL/C 编程指南
南大通用数据技术股份有限公司
- 875 -
0
转换成功。
-1211
程序用尽内存(内存分配错误)。
-1217
格式字符串太大。

示例
demo 目录在文件 rfmtlong.ec 中包含此样例程序。
/*
* rfmtlong.ec *
The following program applies a series of format specifications to a series of longs and
displays the result of each format.
*/

#include

long lngs[] =
{
21020304,
334899312,
-334899312,
-12344455,
0
};

char *formats[] =
{
"################",
"$$$$$$$$$$$$$.##",
"(&,&&&,&&&,&&&.)",
"<<<<,<<<,<<<,<<<",
"$************.**",

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

char result[41];

main()
{
mint x;
mint s = 0, f;

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

while(lngs[s]) /* for each long in lngs[] */
{
printf("Long Number = %d\n", lngs[s]);
f = 0;
while(formats[f]) /* format with each of formats[] */
{
if (x = rfmtlong(lngs[s], formats[f], result))
{
printf("Error %d in formatting %d using %s.\n",
x, lngs[s], formats[f]);
break;
}
/*
* Display result and bump to next format (f++)
*/
result[40] = '\0';
printf(" Format String = '%s'\t", formats[f++]);
printf("\tResult = '%s'\n", result);
}
++s; /* bump to next long */
printf("\n"); /* separate display groups */

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

printf("\nRFMTLONG Sample Program over.\n\n");
}
输出
RFMTLONG ESQL Sample Program running.

Long Number = 21020304
Format String = '################'
Result = ' 21020304'
Format String = '$$$$$$$$$$$$$.##'
Result = ' $21020304.00'
Format String = '(&,&&&,&&&,&&&.)'
Result = ' 00021,020,304. '
Format String = '<<<<,<<<,<<<,<<<'
Result = '21,020,304'
Format String = '$************.**'
Result = '$****21020304.00'

Long Number = 334899312
Format String = '################'
Result = ' 334899312'
Format String = '$$$$$$$$$$$$$.##'
Result = ' $334899312.00'
Format String = '(&,&&&,&&&,&&&.)'
Result = ' 00334,899,312. '
Format String = '<<<<,<<<,<<<,<<<'
Result = '334,899,312'
Format String = '$************.**'
Result = '$***334899312.00'

Long Number = -334899312
Format String = '################'

GBase 8s ESQL/C 编程指南
南大通用数据技术股份有限公司
- 878 -
Result = ' 334899312'
Format String = '$$$$$$$$$$$$$.##'
Result = ' $334899312.00'
Format String = '(&,&&&,&&&,&&&.)'
Result = '(00334,899,312.)'
Format String = '<<<<,<<<,<<<,<<<'
Result = '334,899,312'
Format String = '$************.**'
Result = '$***334899312.00'

Long Number = -12344455
Format String = '################'
Result = ' 12344455'
Format String = '$$$$$$$$$$$$$.##'
Result = ' $12344455.00'
Format String = '(&,&&&,&&&,&&&.)'
Result = '(00012,344,455.)'
Format String = '<<<<,<<<,<<<,<<<'
Result = '12,344,455'
Format String = '$************.**'
Result = ' $****12344455.00'

RFMTLONG Sample Program over.

............................
- 170 -

可以使用 ondblog 或 ontape 来添加或更改日志记录。然后使用 ON-Bar 或 ontape 来备
份数据。在使用 ON-Bar 或 ontape 时,数据库服务器必须处于联机、管理或静默方式。
可以使用 ondblog、ontape 或 Server Administrator (ISA) 来添加或更改日志记录。然后使
用 ON-Bar 或 ontape 来备份数据。在使用 ON-Bar 或 ontape 时,数据库服务器必须处
于联机、管理或静默方式。
有关 ON-Bar 和 ontape 的信息,请参阅《GBase 8s 备份与复原指南》。
下表显示数据库服务器管理员能如何更改数据库记录方式。某些日志记录方式更改是立即
发生的,而另外一些更改需要 0 级备份。
表 1. 日志记录方式转换
转换源:
转换为无日志记

转换为未缓冲日
志记录
转换为已缓冲日
志记录
转换为符合
ANSI 标准
无日志记录
不适用
(受影响存储空
间的)0 级备份
(受影响存储空
间的)0 级备份
(受影响存储空
间的)0 级备份
未缓冲日志
记录

不适用


缓冲的日志
记录


不适用

符合 ANSI
标准
非法
非法
非法
不适用
更改数据库日志记录方式有以下影响:

GBase 8s 管理员指南
南大通用数据技术股份有限公司
- 276 -
• 数据库服务器在更改日志记录状态时对数据库加上互斥锁定以防止其他用户访问
该数据库,而当更改完成时释放该锁定。
• 如果在日志记录方式更改期间发生故障,那么在复原数据库服务器数据后,请检
查 sysmaster 数据库的 sysdatabases 表内标志中的日志记录方式。有关更多信
息,请参阅监视数据库的日志记录方式。然后重试更改日志记录方式。
• 如果在日志记录方式更改期间发生故障,那么在复原数据库服务器数据后,请检
查 ISA 中的日志记录方式或 sysmaster 数据库中 sysdatabases 表中的标志。有
关更多信息,请参阅监视数据库的日志记录方式。然后重试更改日志记录方式。
• 在选择了已缓冲或未缓冲日志记录之后,应用程序就可以使用 SQL 语句 SET
LOG 从一种日志记录方式更改为另一种日志记录方式。此更改在会话期间会一直
持续。有关 SET LOG 的信息,请参阅 GBase 8s SQL 指南:语法。
• 如果您向数据库添加日志记录,那么直至数据库的所有存储空间的下一次 0 级备
份才完成该更改。