Module: ActiveRecord::ConnectionAdapters::SQLServer::DatabaseStatements
- Defined in:
- lib/composite_primary_keys/connection_adapters/sqlserver/database_statements.rb
Instance Method Summary collapse
Instance Method Details
#sql_for_insert(sql, pk, binds) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/composite_primary_keys/connection_adapters/sqlserver/database_statements.rb', line 5 def sql_for_insert(sql, pk, binds) sql = if pk && self.class.use_output_inserted # CPK # quoted_pk = SQLServer::Utils.extract_identifiers(pk).quoted # sql.insert sql.index(/ (DEFAULT )?VALUES/), " OUTPUT INSERTED.#{quoted_pk}" quoted_pks = [pk].flatten.map {|pk| "INSERTED.#{SQLServer::Utils.extract_identifiers(pk).quoted}"} sql.dup.insert sql.index(/ (DEFAULT )?VALUES/), " OUTPUT #{quoted_pks.join(", ")}" else "#{sql}; SELECT CAST(SCOPE_IDENTITY() AS bigint) AS Ident" end # CPK # super [sql, binds] end |