Ken,
Thanks so much for your help! I think I may have something that
will be interesting for you to look at below. I've copied my logs
from both Rails level and TinyTds::Client level so you can see how
things are reacting. The interesting thing is that the .insert
command is returning the wrong ID; however, the longer manual version
is returning the correct ID? Do you still think this is
configuration, or a bug? Let me know anything I can do to get you
more info that would be helpful...
##########################################################
Below is output from my Rails-level command prompt...
##########################################################
ruby-1.8.7-p334 :028 > u = User.new :email => '
ejle...@test.com'
ruby-1.8.7-p334 :029 > u.save!
EXECUTE (43.5ms) BEGIN TRANSACTION
User Load (41.1ms) SELECT TOP (1) [evt_users].[id] FROM [evt_users]
WHERE (LOWER([evt_users].[email]) = LOWER(
N'ejle...@test.com'))
AREL (81.5ms) INSERT INTO [evt_users] ([current_sign_in_ip],
[sign_in_count], [encrypted_password], [email], [last_name],
[last_sign_in_ip], [created_at], [longitude], [reset_password_token],
[birthday], [remember_created_at], [first_name], [roles_mask],
[club_id], [latitude], [current_sign_in_at], [updated_at],
[last_sign_in_at]) VALUES (NULL, 0, N'',
N'ejle...@test.com', NULL,
NULL, '2011-04-28 02:49:11.340', NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, '2011-04-28 02:49:11.340', NULL)
EXECUTE (37.2ms) COMMIT TRANSACTION
=> true
ruby-1.8.7-p334 :030 > u.delete
AREL (36.3ms) DELETE FROM [evt_users] WHERE [evt_users].[id] = 19
=> #<User id: 19, email: "
ejle...@test.com", encrypted_password: "",
reset_password_token: nil, remember_created_at: nil, sign_in_count: 0,
current_sign_in_at: nil, last_sign_in_at: nil, current_sign_in_ip:
nil, last_sign_in_ip: nil, first_name: nil, last_name: nil, birthday:
nil, created_at: "2011-04-28 02:49:11", updated_at: "2011-04-28
02:49:11", latitude: nil, longitude: nil, club_id: nil, roles_mask:
nil>
ruby-1.8.7-p334 :031 > User.last
User Load (42.1ms) SELECT TOP (1) [evt_users].* FROM [evt_users]
ORDER BY
evt_users.id DESC
=> #<User id: 964, email: "
ejle...@test.com", encrypted_password:
"", reset_password_token: nil, remember_created_at: nil,
sign_in_count: 0, current_sign_in_at: nil, last_sign_in_at: nil,
current_sign_in_ip: nil, last_sign_in_ip: nil, first_name: nil,
last_name: nil, birthday: nil, created_at: "2011-04-28 02:49:11",
updated_at: "2011-04-28 02:49:11", latitude: nil, longitude: nil,
club_id: nil, roles_mask: nil>
ruby-1.8.7-p334 :033 > client.execute(" INSERT INTO [evt_users]
([current_sign_in_ip], [sign_in_count], [encrypted_password], [email],
[last_name], [last_sign_in_ip], [created_at], [longitude],
[reset_password_token], [birthday], [remember_created_at],
[first_name], [roles_mask], [club_id], [latitude],
[current_sign_in_at], [updated_at], [last_sign_in_at]) VALUES (NULL,
0, N'',
N'ejle...@test.com', NULL, NULL, '2011-04-28 02:49:11.340',
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '2011-04-28
02:49:11.340', NULL)").insert
=> 19
##########################################################
Using .insert returns 19 as the identity!
##########################################################
ruby-1.8.7-p334 :042 > client.execute(" INSERT INTO [evt_users]
([current_sign_in_ip], [sign_in_count], [encrypted_password], [email],
[last_name], [last_sign_in_ip], [created_at], [longitude],
[reset_password_token], [birthday], [remember_created_at],
[first_name], [roles_mask], [club_id], [latitude],
[current_sign_in_at], [updated_at], [last_sign_in_at]) VALUES (NULL,
0, N'',
N'ejle...@test.com', NULL, NULL, '2011-04-28 02:49:11.340',
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '2011-04-28
02:49:11.340', NULL)").insert
=> 19
##########################################################
Using the long manual version returns the correct ID
##########################################################
ruby-1.8.7-p334 :038 > client.execute(" INSERT INTO [evt_users]
([current_sign_in_ip], [sign_in_count], [encrypted_password], [email],
[last_name], [last_sign_in_ip], [created_at], [longitude],
[reset_password_token], [birthday], [remember_created_at],
[first_name], [roles_mask], [club_id], [latitude],
[current_sign_in_at], [updated_at], [last_sign_in_at]) VALUES (NULL,
0, N'',
N'ejle...@test.com', NULL, NULL, '2011-04-28 02:49:11.340',
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '2011-04-28
02:49:11.340', NULL)").do
=> 1
ruby-1.8.7-p334 :039 > client.execute("SELECT CAST(SCOPE_IDENTITY() AS
bigint) AS Ident").each.first['Ident'].to_i => 966
On Apr 27, 9:30 pm, Ken Collins <
k...@metaskills.net> wrote:
> Eric,
>
> This issue was something I could never reproduce. If I were you I would also debug it at a lower level. Some pseudo code like this would be more appropriate.
>
> client = TinyTds::Client.new :dataserver => 'myQA', :username => '...', :password => '...'
>
> # This is short hand for execute and return scope_identity().
> client.execute("INSERT INTO [users] ([email]) VALUES (
N'...@bar.com')").insert # => ??? (should be identity)
>
> # This is a longer manual version.
> client.execute("INSERT INTO [users] ([email]) VALUES (
N'...@bar.com')").do