static rc_t static_read(void) { rc_t rc; VDBManager *vmgr; rc = VDBManagerMakeUpdate ( & vmgr, 0 ); if ( rc != 0 ) LOGERR ( klogInt, rc, "failed to make VDB manager" ); else { const VTable *vtbl; rc = VDBManagerOpenTableRead(vmgr, &vtbl, 0, table_path ); if ( rc != 0 ) { PLOGERR ( klogErr, (klogErr, rc, "failed to $(cmode) table '$(path)'" , "cmode=%s,path=%s" , "open" , table_path )); } else { const VCursor *curs; rc = VTableCreateCursorRead(vtbl, &curs); if (rc == 0) { uint32_t idx; rc = VCursorAddColumn(curs, &idx, "bar"); if (rc == 0) { rc = VCursorOpen(curs); if (rc == 0) { int i; for (i = 0; rc == 0 && i != 10; ++i) { rc = VCursorOpenRow(curs); if (rc == 0) { char buffer[1024]; uint32_t len; rc = VCursorRead(curs, idx, 8, buffer, sizeof(buffer), &len); assert(len == strlen(buff)); assert(memcmp(buff, buffer, len) == 0); } VCursorCloseRow(curs); } } else { PLOGERR ( klogErr, (klogErr, rc, "failed to $(cmode) cursor" , "cmode=open" )); } } else { PLOGERR ( klogErr, (klogErr, rc, "failed to add column $(col)" , "col=bar" )); } VCursorRelease(curs); } else { PLOGERR ( klogErr, (klogErr, rc, "failed to $(cmode) cursor" , "cmode=create" )); } VTableRelease(vtbl); } VDBManagerRelease(vmgr); } return rc; }
rc_t run_test (VTable * table, test_params * pb) { VCursor * cursor; const VCursor * rcursor; int64_t ix; int64_t rowid; uint32_t dat; uint32_t len; uint32_t clen; uint32_t plen; rc_t rc; rc_t orc; uint8_t b [BUFSIZE]; cursor = NULL; do { if (verbose) printf ("%s call open_write_cursot\n", __func__); rc = open_write_cursor (table, &cursor, &dat, &len, pb->dat_name, pb->len_name); if (rc) { LOGERR (klogDebug1, rc, "failed to create write cursor"); cursor = NULL; break; } for (ix = 0; ix < Limit; ++ix) { if (verbose) printf ("%s call VCursorOpenRow\n", __func__); rc = VCursorOpenRow (cursor); if (rc) { LOGERR (klogErr, rc, "Failed to Open Cursor"); break; } else { uint32_t c[1]; pb->func(ix, b, c); if (verbose) printf ("%s call VCursorWrite %" LD64 "\n", __func__, ix); rc = VCursorWrite (cursor, dat, pb->bits, b, 0, *c); if (rc) { pLOGERR (klogErr, rc, "Write fail dat row $(R)", PLOG_I64(R), ix); break; } if (verbose) printf ("%s call VCursorWrite %" LD64 "\n", __func__, ix); rc = VCursorWrite (cursor, len, 32, &c, 0, 1); if (rc) { pLOGERR (klogErr, rc, "Write fail len row $(R)", PLOG_I64(R), ix); break; } if (verbose) printf ("%s call VCursorCommitRow\n", __func__); rc = VCursorCommitRow (cursor); if (rc) { pLOGERR (klogErr, rc, "Commit fail row $(R)", PLOG_I64(R), ix); break; } if (verbose) printf ("%s call VCursorCloseRow\n", __func__); rc = VCursorCloseRow (cursor); if (rc) { pLOGERR (klogErr, orc, "Commit fail row $(R)", PLOG_I64(R), ix); break; } } if (rc) break; } /* for (ix = 0; ix < Limit; ++ix) */ if (ix != Limit) fprintf (stderr, "Quit early %d\n", (int)ix); if (rc) { pLOGERR (klogInfo, rc, "failed in loop $(T) $(R)", PLOG_2(PLOG_S(T),PLOG_I64(R)), pb->test_name, ix); } else { if (verbose) printf ("%s call VCursorCommit\n", __func__); orc = VCursorCommit (cursor); if (orc && (rc == 0)) rc = orc; } if (verbose) printf ("%s call VCursorRelease\n", __func__); orc = VCursorRelease (cursor); if (orc && (rc == 0)) rc = orc; if (rc) break; if (verbose) printf ("%s call open_read_cursor\n",__func__); rc = open_read_cursor (table, &rcursor, &len, &plen, &clen, &dat, pb->len_name, pb->plen_name, pb->clen_name, pb->dat_name); if (rc) { LOGERR (klogErr, rc, "failed to open read cursor"); break; } for (ix = 0; ix < Limit; ++ix) { uint32_t l; uint32_t p; uint32_t c; uint32_t r; uint32_t x; rc = VCursorRowId (rcursor, &rowid); if (rc) { pLOGERR (klogErr, rc, "failed to get rowid $(R)", PLOG_I64(R), ix); break; } if (rowid != ix+1) { fprintf (stderr, "ROWID failure %" LD64 ":%" LD64 "\n", ix, rowid); failed = true; } rc = VCursorOpenRow (rcursor); if (rc) { pLOGERR (klogErr, rc, "failed to open row $(R)", PLOG_I64(R), ix); break; } rc = VCursorRead (rcursor, len, 32, &l, 1, &r); if (rc) { pLOGERR (klogErr, rc, "failed to read column $(N) $(R)", PLOG_2(PLOG_S(N),PLOG_I64(R)), pb->len_name, ix); break; } rc = VCursorRead (rcursor, clen, 32, &c, 1, &r); if (rc) { pLOGERR (klogErr, rc, "failed to read column $(N) $(R)", PLOG_2(PLOG_S(N),PLOG_I64(R)), pb->clen_name, ix); break; } rc = VCursorRead (rcursor, plen, 32, &p, 1, &r); if (rc) { pLOGERR (klogErr, rc, "failed to read column $(N) $(R)", PLOG_2(PLOG_S(N),PLOG_I64(R)), pb->plen_name, ix); break; } /* rc = VCursorReadBits (rcursor, dat, pb->bits, 0, b, 0, (BUFSIZE*8)/pb->bits, &r, &x); if (rc) { pLOGERR (klogErr, rc, "failed to read column $(N) $(R)", PLOG_2(PLOG_S(N),PLOG_I64(R)), pb->dat_name, ix); break; } */ VCursorCloseRow (rcursor); if (l != p) { fprintf (stderr, "error in physical column row_len() %u != %u\n", l, p); failed = true; } if (l != c) { fprintf (stderr, "error in physical column row_len() %u != %u\n", l, c); failed = true; } } if (verbose) printf ("%s call VCursorRelease\n",__func__); orc = VCursorRelease (rcursor); if (orc) { LOGERR (klogErr, rc, "release was funky"); } if (orc && (rc == 0)) rc = orc; if (rc) break; } while (0); return rc; }