~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/show.cc

MergedĀ fromĀ trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
137
137
** List all table types supported
138
138
***************************************************************************/
139
139
 
140
 
/*
141
 
  find_files() - find files in a given directory.
142
 
 
143
 
  SYNOPSIS
144
 
    find_files()
145
 
    session                 thread handler
146
 
    files               put found files in this list
147
 
    db                  database name to set in TableList structure
148
 
    path                path to database
149
 
    wild                filter for found files
150
 
    dir                 read databases in path if true, read .frm files in
151
 
                        database otherwise
152
 
 
153
 
  RETURN
154
 
    FIND_FILES_OK       success
155
 
    FIND_FILES_OOM      out of memory error
156
 
    FIND_FILES_DIR      no such directory, or directory can't be read
157
 
*/
158
 
 
159
 
 
160
 
find_files_result
161
 
find_files(Session *session, List<LEX_STRING> *files, const char *db,
162
 
           const char *path, const char *wild, bool dir)
 
140
 
 
141
/**
 
142
 * @brief
 
143
 *   Find files in a given directory.
 
144
 *
 
145
 * @param[in]  session    Thread handler
 
146
 * @param[out] files      Put found files in this list
 
147
 * @param[in]  db         Used in error message when directory is not found
 
148
 * @param[in]  path       Path to database
 
149
 * @param[in]  wild       Filter for found files
 
150
 * @param[in]  dir        Read databases in path if true, read .frm files in
 
151
 *                        database otherwise
 
152
 *
 
153
 * @retval FIND_FILES_OK    Success
 
154
 * @retval FIND_FILES_OOM   Out of memory error
 
155
 * @retval FIND_FILES_DIR   No such directory or directory can't be read
 
156
 */
 
157
find_files_result find_files(Session *session, vector<LEX_STRING*> &files,
 
158
                             const char *db, const char *path, const char *wild,
 
159
                             bool dir)
