lastinsertid

Update model with latest autoinc id from database

Hello, which method do you prefer to update my newly saved customer with the last autoincremented Id ? Do you see any disadvantage in one of both methods? CustomerRepository.cs public int AddCustomer(Customer customer) { //.... return lastID; } BillingViewModel.cs //Method 1 SelectedCustomer.Id = _customerRepo.AddCustomer(Sel...

mySQL 5.0.45 LAST_INSERT_ID() and values larger than a signed int

I'm attempting to use LAST_INSERT_ID on an auto incremented index that has moved past the signed int value 2147483647. This column is an unsigned int. However, LAST_INSERT_ID() is returning an invalid negative value. Researching this, I've found a couple comments indicating this is the nature of this function. But I cannot find it offici...

Using LAST_INSERT_ID() via PHP?

When I execute the following in the MySQL console, it works fine: INSERT INTO videos (embed_code) VALUES ('test code here'); SELECT LAST_INSERT_ID(); But, when I execute the above queries via PHP, the result is empty. Under the data abstraction, I am using a database access class named DB. This is how I have tried the above queries v...

Get the last insert id with doctrine 2?

How can I get the last insert id with doctrine 2 ORM? I didn't find this in the documentation of doctrine, is this even possible? ...

Is bulk insert atomic?

I have table with auto increment primary key. I want insert a bunch of data into it and get keys for each of them without additional queries. START TRANSACTION; INSERT INTO table (value) VALUES (x),(y),(z); SELECT LAST_INSERT_ID() AS last_id; COMMIT; Could MySQL guarantee, that all data would be inserted in one continuous ordered flow...

Was: Grab the last inserted id - mysql Now: Where should we call the last insert id ?

Here's the thing, I don't have access to code that inserts data into a given table. However, I need to add related additional data into another table. So, I was thinking about grabbing the last inserted ID and from there... insert the related data into that other table. Since I don't have access to the statement, I believe that mysql la...

LAST_INSERT_ID() MySQL

I have a MySQL question that I think must be quite easy. I need to return the LAST INSERTED ID from table1 when I run the following MySql query: INSERT INTO table1 (title,userid) VALUES ('test',1); INSERT INTO table2 (parentid,otherid,userid) VALUES (LAST_INSERT_ID(),4,1); SELECT LAST_INSERT_ID(); As you can understand the current co...

Get last inserted value from sqlite database Android

I am trying to get the last inserted rowid from a sqlite database in Android. I have read a lot of posts about it, but can't get one to work. This is my method: public Cursor getLastId() { return mDb.query(DATABASE_TABLE, new String[] {KEY_WID}, KEY_WID + "=" + MAX(_id), null, null, null, null, null);} I have tried with MAX, b...