require("cipherstash-pg") $stdout.sync = true TIMEOUT = 5.0 CONN_OPTS = { :host => "localhost", :dbname => "test" } def output_progress(msg) puts(">>> #{msg}\n") end output_progress("Starting connection...") (conn = CipherStashPG.connect(CONN_OPTS) or abort("Unable to create a new connection!")) unless (conn.status == CipherStashPG::CONNECTION_OK) then abort(("Connect failed: %s" % [conn.error_message])) end socket = conn.socket_io output_progress("Sending query") conn.send_query("SELECT * FROM pg_stat_activity") loop do output_progress(" waiting for a response") conn.consume_input while conn.is_busy do output_progress((" waiting for data to be available on %p..." % [socket])) (select([socket], nil, nil, TIMEOUT) or raise("Timeout waiting for query response.")) conn.consume_input end (result = conn.get_result or break) output_progress(("Query result:\n%p\n" % [result.values])) end output_progress("Done.") conn.finish