void test_db() { // Create a database with the default options. auto db = grnxx::open_db(""); assert(db->num_tables() == 0); // Create a table named "Table_1". auto table = db->create_table("Table_1"); assert(table->name() == "Table_1"); assert(db->num_tables() == 1); assert(db->get_table(0) == table); assert(db->find_table("Table_1") == table); assert(!db->find_table("Table_X")); // The following create_table() must fail because "Table_1" already exists. try { db->create_table("Table_1"); assert(false); } catch (...) { } // Create tables named "Table_2" and "Table_3". assert(db->create_table("Table_2")); assert(db->create_table("Table_3")); assert(db->num_tables() == 3); assert(db->get_table(0)->name() == "Table_1"); assert(db->get_table(1)->name() == "Table_2"); assert(db->get_table(2)->name() == "Table_3"); // Remove "Table_2". db->remove_table("Table_2"); assert(db->num_tables() == 2); assert(db->get_table(0)->name() == "Table_1"); assert(db->get_table(1)->name() == "Table_3"); // Recreate "Table_2". assert(db->create_table("Table_2")); // Move "Table_3" to the next to "Table_2". db->reorder_table("Table_3", "Table_2"); assert(db->get_table(0)->name() == "Table_1"); assert(db->get_table(1)->name() == "Table_2"); assert(db->get_table(2)->name() == "Table_3"); // Move "Table_3" to the head. db->reorder_table("Table_3", ""); assert(db->get_table(0)->name() == "Table_3"); assert(db->get_table(1)->name() == "Table_1"); assert(db->get_table(2)->name() == "Table_2"); // Move "Table_2" to the next to "Table_3". db->reorder_table("Table_2", "Table_3"); assert(db->get_table(0)->name() == "Table_3"); assert(db->get_table(1)->name() == "Table_2"); assert(db->get_table(2)->name() == "Table_1"); }
static const char* get_charcode_name_by_locale(const char* const name) { if (find_table(name, LOCALE_UTF8_TABLE)) return NULL; else if (find_table(name, LOCALE_EUC_TABLE)) return CS_EUCJP; else if (find_table(name, LOCALE_SJIS_TABLE)) return CS_SJIS; else return NULL; }
Retcode usb_install_keyboard_driver(Environ *e, Package *pkg, USB_self *usb, usb_device_descriptor_t *dev, usb_config_descriptor_t *cfg, usb_interface_descriptor_t *ifc) { Retcode ret; Byte name[STR_SIZE]; DPRINTF(("usb_install_keyboard_driver: addr=%d interface=%d\n", usb->addr, usb->interface)); ret = prop_set_str(pkg->props, "device_type", CSTR, "keyboard", CSTR); if (ret == NO_ERROR) ret = init_entries(e, pkg->dict, usb_kbd_methods); /* make keyboard aliases if none already exist */ if (ret == NO_ERROR) (void)get_device_name(e, pkg, name); if (ret == NO_ERROR && find_table(e->aliases->props, "keyboard", CSTR) == NULL) ret = make_devalias(e, "keyboard", CSTR, name, CSTR); if (ret == NO_ERROR && find_table(e->aliases->props, "usbkeyboard", CSTR) == NULL) ret = make_devalias(e, "usbkeyboard", CSTR, name, CSTR); /* set config descriptor 0 to turn on keyboard */ ret = usb_setup(e, usb, usb->addr, USB_CONTROL_ENDPOINT, UT_WRITE_DEVICE, UR_SET_CONFIG, 0, cfg->configuration_value, 0, 0, NULL); /* set keyboard to boot protocol (0) */ if (ret == NO_ERROR) ret = usb_setup(e, usb, usb->addr, USB_CONTROL_ENDPOINT, UT_WRITE_CLASS_INTERFACE, UR_SET_PROTOCOL, 0, 0, usb->interface, 0, NULL); if (ret == NO_ERROR) ret = usb_setup(e, usb, usb->addr, USB_CONTROL_ENDPOINT, UT_WRITE_CLASS_INTERFACE, UR_SET_IDLE, 0, 0, usb->interface, 0, NULL); return ret; }
/* ===================== CL_TableDeleteRow ===================== */ static void CL_TableDeleteRow( void ) { tableInfo_t * table = find_table( &cl.db, Cmd_Argv( 1 ) ); if ( table && table->rows ) { const int i = atoi( Cmd_Argv( 2 ) ); cellInfo_t * row = table->rows + (i*table->column_count); const int lastrow = table->row_count-1; if ( cl.db.delete_trigger ) { cl.db.delete_trigger( &cl.db, table, i ); } if ( i == -1 ) { table->row_count = 0; table->last_changed++; } else { memmove( row, row + table->column_count, (lastrow-i) * table->column_count * sizeof(cellInfo_t) ); table->row_count--; table->last_changed++; } if ( uivm ) { Cmd_TokenizeString( va("st_table %s", table->name) ); VM_Call( uivm, UI_CONSOLE_COMMAND, cls.realtime ); } } }
stmtInfo_t * sql_delete_parse( sqlInfo_t * db, const char ** s ) { deleteInfo_t * del = sql_calloc_stmt( db, sizeof(deleteInfo_t) ); del->stmt.type = SQL_DELETE; // 'FROM' if ( SWITCHSTRING( parse_temp( s ) ) == CS('f','r','o','m') ) { del->stmt.table = find_table( db, parse_temp( s ) ); } else return 0; switch ( SWITCHSTRING( parse_temp( s ) ) ) { // 'SEARCH' case CS('s','e','a','r'): Com_Error( ERR_FATAL, "DELETE statement does not support SEARCH.\n" ); break; // 'WHERE' case CS('w','h','e','r'): { parseInfo_t pi = { 0 }; pi.db = db; pi.table = del->stmt.table; pi.params = del->stmt.params; del->where_expr = parse_expression( s, &pi ); } break; } return &del->stmt; }
// Set default policy for an iptables table. static int __lua_iptc_set_policy(lua_State *L) { int i, r; struct ipt_counters counters; const char *table = luaL_checkstring(L, 1); const char *chain = luaL_checkstring(L, 2); const char *policy = luaL_checkstring(L, 3); i = find_table(table); if(i == -1) return eprintf("Invalid table: %s", table); if(!tables[i].handle) return eprintf("Invalid table: %s", table); memset(&counters, 0, sizeof(struct ipt_counters)); r = iptc_set_policy(chain, policy, &counters, tables[i].handle); if(!r) { return eprintf("Unable to set policy to %s: %s: %s", policy, table, chain); } return 0; }
// Iptables command. Essentially the same as the command line version. static int __lua_iptables(lua_State *L) { int i, r; char *rule_copy = NULL; const char *table = luaL_checkstring(L, 1); const char *rule = luaL_checkstring(L, 2); i = find_table(table); if(i == -1) return eprintf("Invalid table: %s", table); if(!tables[i].handle) return eprintf("Invalid table: %s", table); if(debug) syslog(LOG_DEBUG, "iptables -t %s %s", table, rule); rule_copy = strdup(rule); argv_parse(table, rule_copy); r = do_command(iptc_argc, iptc_argv, &iptc_argv[2], &tables[i].handle); if(!r) return eprintf("iptables -t %s %s", table, rule); argv_free(); free(rule_copy); return 0; }
// Commit table changes. static int __lua_iptc_commit(lua_State *L) { int i, r; const char *table = luaL_checkstring(L, 1); i = find_table(table); if(i == -1) return eprintf("Invalid table: %s", table); if(!tables[i].handle) return eprintf("Invalid table: %s", table); if(pretend) return 0; r = iptc_commit(tables[i].handle); tables[i].handle = NULL; if(!r) { return eprintf("Unable to commit: %s: %s.", table, iptc_strerror(errno)); } return 0; }
// Recursive delete of all iptables chains. static int __lua_iptc_flush_all_chains(lua_State *L) { int i, r; const char *chain; const char *table = luaL_checkstring(L, 1); i = find_table(table); if(i == -1) return eprintf("Invalid table: %s", table); if(!tables[i].handle) return eprintf("Invalid table: %s", table); chain = iptc_first_chain(tables[i].handle); while(chain) { r = iptc_flush_entries(chain, tables[i].handle); if(!r) return eprintf("Unable to flush chain: %s: %s", table, chain); chain = iptc_next_chain(tables[i].handle); } return 0; }
static int cache_conditional_string(char *linebuf) { char table_name[256]; char junk[256]; char *paren, string[256]; TABLE *table; if (sscanf(linebuf, "%s%s%*s", table_name, junk) < 2) { printf("Conditional string entry not of form <table_name> <string>: %s\n", linebuf); return PARSE_ERROR; } if ((paren = strchr(linebuf, '(')) == NULL) { printf("String must be delimited by parens: %s\n", linebuf); return PARSE_ERROR; } strcpy(string, paren + 1); if ((paren = strrchr(string, ')')) == NULL) { printf("String must be delimited by parens: %s\n", linebuf); return PARSE_ERROR; } *paren = '\0'; table = find_table(table_name, tables); if (!table || !HasConditional(table)) { printf("Cannot have conditional string for %s: not a conditional table.\n", table_name); return BAD_DATA_ERROR; } else { table->conditional_string = strdup_no_leading_or_trailing_blanks(string); return OK; } }
int ai_findandset_imatch(as_sindex_metadata *imd, as_sindex_pmetadata *pimd, int idx) { if (!Num_tbls) { return AS_SINDEX_ERR; } char *tname = NULL, *cname = NULL, *iname = NULL; int ret = AS_SINDEX_OK; if (!(tname = create_tname_from_imd(imd))) { return AS_SINDEX_ERR_NO_MEMORY; } ret = AS_SINDEX_ERR; AI_GRLOCK(); int tmatch = find_table(tname); if (tmatch == -1) { goto END; } if (imd->iname) { if (!(iname = get_iname_from_imd(imd))) { ret = AS_SINDEX_ERR_NO_MEMORY; goto END; } char idx_str[NAME_STR_LEN]; snprintf(idx_str, sizeof(idx_str), "%d", idx); char *piname = str_concat(iname, '.', idx_str); pimd->imatch = match_partial_index_name(piname); cf_free(piname); } else { if (!(cname = create_cname_from_imd(imd))) { ret = AS_SINDEX_ERR_NO_MEMORY; goto END; } icol_t *ic = find_column(tmatch, cname); if (!ic) { goto END; } pimd->imatch = find_partial_index(tmatch, ic); } if (pimd->imatch == -1) { SITRACE(imd->si, META, debug, "Index%s: %s not found", imd->iname ? "" : "column-name", imd->iname ? iname : cname); goto END; } ret = AS_SINDEX_OK; END: AI_UNLOCK(); cf_free(tname); cf_free(iname); cf_free(cname); return ret; }
//prints table void Database::show(string table_name){ if(table_exists(table_name)){ find_table(table_name)->print(); } else throw runtime_error("Error: Table not found\n"); }
static int xc_dom_load_bin_kernel(struct xc_dom_image *dom) { struct xen_bin_image_table *image_info; char *image = dom->kernel_blob; char *dest; size_t image_size = dom->kernel_size; uint32_t start_addr; uint32_t load_end_addr; uint32_t bss_end_addr; uint32_t skip, text_size, bss_size; image_info = find_table(dom); if ( !image_info ) return -EINVAL; start_addr = image_info->header_addr - ((char *)image_info - image); load_end_addr = image_info->load_end_addr ?: start_addr + image_size; bss_end_addr = image_info->bss_end_addr ?: load_end_addr; /* It's possible that we need to skip the first part of the image */ skip = image_info->load_addr - start_addr; text_size = load_end_addr - image_info->load_addr; bss_size = bss_end_addr - load_end_addr; xc_dom_printf("%s: calculated sizes\n", __FUNCTION__); xc_dom_printf(" skip: 0x%" PRIx32 "\n", skip); xc_dom_printf(" text_size: 0x%" PRIx32 "\n", text_size); xc_dom_printf(" bss_size: 0x%" PRIx32 "\n", bss_size); dest = xc_dom_vaddr_to_ptr(dom, dom->kernel_seg.vstart); memcpy(dest, image + skip, text_size); memset(dest + text_size, 0, bss_size); return 0; }
int myrg_rrnd(MYRG_INFO *info,byte *buf,ulonglong filepos) { int error; MI_INFO *isam_info; DBUG_ENTER("myrg_rrnd"); DBUG_PRINT("info",("offset: %lu", (ulong) filepos)); if (filepos == HA_OFFSET_ERROR) { if (!info->current_table) { if (info->open_tables == info->end_table) { /* No tables */ DBUG_RETURN(my_errno=HA_ERR_END_OF_FILE); } isam_info=(info->current_table=info->open_tables)->table; if (info->cache_in_use) mi_extra(isam_info,HA_EXTRA_CACHE); filepos=isam_info->s->pack.header_length; isam_info->lastinx= (uint) -1; /* Can't forward or backward */ } else { isam_info=info->current_table->table; filepos= isam_info->nextpos; } for (;;) { isam_info->update&= HA_STATE_CHANGED; if ((error=(*isam_info->s->read_rnd)(isam_info,(byte*) buf, (my_off_t) filepos,1)) != HA_ERR_END_OF_FILE) DBUG_RETURN(error); if (info->cache_in_use) mi_extra(info->current_table->table,HA_EXTRA_NO_CACHE); if (info->current_table+1 == info->end_table) DBUG_RETURN(HA_ERR_END_OF_FILE); info->current_table++; info->last_used_table=info->current_table; if (info->cache_in_use) mi_extra(info->current_table->table,HA_EXTRA_CACHE); info->current_table->file_offset= info->current_table[-1].file_offset+ info->current_table[-1].table->state->data_file_length; isam_info=info->current_table->table; filepos=isam_info->s->pack.header_length; isam_info->lastinx= (uint) -1; } } info->current_table=find_table(info->open_tables, info->end_table-1,filepos); isam_info=info->current_table->table; isam_info->update&= HA_STATE_CHANGED; DBUG_RETURN((*isam_info->s->read_rnd) (isam_info, (byte*) buf, (my_off_t) (filepos - info->current_table->file_offset), 0)); }
//在指定列添加记录,列数组以空结束 int add_record2(string & table_name,string col_name[], string col_record[]) { if(isExit_table(table_name)) { if(isExit_column2(table_name, col_name)) { struct record new_record = { {-65535}, {-65535}, {"#"} }; list<table>::iterator iter = find_table(table_name); // 指向表的指示器 (*iter).table_c.push_back(new_record); //将新的记录添加到表中 update_table_last(table_name, col_name, col_record); return 0; } else { cout << "error" << endl; return -1; } } else { cout << "error" << endl; return -1; } }
actuarial_table::actuarial_table(std::string const& filename, int table_number) :filename_ (filename) ,table_number_ (table_number) ,table_type_ (-1) ,min_age_ (-1) ,max_age_ (-1) ,select_period_ (-1) ,max_select_age_ (-1) ,table_offset_ (-1) { if(table_number_ <= 0) { fatal_error() << "There is no table number " << table_number_ << " in file '" << filename_ << "'." << LMI_FLUSH ; } find_table(); parse_table(); }
int mrg_rrnd(MRG_INFO *info,byte *buf,mrg_off_t filepos) { int error; N_INFO *isam_info; if (filepos == ~(mrg_off_t) 0) /* Can't use HA_POS_ERROR */ { if (!info->current_table) { if (info->open_tables == info->end_table) { /* No tables */ my_errno=HA_ERR_END_OF_FILE; return -1; } isam_info=(info->current_table=info->open_tables)->table; if (info->cache_in_use) nisam_extra(isam_info,HA_EXTRA_CACHE); filepos=isam_info->s->pack.header_length; isam_info->lastinx= (uint) -1; /* Can't forward or backward */ } else { isam_info=info->current_table->table; filepos= isam_info->nextpos; } for (;;) { isam_info->update&= HA_STATE_CHANGED; if ((error=(*isam_info->s->read_rnd)(isam_info,(byte*) buf, filepos,1)) >= 0 || my_errno != HA_ERR_END_OF_FILE) return (error); if (info->cache_in_use) nisam_extra(info->current_table->table,HA_EXTRA_NO_CACHE); if (info->current_table+1 == info->end_table) return(-1); info->current_table++; info->last_used_table=info->current_table; if (info->cache_in_use) nisam_extra(info->current_table->table,HA_EXTRA_CACHE); info->current_table->file_offset= info->current_table[-1].file_offset+ info->current_table[-1].table->s->state.data_file_length; isam_info=info->current_table->table; filepos=isam_info->s->pack.header_length; isam_info->lastinx= (uint) -1; } } info->current_table=find_table(info->open_tables, info->end_table-1,filepos); isam_info=info->current_table->table; isam_info->update&= HA_STATE_CHANGED; return ((*isam_info->s->read_rnd)(isam_info,(byte*) buf, (ulong) (filepos - info->current_table->file_offset), 0)); }
/* * Get better charcode name. */ static const char* get_charcode_name() { const char* result = NULL; const char* lang = NULL; switch(Kcode) { case 'E': result = CS_EUCJP; break; case 'S': #if defined _WIN32 || defined __CYGWIN__ result = CS_CP932; #else result = CS_SJIS; #endif break; case 'U': //as is. break; case 'N': default: #if defined _WIN32 || defined __CYGWIN__ if (932 == GetACP()) result = CS_CP932; #elif defined HAVE_NL_LANGINFO setlocale(LC_ALL, "C"); //initialize lang = nl_langinfo(CODESET); if (find_table(lang, NL_EUC_TABLE)) result = CS_EUCJP; else if (find_table(lang, NL_SJIS_TABLE)) result = CS_SJIS; #elif defined HAVE_SETLOCALE setlocale(LC_ALL, "C"); //initialize result = get_charcode_name_by_locale(setlocale(LC_ALL, NULL)); #elif defined HAVE_GETENV if (result = get_charcode_name_by_locale(getenv("LC_ALL"))) ; else if (result = get_charcode_name_by_locale(getenv("LC_CTYPE"))) ; else if (result = get_charcode_name_by_locale(getenv("LANG"))) ; #endif break; } return result; }
static int xc_dom_load_bin_kernel(struct xc_dom_image *dom) { struct xen_bin_image_table *image_info; char *image = dom->kernel_blob; char *dest; size_t image_size = dom->kernel_size; size_t dest_size; uint32_t start_addr; uint32_t load_end_addr; uint32_t bss_end_addr; uint32_t skip, text_size, bss_size; image_info = find_table(dom); if ( !image_info ) return -EINVAL; start_addr = image_info->header_addr - ((char *)image_info - image); load_end_addr = image_info->load_end_addr ?: start_addr + image_size; bss_end_addr = image_info->bss_end_addr ?: load_end_addr; /* It's possible that we need to skip the first part of the image */ skip = image_info->load_addr - start_addr; text_size = load_end_addr - image_info->load_addr; bss_size = bss_end_addr - load_end_addr; DOMPRINTF("%s: calculated sizes", __FUNCTION__); DOMPRINTF(" skip: 0x%" PRIx32 "", skip); DOMPRINTF(" text_size: 0x%" PRIx32 "", text_size); DOMPRINTF(" bss_size: 0x%" PRIx32 "", bss_size); dest = xc_dom_vaddr_to_ptr(dom, dom->kernel_seg.vstart, &dest_size); if ( dest == NULL ) { DOMPRINTF("%s: xc_dom_vaddr_to_ptr(dom, dom->kernel_seg.vstart)" " => NULL", __FUNCTION__); return -EINVAL; } if ( dest_size < text_size || dest_size - text_size < bss_size ) { DOMPRINTF("%s: mapped region is too small for image", __FUNCTION__); return -EINVAL; } if ( image_size < skip || image_size - skip < text_size ) { DOMPRINTF("%s: image is too small for declared text size", __FUNCTION__); return -EINVAL; } memcpy(dest, image + skip, text_size); memset(dest + text_size, 0, bss_size); return 0; }
Table *DB::create_table(const String &name, const TableOptions &options) { if (find_table(name)) { throw "Table already exists"; // TODO } tables_.reserve(num_tables() + 1); std::unique_ptr<Table> new_table = Table::create(this, name, options); tables_.push_back(std::move(new_table)); return tables_.back().get(); }
Table Database::get_table(string table_name){ if(table_exists(table_name)){ return *find_table(table_name); } else{ cout<<"Error: Table not found: "+table_name+"\n"; return Table("NULL"); } }
static int del_route(const struct zone *zone, const struct babel_route *route) { int table = find_table(zone->dst_prefix, zone->dst_plen, zone->src_prefix, zone->src_plen); return kernel_route(ROUTE_FLUSH, table, zone->dst_prefix, zone->dst_plen, zone->src_prefix, zone->src_plen, route->nexthop, route->neigh->ifp->ifindex, metric_to_kernel(route_metric(route)), NULL, 0, 0, 0); }
//insert a record into a table in tables void Database::insert(string table_name, Record record){ if(table_exists(table_name)){ Table* t = find_table(table_name); if(t->is_valid(record)) t->add_record(record); else throw runtime_error("Record is not compatible with table"); } else throw runtime_error("Error: Table not found\n"); }
void Database::update(string table_name,vector<Record> new_records,vector<int> old_records){ if(table_exists(table_name)){ for(int i = 0; i < new_records.size(); i++){ find_table(table_name)->set_record(old_records[i], new_records[i]); } } else throw runtime_error("Error: Table not found\n"); }
void DB::rename_table(const String &name, const String &new_name) { size_t table_id; if (!find_table_with_id(name, &table_id)) { throw "Table not found"; // TODO } if (name == new_name) { return; } if (find_table(new_name)) { throw "Table already exists"; // TODO } tables_[table_id]->rename(new_name); }
static int mark_table_as_conditional(char *linebuf) { TABLE *table; char table_name[256]; int index; if (parse_table_and_index(linebuf, table_name, &index) != OK) return PARSE_ERROR; if ((table = find_table(table_name, tables)) == NULL) { printf("Conditional table %s not included in Tables\n", table_name); return PARSE_ERROR; } table->is_conditional[index] = TRUE; return OK; }
bool isExit_column(string table_name, string col_name) { list<table>::iterator iter_table = find_table(table_name); int i = 0; while("" != (*iter_table).properity[i]) { if(0 == _stricmp(col_name.c_str(), (*iter_table).properity[i].c_str())) { return true; } i++; } return false; }
int append_field(FIELD **list, char *table_name, char *field_name, FIELD_TYPE type, char null_allowable, TABLE *table_list, int index) { FIELD *last, *item = (FIELD *)calloc(1, sizeof(FIELD)); TABLE *table; if (!item) return SYSTEM_ERROR; item->next = NULL; item->index = index; if (field_name) { if (!(item->field_name = (char *)malloc(strlen(field_name) + 1))) return SYSTEM_ERROR; strcpy(item->field_name, field_name); } if (table_name) { if ((table = find_table(table_name, table_list)) == NULL) { fprintf(stderr, "Table %s for field %s not listed\n", table_name, field_name); return BAD_DATA_ERROR; } if (table->multiplicity == 1) { if (index) printf("Problem: Field %s added to table %s with index %d; table has multiplicity 1\n", field_name, table_name, index); } item->table = table; } if (is_xid_type(field_name, table_name) && !is_xid_object) { has_xids = TRUE; if (table->xid_type_name == NULL) { table->xid_type_name = (char *)malloc(strlen(field_name) + 1); strcpy(table->xid_type_name, field_name); } } item->field_type = type; item->null_allowable = null_allowable; if (*list == NULL) *list = item; else { for (last = *list; last->next; last = last->next) ; last->next = item; } return OK; }
static int do_iptables(int argc, char* argv[]) { char *table = "filter"; int ret = 0; if(!find_table(argc, argv)) return 0; #ifdef IP6T ret = do_command6(argc, argv, &table, ¤t_table->handle, true); if (!ret) { fprintf(stderr, "line %d: %s\n", current_line, ip6tc_strerror(errno)); } else { if(!table || strcmp(table, current_table->name)) { fprintf(stderr, "line %d: expected table %s, got %s\n", current_line, current_table->name, table); exit(1); } } #else ret = do_command4(argc, argv, &table, ¤t_table->handle, true); if (!ret) { fprintf(stderr, "line %d: %s\n", current_line, iptc_strerror(errno)); } else { if(!table || strcmp(table, current_table->name)) { fprintf(stderr, "line %d: expected table %s, got %s\n", current_line, current_table->name, table); exit(1); } } #endif return ret; }
// copies records out of a table then over writes it void Database::delete_records(string table_name, vector<int> to_remove){ if(!table_exists(table_name)){ throw runtime_error("Error: Table not found\n"); return; } vector<Record> rec; Table * table = find_table(table_name); for(int i = 0; i < table->rec_size(); i++){ bool found = false; for (int j = 0; j < to_remove.size(); ++j){ if (to_remove[j] == i) found = true; } if (!found) rec.push_back(table->get_record(i)); } table->set_records(rec); }