| 177 | }; |
| 178 | |
| 179 | void load(CheckStatusWrapper* status, ISC_QUAD* blobId, IAttachment* att, ITransaction* tra, FILE* file) |
| 180 | { |
| 181 | /************************************** |
| 182 | * |
| 183 | * l o a d |
| 184 | * |
| 185 | ************************************** |
| 186 | * |
| 187 | * Functional description |
| 188 | * Load a blob from a file. |
| 189 | * |
| 190 | **************************************/ |
| 191 | LocalStatus ls; |
| 192 | CheckStatusWrapper temp(&ls); |
| 193 | |
| 194 | // Open the blob. If it failed, what the hell -- just return failure |
| 195 | IBlob* blob = att->createBlob(status, tra, blobId, 0, NULL); |
| 196 | if (status->getState() & Firebird::IStatus::STATE_ERRORS) |
| 197 | return; |
| 198 | |
| 199 | // Copy data from file to blob. Make up boundaries at end of line. |
| 200 | TEXT buffer[512]; |
| 201 | TEXT* p = buffer; |
| 202 | const TEXT* const buffer_end = buffer + sizeof(buffer); |
| 203 | |
| 204 | for (;;) |
| 205 | { |
| 206 | const SSHORT c = fgetc(file); |
| 207 | if (feof(file)) |
| 208 | break; |
| 209 | |
| 210 | *p++ = static_cast<TEXT>(c); |
| 211 | |
| 212 | if (c != '\n' && p < buffer_end) |
| 213 | continue; |
| 214 | |
| 215 | const SSHORT l = p - buffer; |
| 216 | |
| 217 | blob->putSegment(status, l, buffer); |
| 218 | if (status->getState() & Firebird::IStatus::STATE_ERRORS) |
| 219 | { |
| 220 | blob->close(&temp); |
| 221 | return; |
| 222 | } |
| 223 | |
| 224 | p = buffer; |
| 225 | } |
| 226 | |
| 227 | const SSHORT l = p - buffer; |
| 228 | if (l != 0) |
| 229 | blob->putSegment(status, l, buffer); |
| 230 | |
| 231 | blob->close(&temp); |
| 232 | return; |
| 233 | } |
| 234 | |
| 235 | void dump(CheckStatusWrapper* status, ISC_QUAD* blobId, IAttachment* att, ITransaction* tra, FILE* file) |
| 236 | { |
no test coverage detected