163
160
{
164
 
  uint32_t i;
165
 
  char *ext;
166
 
  MY_DIR *dirp;
167
 
  FILEINFO *file;
168
 
  LEX_STRING *file_name= 0;
169
 
  uint32_t file_name_len;
170
 
  TableList table_list;
171
 
 
172
 
  if (wild && !wild[0])
173
 
    wild=0;
174
 
 
175
 
  if (!(dirp = my_dir(path,MYF(dir ? MY_WANT_STAT : 0))))
 
161
  if (wild && (wild[0] == '\0'))
 
162
    wild= 0;
 
163
 
 
164
  MY_DIR *dirp= my_dir(path, MYF(dir ? MY_WANT_STAT : 0));
 
165
  if (dirp == NULL)
176
166
  {
177
167
    if (my_errno == ENOENT)
178
168
      my_error(ER_BAD_DB_ERROR, MYF(ME_BELL+ME_WAITTANG), db);
179
169
    else
180
170
      my_error(ER_CANT_READ_DIR, MYF(ME_BELL+ME_WAITTANG), path, my_errno);
 
171
 
181
172
    return(FIND_FILES_DIR);
182
173
  }
183
174
 
184
 
  for (i=0 ; i < (uint32_t) dirp->number_off_files  ; i++)
 
175
  for (unsigned i= 0; i < dirp->number_off_files; i++)
185
176
  {
 
177
    uint32_t file_name_len;
186
178
    char uname[NAME_LEN + 1];                   /* Unencoded name */
187
 
    file=dirp->dir_entry+i;
 
179
    FILEINFO *file= dirp->dir_entry+i;
 
180
 
188
181
    if (dir)
189
182
    {                                           /* Return databases */
190
183
      if ((file->name[0] == '.' &&
191
184
          ((file->name[1] == '.' && file->name[2] == '\0') ||
192
185
            file->name[1] == '\0')))
193
186
        continue;                               /* . or .. */
194
 
#ifdef USE_SYMDIR
195
 
      char *ext;
196
 
      char buff[FN_REFLEN];
197
 
      if (my_use_symdir && !strcmp(ext=fn_ext(file->name), ".sym"))
198
 
      {
199
 
        /* Only show the sym file if it points to a directory */
200
 
        char *end;
201
 
        *ext=0;                                 /* Remove extension */
202
 
        unpack_dirname(buff, file->name);
203
 
        end= strchr(buff, '\0');
204
 
        if (end != buff && end[-1] == FN_LIBCHAR)
205
 
          end[-1]= 0;                           // Remove end FN_LIBCHAR
206
 
        if (stat(buff, file->mystat))
207
 
               continue;
208
 
       }
209
 
#endif
 
187
 
210
188
      if (!S_ISDIR(file->mystat->st_mode))
211
189
        continue;
212
190
 
213
191
      file_name_len= filename_to_tablename(file->name, uname, sizeof(uname));
214
192
      if (wild && wild_compare(uname, wild, 0))
215
193
        continue;
216
 
      if (!(file_name=
217
 
            session->make_lex_string(file_name, uname, file_name_len, true)))
218
 
      {
219
 
        my_dirend(dirp);
220
 
        return(FIND_FILES_OOM);
221
 
      }
222
194
    }
223
195
    else
224
196
    {
225
197
      // Return only .frm files which aren't temp files.
226
 
      if (my_strcasecmp(system_charset_info, ext=fn_rext(file->name),".dfe") ||
 
198
      char *ext= fn_rext(file->name);
 
199
      if (my_strcasecmp(system_charset_info, ext, ".dfe") ||
227
200
          is_prefix(file->name, TMP_FILE_PREFIX))
228
201
        continue;
229
 
      *ext=0;
 
202
 
 
203
      *ext= 0;
230
204
      file_name_len= filename_to_tablename(file->name, uname, sizeof(uname));
231
205
      if (wild)
232
206
      {
234
208
          continue;
235
209
      }
236
210
    }
237
 
    if (!(file_name=
238
 
          session->make_lex_string(file_name, uname, file_name_len, true)) ||
239
 
        files->push_back(file_name))
 
211
 
 
212
    LEX_STRING *file_name= 0;
 
213
    file_name= session->make_lex_string(file_name, uname, file_name_len, true);
 
214
    if (file_name == NULL)
240
215
    {
241
216
      my_dirend(dirp);
242
217
      return(FIND_FILES_OOM);
243
218
    }
 
219
 
 
220
    files.push_back(file_name);
244
221
  }
 
222
 
245
223
  my_dirend(dirp);
246
224
 
247
225
  return(FIND_FILES_OK);
1680
1658
}
1681
1659
 
1682
1660
 
1683
 
/*
1684
 
  Create db names list. Information schema name always is first in list
1685
 
 
1686
 
  SYNOPSIS
1687
 
    make_db_list()
1688
 
    session                   thread handler
1689
 
    files                 list of db names
1690
 
    wild                  wild string
1691
 
    idx_field_vals        idx_field_vals->db_name contains db name or
1692
 
                          wild string
1693
 
    with_i_schema         returns 1 if we added 'IS' name to list
1694
 
                          otherwise returns 0
1695
 
 
1696
 
  RETURN
1697
 
    zero                  success
1698
 
    non-zero              error
1699
 
*/
1700
 
 
1701
 
int make_db_list(Session *session, List<LEX_STRING> *files,
 
1661
/**
 
1662
 * @brief
 
1663
 *   Create db names list. Information schema name always is first in list
 
1664
 *
 
1665
 * @param[in]  session          Thread handler
 
1666
 * @param[out] files            List of db names
 
1667
 * @param[in]  wild             Wild string
 
1668
 * @param[in]  idx_field_vals   idx_field_vals->db_name contains db name or
 
1669
 *                              wild string
 
1670
 * @param[out] with_i_schema    Returns 1 if we added 'IS' name to list
 
1671
 *                              otherwise returns 0
 
1672
 *
 
1673
 * @retval 0   Success
 
1674
 * @retval 1   Error
 
1675
 */
 
1676
int make_db_list(Session *session, vector<LEX_STRING*> &files,
1702
1677
                 LOOKUP_FIELD_VALUES *lookup_field_vals,
1703
1678
                 bool *with_i_schema)
1704
1679
{
1720
1695
                           lookup_field_vals->db_value.str))
1721
1696
    {
1722
1697
      *with_i_schema= 1;
1723
 
      if (files->push_back(i_s_name_copy))
1724
 
        return 1;
 
1698
      files.push_back(i_s_name_copy);
1725
1699
    }
1726
1700
    return (find_files(session, files, NULL, drizzle_data_home,
1727
1701
                       lookup_field_vals->db_value.str, 1) != FIND_FILES_OK);
1738
1712
                       lookup_field_vals->db_value.str))
