| 178 | |
| 179 | |
| 180 | bool blb::BLB_close(thread_db* tdbb) |
| 181 | { |
| 182 | /************************************** |
| 183 | * |
| 184 | * b l b : : c l o s e |
| 185 | * |
| 186 | ************************************** |
| 187 | * |
| 188 | * Functional description |
| 189 | * Close a blob. If the blob is open for retrieval, release the |
| 190 | * blob block. If it's a temporary blob, flush out the last page |
| 191 | * (if necessary) in preparation for materialization. |
| 192 | * Return true if the blob was physically destroyed. |
| 193 | * |
| 194 | **************************************/ |
| 195 | |
| 196 | SET_TDBB(tdbb); |
| 197 | |
| 198 | const bool alreadyClosed = (blb_flags & BLB_closed); |
| 199 | |
| 200 | // Release filter control resources |
| 201 | |
| 202 | if (blb_filter) |
| 203 | BLF_close_blob(tdbb, &blb_filter); |
| 204 | |
| 205 | blb_flags &= ~BLB_close_on_read; |
| 206 | blb_flags |= BLB_closed; |
| 207 | |
| 208 | if (!(blb_flags & BLB_temporary)) |
| 209 | { |
| 210 | destroy(true); |
| 211 | return true; |
| 212 | } |
| 213 | |
| 214 | if (!alreadyClosed) |
| 215 | blb_transaction->tra_temp_blobs_count--; |
| 216 | |
| 217 | if (blb_level == 0) |
| 218 | { |
| 219 | //Database* dbb = tdbb->getDatabase(); |
| 220 | |
| 221 | blb_temp_size = blb_clump_size - blb_space_remaining; |
| 222 | |
| 223 | if (blb_temp_size > 0) |
| 224 | { |
| 225 | blb_temp_size += BLP_SIZE; |
| 226 | TempSpace* const tempSpace = blb_transaction->getBlobSpace(); |
| 227 | |
| 228 | blb_temp_offset = tempSpace->allocateSpace(blb_temp_size); |
| 229 | tempSpace->write(blb_temp_offset, getBuffer(), blb_temp_size); |
| 230 | } |
| 231 | } |
| 232 | else if (blb_level >= 1 && blb_space_remaining < blb_clump_size) |
| 233 | { |
| 234 | insert_page(tdbb); |
| 235 | } |
| 236 | |
| 237 | freeBuffer(); |
no test coverage detected