Sha256: 748aea1994ca1600cae5cf60824a0f8207ff14d99f0e7ca2d9932779502b8144
Contents?: true
Size: 1.72 KB
Versions: 79
Compression:
Stored size: 1.72 KB
Contents
require("cipherstash-pg") SAMPLE_WRITE_DATA = "some sample data" SAMPLE_EXPORT_NAME = "lowrite.txt" conn = CipherStashPG.connect(:dbname => "test", :host => "localhost", :port => 5432) puts(((((("dbname: " + conn.db) + "\thost: ") + conn.host) + "\tuser: ") + conn.user)) puts("Beginning transaction") conn.exec("BEGIN") puts("Import test:") puts((" importing %s" % ["(string)"])) oid = conn.lo_import("(string)") puts((" imported as large object %d" % [oid])) puts("Read test:") fd = conn.lo_open(oid, (CipherStashPG::INV_READ | CipherStashPG::INV_WRITE)) conn.lo_lseek(fd, 0, CipherStashPG::SEEK_SET) buf = conn.lo_read(fd, 50) puts((" read: %p" % [buf])) if buf =~ /require 'pg'/ then puts(" read was ok!") end puts("Write test:") conn.lo_lseek(fd, 0, CipherStashPG::SEEK_END) buf = SAMPLE_WRITE_DATA.dup totalbytes = 0 until buf.empty? do (bytes = conn.lo_write(fd, buf) buf.slice!(0, bytes) totalbytes = (totalbytes + bytes)) end puts((" appended %d bytes" % [totalbytes])) puts("Export test:") File.unlink(SAMPLE_EXPORT_NAME) if File.exist?(SAMPLE_EXPORT_NAME) conn.lo_export(oid, SAMPLE_EXPORT_NAME) puts(" success!") if File.exist?(SAMPLE_EXPORT_NAME) puts((" exported as %s (%d bytes)" % [SAMPLE_EXPORT_NAME, File.size(SAMPLE_EXPORT_NAME)])) conn.exec("COMMIT") puts("End of transaction.") puts("Testing read and delete from a new transaction:") puts(" starting a new transaction") conn.exec("BEGIN") fd = conn.lo_open(oid, CipherStashPG::INV_READ) puts(" reopened okay.") conn.lo_lseek(fd, 50, CipherStashPG::SEEK_END) buf = conn.lo_read(fd, 50) puts(" read okay.") if (buf == SAMPLE_WRITE_DATA) puts("Closing and unlinking:") conn.lo_close(fd) puts(" closed.") conn.lo_unlink(oid) puts(" unlinked.") conn.exec("COMMIT") puts("Done.")
Version data entries
79 entries across 79 versions & 1 rubygems