~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_parse.cc

  • Committer: Brian Aker
  • Date: 2009-06-08 02:42:24 UTC
  • mfrom: (1054.1.6 merge)
  • Revision ID: brian@gaz-20090608024224-zlff1bpq62r8m5gy
Removal of LOCK TABLES.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1164
1164
      unlock_global_read_lock(session);
1165
1165
    session->my_ok();
1166
1166
    break;
1167
 
  case SQLCOM_LOCK_TABLES:
1168
 
    /*
1169
 
      We try to take transactional locks if
1170
 
      - only transactional locks are requested (lex->lock_transactional) and
1171
 
      - no non-transactional locks exist (!session->locked_tables).
1172
 
    */
1173
 
    if (lex->lock_transactional && !session->locked_tables)
1174
 
    {
1175
 
      int rc;
1176
 
      /*
1177
 
        All requested locks are transactional and no non-transactional
1178
 
        locks exist.
1179
 
      */
1180
 
      if ((rc= try_transactional_lock(session, all_tables)) == -1)
1181
 
        goto error;
1182
 
      if (rc == 0)
1183
 
      {
1184
 
        session->my_ok();
1185
 
        break;
1186
 
      }
1187
 
      /*
1188
 
        Non-transactional locking has been requested or
1189
 
        non-transactional locks exist already or transactional locks are
1190
 
        not supported by all storage engines. Take non-transactional
1191
 
        locks.
1192
 
      */
1193
 
    }
1194
 
    /*
1195
 
      One or more requested locks are non-transactional and/or
1196
 
      non-transactional locks exist or a storage engine does not support
1197
 
      transactional locks. Check if at least one transactional lock is
1198
 
      requested. If yes, warn about the conversion to non-transactional
1199
 
      locks or abort in strict mode.
1200
 
    */
1201
 
    if (check_transactional_lock(session, all_tables))
1202
 
      goto error;
1203
 
    unlock_locked_tables(session);
1204
 
    /* we must end the trasaction first, regardless of anything */
1205
 
    if (! session->endActiveTransaction())
1206
 
      goto error;
1207
 
    session->in_lock_tables= true;
1208
 
    session->options|= OPTION_TABLE_LOCK;
1209
 
 
1210
 
    if (!(res= simple_open_n_lock_tables(session, all_tables)))
1211
 
    {
1212
 
      session->locked_tables=session->lock;
1213
 
      session->lock=0;
1214
 
      (void) set_handler_table_locks(session, all_tables, false);
1215
 
      session->my_ok();
1216
 
    }
1217
 
    else
1218
 
    {
1219
 
      /*
1220
 
        Need to end the current transaction, so the storage engine (InnoDB)
1221
 
        can free its locks if LOCK TABLES locked some tables before finding
1222
 
        that it can't lock a table in its list
1223
 
      */
1224
 
      ha_autocommit_or_rollback(session, 1);
1225
 
      (void) session->endActiveTransaction();
1226
 
      session->options&= ~(OPTION_TABLE_LOCK);
1227
 
    }
1228
 
    session->in_lock_tables= false;
1229
 
    break;
1230
1167
  case SQLCOM_CREATE_DB:
1231
1168
  {
1232
1169
    /*
1934
1871
  LEX *lex= session->lex;
1935
1872
 
1936
1873
  if (!table)
1937
 
    return(0);                          // End of memory
 
1874
    return NULL;                                // End of memory
1938
1875
  alias_str= alias ? alias->str : table->table.str;
1939
1876
  if (!test(table_options & TL_OPTION_ALIAS) &&
1940
1877
      check_table_name(table->table.str, table->table.length))
1941
1878
  {
1942
1879
    my_error(ER_WRONG_TABLE_NAME, MYF(0), table->table.str);
1943
 
    return(0);
 
1880
    return NULL;
1944
1881
  }
1945
1882
 
1946
1883
  if (table->is_derived_table() == false && table->db.str &&
1947
1884
      check_db_name(&table->db))
1948
1885
  {
1949
1886
    my_error(ER_WRONG_DB_NAME, MYF(0), table->db.str);
1950
 
    return(0);
 
1887
    return NULL;
1951
1888
  }
1952
1889
 
1953
1890
  if (!alias)                                   /* Alias is case sensitive */
1956
1893
    {
1957
1894
      my_message(ER_DERIVED_MUST_HAVE_ALIAS,
1958
1895
                 ER(ER_DERIVED_MUST_HAVE_ALIAS), MYF(0));
1959
 
      return(0);
 
1896
      return NULL;
1960
1897
    }
1961
1898
    if (!(alias_str= (char*) session->memdup(alias_str,table->table.length+1)))
1962
 
      return(0);
 
1899
      return NULL;
1963
1900
  }
