The rtypname() function
The rtypname() function returns a null-terminated string that contains the name of the specified SQL data type.
Syntax
char *rtypname(sqltype)
mint sqltype;
- sqltype
- An integer code for one of the SQL data types. For more information, see Data type constants
The rtypname() function converts a constant for the HCL OneDB™ SQL data type (which sqltypes.h defines) to a character string.
Return codes
The rtypname() function returns a pointer to a string that contains the name of the data type specified sqltype. If sqltype is an invalid value, rtypname() returns a null string (" ").
Example
This sample program is in the rtypname.ec file
in the demo directory.
/*
* rtypname.ec *
This program displays the name and the data type of each column
in the 'orders' table.
*/
#include <stdio.h>
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;
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);
EXEC SQL describe query_1 into sql_desc; /* initialize sqlda */
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++)
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
For a complete listing of the exp_chk() function, see Guide to the exp_chk.ec file or see the exp_chk.ec file for a listing of this exception-handling function.
Output
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.