Write a streaming B-tree table from count items, or an empty table if count == 0. */
| 1858 | |
| 1859 | /* Write a streaming B-tree table from count items, or an empty table if count == 0. */ |
| 1860 | static int write_one_table(write_db_ctx_t *w, uint32_t *root, const void *items, int count, |
| 1861 | fill_record_fn fill_rec, get_rowid_fn get_id) { |
| 1862 | if (count <= 0 || !items) { |
| 1863 | *root = write_table_btree(w->fp, &w->next_page, NULL, NULL, NULL, 0, false); |
| 1864 | return 0; |
| 1865 | } |
| 1866 | PageBuilder pb; |
| 1867 | pb_init(&pb, w->fp, w->next_page, false); |
| 1868 | for (int i = 0; i < count; i++) { |
| 1869 | RecordBuilder r; |
| 1870 | rec_init(&r); |
| 1871 | fill_rec(&r, items, i); |
| 1872 | int64_t rowid = get_id(items, i); |
| 1873 | int64_t prev_id = i > 0 ? get_id(items, i - SKIP_ONE) : 0; |
| 1874 | bool placed = pb_add_table_record_with_flush(&pb, rowid, &r, prev_id); |
| 1875 | rec_free(&r); |
| 1876 | if (!placed) { |
| 1877 | pb_free(&pb); |
| 1878 | return ERR_WRITE_FAILED; |
| 1879 | } |
| 1880 | } |
| 1881 | *root = pb_finalize_table(&pb, &w->next_page, get_id(items, count - SKIP_ONE)); |
| 1882 | return 0; |
| 1883 | } |
| 1884 | |
| 1885 | /* Adapter functions for write_one_table (nodes are written via the streaming |
| 1886 | * PageBuilder in cbm_writer_append_nodes, so no node adapter is needed here). */ |
no test coverage detected