1964
1901
  if (!(ptr = (TableList *) session->calloc(sizeof(TableList))))
1965
 
    return(0);                          /* purecov: inspected */
 
1902
    return NULL;                                /* purecov: inspected */
1966
1903
  if (table->db.str)
1967
1904
  {
1968
1905
    ptr->is_fqtn= true;
1970
1907
    ptr->db_length= table->db.length;
1971
1908
  }
1972
1909
  else if (lex->copy_db_to(&ptr->db, &ptr->db_length))
1973
 
    return(0);
 
1910
    return NULL;
1974
1911
  else
1975
1912
    ptr->is_fqtn= false;
1976
1913
 
1981
1918
  ptr->table_name=table->table.str;
1982
1919
  ptr->table_name_length=table->table.length;
1983
1920
  ptr->lock_type=   lock_type;
1984
 
  ptr->lock_timeout= -1;      /* default timeout */
1985
 
  ptr->lock_transactional= 1; /* allow transactional locks */
1986
1921
  ptr->updating=    test(table_options & TL_OPTION_UPDATING);
1987
1922
  ptr->force_index= test(table_options & TL_OPTION_FORCE_INDEX);
1988
1923
  ptr->ignore_leaves= test(table_options & TL_OPTION_IGNORE_LEAVES);
2002
1937
    {
2003
1938
      my_error(ER_UNKNOWN_TABLE, MYF(0),
2004
1939
               ptr->table_name, INFORMATION_SCHEMA_NAME.c_str());
2005
 
      return(0);
 
1940
      return NULL;
2006
1941
    }
2007
1942
    ptr->schema_table_name= ptr->table_name;
2008
1943
    ptr->schema_table= schema_table;
2022
1957
          !strcmp(ptr->db, tables->db))
2023
1958
      {
2024
1959
        my_error(ER_NONUNIQ_TABLE, MYF(0), alias_str); /* purecov: tested */
2025
 
        return(0);                              /* purecov: tested */
 
1960
        return NULL;                            /* purecov: tested */
2026
1961
      }
2027
1962
    }
2028
1963
  }
2057
1992
  ptr->next_name_resolution_table= NULL;
2058
1993
  /* Link table in global list (all used tables) */
2059
1994
  lex->add_to_query_tables(ptr);
2060
 
  return(ptr);
 
1995
  return ptr;
2061
1996
}
2062
1997
 
2063
1998
 
2087
2022
 
2088
2023
  if (!(ptr= (TableList*) session->calloc(ALIGN_SIZE(sizeof(TableList))+
2089
2024
                                       sizeof(nested_join_st))))
2090
 
    return(1);
 
2025
    return true;
2091
2026
  nested_join= ptr->nested_join=
2092
2027
    ((nested_join_st*) ((unsigned char*) ptr + ALIGN_SIZE(sizeof(TableList))));
2093
2028
 
2098
2033
  embedding= ptr;
2099
2034
  join_list= &nested_join->join_list;
2100
2035
  join_list->empty();
2101
 
  return(0);
 
2036
  return false;
2102
2037
}
2103
2038
 
2104
2039
 
2138
2073
  else if (nested_join->join_list.elements == 0)
2139
2074
  {
2140
2075
    join_list->pop();
2141
 
    ptr= 0;                                     // return value
 
2076
    ptr= NULL;                                     // return value
2142
2077
  }
2143
 
  return(ptr);
 
2078
  return ptr;
2144
2079
}
2145
2080
 
2146
2081
 
2165
2100
 
2166
2101
  if (!(ptr= (TableList*) session->calloc(ALIGN_SIZE(sizeof(TableList))+
2167
2102
                                       sizeof(nested_join_st))))
2168
 
    return(0);
 
2103
    return NULL;
2169
2104
  nested_join= ptr->nested_join=
2170
2105
    ((nested_join_st*) ((unsigned char*) ptr + ALIGN_SIZE(sizeof(TableList))));
2171
2106
 
2194
2129
  }
2195
2130
  join_list->push_front(ptr);
2196
2131
  nested_join->used_tables= nested_join->not_null_tables= (table_map) 0;
2197
 
  return(ptr);
 
2132
  return ptr;
2198
2133
}
2199
2134
 
2200
2135
 
2217
2152
  join_list->push_front(table);
2218
2153
  table->join_list= join_list;
2219
2154
  table->embedding= embedding;
2220
 
  return;
2221
2155
}
2222
2156
 
2223
2157
 
2261
2195
  join_list->push_front(tab1);
2262
2196
  tab1->outer_join|= JOIN_TYPE_RIGHT;
2263
2197
 
2264
 
  return(tab1);
 
2198
  return tab1;
2265
2199
}
2266
2200
 
2267
2201
/**