OTL翻译(8) -- otl_long_string/otl_long_unicode_string类

时间:2023-09-09 19:49:50

otl_long_string/olt_long_unicode_string

这两个类主要用来处理大对象数据。从OTL4.0版本开始,otl_long_string还可以处理任何类型的RAW/BIANRY类型。下面列出了常见数据库的一些大对象类型:

·             Oracle 7: LONG, RAW, LONG RAW

·             Oracle 8, 8i, 9i, 10g, 11g: LONG, RAW, LONG RAW; CLOB, BLOB

·             MS SQL Server: TEXT, IMAGE, VARBINARY, BINARY, VARCHAR(MAX), VARBINARY(MAX)

·             DB2: CLOB, BLOB

·             Sybase: TEXT, IMAGE, VARBINARY, BINARY

·             PostgreSQL: TEXT, BYTEA,

·             SAP/MAX DB: CHAR() BYTE, VARCHAR() BYTE, LONG VARCHAR, LONG VARCHAR BYTE

·             MySQL: LONGTEXT, LONGBLOB, VARBINARY, BINARY

otl_long_unicode_string是用来处理UNICODE字符的大对象类型,它可以处理下面这些类型:

·             Oracle 8i, 9i, 10g: LONG,  CLOB; the database default character set may be set to ASCII, or UTF-8, etc

·             Oracle 8i, 9i, 10g: NCLOB; the database national character set may be set to whatever is allowed for a concrete version of the database (8i and 9i/10g differ / are not the same in that regard, as far as supporting different versions of Unicode, and what sets are allowed for national character data types)

·             MS SQL NTEXT

·             DB2 CLOB / DBCLOB when the database supports Unicode (UTF-8, UCS-2, etc.)

如果定义了OTL_UNICODE宏,那么对于ORACLE的LONG RAWS/BLOB,MS SQL IMAGES,DB2 BLOBS等仍要通过otl_long_string来处理。因为他们仍然是大对象。

OTL还定义了下列类型用于处理LOBS类型。

  • varchar_long for Oracle 7/8/8i/9i/10g LONG, MS SQL Server/Sybase TEXT/NTEXT, DB2 CLOB/DBCLOB
  • raw_long for Oracle 7/8/8i/9i/10g RAW, LONG RAW, MS SQL Server/Sybase IMAGE, DB2 BLOB
  • clob for Oracle 8/8i/9i/10g CLOB, NCLOB (if #define OTL_UNICODE is enabled).
  • blobfor Oracle 8/8i/9i/10g BLOB

大对象和NULL值

大对象和NULL值的操作,与其他类型的字段有很大的区别。对于大对象与NULL的处理方式分为下面两种情况:

一、Oracle 7/8/8i/9i/10g's LONG, Oracle 7/8's LONG RAW, MS SQL Server/Sybase's TEXT, MS SQL Server/Sybase's IMAGE, DB2's CLOB/BLOB:

相对于一般的数据库类型,以上这些大对象可以通过两种方式设置为空。一是往流里面写入一个otl_null()值;二是通过调用otl_long_string::set_len(0)把大对象值设置为0.

对于输出,也有两种方式用来检测是否为空。一是通过is_null()进行判断;二是通过otl_long_string::len()获取结果后与0进行比较。

二、Oracle 8/8i/9i/10g's CLOB, Oracle 8/8i/9i/10g's BLOB:

对于以上的数据库类型,对于大对象空值的判断,在输入参数上,与上面的是同样的具有两川方式处理。但是对于输出参数的处理上,则只能通过otl_long_string::len()返回值与0进行比较。所以推荐使用otl_long_string::len()操作来判断空值。

下面分别介绍一个otl_long_string类和otl_long_unicode_string类。

otl_long_string

序号

函数、成员变量

说明

1

unsigned char * v;

指向LOB值的指针。

2

otl_long_string(…)

序号

参数

说明

1

const int buffer_size = 32760

定义LOB缓冲区大小

2

const int input_length = 0

定义实际的输入字符串长度,如果这个使用了,那么set_len()就可以不必调用

构造函数。创建一个otl_long_string的实例。主要是分配内存,并设置内部变量。

为了保证能分配到正确的大小,otl_connect::set_max_long_size()必须声明的大于或等于otl_long_string的缓冲区大小。

3

otl_long_string(…)

序号

参数

说明

1

const void * external_buffer

指向外部缓冲区的指针

2

const int buffer_size = 32760

定义LOB缓冲区大小

3

const int input_length = 0

定义实际的输入字符串长度,如果这个使用了,那么set_len()就可以不必调用

构造函数。该函数通过定义一个指针指向外部的一个缓冲区来替代默认的缓冲区。同时原来的缓冲区不再分配空间。

4

void set_len(const int len = 0)

动态的设置缓冲区大小。它必须在写LOB值之前调用。

5

void set_last_piece(

const bool last_piece = false)

仅对OCI8i/9i/10g/11g有效。对于ODBC和DB2 CLI不起作用。

当otl_long_string与otl_lob_stream同时使用的时候,该函数表明otl_string_string是写入otl_stream里面的最后一个序列。

6

int len()

返回缓冲区的大小。

7

unsigned char & operator[](int ndx)

读取LOB里面非法的字节。

8

otl_long_string & operator =

(const otl_long_string&)

赋值构造函数

9

otl_long_string(

const otl_long_string&)

拷贝构造函数

otl_long_unicode_string

序号

函数、成员变量

说明

1

otl_long_unicode_string(…)

序号

参数

说明

1

const int buffer_size = 32760

定义LOB缓冲区大小

2

const int input_length = 0

定义实际的输入字符串长度,如果这个使用了,那么set_len()就可以不必调用

构造函数。创建一个otl_long_unicode_string的实例。主要是分配内存,并设置内部变量。

为了保证能分配到正确的大小,otl_connect::set_max_long_size()必须声明的大于或等于otl_long_string的缓冲区大小。

2

otl_long_unicode_string(…)

序号

参数

说明

1

const void * external_buffer

指向外部缓冲区的指针

2

const int buffer_size = 32760

定义LOB缓冲区大小

3

const int input_length = 0

定义实际的输入字符串长度,如果这个使用了,那么set_len()就可以不必调用

构造函数。该函数通过定义一个指针指向外部的一个缓冲区来替代默认的缓冲区。同时原来的缓冲区不再分配空间。

3

void set_len(const int len = 0)

动态的设置缓冲区大小。它必须在写LOB值之前调用。

4

int len(void)

返回缓冲区的大小。

5

unsigned short & operator[](int ndx)

读取LOB里面非法的字节。

6

otl_long_unicode_string & operator =

(const otl_long_unicode_string)

赋值构造函数

7

otl_long_unicode_string(

const otl_long_unicode_string&)

拷贝构造函数