Sha256: 3b130494db85a069e8ddfb3e139b6bc7ecafaf5f083f781539dda4153bfcd616
Contents?: true
Size: 1.9 KB
Versions: 79
Compression:
Stored size: 1.9 KB
Contents
require("cipherstash-pg") conn = CipherStashPG.connect(:dbname => "test") table_name = "issue_119" field_list = ["name", "body_weight", "brain_weight"] method = 0 options = { :truncate => true } sql_parameters = "" conn.set_error_verbosity(CipherStashPG::PQERRORS_VERBOSE) conn.exec("DROP TABLE IF EXISTS #{table_name}") conn.exec("CREATE TABLE #{table_name} ( id SERIAL, name TEXT, body_weight REAL, brain_weight REAL )") text = "Mountain beaver\t1.35\t465\nCow\t465\t423\nGrey wolf\t36.33\t119.5\nGoat\t27.66\t115\nGuinea pig\t1.04\t5.5\nDipliodocus\t11700\t50\nAsian elephant\t2547\t4603\nDonkey\t187.1\t419\nHorse\t521\t655\nPotar monkey\t10\t115\nCat\t3.3\t25.6\nGiraffe\t529\t680\nGorilla\t207\t406\nHuman\t62\t1320\nAfrican elephant\t6654\t5712\nTriceratops\t9400\t70\nRhesus monkey\t6.8\t179\nKangaroo\t35\t56\nGolden hamster\t0.12\t1\nMouse\t0.023\t0.4\nRabbit\t2.5\t12.1\nSheep\t55.5\t175\nJaguar\t100\t157\nChimpanzee\t52.16\t440\nBrachiosaurus\t87000\t154.5\nMole\t0.122\t3\nPig\t192\t18\n" conn.transaction do rc = conn rc.exec("TRUNCATE TABLE #{table_name};") if options[:truncate] sql = "COPY #{table_name} (#{field_list.join(",")}) FROM STDIN #{sql_parameters} " p(sql) rc.exec(sql) errmsg = nil begin if (method == 1) then rc.put_copy_data((text + "\\.\n")) else text.each_line { |line| rc.put_copy_data(line) } end rescue Errno => err errmsg = ("%s while reading copy data: %s" % [err.class.name, err.message]) puts("an error occurred") end if errmsg then rc.put_copy_end(errmsg) puts("ERROR #{errmsg}") else rc.put_copy_end end while res = rc.get_result do st = res.res_status(res.result_status) puts(("Result of COPY is: %s" % [st])) if (res.result_status != CipherStashPG::PGRES_COPY_IN) then puts(res.error_message) end end puts("end") end conn.exec("SELECT name, brain_weight FROM #{table_name}") do |res| p(res.values) end
Version data entries
79 entries across 79 versions & 1 rubygems