Ejemplo n.º 1
0
int myrg_create(const char *name, const char **table_names,
                uint insert_method, my_bool fix_names)
{
  int save_errno;
  uint errpos;
  File file;
  char buff[FN_REFLEN],*end;
  DBUG_ENTER("myrg_create");

  errpos=0;
  if ((file= mysql_file_create(rg_key_file_MRG,
                               fn_format(buff, name, "", MYRG_NAME_EXT,
                                         MY_UNPACK_FILENAME|MY_APPEND_EXT), 0,
                               O_RDWR | O_EXCL | O_NOFOLLOW, MYF(MY_WME))) < 0)
    goto err;
  errpos=1;
  if (table_names)
  {
    for ( ; *table_names ; table_names++)
    {
      my_stpcpy(buff,*table_names);
      if (fix_names)
	fn_same(buff,name,4);
      *(end=strend(buff))='\n';
      end[1]=0;
      if (mysql_file_write(file, (uchar*) buff, (uint) (end-buff+1),
                           MYF(MY_WME | MY_NABP)))
	goto err;
    }
  }
  if (insert_method != MERGE_INSERT_DISABLED)
  {
    end=strxmov(buff,"#INSERT_METHOD=",
		get_type(&merge_insert_method,insert_method-1),"\n",NullS);
    if (mysql_file_write(file, (uchar*) buff, (uint) (end-buff),
                         MYF(MY_WME | MY_NABP)))
        goto err;
  }
  if (mysql_file_close(file, MYF(0)))
    goto err;
  DBUG_RETURN(0);

err:
  save_errno=my_errno() ? my_errno() : -1;
  switch (errpos) {
  case 1:
    (void) mysql_file_close(file, MYF(0));
  }
  set_my_errno(save_errno);
  DBUG_RETURN(save_errno);
} /* myrg_create */
Ejemplo n.º 2
0
void _myisam_log_record(enum myisam_log_commands command, MI_INFO *info,
			const uchar *record, my_off_t filepos, int result)
{
  uchar buff[21],*pos;
  int error,old_errno;
  uint length;
  ulong pid=(ulong) GETPID();

  old_errno=my_errno;
  if (!info->s->base.blobs)
    length=info->s->base.reclength;
  else
    length=info->s->base.reclength+ _my_calc_total_blob_length(info,record);
  buff[0]=(uchar) command;
  mi_int2store(buff+1,info->dfile);
  mi_int4store(buff+3,pid);
  mi_int2store(buff+7,result);
  mi_sizestore(buff+9,filepos);
  mi_int4store(buff+17,length);
  mysql_mutex_lock(&THR_LOCK_myisam);
  error=my_lock(myisam_log_file,F_WRLCK,0L,F_TO_EOF,MYF(MY_SEEK_NOT_DONE));
  (void) mysql_file_write(myisam_log_file, buff, sizeof(buff), MYF(0));
  (void) mysql_file_write(myisam_log_file, record, info->s->base.reclength, MYF(0));
  if (info->s->base.blobs)
  {
    MI_BLOB *blob,*end;

    for (end=info->blobs+info->s->base.blobs, blob= info->blobs;
	 blob != end ;
	 blob++)
    {
      memcpy(&pos, record+blob->offset+blob->pack_length,
                   sizeof(char*));
      (void) mysql_file_write(myisam_log_file, pos, blob->length, MYF(0));
    }
  }
  if (!error)
    error=my_lock(myisam_log_file,F_UNLCK,0L,F_TO_EOF,MYF(MY_SEEK_NOT_DONE));
  mysql_mutex_unlock(&THR_LOCK_myisam);
  my_errno=old_errno;
}
Ejemplo n.º 3
0
void _myisam_log_command(enum myisam_log_commands command, MI_INFO *info,
			 const uchar *buffert, uint length, int result)
{
  uchar buff[9];
  int error,old_errno;
  ulong pid=(ulong) GETPID();

  old_errno=my_errno;
  buff[0]=(char) command;
  mi_int2store(buff+1,info->dfile);
  mi_int4store(buff+3,pid);
  mi_int2store(buff+7,result);
  mysql_mutex_lock(&THR_LOCK_myisam);
  error=my_lock(myisam_log_file,F_WRLCK,0L,F_TO_EOF,MYF(MY_SEEK_NOT_DONE));
  (void) mysql_file_write(myisam_log_file, buff, sizeof(buff), MYF(0));
  if (buffert)
    (void) mysql_file_write(myisam_log_file, buffert, length, MYF(0));
  if (!error)
    error=my_lock(myisam_log_file,F_UNLCK,0L,F_TO_EOF,MYF(MY_SEEK_NOT_DONE));
  mysql_mutex_unlock(&THR_LOCK_myisam);
  my_errno=old_errno;
}