Skip to content
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

Calling member methods that change object state and maintaining in local variable #11

Open
jlincoln opened this issue Jun 26, 2013 · 3 comments

Comments

@jlincoln
Copy link

Is it possible to call a method on a object that changes the state of the object in the Oracle database and have that state reflected in the local ruby variable?

Ex.
my_obj = plsql.my_obj_type(:attr1=>'test',:attr2=>null)
my_obj.is_attr2_null.should == true
my_obj.set_attr2(:attr2=>'test1')
my_obj.is_attr2_null.should == false

@jlincoln
Copy link
Author

I ended up doing the following.

describe "Create New Instance" do
it "should have correct attribute values" do
key_values = []
key_values << plsql.xxmcl_key_value(:key=>'ID',:value=>'1')
key_values << plsql.xxmcl_key_value(:key=>'TEXT1',:value=>'text1')
dao = plsql.xxmcl_dao(:table_name=>'xxmcl_dao_test',:primary_key=>'id',:key_values=>key_values)
dao[:table_name].should == 'XXMCL_DAO_TEST'
dao[:primary_key].should == 'ID'
dao[:database_state].should == NULL
dao.key_at_index(:key=>'TEXT1')[0].should > 0
dao.get_key_value(:key=>'TEXT1')[0].should == 'text1'
dao.insertable[0].should == true
dao.insert_record[0] == true
plsql.commit
plsql.select_one("select count() from xxmcl_dao_test where text1 = 'text1'").should == 1
dao.set_key_value(:key=>'TEXT1',:value=>'TESTUPDATE')[0].should == true
dao.set_key_value(:key=>'TEXT1',:value=>'TESTUPDATE')[1][:self][:database_state].should == 'C'
dao.set_key_value(:key=>'TEXT1',:value=>'TESTUPDATE')[0].should == true
dao2 = dao.set_key_value(:key=>'TEXT1',:value=>'TESTUPDATE')[1][:self]
# create a new PLSQL::ObjectInstance using the hash returned from the method call to continue
dao = plsql.xxmcl_dao(:table_name=>dao2[:table_name],:primary_key=>dao2[:primary_key],:key_values=>dao2[:key_values])
dao.updateable[0].should == true
dao.update_record[0].should == true
plsql.select_one("select count(
) from xxmcl_dao_test where text1 = 'TESTUPDATE'").should == 1 # does not work because local dao var is unchanged by set_key_value
end
end

@jgebal
Copy link
Contributor

jgebal commented Nov 14, 2015

That is not possible at the moment as Ruby object is not directly linked to underlying Oracle object.

Oracle object state "lives" through the duration of database code execution.
If you look at object type unit tests for ruby-plsql framework you will see that the solution is to reference the Oracle object type explicitly each time.

When referencing the Ruby representation of Oracle Object Type Instance, it's best to thing of it as of values of Oracle Object stored in Ruby code, not the object itself.

@jgebal
Copy link
Contributor

jgebal commented Nov 19, 2015

This issue is more related to the ruby-plsql or ruby-oci8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants