Legal | Privacy
#blob.rb: Save and Load BLOB
require 'config.rb'

# Create a connection to Oracle
conn = OCI8.new(DB_USER, DB_PASSWORD, DB_SERVER)

conn.exec("DELETE FROM test_blob")

# Must insert a EMPTY_BLOB before save real data
cursor = conn.parse("INSERT INTO test_blob VALUES(:name, EMPTY_BLOB())")
Dir["*.png"].each do |fname|
	cursor.exec(fname)
end

# Save BLOB into Oracle
conn.exec("SELECT name,image FROM test_blob") do |name, image|
	puts "uploading file: " + name
	File.open(name, 'r') do |f|
		image.write(f.read)
		image.size = f.pos
	end
end

# Load BLOB from Oracle
conn.exec("SELECT name,image FROM test_blob") do |name, image|
	puts "downloading file: " + name
	File.open("download/"+name, 'w') do |f|
		f.write(image.read)
	end
end

# End
conn.logoff
puts '-'*80

E-mail this page
Printer View Printer View
Oracle Is The Information Company About Oracle | Oracle RSS Feeds | Careers | Contact Us | Site Maps | Legal Notices | Terms of Use | Privacy