How to Extract the Code from a Proc Object

How to extract the code from a Proc object?

You can use the ruby2ruby library:

>> # tested with 1.8.7
>> require "parse_tree"
=> true
>> require "ruby2ruby"
=> true
>> require "parse_tree_extensions"
=> true
>> p = Proc.new{test = 0}
>> p.to_ruby
=> "proc { test = 0 }"

You can also turn this string representation of the proc back to ruby and call it:

>> eval(p.to_ruby).call
0

More about ruby2ruby in this video: Hacking with ruby2ruby.

Is it possible to see the ruby code in a proc?

Take a look at the sourcify gem:

proc { x + y }.to_source
# >> "proc { (x + y) }"

extract a string from a stored proc definition

try

SELECT 
name,
table_name = CASE WHEN OBJECT_DEFINITION(OBJECT_ID) LIKE '%BOCTEST.S653C36C.LIVEBOC_A.YP040P%' THEN 'LIVEBOC_A'
WHEN OBJECT_DEFINITION(OBJECT_ID) LIKE '%BOCTEST.S653C36C.LIVEBOC_B.YP040P%' THEN 'LIVEBOC_B' END
FROM sys.objects o
WHERE o.[type] IN ('P', 'PC')
AND name like '%_Extract'

how to extract properties of a list object and passing into stored procedure

It seems like you're simply missing a foreach:

foreach (var emp in emp.Emp_List)
{
// ... blah ...
cmd.Parameters.Add("@Empid", SqlDbType.Int).Value = emp.Id;
cmd.Parameters.Add("@Name", SqlDbType.VarChar, 500).Value = emp.Name;
// ... blah ...
cmd.ExecuteNonQuery();
}

Print the actual Ruby code of a block?

This question is related to:

  • Converting Proc and Method to String
  • How to extract the code from a Proc object?
  • Ruby block to string instead of executing
  • Compare the Content, Not the Results, of Procs

as Andrew suggested me when I asked the first one in this list. By using the gem 'sourcify', you can get something close to the block, but not exactly the same:

require 'sourcify'

def block_to_s(&blk)
blk.to_source(:strip_enclosure => true)
end

puts block_to_s {
str = "Hello"
str.reverse!
print str
}

In above, notice that you either have to put parentheses around the argument of puts (block_to_s ... end) or use {...} instead of do ... end because of the strength of connectivity as discussed repeatedly in stackoverflow.

This will give you:

str = "Hello"
str.reverse!
print(str)

which is equivalent to the original block as a ruby script, but not the exact same string.

Extracting a single procedure from an object file?

I am not sure, there is are easy way in general case.

For example, multiple procedures can refer for one shared piece of code (i.e. static function). So you need to build call graph for all code blocks in file and and take code blocks that are referred by your procedure. Than you should fix addresses in all jumps and calls, since there will be new code layout.

Extract Contents of DataSet into an Object

The simplest and most efficient approach would be to not use a DataSet/DataTable at all:

private List<int> GetSubGroupsBelongingToUser()
{
List<int> list = new List<int>();
using (var con = new SqlConnection(ConfigurationManager.ConnectionStrings["FSK_ServiceMonitor_Users_Management.Properties.Settings.FSK_ServiceMonitorConnectionString"].ConnectionString))
using (var cmd = new SqlCommand("Test", con))
{
cmd.CommandType = CommandType.StoredProcedure;
var param = new SqlParameter("@UserId", SqlDbType.Int).Value = int.Parse(cbxSelectUser.Text);
cmd.Parameters.Add(param);
con.Open();
using (var rd = cmd.ExecuteReader())
{
while (rd.Read()) list.Add(rd.GetInt32(0));
}
} // no need to close the connection with the using

return list;
}

If you insist on the DataTable, at least it's more conscise:

return DS.Tables[0].AsEnumerable().Select(r => r.Field<int>(0)).ToList();

How to extract / use output from SAS proc

An example for you:

proc reg data=SASHELP.CARS;
model Horsepower=EngineSize Cylinders MPG_City;
ods output ParameterEstimates=data1;
run;

data want;
set data1;
odds_ratio=exp(Estimate);
run;


Related Topics



Leave a reply



Submit