MCPcopy Create free account
hub / github.com/MariaDB/server / modify_record

Method modify_record

plugin/handler_socket/handlersocket/database.cpp:529–609  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

527}
528
529int
530dbcontext::modify_record(dbcallback_i& cb, TABLE *const table,
531 const prep_stmt& pst, const cmd_exec_args& args, char mod_op,
532 size_t& modified_count)
533{
534 if (mod_op == 'U') {
535 /* update */
536 handler *const hnd = table->file;
537 uchar *const buf = table->record[0];
538 store_record(table, record[1]);
539 const prep_stmt::fields_type& rf = pst.get_ret_fields();
540 const size_t n = rf.size();
541 for (size_t i = 0; i < n; ++i) {
542 const string_ref& nv = args.uvals[i];
543 uint32_t fn = rf[i];
544 Field *const fld = table->field[fn];
545 if (nv.begin() == 0) {
546 fld->set_null();
547 } else {
548 fld->set_notnull();
549 fld->store(nv.begin(), nv.size(), &my_charset_bin);
550 }
551 }
552 table_vec[pst.get_table_id()].modified = true;
553 const int r = hnd->ha_update_row(table->record[1], buf);
554 if (r != 0 && r != HA_ERR_RECORD_IS_THE_SAME) {
555 return r;
556 }
557 ++modified_count; /* TODO: HA_ERR_RECORD_IS_THE_SAME? */
558 } else if (mod_op == 'D') {
559 /* delete */
560 handler *const hnd = table->file;
561 table_vec[pst.get_table_id()].modified = true;
562 const int r = hnd->ha_delete_row(table->record[0]);
563 if (r != 0) {
564 return r;
565 }
566 ++modified_count;
567 } else if (mod_op == '+' || mod_op == '-') {
568 /* increment/decrement */
569 handler *const hnd = table->file;
570 uchar *const buf = table->record[0];
571 store_record(table, record[1]);
572 const prep_stmt::fields_type& rf = pst.get_ret_fields();
573 const size_t n = rf.size();
574 size_t i = 0;
575 for (i = 0; i < n; ++i) {
576 const string_ref& nv = args.uvals[i];
577 uint32_t fn = rf[i];
578 Field *const fld = table->field[fn];
579 if (fld->is_null() || nv.begin() == 0) {
580 continue;
581 }
582 const long long pval = fld->val_int();
583 const long long llv = atoll_nocheck(nv.begin(), nv.end());
584 /* TODO: llv == 0? */
585 long long nval = 0;
586 if (mod_op == '+') {

Callers

nothing calls this directly

Calls 12

atoll_nocheckFunction · 0.85
set_notnullMethod · 0.80
ha_update_rowMethod · 0.80
ha_delete_rowMethod · 0.80
sizeMethod · 0.45
beginMethod · 0.45
set_nullMethod · 0.45
storeMethod · 0.45
get_table_idMethod · 0.45
is_nullMethod · 0.45
val_intMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected