返回首页

gbase数据、南大通用产品文档:GBase8s临时智能大对象空间

更新日期:2024年09月11日

使用临时智能大对象空间可在不用元数据日志记录和用户数据日志记录的情况下存储临时
智能大对象。如果您将临时智能大对象存储在标准的智能大对象空间中时,将记录元数
据。临时智能大对象空间类似于临时数据库空间。要创建临时智能大对象空间,使用带有
-t 选项的 onspaces -c -S 命令。
您可将临时大对象存储在标准的智能大对象空间或临时的智能大对象空间中。

如果在 SBSPACETEMP 参数中指定临时智能大对象空间,那么可在该临时智能
大对象空间中存储临时智能大对象。

如果在 SBSPACENAME 参数中指定标准智能大对象空间,那么可在该标准智能
大对象空间中存储临时和永久智能大对象。

如果在 CREATE TEMP TABLE 语句中指定临时智能大对象空间名称,那么可在
该临时智能大对象空间中存储临时智能大对象。

GBase 8s 管理员指南
南大通用数据技术股份有限公司
- 164 -

如果在 CREATE TABLE 语句中指定永久智能大对象空间名称,那么可在该永久
智能大对象空间中存储临时智能大对象。

如果省略 SBSPACETEMP 和 SBSPACENAME 参数并创建智能大对象,那么可
能会显示错误消息 -12053。

如果在 SBSPACENAME 参数中指定临时智能大对象空间,那么就不能在该智能
大对象空间中存储永久智能大对象。 您可将临时智能大对象存储在该智能大对象
空间中。
比较临时和标准智能大对象空间
下表比较了标准和临时智能大对象空间。
表 1. 临时和标准智能大对象空间
特征
标准智能大对象空间
临时智能大对象空间
存储智能大对象


存储临时智能大对



记录元数据
始终记录元数据
不记录元数据
记录用户数据
如果 LOGGING=ON,对于临
时智能大对象,不记录用户数
据;对于永久智能大对象,会
记录用户数据
不记录用户数据
创建和删除空间,且记录块的
添加
快速恢复

否(智能大对象空间在数据库
服务器重新启动时清空) 要
设置共享内存而不清除临时智
能大对象,请指定 oninit -p。
如果保留临时大对象,那么它
们的状态是不确定的。
备份与复原


添加和删除块


配置参数
SBSPACENAME
SBSPACETEMP

临时智能大对象
使用临时智能大对象可存储不需要从备份复原或在快速恢复中记录重放的文本或映像数据
(CLOB 或 BLOB)。临时智能大对象将在该用户会话中持续,并且比智能大对象更快
更新。
除非在 ifx_lo_specset_flags 或 mi_lo_specset_flags 函数中设置了 LO_CREATE_TEMP 标
志,否则将以与创建永久智能大对象相同的方式创建临时智能大对象。使用 mi_lo_copy
或 ifx_lo_copy 从临时智能大对象创建永久智能大对象。
重要: 只可在临时表中存储指向临时大对象的指针。如果您将它们存储在标准表中并重
新引导数据库服务器,那么结果会生成一条错误信息,称大对象不存在。

GBase 8s 管理员指南
南大通用数据技术股份有限公司
- 165 -
下表比较了标准和临时智能大对象。
表 1. 临时和标准智能大对象
特征
智能大对象
临时智能大对象
创建标志
LO_CREATE_LOG 或
LO_CREATE_NOLOG
LO_CREATE_TEMP
回滚


日志记录
是,如果打开

持续时间
永久(直到用户将其删除)
在用户会话或事务结束时删除
存储的表类型
永久或临时表
临时表

当安装 GBase 8s ESQL/C 时,安装脚本将头文件存储在 $GBASEDBTDIR/incl/esql
目录
(在 UNIX™ 操作系统上)
和 %GBASEDBTDIR%\incl\esql 目录中
(在 Windows™ 环
境中)。
下表显示了 GBase 8s ESQL/C 产品提供的头文件。
表 1. ESQL/C 头文件
头文件
内容
其它信息
datetime.h
GBase 8s ESQL/C datetime 和 interval 结构的定
义,它们是 DATETIME 和 INTERVAL 列的主变量
时间数据类型
decimal.h
GBase 8s ESQL/C decimal 数据类型的定义,是
DECIMAL 和 MONEY 数据类型的主变量
Numeric 数据
类型
gls.h
用于 GLS 功能的函数原型和数据结构
GBase 8s
GLS 用户指

ifxtypes.h
精确映射 GBase 8s 数据类型 int1 、int2 、int4 、
mint 、mlong 、MSHORT 和 MCHAR ,用于
32 位和 64 位平台
整数主机变量
类型
locator.h
GBase 8s ESQL/C 定位器结构(ifx_loc_t 或 loc_t)
的定义,它是字节和文本列的主变量
简单大对象

GBase 8s ESQL/C 编程指南
南大通用数据技术股份有限公司
- 27 -
sqlca.h
ESQL/C 用来存储错误状态代码的结构的定义
当 esql 预处理器预处理程序时,自动包含此文件。
异常处理
sqlda.h
值指针和结构定义以及动态定义变量的描述
确定 SQL 语

sqlhdr.h
该文件包含 sqlda.h 头文件、其它头文件以及函数原
型。
预处理器预处理程序时自动包含该文件。
在程序中包含
头文件
sqliapi.h
内部库 API 函数原型
仅供内部 GBase 8s ESQL/C 使用。

sqlstype.h
SQL 语句常量的定义
DESCRIBE 语句使用这些常量描述动态准备的 SQL
语句
确定 SQL 语

sqltypes.h
定义与 ESQL/C 和 SQL 数据类型相对应的常量
当程序包含 DESCRIBE 语句时,
ESQL/C 使用这些常
量。
数据类型常量
sqlxtype.h
当在 X/Open 模式时定义与 GBase 8s ESQL/C 和
SQL 数据类型相对应的常量
当程序包含 DESCRIBE 语句时,
ESQL/C 使用这些常
量。
X/Open 数据
类型常量
value.h
GBase 8s ESQL/C 使用的值结构
仅供内部 GBase 8s ESQL/C 使用。

varchar.h
可以使用 VARCHAR 数据类型的宏
字符和字符串
数据类型
下图显示了特定于 GBase 8s 的 GBase 8s ESQL/C 头文件。
表 2. GBase 8s 的 ESQL/C 头文件
头文件
内容
其它信息
collct.h
GBase 8s ESQL/C 中复杂类型的数据结构的定义
复杂数据类型

GBase 8s ESQL/C 编程指南
南大通用数据技术股份有限公司
- 28 -
头文件
内容
其它信息
ifxgls.h
用于 GLS 应用程序编程接口的函数原型
仅供内部 GBase 8s ESQL/C 使用。

int8.h
存储 INT8 数据类型结构的定义
int8 数据类型
下表显示了特定于 Windows 环境的 GBase 8s ESQL/C 头文件。
表 3. Windows 环境中的 ESQL/C 头文件
头文件
内容
其它信息
sqlproto.h
所有 ESQL/C 库函数的函数原型,用于不完全符合
ANSI C 标准的源
声明函数原型
infxcexp.c
包含用于导出 ESQL 客户端接口 DLL 使用的所有 C
运行时例程的地址的 C 代码
相同运行例程的版本独
立性
login.h
InetLogin 和 HostInfoStruct 结构的定义,为应用
程序定制配置参数
因为此文件不包含 ESQL 语句,
所以不需要使用 ESQL
include 伪指令包含它。而是用 C #include 预处理器
伪指令。
InetLogin 结构的字段
声明函数原型
GBase 8s ESQL/C 提供 sqlproto.h 头文件为所有 GBase 8s ESQL/C 库函数声明函数
原型。您使用 ANSI C 编译器的 GBase 8s ESQL/C 源文件需要这些函数原。缺省情况下,
esql 命令处理器不包含函数原型声明。
使处理器包含符合 GBase 8s ESQL/C 函数的 ANSI
兼容的函数原型可以防止 ANSI C 编译器生成警告。
限制:
尽管可以使用 ANSI C 编译器,
GBase 8s ESQL/C 预处理器并不全支持 ANSI
C,因此您可能不能处理遵循 ANSI C 标准的全部程序。
因为 sqlproto.h 文件不包含任何 GBase 8s ESQL/C 语句,使用可用使用以下方法包
含此文件:
使用 GBase 8s ESQL/C include 预处理器伪指令:
EXEC SQL include sqlproto;
使用 C #include 预处理器伪指令:
#include "sqlproto.h";
在程序中包含头文件
GBase 8s ESQL/C 预处理器在程序中自动包含以下 GBase 8s ESQL/C 头文件:

