~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_base.cc

  • Committer: Brian Aker
  • Date: 2009-12-01 02:39:03 UTC
  • mfrom: (1234.1.4 push)
  • Revision ID: brian@gaz-20091201023903-1id5z7xnup695jaq
Merge of Brian + Jay test fixes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1991
1991
      }
1992
1992
      return 1;
1993
1993
    }
1994
 
    if (!entry->s || !entry->s->crashed)
1995
 
      goto err;
1996
 
    // Code below is for repairing a crashed cursor
1997
 
    if ((error= lock_table_name(session, table_list, true)))
1998
 
    {
1999
 
      if (error < 0)
2000
 
        goto err;
2001
 
      if (wait_for_locked_table_names(session, table_list))
2002
 
      {
2003
 
        unlock_table_name(table_list);
2004
 
        goto err;
2005
 
      }
2006
 
    }
2007
 
    pthread_mutex_unlock(&LOCK_open);
2008
 
    session->clear_error();                             // Clear error message
2009
 
    error= 0;
2010
 
    if (open_table_from_share(session, share, alias,
2011
 
                              (uint32_t) (HA_OPEN_KEYFILE | HA_OPEN_RNDFILE |
2012
 
                                          HA_GET_INDEX |
2013
 
                                          HA_TRY_READ_ONLY),
2014
 
                              EXTRA_RECORD,
2015
 
                              ha_open_options | HA_OPEN_FOR_REPAIR,
2016
 
                              entry) || ! entry->cursor)
2017
 
    {
2018
 
      /* Give right error message */
2019
 
      session->clear_error();
2020
 
      my_error(ER_NOT_KEYFILE, MYF(0), share->table_name.str, my_errno);
2021
 
      errmsg_printf(ERRMSG_LVL_ERROR, _("Couldn't repair table: %s.%s"), share->db.str,
2022
 
                    share->table_name.str);
2023
 
      if (entry->cursor)
2024
 
        entry->closefrm(false);
2025
 
      error=1;
2026
 
    }
2027
 
    else
2028
 
      session->clear_error();                   // Clear error message
2029
 
    pthread_mutex_lock(&LOCK_open);
2030
 
    unlock_table_name(table_list);
2031
 
 
2032
 
    if (error)
2033
 
      goto err;
2034
 
    break;
2035
 
  }
2036
 
 
2037
 
  /*
2038
 
    If we are here, there was no fatal error (but error may be still
2039
 
    unitialized).
2040
 
  */
2041
 
  if (unlikely(entry->cursor->implicit_emptied))
2042
 
  {
2043
 
    ReplicationServices &replication_services= ReplicationServices::singleton();
2044
 
    entry->cursor->implicit_emptied= 0;
2045
 
    {
2046
 
      char *query, *end;
2047
 
      uint32_t query_buf_size= 20 + share->db.length + share->table_name.length +1;
2048
 
      if ((query= (char*) malloc(query_buf_size)))
2049
 
      {
2050
 
        /* 
2051
 
          "this DELETE FROM is needed even with row-based binlogging"
2052
 
 
2053
 
          We inherited this from MySQL. TODO: fix it to issue a propper truncate
2054
 
          of the table (though that may not be completely right sematics).
2055
 
        */
2056
 
        end= query;
2057
 
        end+= sprintf(query, "DELETE FROM `%s`.`%s`", share->db.str,
2058
 
                      share->table_name.str);
2059
 
        replication_services.rawStatement(session, query, (size_t)(end - query)); 
2060
 
        free(query);
2061
 
      }
2062
 
      else
2063
 
      {
2064
 
        errmsg_printf(ERRMSG_LVL_ERROR, _("When opening HEAP table, could not allocate memory "
2065
 
                                          "to write 'DELETE FROM `%s`.`%s`' to replication"),
2066
 
                      table_list->db, table_list->table_name);
2067
 
        my_error(ER_OUTOFMEMORY, MYF(0), query_buf_size);
2068
 
        entry->closefrm(false);
2069
 
        goto err;
2070
 
      }
2071
 
    }
2072
 
  }
 
1994
    goto err;
 
1995
  }
 
1996
 
2073
1997
  return 0;
2074
1998
 
2075
1999
err: