I\'m trying to manually execute SQL commands so I can access procedures in NuoDB.
I\'m using Ruby on Rails and I\'m using the following command:
Acti
res = ActiveRecord::Base.connection_pool.with_connection { |con| con.exec_query( "SELECT 1;" ) }
The above code is an example for
For me, I couldn't get this to return a hash.
results = ActiveRecord::Base.connection.execute(sql)
But using the exec_query method worked.
results = ActiveRecord::Base.connection.exec_query(sql)
Reposting the answer from our forum to help others with a similar issue:
@connection = ActiveRecord::Base.connection
result = @connection.exec_query('select tablename from system.tables')
result.each do |row|
puts row
end
The working command I'm using to execute custom SQL statements is:
results = ActiveRecord::Base.connection.execute("foo")
with "foo" being the sql statement( i.e. "SELECT * FROM table").
This command will return a set of values as a hash and put them into the results variable.
So on my rails application_controller.rb I added this:
def execute_statement(sql)
results = ActiveRecord::Base.connection.execute(sql)
if results.present?
return results
else
return nil
end
end
Using execute_statement will return the records found and if there is none, it will return nil.
This way I can just call it anywhere on the rails application like for example:
records = execute_statement("select * from table")
"execute_statement" can also call NuoDB procedures, functions, and also Database Views.