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

Function prev_insert_id

sql/handler.cc:4442–4469  ·  view source on GitHub ↗

@brief Computes the largest number X: - smaller than or equal to "nr" - of the form: auto_increment_offset + N * auto_increment_increment where N>=0. SYNOPSIS prev_insert_id nr Number to "round down" variables variables struct containing auto_increment_increment and auto_increment_offset RETURN The number X if it exists, "nr" oth

Source from the content-addressed store, hash-verified

4440 The number X if it exists, "nr" otherwise.
4441*/
4442inline ulonglong
4443prev_insert_id(ulonglong nr, struct system_variables *variables)
4444{
4445 if (unlikely(nr < variables->auto_increment_offset))
4446 {
4447 /*
4448 There's nothing good we can do here. That is a pathological case, where
4449 the offset is larger than the column's max possible value, i.e. not even
4450 the first sequence value may be inserted. User will receive warning.
4451 */
4452 DBUG_PRINT("info",("auto_increment: nr: %lu cannot honour "
4453 "auto_increment_offset: %lu",
4454 (ulong) nr, variables->auto_increment_offset));
4455 return nr;
4456 }
4457 if (variables->auto_increment_increment == 1)
4458 return nr; // optimization of the formula below
4459 /*
4460 Calculating the number of complete auto_increment_increment extents:
4461 */
4462 nr= (nr - variables->auto_increment_offset) /
4463 (ulonglong) variables->auto_increment_increment;
4464 /*
4465 Adding an offset to the auto_increment_increment extent boundary:
4466 */
4467 return (nr * (ulonglong) variables->auto_increment_increment +
4468 variables->auto_increment_offset);
4469}
4470
4471
4472/**

Callers 1

update_auto_incrementMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected