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

Method cmd_insert_internal

plugin/handler_socket/handlersocket/database.cpp:611–654  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

609}
610
611void
612dbcontext::cmd_insert_internal(dbcallback_i& cb, const prep_stmt& pst,
613 const string_ref *fvals, size_t fvalslen)
614{
615 if (!for_write_flag) {
616 return cb.dbcb_resp_short(2, "readonly");
617 }
618 lock_tables_if();
619 if (lock == 0) {
620 return cb.dbcb_resp_short(1, "lock_tables");
621 }
622 if (pst.get_table_id() >= table_vec.size()) {
623 return cb.dbcb_resp_short(2, "tblnum");
624 }
625 TABLE *const table = table_vec[pst.get_table_id()].table;
626 handler *const hnd = table->file;
627 uchar *const buf = table->record[0];
628 empty_record(table);
629 memset(buf, 0, table->s->null_bytes); /* clear null flags */
630 const prep_stmt::fields_type& rf = pst.get_ret_fields();
631 const size_t n = std::min(rf.size(), fvalslen);
632 for (size_t i = 0; i < n; ++i) {
633 uint32_t fn = rf[i];
634 Field *const fld = table->field[fn];
635 if (fvals[i].begin() == 0) {
636 fld->set_null();
637 } else {
638 fld->store(fvals[i].begin(), fvals[i].size(), &my_charset_bin);
639 }
640 }
641 table->next_number_field = table->found_next_number_field;
642 /* FIXME: test */
643 const int r = hnd->ha_write_row(buf);
644 const ulonglong insert_id = table->file->insert_id_for_cur_row;
645 table->next_number_field = 0;
646 table_vec[pst.get_table_id()].modified = true;
647 if (r == 0 && table->found_next_number_field != 0) {
648 return cb.dbcb_resp_short_num64(0, insert_id);
649 }
650 if (r != 0) {
651 return cb.dbcb_resp_short_num(1, r);
652 }
653 return cb.dbcb_resp_short(0, "");
654}
655
656void
657dbcontext::cmd_sql_internal(dbcallback_i& cb, const prep_stmt& pst,

Callers

nothing calls this directly

Calls 9

dbcb_resp_shortMethod · 0.80
ha_write_rowMethod · 0.80
dbcb_resp_short_num64Method · 0.80
dbcb_resp_short_numMethod · 0.80
get_table_idMethod · 0.45
sizeMethod · 0.45
beginMethod · 0.45
set_nullMethod · 0.45
storeMethod · 0.45

Tested by

no test coverage detected