~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/show.cc

  • Committer: Brian Aker
  • Date: 2011-01-21 04:58:46 UTC
  • mto: This revision was merged to the branch mainline in revision 2102.
  • Revision ID: brian@tangent.org-20110121045846-4yi1aur7cef40ool
More shuffle of show into functions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
184
184
  return true;
185
185
}
186
186
 
 
187
bool buildTables(Session *session, const char *ident)
 
188
{
 
189
  session->getLex()->sql_command= SQLCOM_SELECT;
 
190
 
 
191
  drizzled::statement::Show *select= new statement::Show(session);
 
192
  session->getLex()->statement= select;
 
193
 
 
194
  std::string column_name= "Tables_in_";
 
195
 
 
196
  util::string::const_shared_ptr schema(session->schema());
 
197
  if (ident)
 
198
  {
 
199
    identifier::Schema identifier(ident);
 
200
    column_name.append(ident);
 
201
    session->getLex()->select_lex.db= const_cast<char *>(ident);
 
202
    if (not plugin::StorageEngine::doesSchemaExist(identifier))
 
203
    {
 
204
      my_error(ER_BAD_DB_ERROR, MYF(0), ident);
 
205
    }
 
206
    select->setShowPredicate(ident, "");
 
207
  }
 
208
  else if (schema and not schema->empty())
 
209
  {
 
210
    column_name.append(*schema);
 
211
    select->setShowPredicate(*schema, "");
 
212
  }
 
213
  else
 
214
  {
 
215
    my_error(ER_NO_DB_ERROR, MYF(0));
 
216
    return false;
 
217
  }
 
218
 
 
219
 
 
220
  if (session->getLex()->wild)
 
221
  {
 
222
    column_name.append(" (");
 
223
    column_name.append(session->getLex()->wild->ptr());
 
224
    column_name.append(")");
 
225
  }
 
226
 
 
227
  if (prepare_new_schema_table(session, session->getLex(), "SHOW_TABLES"))
 
228
    return false;
 
229
 
 
230
  Item_field *my_field= new Item_field(&session->lex->current_select->context, NULL, NULL, "TABLE_NAME");
 
231
  my_field->is_autogenerated_name= false;
 
232
  my_field->set_name(column_name.c_str(), column_name.length(), system_charset_info);
 
233
 
 
234
  if (session->add_item_to_list(my_field))
 
235
    return false;
 
236
 
 
237
  if (session->add_order_to_list(my_field, true))
 
238
    return false;
 
239
 
 
240
  return true;
 
241
}
 
242
 
 
243
bool buildTemporaryTables(Session *session)
 
244
{
 
245
  session->getLex()->sql_command= SQLCOM_SELECT;
 
246
 
 
247
  session->getLex()->statement= new statement::Show(session);
 
248
 
 
249
 
 
250
  if (prepare_new_schema_table(session, session->getLex(), "SHOW_TEMPORARY_TABLES"))
 
251
    return false;
 
252
 
 
253
  if (session->add_item_to_list( new Item_field(&session->lex->current_select->context, NULL, NULL, "*")))
 
254
    return false;
 
255
 
 
256
  (session->lex->current_select->with_wild)++;
 
257
 
 
258
  return true;
 
259
}
 
260
 
 
261
bool buildTableStatus(Session *session, const char *ident)
 
262
{
 
263
  session->getLex()->sql_command= SQLCOM_SELECT;
 
264
  drizzled::statement::Show *select= new statement::Show(session);
 
265
  session->getLex()->statement= select;
 
266
 
 
267
  std::string column_name= "Tables_in_";
 
268
 
 
269
  util::string::const_shared_ptr schema(session->schema());
 
270
  if (ident)
 
271
  {
 
272
    session->getLex()->select_lex.db= const_cast<char *>(ident);
 
273
 
 
274
    identifier::Schema identifier(ident);
 
275
    if (not plugin::StorageEngine::doesSchemaExist(identifier))
 
276
    {
 
277
      my_error(ER_BAD_DB_ERROR, MYF(0), ident);
 
278
    }
 
279
 
 
280
    select->setShowPredicate(ident, "");
 
281
  }
 
282
  else if (schema)
 
283
  {
 
284
    select->setShowPredicate(*schema, "");
 
285
  }
 
286
  else
 
287
  {
 
288
    my_error(ER_NO_DB_ERROR, MYF(0));
 
289
    return false;
 
290
  }
 
291
 
 
292
  if (prepare_new_schema_table(session, session->getLex(), "SHOW_TABLE_STATUS"))
 
293
    return false;
 
294
 
 
295
  if (session->add_item_to_list( new Item_field(&session->lex->current_select->
 
296
                                                  context,
 
297
                                                  NULL, NULL, "*")))
 
298
    return false;
 
299
 
 
300
  (session->lex->current_select->with_wild)++;
 
301
 
 
302
  return true;
 
303
}
 
304
 
187
305
bool buildCreateSchema(Session *session, LEX_STRING &ident)
188
306
{
189
307
  session->getLex()->sql_command= SQLCOM_SELECT;