Skip to content

Commit b4863b0

Browse files
committed
temp commit: last_insert_id
1 parent de48e4b commit b4863b0

File tree

9 files changed

+89
-3
lines changed

9 files changed

+89
-3
lines changed

handlersocket/database.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,9 +672,14 @@ dbcontext::cmd_insert_internal(dbcallback_i& cb, const prep_stmt& pst,
672672
}
673673
}
674674
table->next_number_field = table->found_next_number_field;
675+
/* FIXME: test */
675676
const int r = hnd->ha_write_row(buf);
677+
const ulonglong insert_id = table->file->insert_id_for_cur_row;
676678
table->next_number_field = 0;
677679
table_vec[pst.get_table_id()].modified = true;
680+
if (r == 0 && table->found_next_number_field != 0) {
681+
return cb.dbcb_resp_short_num64(0, insert_id);
682+
}
678683
return cb.dbcb_resp_short(r != 0 ? 1 : 0, "");
679684
}
680685

handlersocket/database.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ struct dbcallback_i {
6262
virtual const prep_stmt *dbcb_get_prep_stmt(size_t pst_id) const = 0;
6363
virtual void dbcb_resp_short(uint32_t code, const char *msg) = 0;
6464
virtual void dbcb_resp_short_num(uint32_t code, uint32_t value) = 0;
65+
virtual void dbcb_resp_short_num64(uint32_t code, uint64_t value) = 0;
6566
virtual void dbcb_resp_begin(size_t num_flds) = 0;
6667
virtual void dbcb_resp_entry(const char *fld, size_t fldlen) = 0;
6768
virtual void dbcb_resp_end() = 0;

handlersocket/hstcpsvr_worker.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ struct hstcpsvr_conn : public dbcallback_i {
7878
virtual const prep_stmt *dbcb_get_prep_stmt(size_t pst_id) const;
7979
virtual void dbcb_resp_short(uint32_t code, const char *msg);
8080
virtual void dbcb_resp_short_num(uint32_t code, uint32_t value);
81+
virtual void dbcb_resp_short_num64(uint32_t code, uint64_t value);
8182
virtual void dbcb_resp_begin(size_t num_flds);
8283
virtual void dbcb_resp_entry(const char *fld, size_t fldlen);
8384
virtual void dbcb_resp_end();
@@ -205,6 +206,15 @@ hstcpsvr_conn::dbcb_resp_short_num(uint32_t code, uint32_t value)
205206
cstate.writebuf.append_literal("\n");
206207
}
207208

209+
void
210+
hstcpsvr_conn::dbcb_resp_short_num64(uint32_t code, uint64_t value)
211+
{
212+
write_ui32(cstate.writebuf, code);
213+
cstate.writebuf.append_literal("\t1\t");
214+
write_ui64(cstate.writebuf, value);
215+
cstate.writebuf.append_literal("\n");
216+
}
217+
208218
void
209219
hstcpsvr_conn::dbcb_resp_begin(size_t num_flds)
210220
{

libhsclient/escape.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,18 @@ read_ui32(char *& start, char *finish)
106106
void
107107
write_ui32(string_buffer& buf, uint32_t v)
108108
{
109-
char *wp = buf.make_space(32);
110-
int len = snprintf(wp, 32, "%u", v);
109+
char *wp = buf.make_space(12);
110+
int len = snprintf(wp, 12, "%u", v);
111+
if (len > 0) {
112+
buf.space_wrote(len);
113+
}
114+
}
115+
116+
void
117+
write_ui64(string_buffer& buf, uint64_t v)
118+
{
119+
char *wp = buf.make_space(22);
120+
int len = snprintf(wp, 22, "%llu", static_cast<unsigned long long>(v));
111121
if (len > 0) {
112122
buf.space_wrote(len);
113123
}

libhsclient/escape.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ bool unescape_string(string_buffer& ar, const char *start, const char *finish);
2525

2626
uint32_t read_ui32(char *& start, char *finish);
2727
void write_ui32(string_buffer& buf, uint32_t v);
28+
void write_ui64(string_buffer& buf, uint64_t v);
2829

2930
inline bool
3031
is_null_expression(const char *start, const char *finish)

regtest/test_01_lib/test13.expected

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,44 @@
11
HSINSERT
2+
11 v1hs_0
3+
12 v1hs_1
4+
13 v1hs_2
5+
14 v1hs_3
6+
15 v1hs_4
7+
16 v1hs_5
8+
17 v1hs_6
9+
18 v1hs_7
10+
19 v1hs_8
11+
20 v1hs_9
12+
21 v1hs3_0
13+
22 v1hs3_0
14+
23 v1hs3_0
15+
24 v1hs3_1
16+
25 v1hs3_1
17+
26 v1hs3_1
18+
27 v1hs3_2
19+
28 v1hs3_2
20+
29 v1hs3_2
21+
30 v1hs3_3
22+
31 v1hs3_3
23+
32 v1hs3_3
24+
33 v1hs3_4
25+
34 v1hs3_4
26+
35 v1hs3_4
27+
36 v1hs3_5
28+
37 v1hs3_5
29+
38 v1hs3_5
30+
39 v1hs3_6
31+
40 v1hs3_6
32+
41 v1hs3_6
33+
42 v1hs3_7
34+
43 v1hs3_7
35+
44 v1hs3_7
36+
45 v1hs3_8
37+
46 v1hs3_8
38+
47 v1hs3_8
39+
48 v1hs3_9
40+
49 v1hs3_9
41+
50 v1hs3_9
242
DUMP_TABLE
343
1 v1sql_0 v2sql_0
444
2 v1sql_1 v2sql_1

regtest/test_01_lib/test13.pl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ BEGIN
4747
if ($err != 0) {
4848
my $err_str = $r->[1];
4949
print "$err $err_str\n";
50+
} else {
51+
my $id = $r->[1];
52+
print "$id $v1\n";
5053
}
5154
}
5255
# make sure that it works even when inserts are pipelined. these requests
@@ -63,8 +66,11 @@ BEGIN
6366
for (my $i = 0; $i < 3; ++$i) {
6467
my $err = $r->[$i]->[0];
6568
if ($err != 0) {
66-
my $err_str = $r->[1];
69+
my $err_str = $r->[$i]->[1];
6770
print "$err $err_str\n";
71+
} else {
72+
my $id = $r->[$i]->[1];
73+
print "$id $v1\n";
6874
}
6975
}
7076
}

regtest/test_01_lib/test18.expected

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
HSINSERT
2+
1 v1hs_0
3+
2 v1hs_1
4+
3 v1hs_2
5+
4 v1hs_3
6+
5 v1hs_4
7+
6 v1hs_5
8+
7 v1hs_6
9+
8 v1hs_7
10+
9 v1hs_8
11+
10 v1hs_9
212
DUMP_TABLE
313
1 v1hs_0
414
2 v1hs_1

regtest/test_01_lib/test18.pl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ BEGIN
3939
if ($err != 0) {
4040
my $err_str = $r->[1];
4141
print "$err $err_str\n";
42+
} else {
43+
my $id = $r->[1];
44+
print "$id $v1\n";
4245
}
4346
}
4447

0 commit comments

Comments
 (0)