当前位置: 首页>>代码示例>>C++>>正文


C++ IAttachment::openBlob方法代码示例

本文整理汇总了C++中IAttachment::openBlob方法的典型用法代码示例。如果您正苦于以下问题:C++ IAttachment::openBlob方法的具体用法?C++ IAttachment::openBlob怎么用?C++ IAttachment::openBlob使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IAttachment的用法示例。


在下文中一共展示了IAttachment::openBlob方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main()
{
	int rc = 0;

	// set default password if none specified in environment
	setenv("ISC_USER", "sysdba", 0);
	setenv("ISC_PASSWORD", "masterkey", 0);

	// With ThrowStatusWrapper passed as status interface FbException will be thrown on error
	ThrowStatusWrapper status(master->getStatus());

	// Declare pointers to required interfaces
	IProvider* prov = master->getDispatcher();
	IAttachment* att = NULL;
	ITransaction* tra = NULL;
	IBlob* blob = NULL;

	try
	{
		// create database
		att = prov->createDatabase(&status, "blob_07.fdb", 0, NULL);
		tra = att->startTransaction(&status, 0, NULL);

		// create table
		att->execute(&status, tra, 0, "create table blobs_table (b blob sub_type text)", SAMPLES_DIALECT,
			NULL, NULL, NULL, NULL);
		tra->commitRetaining(&status);

		// Message for data exchange
		FB_MESSAGE(Msg, ThrowStatusWrapper,
			(FB_BLOB, b)
		) message(&status, master);
		message.clear();

		// create blob
		blob = att->createBlob(&status, tra, &message->b, 0, NULL);

		// populate blob with data
		for (const char** seg = testData; *seg; ++seg)
			blob->putSegment(&status, strlen(*seg), *seg);
		blob->close(&status);
		blob = NULL;

		// insert blob into the table
		att->execute(&status, tra, 0, "insert into blobs_table(b) values(?)", SAMPLES_DIALECT,
			message.getMetadata(), message.getData(), NULL, NULL);
		tra->commitRetaining(&status);
		printf("Test blob inserted into blobs_table\n...\n");

		// Read blob from table
		message.clear();
		att->execute(&status, tra, 0, "select first(1) b from blobs_table", SAMPLES_DIALECT,
			NULL, NULL, message.getMetadata(), message.getData());
		blob = att->openBlob(&status, tra, &message->b, 0, NULL);

		// Read segments from blob
		// Use very small segment buffer to show read of incomplete segment
		printf("Read inserted blob from blobs_table\n...\n");
		int bufOver = 0;
		for(bool eof = false; !eof; )
		{
			const char* lineFeed = "\n";
			char buf[32];
			unsigned l = 0;
			switch (blob->getSegment(&status, sizeof(buf) - 1, buf, &l))
			{
				case IStatus::RESULT_OK:
					break;
				case IStatus::RESULT_SEGMENT:
					lineFeed = "";
					bufOver++;
					break;
				default:
					eof = true;
					continue;
			}
			buf[l] = 0;
			printf("%s%s", buf, lineFeed);
		}
		printf("\nSegment not fit in buffer counter = %d\n\n", bufOver);

		// cleanup
		blob->close(&status);
		blob = NULL;
		tra->commit(&status);
		tra = NULL;

		// uncomment next line to play with errors during drop database
		// printf("Attach with any client to blob_07.fdb to prevent it being dropped and press enter"); getchar();

		// drop database
		drop(&att);
	}
	catch (const FbException& error)
	{
		// handle error
		rc = 1;
		errPrint(error.getStatus());

		if (att)
//.........这里部分代码省略.........
开发者ID:FirebirdSQL,项目名称:firebird,代码行数:101,代码来源:07.blob.cpp


注:本文中的IAttachment::openBlob方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。