返回首页

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

更新日期:2024年09月11日

stchar() 函数在定长的字符串中存储以空终止的字符串,如果有必要,则以空格填充
末尾。

语法

void stchar(from, to, count)
char *from;
char *to;
mint count;
from
指向以空终止的源字符串的第一个字节的指针。

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

to
指向定长目标字符串的指针。此参数可指向重叠 from 参数指向的位置的位置。在此
情况下,GBase 8s ESQL/C 丢弃 from 指向的值。
count
定长目标字符串中的字节数。

示例

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

The following program shows the blank padded result produced by stchar() function.
*/

#include

main()
{
static char src[] = "start";
static char dst[25] = "123abcdefghijkl;.";

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

printf("Source string: [%s]\n", src);
printf("Destination string before stchar: [%s]\n", dst);

stchar(src, dst, sizeof(dst) - 1);

printf("Destination string after stchar: [%s]\n", dst);

printf("\nSTCHAR Sample Program over.\n\n");
}

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

输出

STCHAR Sample ESQL Program running.

Source string: [start]
Destination string before stchar: [123abcdefghijkl;.]
Destination string after stchar: [start ]

STCHAR Sample Program over.

功能描述
与数据库服务器建立一个新的链接。
原型
PGconn *PQsetdbLogin(const char *pghost,
const char *pgport,
const char *pgoptions,
const char *pgtty,
const char *dbName,
const char *login,
const char *pwd);
参数
表8-38 PQsetdbLogin 参数
关键字
参数说明
pghost
要链接的主机名,详见6.4.5 链接参数章节描述的host 字段。
pgport
主机服务器的端口号,详见6.4.5 链接参数描述的port 字段。
pgoptions
添加命令行选项以在运行时发送到服务器,详见6.4.5 链接参数
描述的options 字段。
pgtty
忽略(以前,这个选项声明服务器日志的输出方向)。
dbName
要链接的数据库名,详见6.4.5 链接参数描述的dbname 字段。
login
要链接的用户名,详见6.4.5 链接参数章节描述的user 字段。
pwd
如果服务器要求口令认证,所用的口令,详见6.4.5 链接参数描
述的password 字段。
返回值
PGconn *:指向包含链接的对象指针,内存在函数内部申请。
注意事项

该函数为PQconnectdb 前身,参数个数固定,未定义参数被调用时使用缺省值,若需

GBase 8c V5 开发者手册
南大通用数据技术股份有限公司
281
要给固定参数设置缺省值,则可赋值NULL 或者空字符串。

若dbName 中包含“=”或链接URL 的有效前缀,
则该dbName 被看做一个conninfo 字符
串并传递至PQconnectdb 中,其余参数与PQconnectdbParams 保持一致。
示例
参见6.4.3 示例。

rjulmdy() 函数创建一个三个 short 整数值的数组,其表示来自内部 DATE 值的月份、
日子和年份。


GBase 8s ESQL/C 编程指南
南大通用数据技术股份有限公司
- 887 -
语法
mint rjulmdy(jdate, mdy)
int4 jdate;
int2 mdy[3];
jdate
该日期的内部表示。
mdy
short 整数的数值,其中 mdy[0] 为月份(1 - 12),mdy[1] 为日子(1 - 31),mdy[2]
为年份(1 - 9999)。

返回代码
0
操作成功。
< 0
操作失败。
-1210
无法将内部的日期转换为字符串格式。

示例
demo 目录在 rjulmdy.ec 文件中包含此样例程序。
/*
* rjulmdy.ec *

The following program accepts a date entered from the console and converts it to an array
of three short integers that contain the month, day, and year.
*/

#include

main()
{
int4 i_date;
short mdy_array[3];

GBase 8s ESQL/C 编程指南
南大通用数据技术股份有限公司
- 888 -
mint errnum;
char date[20];
mint x;

static char fmtstr[9] = "mmddyyyy";

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

/* Allow user to enter a date */
printf("Enter a date as a single string, month.day.year\n");
gets(date);

printf("\nThe date string is %s.\n", date);

/* Put entered date in internal format */
if (x = rdefmtdate(&i_date, fmtstr, date))
printf("Error %d on rdefmtdate conversion\n", x);
else
{

/* Convert from internal format to MDY array */
if ((errnum = rjulmdy(i_date, mdy_array)) == 0)
{
printf("\tThe month component is: %d\n", mdy_array[0]);
printf("\tThe day component is: %d\n", mdy_array[1]);
printf("\tThe year component is: %d\n", mdy_array[2]);
}
else
printf("rjulmdy() call failed with error %d", errnum);
}

printf("\nRJULMDY Sample Program over.\n\n");
}

GBase 8s ESQL/C 编程指南
南大通用数据技术股份有限公司
- 889 -
输出
RJULMDY Sample ESQL Program running.

Enter a date as a single string, month.day.year
10.12.07

The date string is 10.12.07.
The month component is: 10
The day component is: 12
The year component is: 2007

RJULMDY Sample Program over.