~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_table.cc

  • Committer: Toru Maesaka
  • Date: 2008-12-10 18:33:08 UTC
  • mto: (670.1.11 devel)
  • mto: This revision was merged to the branch mainline in revision 672.
  • Revision ID: dev@torum.net-20081210183308-mb6a5x0sbl1dhc5c
Replaced MySQL's my_stpncpy() with libc and c++ calls

Show diffs side-by-side

added added

removed removed

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