From f32ecf46e47c40755f57d7f8e417b48dca65f847 Mon Sep 17 00:00:00 2001 From: Alexia23 Date: Sun, 11 Jan 2015 23:40:11 +0800 Subject: [PATCH] fix update bug --- DBMS/DBMS/dbManage.cpp | 21 ++++++++++++++++++++- DBMS/DBMS/orderDB/publisher | Bin 8192 -> 8192 bytes DBMS/DBMS/wq_parser.h | 3 +-- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/DBMS/DBMS/dbManage.cpp b/DBMS/DBMS/dbManage.cpp index f3af1e7..f28b067 100644 --- a/DBMS/DBMS/dbManage.cpp +++ b/DBMS/DBMS/dbManage.cpp @@ -83,6 +83,7 @@ void DBManager::dropTable(string tableName){ } bool DBManager::insertRecord(RecordEntry *input, string colName[], string tableName){ + //get full record char record[PAGE_SIZE]; memset(record, MEMSET_NUM, PAGE_SIZE); @@ -109,9 +110,14 @@ bool DBManager::insertRecord(RecordEntry *input, string colName[], string tableN } bool DBManager::updateRecord(string tableName,BYTE **Value,string *colName,BYTE *type,BYTE *len,BYTE *op, BYTE condCnt){ + //int=123: string:'123'; SysObject* table = sysManager.findTable(tableName); if (table == NULL) return true; + vector sysColumns = sysManager.getTableAttr(tableName); + string* colNames = new string[sysColumns.size()]; + for (int i = 0; i < sysColumns.size(); i++) + colNames[i] = sysColumns[i]->name; TYPE_ID pageid = 0; Node* dataPage = readPage(table->id, pageid); TYPE_OFFSET recordLength = sysManager.getRecordLength(tableName); @@ -154,9 +160,21 @@ bool DBManager::updateRecord(string tableName,BYTE **Value,string *colName,BYTE if (op[i] != SET) continue; col = getTableColumn(tableName, colName[i]); - dataUtility::bytefillbyte(dataPage->page->data, (unsigned char*)Value[i], offset*recordLength+col->index, len[i]); + if (col->xtype == INT_TYPE) { + len[i] = 4; + char* temp = new char[4]; + temp = dataUtility::data_to_char(atoi((char*)Value[i])); + dataUtility::bytefillbyte(dataPage->page->data, (unsigned char*)temp, offset*recordLength+col->index, len[i]); + delete[] temp; + }else { + char* temp = new char[col->length-len[i]]; + dataUtility::bytefillbyte(dataPage->page->data, (unsigned char*)Value[i], offset*recordLength+col->index, len[i]); + dataUtility::bytefillbyte(dataPage->page->data, (unsigned char*)temp, offset*recordLength+col->index+len[i], col->length-len[i]); + delete[] temp; + } dataPage->dirty = true; } + printRecord(tableName,sysColumns.size(),colNames, offset,pageid); } } pageid++; @@ -166,6 +184,7 @@ bool DBManager::updateRecord(string tableName,BYTE **Value,string *colName,BYTE } bool DBManager::deleteRecord(string tableName,BYTE **Value,string *colName,BYTE *type,BYTE *len,BYTE *op, BYTE condCnt){ + //int=123: string:'123'; SysObject* table = sysManager.findTable(tableName); if (table == NULL) return true; diff --git a/DBMS/DBMS/orderDB/publisher b/DBMS/DBMS/orderDB/publisher index 78b16bc9dd53fb8af53b9d900392c7037cb691f0..476bfdb2263d037359a057669e9685d7494a689f 100644 GIT binary patch literal 8192 zcmeIu;R!%M96<5EN!%*~UeTH8g% z*7lQ1^`Pgrac?JO5jiKP|1Fj2Ms2$5!z9U`A0dDM0tg_000IagfB*srAbn+a diff --git a/DBMS/DBMS/wq_parser.h b/DBMS/DBMS/wq_parser.h index 235c965..63b9e58 100644 --- a/DBMS/DBMS/wq_parser.h +++ b/DBMS/DBMS/wq_parser.h @@ -19,13 +19,12 @@ struct columnRequire { BYTE len; BYTE op; columnRequire(string value_v, string colName_v, BYTE type_v, BYTE len_v, BYTE op_v) { - cout << "Requirement: " << value << " " << colName_v << " " << (int)type_v << " " << (int)len_v << " " << (int)op_v << endl; value = value_v; len = value.length(); colName = colName_v; type = type_v; op = op_v; - cout << "Value: " << value << endl; + cout << "Requirement: " << value << " " << colName_v << " " << (int)type_v << " " << (int)len_v << " " << (int)op_v << endl; } }; class parser{