Commit f8e6e74c authored by monty@hundin.mysql.fi's avatar monty@hundin.mysql.fi
Browse files

Fix problem with not getting 'No Database Selected' error

parent 68c2afa8
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -45712,6 +45712,10 @@ Our TODO section contains what we plan to have in 4.0. @xref{TODO MySQL 4.0}.
@itemize @bullet
@item
Cleaned up global lock handling for @code{FLUSH TABLES WITH READ LOCK}
@item
Fixed problem with @code{DATETIME = constant} in @code{WHERE} optimization.
@item
Speed up all internal list handling.
@item
Added support for @code{UNION}.
+8 −9
Original line number Diff line number Diff line
@@ -1323,7 +1323,7 @@ int open_tables(THD *thd,TABLE_LIST *start)
  {
    if (!tables->table &&
	!(tables->table=open_table(thd,
				   tables->db ? tables->db : thd->db,
				   tables->db,
				   tables->real_name,
				   tables->name, &refresh)))
    {
@@ -1380,7 +1380,7 @@ TABLE *open_ltable(THD *thd, TABLE_LIST *table_list, thr_lock_type lock_type)
  DBUG_ENTER("open_ltable");

  thd->proc_info="Opening table";
  while (!(table=open_table(thd,table_list->db ? table_list->db : thd->db,
  while (!(table=open_table(thd,table_list->db,
			    table_list->real_name,table_list->name,
			    &refresh)) && refresh) ;
  if (table)
@@ -1612,9 +1612,7 @@ find_field_in_tables(THD *thd,Item_field *item,TABLE_LIST *tables)
    for (; tables ; tables=tables->next)
    {
      if (!strcmp(tables->name,table_name) &&
	  (!db ||
	   (tables->db && !strcmp(db,tables->db)) ||
	   (!tables->db && !strcmp(db,thd->db))))
	  (!db || !strcmp(db,tables->db)))
      {
	found_table=1;
	Field *find=find_field_in_table(thd,tables->table,name,length,
@@ -1854,8 +1852,7 @@ insert_fields(THD *thd,TABLE_LIST *tables, const char *db_name,
	check_grant_all_columns(thd,SELECT_ACL,table) )
      DBUG_RETURN(-1);
    if (!table_name || (!strcmp(table_name,tables->name) &&
			(!db_name || !tables->db ||
			 !strcmp(tables->db,db_name))))
			(!db_name || !strcmp(tables->db,db_name))))
    {
      Field **ptr=table->field,*field;
      thd->used_tables|=table->map;
@@ -2079,7 +2076,8 @@ int mysql_create_index(THD *thd, TABLE_LIST *table_list, List<Key> &keys)
  create_info.db_type=DB_TYPE_DEFAULT;
  DBUG_RETURN(mysql_alter_table(thd,table_list->db,table_list->real_name,
				&create_info, table_list,
				fields, keys, drop, alter, (ORDER*)0, FALSE, DUP_ERROR));
				fields, keys, drop, alter, (ORDER*)0, FALSE,
				DUP_ERROR));
}


@@ -2094,7 +2092,8 @@ int mysql_drop_index(THD *thd, TABLE_LIST *table_list, List<Alter_drop> &drop)
  create_info.db_type=DB_TYPE_DEFAULT;
  DBUG_RETURN(mysql_alter_table(thd,table_list->db,table_list->real_name,
				&create_info, table_list,
				fields, keys, drop, alter, (ORDER*)0, FALSE, DUP_ERROR));
				fields, keys, drop, alter, (ORDER*)0, FALSE,
				DUP_ERROR));
}

/*****************************************************************************
+6 −6
Original line number Diff line number Diff line
@@ -1810,16 +1810,14 @@ mysql_execute_command(void)
    DBUG_VOID_RETURN;
#else
    {
      char *db=tables->db ? tables->db : thd->db;
      if (!db)
      char *db=tables->db;
      if (!*db)
      {
	send_error(&thd->net,ER_NO_DB_ERROR);	/* purecov: inspected */
	goto error;				/* purecov: inspected */
      }
      remove_escape(db);			// Fix escaped '_'
      remove_escape(tables->name);
      if (!tables->db)
	tables->db=thd->db;
      if (check_access(thd,SELECT_ACL | EXTRA_ACL,db,&thd->col_access))
	goto error;				/* purecov: inspected */
      tables->grant.privilege=thd->col_access;
@@ -1837,7 +1835,7 @@ mysql_execute_command(void)
    DBUG_VOID_RETURN;
#else
    {
      char *db=tables->db ? tables->db : thd->db;
      char *db=tables->db;
      if (!db)
      {
	send_error(&thd->net,ER_NO_DB_ERROR);	/* purecov: inspected */
@@ -2178,7 +2176,7 @@ check_access(THD *thd,uint want_access,const char *db, uint *save_priv,
  else
    save_priv= &dummy;

  if (!db && !thd->db && !dont_check_global_grants)
  if (!db[0] && !thd->db && !dont_check_global_grants)
  {
    send_error(&thd->net,ER_NO_DB_ERROR);	/* purecov: tested */
    return TRUE;				/* purecov: tested */
@@ -2725,6 +2723,8 @@ add_proc_to_list(Item *item)

static void remove_escape(char *name)
{
  if (!*name)					// For empty DB names
    return;
  char *to;
#ifdef USE_MB
  char *strend=name+(uint) strlen(name);