返回首页

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 -

取值:[0|1]
默认值:0
说明:根据vcid 判断该vc 下是否有event,没有的话函数返回,不再根据其他信息
详细查询。取值范围[0,1],默认值0,0---关闭1--启用。
修改方式:可使用set 语句修改值也可在配置文件中修改值。适用于global 范围。


GBase JDBC 8.3.81.x
版本之前使用使用SELECT
别名的情况,
ResultSetMetaData.getColumnName()返回的是列的别名。