On Thursday, March 3, 2016 at 12:16:44 PM UTC-8, Ryan Snodgrass wrote:
>
> Thanks for the quick reply Jeremy.
>
> What I'm going to try is to write out a custom row count and manually 
> insert the Execute as User statement for each functionality - row count and 
> iteration.
>

As I mentioned earlier, your approach below using multiple statements in a 
single query is not supported, and will result in undefined behavior. 
 Proceed at your own risk.  I can tell you that it will probably leave the 
connection executing as the ADND\user user, instead of the user you 
specified in ENV.  If you don't understand why that is, you shouldn't use 
the approach below.  If you do understand why that is, you wouldn't use the 
approach below.

Jeremy
 

>
> @sql = "SELECT * FROM [secure].[Employee Snapshot Fact] [Employee 
> Snapshot Fact]"
> def row_count
>   "EXECUTE AS USER='ADND\\user'; SELECT COUNT(*) AS total_rows FROM 
> (#{@sql}) x"
> end
>
> def query
>   "EXECUTE AS USER='ADND\\user'; #{@sql}"
> end
>
> a = Sequel.connect(
> "tinytds://#{ENV['SQL_SERVER_development_USERNAME']}:#{ENV['SQL_SERVER_development_PASSWORD']}@#{ENV['SQL_SERVER_development_HOST']}:#{ENV['SQL_SERVER_development_PORT']}/#{ENV['SQL_SERVER_development_DB']}"
> )
>
> a[row_count].first
> => {:total_rows=>4167860}
>
> a[query].first
> => {:"employee key"=>126, :"job key"=>0, :"active faculty key"=>21, 
> :"faculty appointment key"=>6, :"date key"=>20020630}
>
> I have to watch out for ORDER BY. I think I'm just going to Regex out any 
> order clauses at time of row_count. I found a good example here 
> <https://regex101.com/r/jS5fN1/1#javascript>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to