-
Notifications
You must be signed in to change notification settings - Fork 383
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mssql get_table_name bug #583
Comments
please always confirm the issue on latest release ... in this case 1.3.10 - it's probably there but we shall make sure (traces might differ). there's lot of excellent explanation but a (pseudo) piece of code reproducing the issue would be great. AR-JDBC and esp. the MS-SQL adapter is mostly as good as the community of JRuby @ SQLServer users make it, just in case you'll be wating for the fix :) |
Apologies, hadn't noticed a new version so hadn't updated but I'll try it at some point. The code I was looking through however was from github and not my local copy so any code references here should be from the latest version. Not in a major hurry for a fix so no worries. Just in case anyone else runs into it :) For replicating it, not sure what to put for pseudocode or actual code. You can replicate it with a 1 liner in any existing rails project. I can edit the original post to include an example with migrations and model creation if needed? Otherwise the example that's already there will do it
:) |
@pareeohnos thanks a lot ... I thought that there was some special table naming necessary - my bad! |
😋 if we omit the year ... we can call it a same day fix :) |
I'm not sure if this is also an issue for other adapters, but I've only noticed it for the MSSql adapter.
The application I'm working on retrieves application generated alerts about the status of the software. These alerts primarily contain errors, and in some cases these error contain a SQL query that was run that caused the error. Until recently I hadn't had any issues until a particular error arrived that caused the application to fail, stating that the table didn't exist.
Strangely though, the table it was searching for is not a table within the application itself, but rather a table that the remote software is using, so I knew that the error was somehow being injected. I've done some more digging as I thought that it may have been an accidental SQL injection, however all of the SQL that our application builds up uses active record, and everything is escaped.
The error I was getting pointed to the
get_table_name
method within theutils.rb
file of the MSSQL adapter. I looked at the code and saw that regexes are being use to determine the table name from the query being run, and after a quick test realised that this was the problem.The query that my application is attempting to run is a simple
SELECT COUN(*)
, however theWHERE
clause contains anINSERT
statement. An example of a failing query isThe MSSQL adapter then uses the regex
to pull the table names. If you run this regex against this query on something like
regexpal.com
with them
flag enabled, it highlights theINSERT INTO their_table
instead of theFROM our_table
.I THINK this would be resolved by simply changing the order of the if statement to run the other regex first, however this could well cause issues for other queries.
This can also easily be replicated within rails by simply doing something like
Which gives the stack trace
Running the same code in rails with a postgres connection works as expected.
I'm working with Rails 4.1.1, jRuby 1.7.13, and activerecord-jdbc 1.3.9
you can support MS-SQL fixes at BountySource
The text was updated successfully, but these errors were encountered: