返回首页

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

更新日期:2024年09月11日

rtypname() 函数返回包含指定的 SQL 数据类型的名称的以空终止的字符串。

语法
char *rtypname(sqltype)
mint sqltype;

sqltype
SQL 数据类型之一的整数代码。

rtypname() 函数将
(sqltypes.h 定义的)
GBase 8s SQL 数据类型的常量转换为字符串。

返回代码

GBase 8s ESQL/C 编程指南
南大通用数据技术股份有限公司
- 918 -
rtypname() 函数返回指向包含 sqltype 指定的数据类型的名称的字符串的指针。如果
sqltype 是无效的值,则 rtypname() 返回空字符串(" ")。

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

This program displays the name and the data type of each column in the 'orders' table.
*/

#include

EXEC SQL include sqltypes;

#define WARNNOTIFY 1
#define NOWARNNOTIFY 0

main(argc, argv)
int argc;
char *argv[];
{
mint i;
int4 err_chk();
char db_stmnt[50];
char *rtypname();
struct sqlda *sql_desc;
struct sqlvar_struct *col;

EXEC SQL BEGIN DECLARE SECTION;
char db_name[20];
EXEC SQL END DECLARE SECTION;


GBase 8s ESQL/C 编程指南
南大通用数据技术股份有限公司
- 919 -
printf("RTYPNAME 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");

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 orders';
/* prepare select */
if(exp_chk("Prepare", WARNNOTIFY) == 1)
exit(1);
/* initialize sqlda */
EXEC SQL describe query_1 into sql_desc;
if(exp_chk("Describe", WARNNOTIFY) == 1)
exit(1);
printf("\n\tColumn Name \t\tSQL type\n\n");

/*
* For each column in the orders table display the column name and the name
of the SQL data type
*/
for (i = 0, col = sql_desc->sqlvar; i < sql_desc->sqld; i++, col++)

GBase 8s ESQL/C 编程指南
南大通用数据技术股份有限公司
- 920 -
printf("\t%-15s\t\t%s\n",col->sqlname, rtypname(col->sqltype));

printf("\nRTYPNAME 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

输出

RTYPNAME Sample ESQL Program running.

Connected to stores7 database
Column Name SQL type

order_num serial
order_date date
customer_num integer
ship_instruct char
backlog char
po_num char
ship_date date
ship_weight decimal
ship_charge money
paid_date date

RTYPNAME Sample Program over.

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

rstoi() 函数将以空终止的字符串转换为 short integer 值。

语法

mint rstoi(string, ival)
char *string;
mint *ival;
string
指向以空终止的字符串的指针。
ival
指向保存转换了的值的 mint 值的指针。

用法
值的合法范围为 -32767 - 32767。值 -32768 不是有效的,因为此值为指示空的保留
值。

如果 string 对应于空整数,则 ival 指向 SMALLINT 空的表示。要转换对应于 long
integer 的字符串,请使用 rstol()。该操作的失败可导致错误的数据表示。

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


返回代码
=0
转换成功。
!=0
转换失败。

示例

此样例程序在 demo 目录中的 rstoi.ec 文件中。
/*
* rstoi.ec *
The following program tries to convert three strings to integers. It displays the result of
each conversion.
*/

#include

EXEC SQL include sqltypes;

main()
{
mint err;
mint i;
short s;

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

i = 0;
printf("Converting String 'abc':\n");
if((err = rstoi("abc", &i)) == 0)
printf("\tResult = %d\n\n", i);
else

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

printf("\tError %d in conversion of string #1\n\n", err);

i = 0;
printf("Converting String '32766':\n");
if((err = rstoi("32766", &i)) == 0)
printf("\tResult = %d\n\n", i);
else
printf("\tError %d in conversion of string #2\n\n", err);

i = 0;
printf("Converting String '':\n");
if((err = rstoi("", &i)) == 0)
{
s = i; /* assign to a SHORT variable */
if (risnull(CSHORTTYPE, (char *) &s))
/* and then test for NULL */
printf("\tResult = NULL\n\n");
else
printf("\tResult = %d\n\n", i);
}
else
printf("\tError %d in conversion of string #3\n\n", err);

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

Converting String 'abc':
Error -1213 in conversion of string #1

Converting String '32766':
Result = 32766

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


Converting String '':
Result = NULL

RSTOI Sample Program over.

目前版本支持自动重连功能,如果想关闭该功能可以通过以下设置关闭:
“窗口”“首选项”“数据库”选择“连接”设置界面,可以将自动重连
的选项前面的勾去掉后点击确定按钮即可。