Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mariadb
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
mariadb
Commits
d33cb08e
Commit
d33cb08e
authored
Jun 15, 2003
by
monty@narttu.mysql.fi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
LAST_INSERT_ID()}will now return 0 if the last INSERT didn't insert any rows.
parent
1e62d607
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
3 deletions
+14
-3
mysql-test/r/auto_increment.result
mysql-test/r/auto_increment.result
+1
-1
sql/sql_insert.cc
sql/sql_insert.cc
+13
-2
No files found.
mysql-test/r/auto_increment.result
View file @
d33cb08e
...
@@ -143,5 +143,5 @@ insert into t1 values (NULL, 10);
...
@@ -143,5 +143,5 @@ insert into t1 values (NULL, 10);
ERROR 23000: Duplicate entry '10' for key 2
ERROR 23000: Duplicate entry '10' for key 2
select last_insert_id();
select last_insert_id();
last_insert_id()
last_insert_id()
3
0
drop table t1;
drop table t1;
sql/sql_insert.cc
View file @
d33cb08e
...
@@ -308,6 +308,11 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list,
...
@@ -308,6 +308,11 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list,
}
}
thd
->
row_count
++
;
thd
->
row_count
++
;
}
}
/*
Now all rows are inserted. Time to update logs and sends response to
user
*/
if
(
lock_type
==
TL_WRITE_DELAYED
)
if
(
lock_type
==
TL_WRITE_DELAYED
)
{
{
if
(
!
error
)
if
(
!
error
)
...
@@ -341,7 +346,7 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list,
...
@@ -341,7 +346,7 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list,
}
}
if
(
id
&&
values_list
.
elements
!=
1
)
if
(
id
&&
values_list
.
elements
!=
1
)
thd
->
insert_id
(
id
);
// For update log
thd
->
insert_id
(
id
);
// For update log
else
if
(
table
->
next_number_field
)
else
if
(
table
->
next_number_field
&&
info
.
copied
)
id
=
table
->
next_number_field
->
val_int
();
// Return auto_increment value
id
=
table
->
next_number_field
->
val_int
();
// Return auto_increment value
/*
/*
...
@@ -383,9 +388,15 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list,
...
@@ -383,9 +388,15 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list,
thd
->
next_insert_id
=
0
;
// Reset this if wrongly used
thd
->
next_insert_id
=
0
;
// Reset this if wrongly used
if
(
duplic
!=
DUP_ERROR
)
if
(
duplic
!=
DUP_ERROR
)
table
->
file
->
extra
(
HA_EXTRA_NO_IGNORE_DUP_KEY
);
table
->
file
->
extra
(
HA_EXTRA_NO_IGNORE_DUP_KEY
);
/* Reset value of LAST_INSERT_ID if no rows where inserted */
if
(
!
info
.
copied
&&
thd
->
insert_id_used
)
{
thd
->
insert_id
(
0
);
id
=
0
;
}
if
(
error
)
if
(
error
)
goto
abort
;
goto
abort
;
if
(
values_list
.
elements
==
1
&&
(
!
(
thd
->
options
&
OPTION_WARNINGS
)
||
if
(
values_list
.
elements
==
1
&&
(
!
(
thd
->
options
&
OPTION_WARNINGS
)
||
!
thd
->
cuted_fields
))
!
thd
->
cuted_fields
))
send_ok
(
thd
,
info
.
copied
+
info
.
deleted
,
id
);
send_ok
(
thd
,
info
.
copied
+
info
.
deleted
,
id
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment