| | | 
Progenic Crew

Group: Administrators Last Login: Monday, July 26, 2010 2:34 AM Posts: 2,759, Visits: 38,407 |
| | 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?
|
| | | | 
Progenic Crew

Group: Administrators Last Login: Monday, July 26, 2010 2:34 AM Posts: 2,759, Visits: 38,407 |
| 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; }
|
| | | | 
Progenic Family

Group: Forum Members Last Login: Monday, February 22, 2010 10:41 PM Posts: 537, Visits: 1,389 |
| just out of curiosity
where are u using this
just if ya want to say |
| | | | 
Progenic Crew

Group: Administrators Last Login: Monday, July 26, 2010 2:34 AM Posts: 2,759, Visits: 38,407 |
| | 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 .
|
| | | | 
Progenic Crew

Group: Administrators Last Login: Friday, June 25, 2010 11:11 AM Posts: 1,063, Visits: 5,883 |
| | 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 |
| | | | 
Progenic Family

Group: Forum Members Last Login: Monday, February 22, 2010 10:41 PM Posts: 537, 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 |
| | | | 
Progenic Crew

Group: Administrators Last Login: Monday, July 26, 2010 2:34 AM Posts: 2,759, Visits: 38,407 |
| 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?
|
| | | | 
Progenic Crew

Group: Administrators Last Login: Friday, June 25, 2010 11:11 AM Posts: 1,063, Visits: 5,883 |
| | 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  |
| | | | 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" |
| | | | 
Progenic Crew

Group: Administrators Last Login: Monday, July 26, 2010 2:34 AM Posts: 2,759, Visits: 38,407 |
| | |
|
|