GBase 8s ESQL/C 编程指南
南大通用数据技术股份有限公司
- 29 -
sqlhdr.h 文件为您的 GBase 8s ESQL/C 程序提供和游标相关的结构。
该头文件自动包含 sqlda.h 和 ifxtypes.h 头文件。
sqlca.h 文件,允许您的查询检查带有 SQLSTATE 或 SQLCODE 变量的 GBase 8s
ESQL/C 语句的成功或失败。
限制: 尽管现在使用 ANSI C 编译器,GBase 8s ESQL/C 预处理器也不完全支持
ANSI C,因此可能不能处理所有遵循 ANSI C 标准的程序。
要在您的 GBase 8s ESQL/C 程序中包含任何其它头文件,必须使用 include 预处理
器伪指令。但是,如果您的程序引用头文件定义的结构或定义,则必须包含 GBase 8s
ESQL/C 头文件。例如:如果您的程序访问 datetime 数据,那么必须包含 datetime.h 头文
件,如下所示:
EXEC SQL include datetime.h;
确保使用分号结束代码行。一些其它示例如下:
EXEC SQL include varchar.h;
EXEC SQL include sqlda;
$include sqlstype;
提示: 不需要对 GBase 8s ESQL/C 头文件输入 .h 文件扩展名;esql 预处理器假
定 .h 扩展。

create_clob 演示如何对智能大对象执行下列任务:
以用户定义的存储特征来创建智能大对象。

GBase 8s ESQL/C 编程指南
南大通用数据技术股份有限公司
- 961 -
将新的智能大对象插入至数据库列内。
示例的存储特征
create_clob 程序创建 advert_descr 智能大对象,其有下列用户定义的存储特征:
开启日志记录:LO_LOG
保持最后的访问时间(缺省来自 advert_descr 列):LO_KEEP_ACCESSTIME
完整性高
分配 extent 大小为 10 KB
EXEC SQL include int8;
EXEC SQL include locator;
EXEC SQL define BUFSZ 10;

extern char statement[80];

main()
{
EXEC SQL BEGIN DECLARE SECTION;
int8 catalog_num, estbytes, offset;
int error, numbytes, lofd, ic_num, buflen = 256;
char buf[256], srvr_name[256], col_name[300];
ifx_lo_create_spec_t *create_spec;
fixed binary 'clob' ifx_lo_t descr;
EXEC SQL END DECLARE SECTION;

void nullterm(char *);
void handle_lo_error(int);

EXEC SQL whenever sqlerror call whenexp_chk;
EXEC SQL whenever sqlwarning call whenexp_chk;

printf("CREATE_CLOB Sample ESQL program running.\n\n");
strcpy(statement, "CONNECT stmt");
EXEC SQL connect to 'stores7';
EXEC SQL get diagnostics exception 1
:srvr_name = server_name;
nullterm(srvr_name);

/* Allocate and initialize the LO-specification structure */
error = ifx_lo_def_create_spec(&create_spec);
if (error < 0)
{
strcpy(statement, "ifx_lo_def_create_spec()");
handle_lo_error(error);
}

/* Get the column-level storage characteristics for the
* CLOB column, advert_descr.
*/
sprintf(col_name, "stores7@%s:catalog.advert_descr",
srvr_name);
error = ifx_lo_col_info(col_name, create_spec);
if (error < 0)

GBase 8s ESQL/C 编程指南
南大通用数据技术股份有限公司
- 962 -
{
strcpy(statement, "ifx_lo_col_info()");
handle_lo_error(error);
}

/* Override column-level storage characteristics for
* advert_desc with the following user-defined storage
* characteristics:
* no logging
* extent size = 10 kilobytes
*/
ifx_lo_specset_flags(create_spec,LO_LOG);
ifx_int8cvint(BUFSZ, &estbytes);
ifx_lo_specset_estbytes(create_spec, &estbytes);

/* Create an LO-specification structure for the smart large object */

if ((lofd = ifx_lo_create(create_spec, LO_RDWR,
&descr, &error)) == -1)
{
strcpy(statement, "ifx_lo_create()");
handle_lo_error(error);
}
/* Copy data into the character buffer 'buf' */

sprintf(buf, "%s %s",
"Pro model infielder's glove. Highest quality leather and
stitching. "
"Long-fingered, deep pocket, generous web.");

/* Write contents of character buffer to the open smart
* large object that lofd points to. */

ifx_int8cvint(0, &offset);
numbytes = ifx_lo_writewithseek(lofd, buf, buflen,
&offset, LO_SEEK_SET, &error);
if ( numbytes < buflen )
{
strcpy(statement, "ifx_lo_writewithseek()");
handle_lo_error(error);
}

/* Insert the smart large object into the table */
strcpy(statement, "INSERT INTO catalog");
EXEC SQL insert into catalog values (0, 1, 'HSK', 'case', ROW(NULL,
NULL),:descr);

/* Need code to find out what the catalog_num value was
* assigned to new row */
/* Close the LO file descriptor */
ifx_lo_close(lofd);

/* Select back the newly inserted value. The SELECT
* returns an LO-pointer structure, which you then use to
* open a smart large object to get an LO file descriptor.
*/
ifx_getserial8(&catalog_num);

GBase 8s ESQL/C 编程指南
南大通用数据技术股份有限公司
- 963 -
strcpy(statement, "SELECT FROM catalog");
EXEC SQL select advert_descr into :descr from catalog
where catalog_num = :catalog_num;

/* Use the returned LO-pointer structure to open a smart
* large object and get an LO file descriptor.
*/
lofd = ifx_lo_open(&descr, LO_RDONLY, &error);
if (error < 0)
{
strcpy(statement, "ifx_lo_open()");
handle_lo_error(error);
}
/* Use the LO file descriptor to read the data in the
* smart large object.
*/
ifx_int8cvint(0, &offset);
strcpy(buf, "");
numbytes = ifx_lo_readwithseek(lofd, buf, buflen,
&offset, LO_SEEK_CUR, &error);
if (error || numbytes == 0)
{
strcpy(statement, "ifx_lo_readwithseek()");
handle_lo_error(error);
}
if(ifx_int8soint(&catalog_num, ⁣_num) != 0)
printf("\nifx_int8soint failed to convert catalog_num to int");
printf("\nContents of column \'descr\' for catalog_num:
%d \n\t%s\n",
ic_num, buf);
/* Close open smart large object */
ifx_lo_close(lofd);
/* Free LO-specification structure */
ifx_lo_spec_free(create_spec);
}

