Skip to content
Snippets Groups Projects
Commit 2124636c authored by Dmitry Isaikin's avatar Dmitry Isaikin Committed by Konstantin Osipov
Browse files

- box.auto_increment works with NUM64 keys

- auto_increment key start from '1' now

Conflicts:

	test/big/tarantool.cfg
parent 0319c747
No related branches found
No related tags found
No related merge requests found
...@@ -102,15 +102,23 @@ function box.update(space, key, format, ...) ...@@ -102,15 +102,23 @@ function box.update(space, key, format, ...)
...)) ...))
end end
-- Assumes that spaceno has a TREE int32 (NUM) primary key -- Assumes that spaceno has a TREE int32 (NUM) or int64 (NUM64) primary key
-- inserts a tuple after getting the next value of the -- inserts a tuple after getting the next value of the
-- primary key and returns it back to the user -- primary key and returns it back to the user
function box.auto_increment(spaceno, ...) function box.auto_increment(spaceno, ...)
spaceno = tonumber(spaceno) spaceno = tonumber(spaceno)
local max_tuple = box.space[spaceno].index[0].idx:max() local max_tuple = box.space[spaceno].index[0].idx:max()
local max = -1 local max = 0
if max_tuple ~= nil then if max_tuple ~= nil then
max = box.unpack('i', max_tuple[0]) max = max_tuple[0]
local fmt = 'i'
if #max == 8 then fmt = 'l' end
max = box.unpack(fmt, max)
else
-- first time
if box.space[spaceno].index[0].key_field[0].type == "NUM64" then
max = tonumber64(max)
end
end end
return box.insert(spaceno, max + 1, ...) return box.insert(spaceno, max + 1, ...)
end end
......
...@@ -327,7 +327,7 @@ lua box.space[18]:truncate() ...@@ -327,7 +327,7 @@ lua box.space[18]:truncate()
... ...
lua box.auto_increment(18, 'a') lua box.auto_increment(18, 'a')
--- ---
- 0: {'a'} - 1: {'a'}
... ...
lua box.insert(18, 5) lua box.insert(18, 5)
--- ---
...@@ -344,6 +344,28 @@ lua box.auto_increment(18, 'c') ...@@ -344,6 +344,28 @@ lua box.auto_increment(18, 'c')
lua box.space[18]:truncate() lua box.space[18]:truncate()
--- ---
... ...
lua box.space[25]:truncate()
---
...
lua box.auto_increment(25, 'a')
---
- 1: {'a'}
...
lua box.insert(25, tonumber64(5))
---
- 5: {}
...
lua box.auto_increment(25, 'b')
---
- 6: {'b'}
...
lua box.auto_increment(25, 'c')
---
- 7: {'c'}
...
lua box.space[25]:truncate()
---
...
lua t=box.insert(12, '1', '2', '3', '4', '5', '6', '7') lua t=box.insert(12, '1', '2', '3', '4', '5', '6', '7')
--- ---
... ...
......
...@@ -125,6 +125,16 @@ exec admin "lua box.auto_increment(18, 'b')" ...@@ -125,6 +125,16 @@ exec admin "lua box.auto_increment(18, 'b')"
exec admin "lua box.auto_increment(18, 'c')" exec admin "lua box.auto_increment(18, 'c')"
exec admin "lua box.space[18]:truncate()" exec admin "lua box.space[18]:truncate()"
#
# Tests for lua box.auto_increment with NUM64 keys
#
exec admin "lua box.space[25]:truncate()"
exec admin "lua box.auto_increment(25, 'a')"
exec admin "lua box.insert(25, tonumber64(5))"
exec admin "lua box.auto_increment(25, 'b')"
exec admin "lua box.auto_increment(25, 'c')"
exec admin "lua box.space[25]:truncate()"
# #
# Tests for lua tuple:transform() # Tests for lua tuple:transform()
# #
......
...@@ -252,3 +252,10 @@ space[23].index[0].key_field[0].fieldno = 2 ...@@ -252,3 +252,10 @@ space[23].index[0].key_field[0].fieldno = 2
space[23].index[0].key_field[0].type = "NUM" space[23].index[0].key_field[0].type = "NUM"
space[23].index[0].key_field[1].fieldno = 1 space[23].index[0].key_field[1].fieldno = 1
space[23].index[0].key_field[1].type = "NUM" space[23].index[0].key_field[1].type = "NUM"
# lua box.auto_increment() with NUM64 keys testing
space[25].enabled = 1
space[25].index[0].type = "TREE"
space[25].index[0].unique = 1
space[25].index[0].key_field[0].fieldno = 0
space[25].index[0].key_field[0].type = "NUM64"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment