struct InterCodes* translate_VarDec(struct TreeNode* VarDec){ if(strcmp(VarDec->children->name, "ID") == 0){ printf("VarDec - ID\n"); FieldList item = (FieldList)malloc(sizeof(struct FieldList_)); lookupTable(VarDec->children->value_str,&item,0); if(item->type->kind == structure){ struct InterCodes* code1 = (struct InterCodes*)malloc(sizeof(struct InterCodes)); code1->code.kind = DEC_; code1->code.u.dec.space = (Operand)malloc(sizeof(struct Operand_)); code1->code.u.dec.space->kind = VARIABLE; strcpy(code1->code.u.dec.space->u.ID, item->inter_name); code1->code.u.dec.size = dec_size(item->type); return code1; } } if(strcmp(VarDec->children->name, "RB") == 0){ printf("VarDec - VarDec LB INT RB\n"); FieldList item = (FieldList)malloc(sizeof(struct FieldList_)); lookupTable(VarDec->children->neighbours->neighbours->neighbours->children->value_str,&item,0); struct InterCodes* code1 = (struct InterCodes*)malloc(sizeof(struct InterCodes)); code1->code.kind = DEC_; code1->code.u.dec.space = (Operand)malloc(sizeof(struct Operand_)); code1->code.u.dec.space->kind = VARIABLE; strcpy(code1->code.u.dec.space->u.ID, item->inter_name); code1->code.u.dec.size = dec_size(item->type); } }
void buffer::erase_trailing(size_t num_bytes) { if (num_bytes >= size()) { clear(); } else { dec_size(num_bytes); } }
void buffer::erase_leading(size_t num_bytes) { if (num_bytes >= size()) { clear(); } else { memmove(m_data, m_data + num_bytes, size() - num_bytes); dec_size(num_bytes); } }
void xyzsql_process_delete() { auto s = dynamic_cast<delete_stmt *>(stmt_queue.front().second); if (s->condition_list->empty()) { // delete all system(("rm " + s->table_name + "/*.db").c_str()); RecordManager.createMaster(s->table_name); auto table_info = catm.exist_relation(s->table_name); auto cols = table_info->cols; table_info->set_size(0); for(auto x : *cols) if(x->flag & (table_column::unique_attr | table_column::primary_attr)) IndexManager.createIndex(s->table_name + "/index_" + x->name + ".db", data_type_to_str(x->data_type), x->str_len, 0, {}, {}, {}); } else { auto table_info = catm.exist_relation(s->table_name); int record_size = catm.calc_record_size(s->table_name); BufferManager.newTrashCan(); // unique condition *p = NULL, *eq = NULL; for(auto x : *(s->condition_list)) { if ( catm.is_indexed(x->left_attr) ) { p = x; if (x->op == condition::EQUALTO) eq = x; } } if ( eq != NULL || p != NULL ) { cout << "Index used: " << p->left_attr->full_name << endl; auto t = eq == NULL ? p->left_attr : eq->left_attr; if (eq != NULL) p = eq; indexIterator a; int asdf = IndexManager.selectNode(a, base_addr + "/" + t->relation_name + "/index_" + t->attribute_name + ".db", p->op, (p->v).to_str(catm.get_data_type(t))); if ( asdf == 0 ) { int b = 0, c = 0; while (a.next(b, c) == 0) { Record a = RecordManager.getRecord(t->relation_name, b, c, record_size); if (calc_conditions(s->condition_list, a)) BufferManager.appendTrashCan(b, c); } } } else { indexIterator a; int asdf = IndexManager.getStarter(a, s->table_name + "/index_" + catm.get_primary(s->table_name) + ".db"); if (asdf == 0) { int b = 0, c = 0; while (a.next(b, c) == 0) { Record a = RecordManager.getRecord(s->table_name, b, c, record_size); if (calc_conditions(s->condition_list, a)) BufferManager.appendTrashCan(b, c); } } } BufferManager.beginFetchTrash(); int blockNum, offset; while(BufferManager.fetchTrash(blockNum, offset)) { auto r = RecordManager.getRecord(s->table_name, blockNum, offset, record_size); for(auto x : *(r.table_info)) { if(x->flag & (table_column::unique_attr | table_column::primary_attr)) { indexIterator cursor; IndexManager.deleteNode(s->table_name + "/index_" + x->name + ".db", r.get_value(x).to_str(x->data_type)); } } RecordManager.deleteRecord(s->table_name, blockNum, offset, record_size); table_info->dec_size(); } } cout << "records deleted." << endl; }