void handle_lo_error(error_num)
int error_num;
{
printf("%s generated error %d\n", statement, error_num);
exit(1);
}

void nullterm(str)
char *str;
{
char *end;

end = str + 256;
while(*str != ' ' && *str != '\0' && str < end)
{
++str;
}
if(str >= end)
printf("Error: end of str reached\n");
if(*str == ' ')
*str = '\0';

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

/* Include source code for whenexp_chk() exception-checking
* routine
*/

EXEC SQL include exp_chk.ec;
get_lo_info.ec 程序
此程序检索关于存储在 BLOB 列中的智能大对象的信息。
#include

EXEC SQL define BUFSZ 10;

extern char statement[80];

main()
{
int error, ic_num, oflags, cflags, extsz, imsize, isize, iebytes;
time_t time;
struct tm *date_time;
char col_name[300], sbspc[129];

EXEC SQL BEGIN DECLARE SECTION;
fixed binary 'blob' ifx_lo_t picture;
char srvr_name[256];
ifx_lo_create_spec_t *cspec;
ifx_lo_stat_t *stats;
ifx_int8_t size, c_num, estbytes, maxsize;
int lofd;
long atime, ctime, mtime, refcnt;
EXEC SQL END DECLARE SECTION;

void nullterm(char *);
void handle_lo_error(int);

imsize = isize = iebytes = 0;
EXEC SQL whenever sqlerror call whenexp_chk;
EXEC SQL whenever sqlwarning call whenexp_chk;

printf("GET_LO_INFO Sample ESQL program running.\n\n");
strcpy(statement, "CONNECT stmt");
EXEC SQL connect to 'stores7';
EXEC SQL get diagnostics exception 1
:srvr_name = server_name;
nullterm(srvr_name);

EXEC SQL declare ifxcursor cursor for
select catalog_num, advert.picture
into :c_num, :picture
from catalog
where advert.picture is not null;

EXEC SQL open ifxcursor;
while(1)
{
EXEC SQL fetch ifxcursor;
if (strncmp(SQLSTATE, "00", 2) != 0)

GBase 8s ESQL/C 编程指南
南大通用数据技术股份有限公司
- 965 -
{
if(strncmp(SQLSTATE, "02", 2) != 0)
printf("SQLSTATE after fetch is %s\n", SQLSTATE);
break;
}
/* Use the returned LO-pointer structure to open a smart
* large object and get an LO file descriptor.
*/
lofd = ifx_lo_open(&picture, LO_RDONLY, &error);
if (error < 0)
{
strcpy(statement, "ifx_lo_open()");
handle_lo_error(error);
}
if(ifx_lo_stat(lofd, &stats) < 0)
{
printf("\nifx_lo_stat() < 0");
break;
}
if(ifx_int8soint(&c_num, ⁣_num) != 0)
ic_num = 99999;
if((ifx_lo_stat_size(stats, &size)) < 0)
isize = 0;
else
if(ifx_int8soint(&size, &isize) != 0)
{
printf("\nFailed to convert size");
isize = 0;
}
if((refcnt = ifx_lo_stat_refcnt(stats)) < 0)
refcnt = 0;
printf("\n\nCatalog number %d", ic_num);
printf("\nSize is %d, reference count is %d", isize, refcnt);

if((atime = ifx_lo_stat_atime(stats)) < 0)
printf("\nNo atime available");
else
{
time = (time_t)atime;
date_time = localtime(&time);
printf("\nTime of last access: %s", asctime(date_time));
}
if((ctime = ifx_lo_stat_ctime(stats)) < 0)
printf("\nNo ctime available");
else
{
time = (time_t)ctime;
date_time = localtime(&time);
printf("Time of last change: %s", asctime(date_time));
}

if((mtime = ifx_lo_stat_mtime_sec(stats)) < 0)
printf("\nNo mtime available");
else
{
time = (time_t)mtime;
date_time = localtime(&time);

GBase 8s ESQL/C 编程指南
南大通用数据技术股份有限公司
- 966 -
printf("Time to the second of last modification: %s",
asctime(date_time));
}
if((cspec = ifx_lo_stat_cspec(stats)) == NULL)
{
printf("\nUnable to access ifx_lo_create_spec_t structure");
break;
}
oflags = ifx_lo_specget_def_open_flags(cspec);
printf("\nDefault open flags are: %d", oflags);
if(ifx_lo_specget_estbytes(cspec, &estbytes) == -1)
{
printf("\nifx_lo_specget_estbytes() failed");
break;
}
if(ifx_int8soint(&estbytes, &iebytes) != 0)
{
printf("\nFailed to convert estimated bytes");
}
printf("\nEstimated size of smart LO is: %d", iebytes);
if((extsz = ifx_lo_specget_extsz(cspec)) == -1)
{
printf("\nifx_lo_specget_extsz() failed");
break;
}
printf("\nAllocation extent size of smart LO is: %d", extsz);
if((cflags = ifx_lo_specget_flags(cspec)) == -1)
{
printf("\nifx_lo_specget_flags() failed");
break;
}
printf("\nCreate-time flags of smart LO are: %d", cflags);
if(ifx_lo_specget_maxbytes(cspec, &maxsize) == -1)
{
printf("\nifx_lo_specget_maxsize() failed");
break;
}
if(ifx_int8soint(&maxsize, &imsize) != 0)
{
printf("\nFailed to convert maximum size");
break;
}
if(imsize == -1)
printf("\nMaximum size of smart LO is: No limit");
else
printf("\nMaximum size of smart LO is: %d\n", imsize);
if(ifx_lo_specget_sbspace(cspec, sbspc, sizeof(sbspc)) == -1)
printf("\nFailed to obtain sbspace name");
else
printf("\nSbspace name is %s\n", sbspc);

}
/* Close smart large object */
ifx_lo_close(lofd);
ifx_lo_stat_free(stats);
EXEC SQL close ifxcursor;
EXEC SQL free ifxcursor;

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

void handle_lo_error(error_num)
int error_num;
{
printf("%s generated error %d\n", statement, error_num);
exit(1);
}

void nullterm(str)
char *str;
{
char *end;

end = str + 256;
while(*str != ' ' && *str != '\0' && str < end)
{
++str;
}
if(str >= end)
printf("Error: end of str reached\n");
if(*str == ' ')
*str = '\0';
}
/* Include source code for whenexp_chk() exception-checking
* routine
*/

EXEC SQL include exp_chk.ec;