Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PDO lastInsertId primary bigInt, after id 999999999 return '' #735

Closed
Litiano opened this issue Apr 3, 2018 · 7 comments
Closed

PDO lastInsertId primary bigInt, after id 999999999 return '' #735

Litiano opened this issue Apr 3, 2018 · 7 comments

Comments

@Litiano
Copy link

Litiano commented Apr 3, 2018

+## Driver version or file name
+v5.2.0 TS
+
+## SQL Server version
+13.0.4206.0
+
+## Client operating system
+Windows 10 x64.
+
+## PHP version
+7.2.3 x86
+
+## Microsoft ODBC Driver version
+13 (13.1.14414.46).
+
+## Table schema
CREATE TABLE [dbo].[big_int](
[id] [bigint] IDENTITY(1,1) NOT NULL,
[name] nvarchar NOT NULL,
[created_at] [datetime] NULL,
[updated_at] [datetime] NULL,
PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
+
+## Problem description
+PDO lastInsertId no work correctly with primary bigInt, after id 999999999 return ''
+

@yitam
Copy link
Contributor

yitam commented Apr 3, 2018

Hi @Litiano,
Did you mean lastinsertid() failed after inserting 999999999 records? If you like, please provide a simple PHP script to repro this problem. Thanks!

@Litiano
Copy link
Author

Litiano commented Apr 3, 2018

Hi @yitam .

I used 'DBCC checkident ('big_int', reseed, 999999000)' to speed up the process.

$conn = new PDO( "sqlsrv:server=$serverName ; Database = $database", $uid, $pwd); for ($i = 0; $i <= 1000; $i++) { $d = $conn->query("INSERT INTO [big_int] ([name]) VALUES ('name')"); if($conn->lastInsertId() === '') { echo "Error i = {$i}"; exit(); } }

Table:
CREATE TABLE [dbo].[big_int]( [id] [bigint] IDENTITY(1,1) NOT NULL, [name] [nvarchar](255) NOT NULL, [created_at] [datetime] NULL, [updated_at] [datetime] NULL, PRIMARY KEY CLUSTERED ( [id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY]

@yitam
Copy link
Contributor

yitam commented Apr 3, 2018

Thanks @Litiano
I can reproduce the problem and will do some investigation. We will keep you posted.

@yitam
Copy link
Contributor

yitam commented Apr 4, 2018

Hi @Litiano, the buffer allocated in our driver when returning the lastinsertid() has the size of a maximum integer (10 digits), and in your case, a bigint over 999999999 has exceeded the limit.

@Litiano
Copy link
Author

Litiano commented Apr 4, 2018

Hi @yitam ,

How can we solve this?

@yitam
Copy link
Contributor

yitam commented Apr 4, 2018

Yes @Litiano we can fix it, but will check the plan when to release a preview. Please stay tuned.

@yitam
Copy link
Contributor

yitam commented May 30, 2018

Fixed in 5.2.1-preview. Please reopen the issue if otherwise, @Litiano

@yitam yitam closed this as completed May 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants