MCPcopy Create free account
hub / github.com/DeNA/HandlerSocket-Plugin-for-MySQL / modify_record

Method modify_record

handlersocket/database.cpp:570–650  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

568}
569
570int
571dbcontext::modify_record(dbcallback_i& cb, TABLE *const table,
572 const prep_stmt& pst, const cmd_exec_args& args, char mod_op,
573 size_t& modified_count)
574{
575 if (mod_op == 'U') {
576 /* update */
577 handler *const hnd = table->file;
578 uchar *const buf = table->record[0];
579 store_record(table, record[1]);
580 const prep_stmt::fields_type& rf = pst.get_ret_fields();
581 const size_t n = rf.size();
582 for (size_t i = 0; i < n; ++i) {
583 const string_ref& nv = args.uvals[i];
584 uint32_t fn = rf[i];
585 Field *const fld = table->field[fn];
586 if (nv.begin() == 0) {
587 fld->set_null();
588 } else {
589 fld->set_notnull();
590 fld->store(nv.begin(), nv.size(), &my_charset_bin);
591 }
592 }
593 table_vec[pst.get_table_id()].modified = true;
594 const int r = hnd->ha_update_row(table->record[1], buf);
595 if (r != 0 && r != HA_ERR_RECORD_IS_THE_SAME) {
596 return r;
597 }
598 ++modified_count; /* TODO: HA_ERR_RECORD_IS_THE_SAME? */
599 } else if (mod_op == 'D') {
600 /* delete */
601 handler *const hnd = table->file;
602 table_vec[pst.get_table_id()].modified = true;
603 const int r = hnd->ha_delete_row(table->record[0]);
604 if (r != 0) {
605 return r;
606 }
607 ++modified_count;
608 } else if (mod_op == '+' || mod_op == '-') {
609 /* increment/decrement */
610 handler *const hnd = table->file;
611 uchar *const buf = table->record[0];
612 store_record(table, record[1]);
613 const prep_stmt::fields_type& rf = pst.get_ret_fields();
614 const size_t n = rf.size();
615 size_t i = 0;
616 for (i = 0; i < n; ++i) {
617 const string_ref& nv = args.uvals[i];
618 uint32_t fn = rf[i];
619 Field *const fld = table->field[fn];
620 if (fld->is_null() || nv.begin() == 0) {
621 continue;
622 }
623 const long long pval = fld->val_int();
624 const long long llv = atoll_nocheck(nv.begin(), nv.end());
625 /* TODO: llv == 0? */
626 long long nval = 0;
627 if (mod_op == '+') {

Callers

nothing calls this directly

Calls 5

atoll_nocheckFunction · 0.85
get_table_idMethod · 0.80
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected