signature=406355c796db59b5424a3861d01f0f1d,Understanding and Using TTClasses

本文介绍如何在TimesTen数据库中使用LOB(Large Object)类型,包括NCLOB、BLOB和CLOB列的操作,涉及查询、获取不同类型数据长度及处理null值的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Example 2-15 Using LOBs in TTClasses

This example assumes a table with NCLOB, BLOB, and CLOB columns has been created and populated. The methods executed on these LOB types are the same as for NCHAR, BINARY, and CHAR, respectively.

#ifdef _WIN32

#include

#endif

#include "TTInclude.h"

#define LOB_COL_SIZE 4194304

int main(int argc, char** argv) {

TTConnection conn;

TTCmd query;

char conn_str[100] = "... your connection string ...";

char tbl_name[20] = "... test table name ...";

int num_rows = 0;

char query_stmt[1000];

int fetch_next;

int value_is_null = 0;

int column_type;

SQLWCHAR * unicode_val;

u_char * binary_val;

char * alfanum_val;

int b_len;

int u_len;

cerr << "Connecting to TimesTen " << endl;

try {

conn.Connect(conn_str);

sprintf(query_stmt, "select * from %s", tbl_name);

query.Prepare(&conn, query_stmt);

query.Execute();

const int num_result_cols = query.getNColumns();

while (true) {

// loop until no rows found

// fetch a row; if no more rows, break out of loop

// FetchNext returns 0 for success, 1 for SQL_NO_DATA_FOUND

fetch_next = query.FetchNext();

if (fetch_next == 1)

break;

for (int col = 1; col <= num_result_cols; col++) {

value_is_null = 0;

column_type = query.getColumnType(col);

switch (column_type) {

case SQL_WLONGVARCHAR:

value_is_null = query.getColumnNullable(col,

(SQLWCHAR**) & unicode_val, &u_len);

if (value_is_null) {

cerr << "NCLOB value is NULL";

} else {

cerr << "NCLOB value length = " << u_len << endl;

// do something with NCLOB value

}

break;

case SQL_LONGVARBINARY:

value_is_null = query.getColumnNullable(col,

(void**) & binary_val, &b_len);

if (value_is_null) {

cerr << "BLOB value is NULL";

} else {

cerr << "BLOB value length = " << b_len << endl;

// do something with BLOB value

}

break;

case SQL_LONGVARCHAR:

alfanum_val = (char*) malloc(LOB_COL_SIZE + 1);

value_is_null = query.getColumnNullable(col, alfanum_val);

if (value_is_null) {

cerr << "CLOB value is NULL";

} else {

cerr << "CLOB value length = " << strlen(alfanum_val) << endl;

// do something with BLOB value

}

free(alfanum_val);

break;

default:

break;

}

}

num_rows++;

cerr << "row " << num_rows << " fetched" << endl;

}

cerr << num_rows << " rows returned" << endl;

} catch (TTError err) {

cerr << "\nError" << err << endl;

}

query.Drop();

conn.Disconnect();

return 0;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值