Skip to content

Commit

Permalink
Text完成
Browse files Browse the repository at this point in the history
  • Loading branch information
CGHu committed May 6, 2024
1 parent 180e3d4 commit c8b57e2
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 72 deletions.
65 changes: 3 additions & 62 deletions src/observer/net/plain_communicator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,7 @@ RC PlainCommunicator::write_tuple(SqlResult *sql_result) {
else
last_values.push_back(value);
}
return RC::SUCCESS;

//return RC::SUCCESS;
writer_->writen("\n", 1);
}

Expand Down Expand Up @@ -266,7 +265,6 @@ RC PlainCommunicator::write_result_internal(SessionEvent *event, bool &need_disc
if (nullptr != alias || alias[0] != 0) {
if (0 != i) {
const char *delim = " | ";

rc = writer_->writen(delim, strlen(delim));
if (OB_FAIL(rc)) {
LOG_WARN("failed to send data to client. err=%s", strerror(errno));
Expand All @@ -287,63 +285,6 @@ RC PlainCommunicator::write_result_internal(SessionEvent *event, bool &need_disc

if (cell_num > 0) {
char newline = '\n';

rc = writer_->writen(&newline, 1);
if (OB_FAIL(rc)) {
LOG_WARN("failed to send data to client. err=%s", strerror(errno));
sql_result->close();
return rc;
}
}

// rc = write_tuple(sql_result);
// if (rc == RC::RECORD_EOF) {
// rc = RC::SUCCESS;
// } else {
// LOG_WARN("write tuple failed: %s", strrc(rc));
// sql_result->close();
// sql_result->set_return_code(rc);
// return write_state(event, need_disconnect);
// }

rc = RC::SUCCESS;

Tuple *tuple = nullptr;
while (RC::SUCCESS == (rc = sql_result->next_tuple(tuple))) {
assert(tuple != nullptr);

int cell_num = tuple->cell_num();
for (int i = 0; i < cell_num; i++) {
if (i != 0) {
const char *delim = " | ";

rc = writer_->writen(delim, strlen(delim));
if (OB_FAIL(rc)) {
LOG_WARN("failed to send data to client. err=%s", strerror(errno));
sql_result->close();
return rc;
}
}

Value value;
rc = tuple->cell_at(i, value);
if (rc != RC::SUCCESS) {
sql_result->close();
return rc;
}

string cell_str = value.to_string();

rc = writer_->writen(cell_str.data(), cell_str.size());
if (OB_FAIL(rc)) {
LOG_WARN("failed to send data to client. err=%s", strerror(errno));
sql_result->close();
return rc;
}
}

char newline = '\n';

rc = writer_->writen(&newline, 1);
if (OB_FAIL(rc)) {
LOG_WARN("failed to send data to client. err=%s", strerror(errno));
Expand All @@ -352,15 +293,15 @@ RC PlainCommunicator::write_result_internal(SessionEvent *event, bool &need_disc
}
}

rc = write_tuple(sql_result);
if (rc == RC::RECORD_EOF) {
rc = RC::SUCCESS;
}else {
} else {
LOG_WARN("write tuple failed: %s", strrc(rc));
sql_result->close();
sql_result->set_return_code(rc);
return write_state(event, need_disconnect);
}

if (cell_num == 0) {
// 除了select之外,其它的消息通常不会通过operator来返回结果,表头和行数据都是空的
// 这里针对这种情况做特殊处理,当表头和行数据都是空的时候,就返回处理的结果
Expand Down
6 changes: 3 additions & 3 deletions src/observer/sql/parser/value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ void Value::set_string(const char *s, int len /*= 0*/)
}


void Value::set_text(const char *s, int len /*= 0*/)
void Value::set_text(const char *s, int len)
{
attr_type_ = TEXTS;
str_value_.assign(s, len);
Expand All @@ -146,7 +146,7 @@ void Value::set_value(const Value &value)
set_boolean(value.get_boolean());
} break;
case TEXTS: {
set_text(value.get_string().c_str());
set_text(value.get_string().c_str(),value.get_string().length());
} break;
case UNDEFINED: {
ASSERT(false, "got an invalid value type");
Expand Down Expand Up @@ -369,7 +369,7 @@ bool Value::convert(AttrType from, AttrType to, Value &value) {
return true;
}
if (from == CHARS && to == TEXTS) {
value.set_text(value.get_string().c_str());
value.set_text(value.get_string().c_str(),value.get_string().length());
return true;
}
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/observer/storage/field/field_meta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ bool FieldMeta::match(Value &value) const {
if (value.get_string().size() > 65535)
return false;

value.set_text(value.get_string().c_str());
value.set_text(value.get_string().c_str(),value.get_string().length());
value.set_text_f();
return true;
}
Expand Down
18 changes: 12 additions & 6 deletions src/observer/storage/table/table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ See the Mulan PSL v2 for more details. */
#include "storage/trx/trx.h"
#include "storage/field/field.h"

RC make_text_value(RecordFileHandler *record_handler, Value &value);
RC handle_text_value(RecordFileHandler *record_handler, Value &value);
Table::~Table()
{
if (record_handler_ != nullptr) {
Expand Down Expand Up @@ -271,7 +271,11 @@ RC Table::visit_record(const RID &rid, bool readonly, std::function<void(Record

RC Table::get_record(const RID &rid, Record &record)
{
const int record_size = table_meta_.record_size();
int record_size = table_meta_.record_size();
if (rid.init) {
LOG_TRACE("rid init))))))))))=>>>");
record_size = rid.over_len;
}
char *record_data = (char *)malloc(record_size);
ASSERT(nullptr != record_data, "failed to malloc memory. record data size=%d", record_size);

Expand All @@ -284,6 +288,8 @@ RC Table::get_record(const RID &rid, Record &record)
free(record_data);
LOG_WARN("failed to visit record. rid=%s, table=%s, rc=%s", rid.to_string().c_str(), name(), strrc(rc));
return rc;
}else{
LOG_TRACE("get_text_record 11))))))))))=>>>");
}

record.set_data_owner(record_data, record_size);
Expand Down Expand Up @@ -639,13 +645,13 @@ RC handle_text_value(RecordFileHandler *record_handler, Value &value)
RID *rid = new RID; //最后的空指针
while (end - datass > MAX_SIZE) {
RID *new_rid = new RID;
rc = record_handler->insert_text_record(end - MAX_SIZE, MAX_SIZE, new_rid); //存进一个record中
rc = record_handler->insert_text_record(end - MAX_SIZE,(size_t)MAX_SIZE, new_rid); //存进一个record中

if (rc != RC::SUCCESS) {
LOG_ERROR("Insert text chunk failed: %s", strrc(rc));
return rc;
}else{
LOG_TRACE("Insert record.))))))))))=>>>%s",value.text_data());
LOG_TRACE("Insert record.))))))))))=>>>%d",MAX_SIZE);
return rc;
}

Expand All @@ -658,12 +664,12 @@ RC handle_text_value(RecordFileHandler *record_handler, Value &value)
}

RID *rid_last = new RID;
rc = record_handler->insert_text_record(datass, end - datass, rid_last); //将最后剩下的存进去
rc = record_handler->insert_text_record(datass, (size_t)(end - datass), rid_last); //将最后剩下的存进去
if (rc != RC::SUCCESS) {
LOG_ERROR("Insert text chunk failed: %s", strrc(rc));
return rc;
}else{
LOG_TRACE("Insert record handle_text_value))))))))))=>>>%s",datass);
LOG_TRACE("Insert record handle_text_value text_data().length()))))))))))=>>>%d",value.text_data().length());
}

if (rid->init == true) {
Expand Down

0 comments on commit c8b57e2

Please sign in to comment.