22 #include <drizzled/function/str/strfunc.h>
23 #include <drizzled/function/str/load_file.h>
24 #include <drizzled/error.h>
25 #include <drizzled/catalog/local.h>
26 #include <drizzled/session.h>
27 #include <drizzled/internal/my_sys.h>
28 #include <drizzled/sys_var.h>
29 #include <drizzled/system_variables.h>
31 #include <boost/filesystem.hpp>
37 namespace fs=boost::filesystem;
48 struct stat stat_info;
50 if (!(file_name= args[0]->val_str(str)))
56 fs::path target_path(fs::system_complete(catalog::local_identifier().getPath()));
57 fs::path to_file(file_name->c_ptr());
58 if (not to_file.has_root_directory())
60 target_path /= to_file;
68 if (not secure_file_priv.string().empty())
70 fs::path secure_file_path(fs::system_complete(secure_file_priv));
71 if (target_path.file_string().substr(0, secure_file_path.file_string().size()) != secure_file_path.file_string())
74 my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0),
"--secure-file-priv");
80 if (stat(target_path.file_string().c_str(), &stat_info))
82 my_error(ER_TEXTFILE_NOT_READABLE, MYF(0), file_name->c_ptr());
86 if (!(stat_info.st_mode & S_IROTH))
88 my_error(ER_TEXTFILE_NOT_READABLE, MYF(0), file_name->c_ptr());
92 if (stat_info.st_size > (
long) session.
variables.max_allowed_packet)
94 push_warning_printf(&session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
95 ER_WARN_ALLOWED_PACKET_OVERFLOWED,
96 ER(ER_WARN_ALLOWED_PACKET_OVERFLOWED),
97 func_name(), session.
variables.max_allowed_packet);
101 if (stat_info.st_size == 0)
106 tmp_value.alloc((
size_t)stat_info.st_size);
107 if ((file = internal::my_open(target_path.file_string().c_str(), O_RDONLY, MYF(0))) < 0)
109 if (internal::my_read(file, (
unsigned char*) tmp_value.ptr(), (size_t)stat_info.st_size, MYF(MY_NABP)))
111 internal::my_close(file, MYF(0));
114 if (strlen(tmp_value.ptr()) == 0)
118 tmp_value.length((
size_t)stat_info.st_size);
119 internal::my_close(file, MYF(0));