| | Posted Wednesday, September 05, 2007 7:55 AM | |
| 
Progenic Crew

Group: Administrators Last Login: Sunday, November 27, 2011 7:50 AM Posts: 2,738, Visits: 38,421 |
| | I'm trying to get the row id for the record i just entered, i could select the max id for the primary key but this is going to be a huge multithreaded system and can't risk returning the wrong ID. In mssql you have @@Identiy which can return the id of the row you added, anybody know if there is an equivalant in mysql?
|
| | | Posted Wednesday, September 05, 2007 8:27 AM | |
| 
Progenic Crew

Group: Administrators Last Login: Sunday, November 27, 2011 7:50 AM Posts: 2,738, Visits: 38,421 |
| sorted it's SELECT LAST_INSERT_ID() and it can be used in c# like so: public int InsertContactList(objContactList list) { MySqlCommand cmd; conn.Open(); cmd = new MySqlCommand("insert into contact_lists (ListName,UserID) values (?ListName,?UserID);Select LAST_INSERT_ID();", conn); cmd.Parameters.AddWithValue("?ListName", list.ListName); cmd.Parameters.AddWithValue("?UserID", list.UserID); int i = (int)(long)cmd.ExecuteScalar(); conn.Close(); return i; }
|
| | | Posted Wednesday, September 05, 2007 10:12 AM | |
| 
Progenic Family

Group: Forum Members Last Login: Monday, February 22, 2010 10:41 PM Posts: 533, Visits: 1,389 |
| just out of curiosity
where are u using this
just if ya want to say |
| | | Posted Wednesday, September 05, 2007 10:52 AM | |
| 
Progenic Crew

Group: Administrators Last Login: Sunday, November 27, 2011 7:50 AM Posts: 2,738, Visits: 38,421 |
| | It's for an antispam system i'm working on. It's been quite interesting learning how mysql differs from mssql. Two other differences that stumped me for a while were that mysql doesn't have GetDate() as an sql function so i had to swap that to Now(), and the one I got stuck on the longest was when you use parameterized queries, mssql variables are named like @Variable but in mysql it's ?Variable. It gave me no error messages when i used @Variable it just didn't work, took me f**king forever to work that out .
|
| | | Posted Wednesday, September 05, 2007 11:28 AM | |
| 
Progenic Crew

Group: Administrators Last Login: Monday, April 11, 2011 11:12 AM Posts: 1,053, Visits: 5,891 |
| | I hope it's not actually the same as @@identity, but rather scope_identity().. scope_identity() is the last inserted id for your scope (query, stored proc, trigger) @@identity is last inserted id for the database for your connection Or in other words - on busy systems with heavy inserting going on, @@identity can return the wrong id |
| | | Posted Wednesday, September 05, 2007 11:29 AM | |
| 
Progenic Family

Group: Forum Members Last Login: Monday, February 22, 2010 10:41 PM Posts: 533, Visits: 1,389 |
| mhm....all i can agree with is that databasez are bitches
hed trouble with swl at absolutel every site i worked on
absolutely no exceptions |
| | | Posted Wednesday, September 05, 2007 12:19 PM | |
| 
Progenic Crew

Group: Administrators Last Login: Sunday, November 27, 2011 7:50 AM Posts: 2,738, Visits: 38,421 |
| wax (9/5/2007)
I hope it's not actually the same as @@identity, but rather scope_identity().. scope_identity() is the last inserted id for your scope (query, stored proc, trigger) @@identity is last inserted id for the database for your connection Or in other words - on busy systems with heavy inserting going on, @@identity can return the wrong id hmm from what I read it is for the current connection which i assume means between con.open and con.close. Sound right to you?
|
| | | Posted Wednesday, September 05, 2007 1:02 PM | |
| 
Progenic Crew

Group: Administrators Last Login: Monday, April 11, 2011 11:12 AM Posts: 1,053, Visits: 5,891 |
| | Sounds about right, not sure how ado.net's connection pooling comes into play here though, it keeps connections alive so theoretically that could mess things up. But you'd have to read up / test that really. That being said though, any sort of trigger will definitely live inside your connection's scope, so if one of those does an insert somewhere on an identity field because of something you did, you're in trouble. Moral of the story - use scope_identity(), there's no reason not to  |
| | | Posted Sunday, January 24, 2010 11:00 PM | |
| New Member

Group: Forum Members Last Login: Sunday, February 28, 2010 3:29 PM Posts: 4, Visits: 17 |
| he obviously is using it for mysql injection teqniques the identify string is the hard part of the injection
'1=1'OR"1"
mentor's words:"freedom of speach is yelling theater in a crowded fire" |
| | | Posted Monday, January 25, 2010 4:22 AM | |
| 
Progenic Crew

Group: Administrators Last Login: Sunday, November 27, 2011 7:50 AM Posts: 2,738, Visits: 38,421 |
| | |
|
|