1739
1713
    {
1740
1714
      *with_i_schema= 1;
1741
 
      if (files->push_back(i_s_name_copy))
1742
 
        return 1;
 
1715
      files.push_back(i_s_name_copy);
1743
1716
      return 0;
1744
1717
    }
1745
 
    if (files->push_back(&lookup_field_vals->db_value))
1746
 
      return 1;
 
1718
 
 
1719
    files.push_back(&lookup_field_vals->db_value);
1747
1720
    return 0;
1748
1721
  }
1749
1722
 
1751
1724
    Create list of existing databases. It is used in case
1752
1725
    of select from information schema table
1753
1726
  */
1754
 
  if (files->push_back(i_s_name_copy))
1755
 
    return 1;
 
1727
  files.push_back(i_s_name_copy);
 
1728
 
1756
1729
  *with_i_schema= 1;
1757
1730
  return (find_files(session, files, NULL,
1758
1731
                     drizzle_data_home, NULL, 1) != FIND_FILES_OK);
1759
1732
}
1760
1733
 
1761
1734
 
1762
 
struct st_add_schema_table
1763
 
{
1764
 
  List<LEX_STRING> *files;
1765
 
  const char *wild;
1766
 
};
1767
 
 
1768
 
 
1769
1735
class AddSchemaTable : public unary_function<InfoSchemaTable *, bool>
1770
1736
{
1771
1737
  Session *session;
1772
 
  st_add_schema_table *data;
 
1738
  const char *wild;
 
1739
  vector<LEX_STRING*> &files;
 
1740
 
1773
1741
public:
1774
 
  AddSchemaTable(Session *session_arg, st_add_schema_table *data_arg)
1775
 
    : session(session_arg), data(data_arg) {}
 
1742
  AddSchemaTable(Session *session_arg, vector<LEX_STRING*> &files_arg, const char *wild_arg)
 
1743
    : session(session_arg), wild(wild_arg), files(files_arg)
 
1744
  {}
 
1745
 
1776
1746
  result_type operator() (argument_type schema_table)
1777
1747
  {
1778
 
    LEX_STRING *file_name= 0;
1779
 
    List<LEX_STRING> *file_list= data->files;
1780
 
    const char *wild= data->wild;
1781
 
  
1782
1748
    if (schema_table->isHidden())
1783
 
        return(0);
1784
 
    if (wild)
1785
 
    {
1786
 
      if (wild_case_compare(files_charset_info,
1787
 
                            schema_table->getTableName().c_str(),
1788
 
                            wild))
1789
 
        return(0);
1790
 
    }
1791
 
  
1792
 
    if ((file_name= session->make_lex_string(file_name, 
1793
 
                                             schema_table->getTableName().c_str(),
1794
 
                                             schema_table->getTableName().length(),
1795
 
                                             true)) &&
1796
 
        !file_list->push_back(file_name))
1797
 
      return(0);
1798
 
    return(1);
 
1749
    {
 
1750
      return false;
 
1751
    }
 
1752
 
 
1753
    const string &schema_table_name= schema_table->getTableName();
 
1754
 
 
1755
    if (wild && wild_case_compare(files_charset_info, schema_table_name.c_str(), wild))
 
1756
    {
 
1757
      return false;
 
1758
    }
 
1759
 
 
1760
    LEX_STRING *file_name= 0;
 
1761
    file_name= session->make_lex_string(file_name, schema_table_name.c_str(),
 
1762
                                        schema_table_name.length(), true);
 
1763
    if (file_name == NULL)
 
1764
    {
 
1765
      return true;
 
1766
    }
 
1767
 
 
1768
    files.push_back(file_name);
 
1769
    return false;
1799
1770
  }
1800
1771
};
1801
1772
 
1802
1773
 
1803
 
static int schema_tables_add(Session *session, List<LEX_STRING> *files, const char *wild)
 
