Class: OCI8::BFILE
Overview
This class is a ruby-side class of Oracle BFILE datatype. It is a read-only LOB. You cannot change the contents.
You can read files on the server-side as follows:
-
Connect to the Oracle server as a user who has CREATE DIRECTORY privilege.
# create a directory object on the Oracle server. CREATE DIRECTORY file_storage_dir AS '/opt/file_storage'; # grant a privilege to read files on file_storage_dir directory to a user. GRANT READ ON DIRECTORY file_storage_dir TO username; -
Create a file ‘hello_world.txt’ in the directory ‘/opt/file_storage’ on the server filesystem.
echo 'Hello World!' > /opt/file_storage/hello_world.txt -
Read the file by ruby-oci8.
require 'oci8' # The user must have 'READ ON DIRECTORY file_storage_dir' privilege. conn = OCI8.new('username/password') # The second argument is usually an uppercase string unless the directory # object is explicitly created as *double-quoted* lowercase characters. bfile = OCI8::BFILE.new(conn, 'FILE_STORAGE_DIR', 'hello_world.txt') bfile.read # => "Hello World!\n"
Instance Method Summary collapse
-
#dir_alias ⇒ String
Returns the directory object name.
-
#dir_alias=(dir_alias) ⇒ Object
Changes the directory object name.
-
#exists? ⇒ Boolean
Returns
truewhen the BFILE exists on the server’s operating system. -
#filename ⇒ String
Returns the file name.
-
#filename=(filename) ⇒ Object
Changes the file name.
-
#initialize(conn, directory = nil, filename = nil) ⇒ OCI8::BFILE
constructor
Creates a BFILE object.
-
#size=(dummy) ⇒ Object
Raises
RuntimeErroralways. -
#truncate(dummy) ⇒ Object
Raises
RuntimeErroralways. -
#write(dummy) ⇒ Object
Raises
RuntimeErroralways.
Methods inherited from LOB
#available?, #chunk_size, #close, #eof?, #pos, #read, #rewind, #seek, #size
Constructor Details
#initialize(conn, directory = nil, filename = nil) ⇒ OCI8::BFILE
958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 |
# File 'ext/oci8/lob.c', line 958 static VALUE oci8_bfile_initialize(int argc, VALUE *argv, VALUE self) { oci8_lob_t *lob = TO_LOB(self); VALUE svc; VALUE dir_alias; VALUE filename; oci8_svcctx_t *svcctx; int rv; rb_scan_args(argc, argv, "12", &svc, &dir_alias, &filename); svcctx = oci8_get_svcctx(svc); rv = OCIDescriptorAlloc(oci8_envhp, &lob->base.hp.ptr, OCI_DTYPE_LOB, 0, NULL); if (rv != OCI_SUCCESS) { oci8_env_raise(oci8_envhp, rv); } lob->base.type = OCI_DTYPE_LOB; lob->pos = 0; lob->char_width = 1; lob->csfrm = SQLCS_IMPLICIT; lob->lobtype = OCI_TEMP_BLOB; lob->state = S_BFILE_CLOSE; if (argc != 1) { OCI8SafeStringValue(dir_alias); OCI8SafeStringValue(filename); oci8_bfile_set_name(self, dir_alias, filename); } oci8_link_to_parent(&lob->base, &svcctx->base); lob->svcctx = svcctx; return Qnil; } |
Instance Method Details
#dir_alias ⇒ String
996 997 998 999 1000 1001 1002 |
# File 'ext/oci8/lob.c', line 996 static VALUE oci8_bfile_get_dir_alias(VALUE self) { VALUE dir_alias; oci8_bfile_get_name(self, &dir_alias, NULL); return dir_alias; } |
#dir_alias=(dir_alias) ⇒ Object
1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 |
# File 'ext/oci8/lob.c', line 1026 static VALUE oci8_bfile_set_dir_alias(VALUE self, VALUE dir_alias) { VALUE filename; OCI8SafeStringValue(dir_alias); oci8_bfile_get_name(self, NULL, &filename); oci8_bfile_set_name(self, dir_alias, filename); rb_ivar_set(self, id_dir_alias, dir_alias); return dir_alias; } |
#exists? ⇒ Boolean
1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 |
# File 'ext/oci8/lob.c', line 1060 static VALUE oci8_bfile_exists_p(VALUE self) { oci8_lob_t *lob = TO_LOB(self); oci8_svcctx_t *svcctx = check_svcctx(lob); boolean flag; chker2(OCILobFileExists_nb(svcctx, svcctx->base.hp.svc, oci8_errhp, lob->base.hp.lob, &flag), &svcctx->base); return flag ? Qtrue : Qfalse; } |
#filename ⇒ String
1011 1012 1013 1014 1015 1016 1017 |
# File 'ext/oci8/lob.c', line 1011 static VALUE oci8_bfile_get_filename(VALUE self) { VALUE filename; oci8_bfile_get_name(self, NULL, &filename); return filename; } |
#filename=(filename) ⇒ Object
1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 |
# File 'ext/oci8/lob.c', line 1044 static VALUE oci8_bfile_set_filename(VALUE self, VALUE filename) { VALUE dir_alias; OCI8SafeStringValue(filename); oci8_bfile_get_name(self, &dir_alias, NULL); oci8_bfile_set_name(self, dir_alias, filename); rb_ivar_set(self, id_filename, filename); return filename; } |
#size=(dummy) ⇒ Object
Raises RuntimeError always.
1076 1077 1078 1079 |
# File 'ext/oci8/lob.c', line 1076 static VALUE oci8_bfile_error(VALUE self, VALUE dummy) { rb_raise(rb_eRuntimeError, "cannot modify a read-only BFILE object"); } |
#truncate(dummy) ⇒ Object
Raises RuntimeError always.
1076 1077 1078 1079 |
# File 'ext/oci8/lob.c', line 1076 static VALUE oci8_bfile_error(VALUE self, VALUE dummy) { rb_raise(rb_eRuntimeError, "cannot modify a read-only BFILE object"); } |
#write(dummy) ⇒ Object
Raises RuntimeError always.
1076 1077 1078 1079 |
# File 'ext/oci8/lob.c', line 1076 static VALUE oci8_bfile_error(VALUE self, VALUE dummy) { rb_raise(rb_eRuntimeError, "cannot modify a read-only BFILE object"); } |