Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Last Inserted ID for MySQL. #1206

Answered by aitva
abhishek-hotstar asked this question in Q&A
Discussion options

CREATE TABLE IF NOT EXISTS student
(
id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(50) NOT NULL
);

/* name: InsertStudent :exec */
INSERT INTO student (name)
VALUES (?);

The result only returns an error, not the sql.Result. Only on the result pointer can we call LastInsertId(). Please suggest a way forward.

Thank you.

You must be logged in to vote

You can get an sql.Result by using the :execresult command:

CREATE TABLE IF NOT EXISTS student
(
id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(50) NOT NULL
);
/* name: InsertStudent :execresult */
INSERT INTO student (name)
VALUES (?);

Replies: 1 comment

Comment options

You can get an sql.Result by using the :execresult command:

CREATE TABLE IF NOT EXISTS student
(
id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(50) NOT NULL
);
/* name: InsertStudent :execresult */
INSERT INTO student (name)
VALUES (?);
You must be logged in to vote
0 replies
Answer selected by abhishek-hotstar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /