| 70 | } |
| 71 | |
| 72 | int main() |
| 73 | { |
| 74 | int rc = 0; |
| 75 | |
| 76 | // set default password if none specified in environment |
| 77 | setenv("ISC_USER", "sysdba", 0); |
| 78 | setenv("ISC_PASSWORD", "masterkey", 0); |
| 79 | |
| 80 | // With ThrowStatusWrapper passed as status interface FbException will be thrown on error |
| 81 | ThrowStatusWrapper status(master->getStatus()); |
| 82 | |
| 83 | // Declare pointers to required interfaces |
| 84 | IProvider* prov = master->getDispatcher(); |
| 85 | IAttachment* att = NULL; |
| 86 | ITransaction* tra = NULL; |
| 87 | IBlob* blob = NULL; |
| 88 | |
| 89 | try |
| 90 | { |
| 91 | // create database |
| 92 | att = prov->createDatabase(&status, "blob_07.fdb", 0, NULL); |
| 93 | tra = att->startTransaction(&status, 0, NULL); |
| 94 | |
| 95 | // create table |
| 96 | att->execute(&status, tra, 0, "create table blobs_table (b blob sub_type text)", SAMPLES_DIALECT, |
| 97 | NULL, NULL, NULL, NULL); |
| 98 | tra->commitRetaining(&status); |
| 99 | |
| 100 | // Message for data exchange |
| 101 | FB_MESSAGE(Msg, ThrowStatusWrapper, |
| 102 | (FB_BLOB, b) |
| 103 | ) message(&status, master); |
| 104 | message.clear(); |
| 105 | |
| 106 | // create blob |
| 107 | blob = att->createBlob(&status, tra, &message->b, 0, NULL); |
| 108 | |
| 109 | // populate blob with data |
| 110 | for (const char** seg = testData; *seg; ++seg) |
| 111 | blob->putSegment(&status, strlen(*seg), *seg); |
| 112 | blob->close(&status); |
| 113 | blob = NULL; |
| 114 | |
| 115 | // insert blob into the table |
| 116 | att->execute(&status, tra, 0, "insert into blobs_table(b) values(?)", SAMPLES_DIALECT, |
| 117 | message.getMetadata(), message.getData(), NULL, NULL); |
| 118 | tra->commitRetaining(&status); |
| 119 | printf("Test blob inserted into blobs_table\n...\n"); |
| 120 | |
| 121 | // Read blob from table |
| 122 | message.clear(); |
| 123 | att->execute(&status, tra, 0, "select first(1) b from blobs_table", SAMPLES_DIALECT, |
| 124 | NULL, NULL, message.getMetadata(), message.getData()); |
| 125 | blob = att->openBlob(&status, tra, &message->b, 0, NULL); |
| 126 | |
| 127 | // Read segments from blob |
| 128 | // Use very small segment buffer to show read of incomplete segment |
| 129 | printf("Read inserted blob from blobs_table\n...\n"); |
nothing calls this directly
no test coverage detected