1774
static int schema_tables_add(Session *session, vector<LEX_STRING*> &files, const char *wild)
1804
1775
{
1805
 
  LEX_STRING *file_name= 0;
1806
1776
  InfoSchemaTable *tmp_schema_table= schema_tables;
1807
 
  st_add_schema_table add_data;
1808
1777
 
1809
1778
  for (; tmp_schema_table->getTableName().length() != 0; tmp_schema_table++)
1810
1779
  {
1811
1780
    if (tmp_schema_table->isHidden())
1812
 
      continue;
1813
 
    if (wild)
1814
 
    {
1815
 
      if (wild_case_compare(files_charset_info,
1816
 
                            tmp_schema_table->getTableName().c_str(),
1817
 
                            wild))
1818
 
        continue;
1819
 
    }
1820
 
    if ((file_name=
1821
 
         session->make_lex_string(file_name, 
1822
 
                                  tmp_schema_table->getTableName().c_str(),
1823
 
                                  tmp_schema_table->getTableName().length(), 
1824
 
                                  true)) &&
1825
 
        !files->push_back(file_name))
1826
 
      continue;
1827
 
    return(1);
 
1781
    {
 
1782
      continue;
 
1783
    }
 
1784
 
 
1785
    const string &schema_table_name= tmp_schema_table->getTableName();
 
1786
 
 
1787
    if (wild && wild_case_compare(files_charset_info, schema_table_name.c_str(), wild))
 
1788
    {
 
1789
      continue;
 
1790
    }
 
1791
 
 
1792
    LEX_STRING *file_name= 0;
 
1793
    file_name= session->make_lex_string(file_name, schema_table_name.c_str(),
 
1794
                                        schema_table_name.length(), true);
 
1795
    if (file_name == NULL)
 
1796
    {
 
1797
      return 1;
 
1798
    }
 
1799
 
 
1800
    files.push_back(file_name);
1828
1801
  }
1829
1802
 
1830
 
  add_data.files= files;
1831
 
  add_data.wild= wild;
1832
 
  vector<InfoSchemaTable *>::iterator iter=
1833
 
    find_if(all_schema_tables.begin(), all_schema_tables.end(),
1834
 
           AddSchemaTable(session, &add_data));
 
1803
  vector<InfoSchemaTable *>::iterator iter= find_if(all_schema_tables.begin(),
 
1804
                                                    all_schema_tables.end(),
 
1805
                                                    AddSchemaTable(session, files, wild));
 
1806
 
1835
1807
  if (iter != all_schema_tables.end())
1836
1808
    return 1;
1837
 
  return 0 ;
 
1809
 
 
1810
  return 0;
1838
1811
}
1839
1812
 
1840
1813
 
1858
1831
*/
1859
1832
 
1860
1833
static int
1861
 
make_table_name_list(Session *session, List<LEX_STRING> *table_names, LEX *lex,
 
1834
make_table_name_list(Session *session, vector<LEX_STRING*> &table_names, LEX *lex,
1862
1835
                     LOOKUP_FIELD_VALUES *lookup_field_vals,
1863
1836
                     bool with_i_schema, LEX_STRING *db_name)
1864
1837
{
1871
1844
    {
1872
1845
      if (find_schema_table(lookup_field_vals->table_value.str))
1873
1846
      {
1874
 
        if (table_names->push_back(&lookup_field_vals->table_value))
1875
 
          return 1;
 
1847
        table_names.push_back(&lookup_field_vals->table_value);
1876
1848
      }
1877
1849
    }
1878
1850
    else
1879
1851
    {
1880
 
      if (table_names->push_back(&lookup_field_vals->table_value))
1881
 
        return 1;
 
1852
      table_names.push_back(&lookup_field_vals->table_value);
1882
1853
    }
1883
1854
    return 0;
1884
1855
  }
2160
2131
  InfoSchemaTable *schema_table= tables->schema_table;
2161
2132
  Select_Lex sel;
2162
2133
  LOOKUP_FIELD_VALUES lookup_field_vals;
2163
 
  LEX_STRING *db_name, *table_name;
2164
2134
  bool with_i_schema;
2165
 
  List<LEX_STRING> db_names;
2166
 
  List_iterator_fast<LEX_STRING> it(db_names);
 
2135
  vector<LEX_STRING*> db_names, table_names;
2167
2136
  COND *partial_cond= 0;
2168
2137
  uint32_t derived_tables= lex->derived_tables;
2169
2138
  int error= 1;
2216
2185
  if (lookup_field_vals.db_value.length &&
2217
2186
      !lookup_field_vals.wild_db_value)
2218
2187
    tables->has_db_lookup_value= true;
 
2188
 
2219
2189
  if (lookup_field_vals.table_value.length &&
2220
2190
      !lookup_field_vals.wild_table_value)
2221
2191
    tables->has_table_lookup_value= true;
2232
2202
    goto err;
2233
2203
  }
