133
133
static uint32_t get_counter()
135
135
boost::mutex::scoped_lock lock(counter_mutex);
141
std::string Table::build_tmptable_filename()
144
os << "/" << TMP_FILE_PREFIX << current_pid << pthread_self() << "-" << get_counter();
145
return drizzle_tmpdir + boost::to_lower_copy(os.str());
144
size_t Table::build_tmptable_filename(std::string &buffer)
146
ostringstream post_tmpdir_str;
148
buffer.append(drizzle_tmpdir);
149
size_t tmpdir_length= buffer.length();
151
post_tmpdir_str << "/" << TMP_FILE_PREFIX << current_pid;
152
post_tmpdir_str << pthread_self() << "-" << get_counter();
154
buffer.append(post_tmpdir_str.str());
156
transform(buffer.begin() + tmpdir_length, buffer.end(), buffer.begin() + tmpdir_length, ::tolower);
158
return buffer.length();
161
size_t Table::build_tmptable_filename(std::vector<char> &buffer)
163
ostringstream post_tmpdir_str;
165
post_tmpdir_str << drizzle_tmpdir << "/" << TMP_FILE_PREFIX << current_pid;
166
post_tmpdir_str << pthread_self() << "-" << get_counter();
168
buffer.resize(post_tmpdir_str.str().length() + 1);
169
memcpy(&buffer[0], post_tmpdir_str.str().c_str(), post_tmpdir_str.str().size());
170
buffer[post_tmpdir_str.str().size()]= 0;
172
return buffer.size();
149
177
Creates path to a cursor: drizzle_data_dir/db/table.ext
177
205
path length on success, 0 on failure
180
std::string Table::build_table_filename(const std::string &in_db, const std::string &in_table_name, bool is_tmp)
208
size_t Table::build_table_filename(std::string &in_path, const std::string &in_db, const std::string &in_table_name, bool is_tmp)
182
string in_path= util::tablename_to_filename(in_db) + FN_LIBCHAR;
183
return in_path + (is_tmp ? in_table_name : util::tablename_to_filename(in_table_name));
210
if (util::tablename_to_filename(in_db, in_path))
212
errmsg_printf(error::ERROR, _("Schema name cannot be encoded and fit within filesystem name length restrictions."));
216
in_path.append(FN_ROOTDIR);
218
if (is_tmp) // It a conversion tmp
220
in_path.append(in_table_name);
222
else if (util::tablename_to_filename(in_table_name, in_path))
224
errmsg_printf(error::ERROR, _("Table name cannot be encoded and fit within filesystem name length restrictions."));
228
return in_path.length();
186
231
Table::Table(const drizzled::Table &table) :
197
242
void Table::init()
201
245
case message::Table::FUNCTION:
202
246
case message::Table::STANDARD:
203
assert(path.empty());
204
path= build_table_filename(getSchemaName(), table_name, false);
247
assert(path.size() == 0);
248
build_table_filename(path, getSchemaName(), table_name, false);
206
250
case message::Table::INTERNAL:
207
assert(path.empty());
208
path= build_table_filename(getSchemaName(), table_name, true);
251
assert(path.size() == 0);
252
build_table_filename(path, getSchemaName(), table_name, true);
210
254
case message::Table::TEMPORARY:
211
255
if (path.empty())
212
path= build_tmptable_filename();
257
build_tmptable_filename(path);
216
if (type == message::Table::TEMPORARY)
218
size_t pos= path.find("tmp/#sql");
219
if (pos != std::string::npos)
220
key_path= path.substr(pos);
263
case message::Table::FUNCTION:
264
case message::Table::STANDARD:
265
case message::Table::INTERNAL:
267
case message::Table::TEMPORARY:
271
pos= path.find("tmp/#sql");
272
if (pos != std::string::npos)
274
key_path= path.substr(pos);
223
280
hash_value= util::insensitive_hash()(path);
224
key.set(getKeySize(), getSchemaName(), boost::to_lower_copy(std::string(getTableName())));
282
std::string tb_name(getTableName());
283
boost::to_lower(tb_name);
284
key.set(getKeySize(), getSchemaName(), tb_name);