/* NewSpot * creates a new spot record, * returning spot id. * * "id" [ OUT ] - return parameter for id of newly created spot */ LIB_EXPORT rc_t CC SRATableNewSpot( SRATable *self, spotid_t *id ) { rc_t rc; if (self == NULL) return RC(RC_MODULE, RC_TARGET, rcInserting, rcSelf, rcNull); if (id == NULL) return RC(RC_MODULE, RC_TARGET, rcInserting, rcParam, rcNull); if (self->curs_open == false) { SRADBG(("opening cursor\n")); rc = VCursorOpen(self->curs); if (rc) return rc; self->curs_open = true; } rc = VCursorOpenRow(self->curs); if (rc == 0) { int64_t rowid; if( (rc = VCursorRowId(self->curs, &rowid)) == 0 ) { *id = rowid; } } return rc; }
static rc_t static_write(void) { const char *schema_text = "version 1; include 'vdb/vdb.vschema'; table foo #1 { column ascii bar { read = .bar; } physical ascii .bar = bar; }"; bool force = 1; rc_t rc; VDBManager *vmgr; rc = VDBManagerMakeUpdate ( & vmgr, NULL ); if ( rc != 0 ) LOGERR ( klogInt, rc, "failed to make VDB manager" ); else { VSchema *schema; rc = VDBManagerMakeSchema ( vmgr, & schema ); if ( rc != 0 ) LOGERR ( klogInt, rc, "failed to make empty schema" ); else { rc = VSchemaParseText( schema, "static_schema", schema_text, strlen(schema_text) ); if ( rc != 0 ) PLOGERR ( klogErr, (klogErr, rc, "failed to parse schema '$(text)'", "test=%s", schema_text )); else { VTable *vtbl; rc = VDBManagerCreateTable ( vmgr, & vtbl, schema, "foo", force ? kcmInit : kcmCreate, table_path ); if ( rc != 0 ) { PLOGERR ( klogErr, (klogErr, rc, "failed to $(cmode) table '$(path)'" , "cmode=%s,path=%s" , force ? "create or replace" : "create" , table_path )); } else { VCursor *curs; rc = VTableCreateCursorWrite ( vtbl, & curs, kcmInsert ); if ( rc != 0 ) LOGERR ( klogInt, rc, "failed to create cursor" ); else { uint32_t idx; rc = VCursorAddColumn ( curs, &idx, "bar" ); if ( rc != 0 ) { PLOGERR ( klogErr, (klogErr, rc, "failed to add column '$(col)' to cursor" , "col=bar" )); } else { rc = VCursorOpen ( curs ); if ( rc != 0 ) LOGERR ( klogErr, rc, "failed to open cursor" ); else { int i; for ( i = 0; i != 10 && rc == 0; ++i ) { rc = VCursorOpenRow ( curs ); if ( rc != 0 ) LOGERR ( klogErr, rc, "failed to open cursor row" ); else { rc_t rc2; uint32_t count = sizeof(buff) - 1; rc = VCursorWrite ( curs, idx, 8, buff, 0, count ); if ( rc != 0 ) { int64_t rid = 0; VCursorRowId ( curs, & rid ); PLOGERR ( klogInt, (klogInt, rc, "failed to write data to row $(row_id)'" , "row_id=%ld" , rid )); break; } if ( rc == 0 ) { rc = VCursorCommitRow ( curs ); if ( rc != 0 ) LOGERR ( klogErr, rc, "failed to commit row" ); } rc2 = VCursorCloseRow ( curs ); if ( rc2 != 0 ) { LOGERR ( klogErr, rc2, "failed to close cursor row" ); if ( rc == 0 ) rc = rc2; } } } if ( GetRCState ( rc ) == rcDone ) rc = 0; if ( rc == 0 ) rc = VCursorCommit ( curs ); } } VCursorRelease ( curs ); } #if 1 if ( rc == 0 ) rc = VTableReindex ( vtbl ); #endif VTableRelease ( vtbl ); } } VSchemaRelease ( schema ); } 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; }