2234
2204
 
2235
 
  if (make_db_list(session, &db_names, &lookup_field_vals, &with_i_schema))
 
2205
  if (make_db_list(session, db_names, &lookup_field_vals, &with_i_schema))
2236
2206
    goto err;
2237
 
  it.rewind(); /* To get access to new elements in basis list */
2238
 
  while ((db_name= it++))
 
2207
 
 
2208
  for (vector<LEX_STRING*>::iterator db_name= db_names.begin(); db_name != db_names.end(); ++db_name )
2239
2209
  {
 
2210
    session->no_warnings_for_error= 1;
 
2211
    table_names.clear();
 
2212
    int res= make_table_name_list(session, table_names, lex,
 
2213
                                  &lookup_field_vals,
 
2214
                                  with_i_schema, *db_name);
 
2215
 
 
2216
    if (res == 2)   /* Not fatal error, continue */
 
2217
      continue;
 
2218
 
 
2219
    if (res)
 
2220
      goto err;
 
2221
 
 
2222
    
 
2223
    for (vector<LEX_STRING*>::iterator table_name= table_names.begin(); table_name != table_names.end(); ++table_name)
2240
2224
    {
2241
 
      session->no_warnings_for_error= 1;
2242
 
      List<LEX_STRING> table_names;
2243
 
      int res= make_table_name_list(session, &table_names, lex,
2244
 
                                    &lookup_field_vals,
2245
 
                                    with_i_schema, db_name);
2246
 
      if (res == 2)   /* Not fatal error, continue */
2247
 
        continue;
2248
 
      if (res)
2249
 
        goto err;
 
2225
      table->restoreRecordAsDefault();
 
2226
      table->field[schema_table->getFirstColumnIndex()]->
 
2227
        store((*db_name)->str, (*db_name)->length, system_charset_info);
 
2228
      table->field[schema_table->getSecondColumnIndex()]->
 
2229
        store((*table_name)->str, (*table_name)->length, system_charset_info);
2250
2230
 
2251
 
      List_iterator_fast<LEX_STRING> it_files(table_names);
2252
 
      while ((table_name= it_files++))
 
2231
      if (!partial_cond || partial_cond->val_int())
2253
2232
      {
2254
 
        table->restoreRecordAsDefault();
2255
 
        table->field[schema_table->getFirstColumnIndex()]->
2256
 
          store(db_name->str, db_name->length, system_charset_info);
2257
 
        table->field[schema_table->getSecondColumnIndex()]->
2258
 
          store(table_name->str, table_name->length, system_charset_info);
 
2233
        /*
 
2234
          If table is I_S.tables and open_table_method is 0 (eg SKIP_OPEN)
 
2235
          we can skip table opening and we don't have lookup value for
 
2236
          table name or lookup value is wild string(table name list is
 
2237
          already created by make_table_name_list() function).
 
2238
        */
 
2239
        if (! table_open_method &&
 
2240
            schema_table->getTableName().compare("TABLES") == 0 &&
 
2241
            (! lookup_field_vals.table_value.length ||
 
2242
             lookup_field_vals.wild_table_value))
 
2243
        {
 
2244
          if (schema_table_store_record(session, table))
 
2245
            goto err;      /* Out of space in temporary table */
 
2246
          continue;
 
2247
        }
2259
2248
 
2260
 
        if (!partial_cond || partial_cond->val_int())
 
2249
        /* SHOW Table NAMES command */
 
2250
        if (schema_table->getTableName().compare("TABLE_NAMES") == 0)
2261
2251
        {
2262
 
          /*
2263
 
            If table is I_S.tables and open_table_method is 0 (eg SKIP_OPEN)
2264
 
            we can skip table opening and we don't have lookup value for
2265
 
            table name or lookup value is wild string(table name list is
2266
 
            already created by make_table_name_list() function).
2267
 
          */
2268
 
          if (! table_open_method &&
2269
 
              schema_table->getTableName().compare("TABLES") == 0 &&
2270
 
              (! lookup_field_vals.table_value.length ||
2271
 
               lookup_field_vals.wild_table_value))
2272
 
          {
2273
 
            if (schema_table_store_record(session, table))
2274
 
              goto err;      /* Out of space in temporary table */
 
2252
          if (fill_schema_table_names(session, tables->table, *db_name,
 
2253
                                      *table_name, with_i_schema))
2275
2254
            continue;
2276
 
          }
2277
 
 
2278
 
          /* SHOW Table NAMES command */
2279
 
          if (schema_table->getTableName().compare("TABLE_NAMES") == 0)
 
2255
        }
 
2256
        else
 
2257
        {
 
2258
          if (!(table_open_method & ~OPEN_FRM_ONLY) &&
 
2259
              !with_i_schema)
2280
2260
          {
2281
 
            if (fill_schema_table_names(session, tables->table, db_name,
2282
 
                                        table_name, with_i_schema))
 
2261
            if (!fill_schema_table_from_frm(session, tables, schema_table, *db_name,
 
2262
                                            *table_name))
2283
2263
              continue;
2284
2264
          }
 
2265
 
 
2266
          LEX_STRING tmp_lex_string, orig_db_name;
 
2267
          /*
 
2268
            Set the parent lex of 'sel' because it is needed by
 
2269
            sel.init_query() which is called inside make_table_list.
 
2270
          */
 
2271
          session->no_warnings_for_error= 1;
 
2272
          sel.parent_lex= lex;
 
2273
          /* db_name can be changed in make_table_list() func */
 
2274
          if (!session->make_lex_string(&orig_db_name, (*db_name)->str,
 
2275
                                        (*db_name)->length, false))
 
2276
            goto err;
 
2277
 
 
2278
          if (make_table_list(session, &sel, *db_name, *table_name))
 
2279
            goto err;
 
2280
 
 
2281
          TableList *show_table_list= (TableList*) sel.table_list.first;
 
2282
          lex->all_selects_list= &sel;
 
2283
          lex->derived_tables= 0;
 
2284
          lex->sql_command= SQLCOM_SHOW_FIELDS;
 
2285
          show_table_list->i_s_requested_object=
 
2286
            schema_table->getRequestedObject();
 
2287
          res= session->open_normal_and_derived_tables(show_table_list, DRIZZLE_LOCK_IGNORE_FLUSH);
 
2288
          lex->sql_command= save_sql_command;
 
2289
          /*
 
2290
            XXX->  show_table_list has a flag i_is_requested,
 
2291
            and when it's set, open_normal_and_derived_tables()
 
2292
            can return an error without setting an error message
 
2293
            in Session, which is a hack. This is why we have to
 
2294
            check for res, then for session->is_error() only then
 
2295
            for session->main_da.sql_errno().
 
2296
          */
 
2297
          if (res && session->is_error() &&
 
2298
              session->main_da.sql_errno() == ER_NO_SUCH_TABLE)
 
2299
          {
 
2300
            /*
 
2301
              Hide error for not existing table.
 
2302
              This error can occur for example when we use
 
2303
              where condition with db name and table name and this
 
2304
              table does not exist.
 
2305
            */
 
2306
            res= 0;
 
2307
            session->clear_error();
 
2308
          }
2285
2309
          else
2286
2310
          {
2287
 
            if (!(table_open_method & ~OPEN_FRM_ONLY) &&
2288
 
                !with_i_schema)
2289
 
            {
2290
 
              if (!fill_schema_table_from_frm(session, tables, schema_table, db_name,
2291
 
                                              table_name))
2292
 
                continue;
2293
 
            }
2294
 
 
2295
 
            LEX_STRING tmp_lex_string, orig_db_name;
2296
 
            /*
2297
 
              Set the parent lex of 'sel' because it is needed by
2298
 
              sel.init_query() which is called inside make_table_list.
2299
 
            */
2300
 
            session->no_warnings_for_error= 1;
2301
 
            sel.parent_lex= lex;
2302
 
            /* db_name can be changed in make_table_list() func */
2303
 
            if (!session->make_lex_string(&orig_db_name, db_name->str,
2304
 
                                          db_name->length, false))
2305
 
              goto err;
2306
 
            if (make_table_list(session, &sel, db_name, table_name))
2307
 
              goto err;
2308
 
            TableList *show_table_list= (TableList*) sel.table_list.first;
2309
 
            lex->all_selects_list= &sel;
2310
 
            lex->derived_tables= 0;
2311
 
            lex->sql_command= SQLCOM_SHOW_FIELDS;
2312
 
            show_table_list->i_s_requested_object=
2313
 
              schema_table->getRequestedObject();
2314
 
            res= session->open_normal_and_derived_tables(show_table_list, DRIZZLE_LOCK_IGNORE_FLUSH);
2315
 
            lex->sql_command= save_sql_command;
2316
 
            /*
2317
 
              XXX->  show_table_list has a flag i_is_requested,
2318
 
              and when it's set, open_normal_and_derived_tables()
2319
 
              can return an error without setting an error message
2320
 
              in Session, which is a hack. This is why we have to
2321
 
              check for res, then for session->is_error() only then
2322
 
              for session->main_da.sql_errno().
2323
 
            */
2324
 
            if (res && session->is_error() &&
2325
 
                session->main_da.sql_errno() == ER_NO_SUCH_TABLE)
2326
 
            {
2327
 
              /*
2328
 
                Hide error for not existing table.
2329
 
                This error can occur for example when we use
2330
 
                where condition with db name and table name and this
2331
 
                table does not exist.
2332
 
              */
2333
 
              res= 0;
2334
 
              session->clear_error();
2335
 
            }
2336
 
            else
2337
 
            {
2338
 
              /*
2339
 
                We should use show_table_list->alias instead of
2340
 
                show_table_list->table_name because table_name
2341
 
                could be changed during opening of I_S tables. It's safe
2342
 
                to use alias because alias contains original table name
2343
 
                in this case.
2344
 
              */
2345
 
              session->make_lex_string(&tmp_lex_string, show_table_list->alias,
2346
 
                                       strlen(show_table_list->alias), false);
2347
 
              res= schema_table->processTable(session, show_table_list, table,
2348
 
                                              res, &orig_db_name,
2349
 
                                              &tmp_lex_string);
2350
 
              session->close_tables_for_reopen(&show_table_list);
2351
 
            }
2352
 
            assert(!lex->query_tables_own_last);
2353
 
            if (res)
2354
 
              goto err;
 
2311
            /*
 
2312
              We should use show_table_list->alias instead of
 
2313
              show_table_list->table_name because table_name
 
2314
              could be changed during opening of I_S tables. It's safe
 
2315
              to use alias because alias contains original table name
 
2316
              in this case.
 
2317
            */
 
2318
            session->make_lex_string(&tmp_lex_string, show_table_list->alias,
 
2319
                                     strlen(show_table_list->alias), false);
 
2320
            res= schema_table->processTable(session, show_table_list, table,
 
2321
                                            res, &orig_db_name,
 
2322
                                            &tmp_lex_string);
 
2323
            session->close_tables_for_reopen(&show_table_list);
2355
2324
          }
 
2325
          assert(!lex->query_tables_own_last);
 
2326
          if (res)
 
2327
            goto err;
2356
2328
        }
2357
2329
      }
2358
 
      /*
2359
 
        If we have information schema its always the first table and only
2360
 
        the first table. Reset for other tables.
2361
 
      */
2362
 
      with_i_schema= 0;
2363
2330
    }
 
2331
    /*
 
2332
      If we have information schema its always the first table and only
 
2333
      the first table. Reset for other tables.
 
2334
    */
 
2335
    with_i_schema= 0;
2364
2336
  }
2365
2337
 
2366
2338
  error= 0;
 
2339
 
2367
2340
err:
2368
2341
  session->restore_backup_open_tables_state(&open_tables_state_backup);
2369
2342
  lex->derived_tables= derived_tables;