require("cipherstash-pg") require("stringio") $stderr.puts("Opening database connection ...") conn = CipherStashPG.connect(:dbname => "test") conn.exec("DROP TABLE IF EXISTS logs;\nCREATE TABLE logs (\n\tclient_ip inet,\n\tusername text,\n\tts timestamp,\n\trequest text,\n\tstatus smallint,\n\tbytes int\n);\n") csv_io = StringIO.new("\"127.0.0.1\",\"\",\"30/Aug/2010:08:21:24 -0700\",\"GET /manual/ HTTP/1.1\",404,205\n\"127.0.0.1\",\"\",\"30/Aug/2010:08:21:24 -0700\",\"GET /favicon.ico HTTP/1.1\",404,209\n\"127.0.0.1\",\"\",\"30/Aug/2010:08:21:24 -0700\",\"GET /favicon.ico HTTP/1.1\",404,209\n\"127.0.0.1\",\"\",\"30/Aug/2010:08:22:29 -0700\",\"GET /manual/ HTTP/1.1\",200,11094\n\"127.0.0.1\",\"\",\"30/Aug/2010:08:22:38 -0700\",\"GET /manual/index.html HTTP/1.1\",200,725\n\"127.0.0.1\",\"\",\"30/Aug/2010:08:27:56 -0700\",\"GET /manual/ HTTP/1.1\",200,11094\n\"127.0.0.1\",\"\",\"30/Aug/2010:08:27:57 -0700\",\"GET /manual/ HTTP/1.1\",200,11094\n\"127.0.0.1\",\"\",\"30/Aug/2010:08:28:06 -0700\",\"GET /manual/index.html HTTP/1.1\",200,7709\n\"127.0.0.1\",\"\",\"30/Aug/2010:08:28:06 -0700\",\"GET /manual/images/feather.gif HTTP/1.1\",200,6471\n\"127.0.0.1\",\"\",\"30/Aug/2010:08:28:06 -0700\",\"GET /manual/images/left.gif HTTP/1.1\",200,60\n\"127.0.0.1\",\"\",\"30/Aug/2010:08:28:06 -0700\",\"GET /manual/style/css/manual.css HTTP/1.1\",200,18674\n\"127.0.0.1\",\"\",\"30/Aug/2010:08:28:06 -0700\",\"GET /manual/style/css/manual-print.css HTTP/1.1\",200,13200\n\"127.0.0.1\",\"\",\"30/Aug/2010:08:28:06 -0700\",\"GET /manual/images/favicon.ico HTTP/1.1\",200,1078\n\"127.0.0.1\",\"\",\"30/Aug/2010:08:28:06 -0700\",\"GET /manual/style/css/manual-loose-100pc.css HTTP/1.1\",200,3065\n\"127.0.0.1\",\"\",\"30/Aug/2010:08:28:14 -0700\",\"OPTIONS * HTTP/1.0\",200,0\n\"127.0.0.1\",\"\",\"30/Aug/2010:08:28:15 -0700\",\"OPTIONS * HTTP/1.0\",200,0\n\"127.0.0.1\",\"\",\"30/Aug/2010:08:28:47 -0700\",\"GET /manual/mod/directives.html HTTP/1.1\",200,33561\n\"127.0.0.1\",\"\",\"30/Aug/2010:08:28:53 -0700\",\"GET /manual/mod/mpm_common.html HTTP/1.1\",200,67683\n\"127.0.0.1\",\"\",\"30/Aug/2010:08:28:53 -0700\",\"GET /manual/images/down.gif HTTP/1.1\",200,56\n\"127.0.0.1\",\"\",\"30/Aug/2010:08:28:53 -0700\",\"GET /manual/images/up.gif HTTP/1.1\",200,57\n\"127.0.0.1\",\"\",\"30/Aug/2010:09:19:58 -0700\",\"GET /manual/mod/mod_log_config.html HTTP/1.1\",200,28307\n\"127.0.0.1\",\"\",\"30/Aug/2010:09:20:19 -0700\",\"GET /manual/mod/core.html HTTP/1.1\",200,194144\n\"127.0.0.1\",\"\",\"30/Aug/2010:16:02:56 -0700\",\"GET /manual/ HTTP/1.1\",200,11094\n\"127.0.0.1\",\"\",\"30/Aug/2010:16:03:00 -0700\",\"GET /manual/ HTTP/1.1\",200,11094\n\"127.0.0.1\",\"\",\"30/Aug/2010:16:06:16 -0700\",\"GET /manual/mod/mod_dir.html HTTP/1.1\",200,10583\n\"127.0.0.1\",\"\",\"30/Aug/2010:16:06:44 -0700\",\"GET /manual/ HTTP/1.1\",200,7709\n") $stderr.puts("Running COPY command with data ...") buf = "" conn.transaction do res = conn.copy_data("COPY logs FROM STDIN WITH csv") do $stderr.print("Sending lines... ") csv_io.each_line.with_index do |buf, i| $stderr.print("#{(i + 1)} ") conn.put_copy_data(buf) end $stderr.puts("done.") end $stderr.puts(("Result of COPY is: %s" % [res.res_status(res.result_status)])) $stderr.puts((" tuples copied: %p" % [res.cmd_tuples])) end conn.finish