本文整理汇总了C++中IAttachment::createBlob方法的典型用法代码示例。如果您正苦于以下问题:C++ IAttachment::createBlob方法的具体用法?C++ IAttachment::createBlob怎么用?C++ IAttachment::createBlob使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IAttachment
的用法示例。
在下文中一共展示了IAttachment::createBlob方法的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)
//.........这里部分代码省略.........