static rc_t OpenTableAndCursor(VDatabase *db, VTable **ptbl, VCursor **pcurs, uint32_t cid[], unsigned ncols) { rc_t rc = VDatabaseCreateTable(db, ptbl, "READ_STATS", kcmCreate | kcmMD5, "READ_STATS"); if (rc == 0) { rc = VTableColumnCreateParams(*ptbl, kcmCreate, kcsCRC32, 0); if (rc == 0) { rc = VTableCreateCursorWrite(*ptbl, &pcurs, kcmInsert); if (rc == 0) { unsigned i; for (i = 0; i < ncols && rc == 0; ++i) { rc = VCursorAddColumn(*pcurs, &cid[i], column_name[i]); } if (rc == 0) { rc = VCursorOpen(*pcurs); if (rc == 0) return 0; } VCursorRelease(*pcurs); } } VTableRelease(*ptbl); } *pcurs = NULL; *ptbl = NULL; return rc; }
LIB_EXPORT rc_t CC SRAMgrVCreateTable ( SRAMgr *self, SRATable **rslt, const char *typespec, const char *spec, va_list args ) { rc_t rc; if ( rslt == NULL ) rc = RC ( rcSRA, rcTable, rcConstructing, rcParam, rcNull ); else { if ( self == NULL ) rc = RC ( rcSRA, rcTable, rcConstructing, rcSelf, rcNull ); else if ( spec == NULL ) rc = RC ( rcSRA, rcTable, rcConstructing, rcString, rcNull ); else if ( spec [ 0 ] == 0 ) rc = RC ( rcSRA, rcTable, rcConstructing, rcString, rcEmpty ); else { char path [ 4097 ]; size_t act_size = 0; rc = string_vprintf(path, 4097, &act_size, spec, args); path[act_size] = '\0'; if ( rc == 0 ) { VTable *vtbl; rc = VDBManagerCreateTable ( self -> vmgr, & vtbl, self -> schema, typespec, ( self -> mode & kcmBitMask ) | kcmCreate, "%s", path ); if ( rc == 0 ) { rc = VTableColumnCreateParams ( vtbl, kcmCreate, kcsCRC32, 0 ); if ( rc == 0 ) { SRATable *tbl = calloc ( 1, sizeof * tbl ); if ( tbl == NULL ) rc = RC ( rcSRA, rcTable, rcConstructing, rcMemory, rcExhausted ); else { tbl -> vtbl = vtbl; rc = VTableOpenMetadataUpdate ( vtbl, & tbl -> meta ); if ( rc == 0 ) rc = KMetadataVersion ( tbl -> meta, & tbl -> metavers ); if ( rc == 0 ) rc = VTableCreateCursorWrite ( vtbl, & tbl -> curs, kcmInsert ); if ( rc == 0 ) { tbl -> mgr = SRAMgrAttach ( self ); tbl -> mode = self -> mode; tbl -> read_only = false; KRefcountInit ( & tbl -> refcount, 1, "SRATable", "OpenTableUpdate", path ); VectorInit ( & tbl -> wcol, 0, 16 ); * rslt = tbl; return 0; } vtbl = NULL; SRATableWhack ( tbl ); } } VTableRelease ( vtbl ); } } } * rslt = NULL; } return rc; }