~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_table.cc

  • Committer: Monty Taylor
  • Date: 2008-12-11 07:51:00 UTC
  • mfrom: (670.3.3 remove-my-stpncpy)
  • mto: This revision was merged to the branch mainline in revision 672.
  • Revision ID: monty@inaugust.com-20081211075100-1jaqspnugi2u87u0
MergedĀ fromĀ Toru.

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
#include <drizzled/lock.h>
32
32
#include <drizzled/unireg.h>
33
33
 
 
34
using namespace std;
 
35
 
34
36
extern HASH lock_db_cache;
35
37
 
36
38
int creating_table= 0;        // How many mysql_create_table are running
94
96
  if (!memcmp(from, TMP_FILE_PREFIX, TMP_FILE_PREFIX_LENGTH))
95
97
  {
96
98
    /* Temporary table name. */
97
 
    res= (my_stpncpy(to, from, to_length) - to);
 
99
    res= strlen(strncpy(to, from, to_length));
98
100
  }
99
101
  else
100
102
  {
176
178
    build_tmptable_filename() for them.
177
179
 
178
180
  RETURN
179
 
    path length
 
181
    path length on success, 0 on failure
180
182
*/
181
183
 
182
184
uint32_t build_table_filename(char *buff, size_t bufflen, const char *db,
183
185
                          const char *table_name, const char *ext, uint32_t flags)
184
186
{
 
187
  string table_path;
185
188
  char dbbuff[FN_REFLEN];
186
189
  char tbbuff[FN_REFLEN];
 
190
  int rootdir_len= strlen(FN_ROOTDIR);
187
191
 
188
192
  if (flags & FN_IS_TMP) // FN_FROM_IS_TMP | FN_TO_IS_TMP
189
 
    my_stpncpy(tbbuff, table_name, sizeof(tbbuff));
 
193
    strncpy(tbbuff, table_name, sizeof(tbbuff));
190
194
  else
191
195
    tablename_to_filename(table_name, tbbuff, sizeof(tbbuff));
192
196
 
193
197
  tablename_to_filename(db, dbbuff, sizeof(dbbuff));
 
198
  table_path= drizzle_data_home;
 
199
  int without_rootdir= table_path.length()-rootdir_len;
194
200
 
195
 
  char *end = buff + bufflen;
196
201
  /* Don't add FN_ROOTDIR if dirzzle_data_home already includes it */
197
 
  char *pos = my_stpncpy(buff, drizzle_data_home, bufflen);
198
 
  int rootdir_len= strlen(FN_ROOTDIR);
199
 
  if (pos - rootdir_len >= buff &&
200
 
      memcmp(pos - rootdir_len, FN_ROOTDIR, rootdir_len) != 0)
201
 
    pos= my_stpncpy(pos, FN_ROOTDIR, end - pos);
202
 
  pos= my_stpncpy(pos, dbbuff, end-pos);
203
 
  pos= my_stpncpy(pos, FN_ROOTDIR, end-pos);
 
202
  if (without_rootdir >= 0)
 
203
  {
 
204
    char *tmp= (char*)table_path.c_str()+without_rootdir;
 
205
    if (memcmp(tmp, FN_ROOTDIR, rootdir_len) != 0)
 
206
      table_path.append(FN_ROOTDIR);
 
207
  }
 
208
 
 
209
  table_path.append(dbbuff);
 
210
  table_path.append(FN_ROOTDIR);
204
211
#ifdef USE_SYMDIR
205
 
  unpack_dirname(buff, buff);
206
 
  pos= strend(buff);
 
212
  table_path.clear();
207
213
#endif
208
 
  pos= my_stpncpy(pos, tbbuff, end - pos);
209
 
  pos= my_stpncpy(pos, ext, end - pos);
210
 
 
211
 
  return(pos - buff);
 
214
  table_path.append(tbbuff);
 
215
  table_path.append(ext);
 
216
 
 
217
  if (bufflen < table_path.length())
 
218
    return 0;
 
219
 
 
220
  strcpy(buff, table_path.c_str());
 
221
  return table_path.length();
212
222
}
213
223
 
214
224
 
217
227
 
218
228
  SYNOPSIS
219
229
   build_tmptable_filename()
220
 
     session                        The thread handle.
 
230
     session                    The thread handle.
221
231
     buff                       Where to write result in my_charset_filename.
222
232
     bufflen                    buff size
223
233
 
227
237
    a file name in drizzle_tmpdir.
228
238
 
229
239
  RETURN
230
 
    path length
 
240
    path length on success, 0 on failure
231
241
*/
232
242
 
233
243
uint32_t build_tmptable_filename(Session* session, char *buff, size_t bufflen)
234
244
{
 
245
  uint32_t length;
 
246
  ostringstream path_str, post_tmpdir_str;
 
247
  string tmp;
235
248
 
236
 
  char *p= my_stpncpy(buff, drizzle_tmpdir, bufflen);
237
 
  snprintf(p, bufflen - (p - buff), "/%s%lx_%"PRIx64"_%x%s",
238
 
           TMP_FILE_PREFIX, (unsigned long)current_pid,
239
 
           session->thread_id, session->tmp_table++, reg_ext);
 
249
  path_str << drizzle_tmpdir;
 
250
  post_tmpdir_str << "/" << TMP_FILE_PREFIX << current_pid;
 
251
  post_tmpdir_str << session->thread_id << session->tmp_table++ << reg_ext;
 
252
  tmp= post_tmpdir_str.str();
240
253
 
241
254
  if (lower_case_table_names)
242
 
  {
243
 
    /* Convert all except tmpdir to lower case */
244
 
    my_casedn_str(files_charset_info, p);
245
 
  }
246
 
 
247
 
  uint32_t length= unpack_filename(buff, buff);
248
 
  return(length);
 
255
    transform(tmp.begin(), tmp.end(), tmp.begin(), ::tolower);
 
256
 
 
257
  path_str << tmp;
 
258
 
 
259
  if (bufflen < path_str.str().length())
 
260
    length= 0;
 
261
  else
 
262
    length= unpack_filename(buff, path_str.str().c_str());
 
263
 
 
264
  return length;
249
265
}
250
266
 
251
267
/*
4395
4411
                       uint32_t order_num, order_st *order, bool ignore)
4396
4412
{
4397
4413
  Table *table, *new_table=0, *name_lock= 0;;
 
4414
  string new_name_str;
4398
4415
  int error= 0;
4399
4416
  char tmp_name[80],old_name[32],new_name_buff[FN_REFLEN];
4400
4417
  char new_alias_buff[FN_REFLEN], *table_name, *db, *new_alias, *alias;
4430
4447
    /* Conditionally writes to binlog. */
4431
4448
    return(mysql_discard_or_import_tablespace(session,table_list,
4432
4449
                                              alter_info->tablespace_op));
4433
 
  char* pos= new_name_buff;
4434
 
  char* pos_end= pos+strlen(new_name_buff)-1;
4435
 
  pos= my_stpncpy(new_name_buff, drizzle_data_home, pos_end-pos);
4436
 
  pos= my_stpncpy(new_name_buff, "/", pos_end-pos);
4437
 
  pos= my_stpncpy(new_name_buff, db, pos_end-pos);
4438
 
  pos= my_stpncpy(new_name_buff, "/", pos_end-pos);
4439
 
  pos= my_stpncpy(new_name_buff, table_name, pos_end-pos);
4440
 
  pos= my_stpncpy(new_name_buff, reg_ext, pos_end-pos);
 
4450
  ostringstream oss;
 
4451
  oss << drizzle_data_home << "/" << db << "/" << table_name << reg_ext;
4441
4452
 
4442
 
  (void) unpack_filename(new_name_buff, new_name_buff);
 
4453
  (void) unpack_filename(new_name_buff, oss.str().c_str());
4443
4454
  /*
4444
4455
    If this is just a rename of a view, short cut to the
4445
4456
    following scenario: 1) lock LOCK_open 2) do a RENAME