List:Internals« Previous MessageNext Message »
From:msvensson Date:June 22 2005 2:10pm
Subject:bk commit into 5.0 tree (msvensson:1.1987)
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of msvensson. When msvensson does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet
  1.1987 05/06/22 14:10:02 msvensson@neptunus.(none) +13 -0
  Merged from mysql-4.1 to mysql-5.0

  sql/sql_table.cc
    1.254 05/06/22 14:09:59 msvensson@neptunus.(none) +3 -7
    Merge

  sql/sql_base.cc
    1.257 05/06/22 14:09:59 msvensson@neptunus.(none) +0 -1
    Merge

  sql/handler.h
    1.144 05/06/22 14:09:59 msvensson@neptunus.(none) +1 -2
    Merge

  sql/handler.cc
    1.176 05/06/22 14:09:58 msvensson@neptunus.(none) +1 -1
    Merge

  sql/ha_ndbcluster.cc
    1.188 05/06/22 14:09:58 msvensson@neptunus.(none) +0 -1
    Merge

  ndb/test/ndbapi/create_tab.cpp
    1.8 05/06/22 14:09:58 msvensson@neptunus.(none) +0 -1
    Merge

  mysql-test/r/ndb_autodiscover.result
    1.22 05/06/22 14:09:58 msvensson@neptunus.(none) +0 -0
    Merge

  client/mysqldump.c
    1.182 05/06/22 14:09:58 msvensson@neptunus.(none) +11 -11
    Merge from 4.1 to 5.0

  sql/item_strfunc.cc
    1.234 05/06/22 13:48:27 msvensson@neptunus.(none) +0 -0
    Auto merged

  sql/ha_ndbcluster.h
    1.86 05/06/22 13:48:26 msvensson@neptunus.(none) +0 -0
    Auto merged

  mysql-test/t/ndb_autodiscover.test
    1.20 05/06/22 13:48:26 msvensson@neptunus.(none) +20 -20
    Auto merged

  mysql-test/mysql-test-run.sh
    1.272 05/06/22 13:48:26 msvensson@neptunus.(none) +0 -0
    Auto merged

  client/mysqltest.c
    1.145 05/06/22 13:48:25 msvensson@neptunus.(none) +0 -1
    Auto merged

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	msvensson
# Host:	neptunus.(none)
# Root:	/home/msvensson/mysql/mysql-5.0/RESYNC

--- 1.181/client/mysqldump.c	2005-05-26 12:19:36 +02:00
+++ 1.182/client/mysqldump.c	2005-06-22 14:09:58 +02:00
@@ -57,6 +57,7 @@
 #define EX_CONSCHECK 3
 #define EX_EOM 4
 #define EX_EOF 5 /* ferror for output file was got */
+#define EX_ILLEGAL_TABLE 6
 
 /* index into 'show fields from table' */
 
@@ -142,14 +143,6 @@
 TYPELIB compatible_mode_typelib= {array_elements(compatible_mode_names) - 1,
 				  "", compatible_mode_names, NULL};
 
-#define TABLE_RULE_HASH_SIZE   16
-
-typedef struct st_table_rule_ent
-{
-  char* key;    /* dbname.tablename */
-  uint key_len;
-} TABLE_RULE_ENT;
-
 HASH ignore_table;
 
 static struct my_option my_long_options[] =
@@ -544,29 +537,21 @@
 } /* write_footer */
 
 
-static void free_table_ent(TABLE_RULE_ENT* e)
-{
-  my_free((gptr) e, MYF(0));
-}
-
-
-static byte* get_table_key(TABLE_RULE_ENT* e, uint* len,
-			   my_bool not_used __attribute__((unused)))
+byte* get_table_key(const char *entry, uint *length,
+				my_bool not_used __attribute__((unused)))
 {
-  *len= e->key_len;
-  return (byte*)e->key;
+  *length= strlen(entry);
+  return (byte*) entry;
 }
 
 
 void init_table_rule_hash(HASH* h)
 {
-  if(hash_init(h, charset_info, TABLE_RULE_HASH_SIZE, 0, 0,
-	       (hash_get_key) get_table_key,
-	       (hash_free_key) free_table_ent, 0))
+  if(hash_init(h, charset_info, 16, 0, 0,
+	       (hash_get_key) get_table_key, 0, 0))
     exit(EX_EOM);
 }
 
-
 static my_bool
 get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
 	       char *argument)
@@ -639,25 +624,15 @@
     break;
   case (int) OPT_IGNORE_TABLE:
   {
-    uint len= (uint)strlen(argument);
-    TABLE_RULE_ENT* e;
     if (!strchr(argument, '.'))
     {
       fprintf(stderr, "Illegal use of option
--ignore-table=<database>.<table>\n");
       exit(1);
     }
-    /* len is always > 0 because we know the there exists a '.' */
-    e= (TABLE_RULE_ENT*)my_malloc(sizeof(TABLE_RULE_ENT) + len, MYF(MY_WME));
-    if (!e)
-      exit(EX_EOM);
-    e->key= (char*)e + sizeof(TABLE_RULE_ENT);
-    e->key_len= len;
-    memcpy(e->key, argument, len);
-
     if (!hash_inited(&ignore_table))
       init_table_rule_hash(&ignore_table);
 
-    if(my_hash_insert(&ignore_table, (byte*)e))
+    if (my_hash_insert(&ignore_table, (byte*)my_strdup(argument, MYF(0))))
       exit(EX_EOM);
     break;
   }
@@ -980,7 +955,28 @@
   return buff;
 } /* quote_name */
 
+/*
+  Quote a table name so it can be used in "SHOW TABLES LIKE <tabname>"
 
+  SYNOPSIS
+    quote_for_like
+    name     - name of the table
+    buff     - quoted name of the table
+
+  DESCRIPTION
+    Quote \, _, ' and % characters
+
+    Note: Because MySQL uses the C escape syntax in strings
+    (for example, '\n' to represent newline), you must double
+    any '\' that you use in your LIKE  strings. For example, to
+    search for '\n', specify it as '\\n'. To search for '\', specify
+    it as '\\\\' (the backslashes are stripped once by the parser
+    and another time when the pattern match is done, leaving a
+    single backslash to be matched).
+
+    Example: "t\1" => "t\\\\1"
+
+*/
 
 static char *quote_for_like(const char *name, char *buff)
 {
@@ -988,7 +984,13 @@
   *to++= '\'';
   while (*name)
   {
-    if (*name == '\'' || *name == '_' || *name == '\\' || *name == '%')
+    if (*name == '\\')
+    {
+      *to++='\\';
+      *to++='\\';
+      *to++='\\';
+    }
+    else if (*name == '\'' || *name == '_'  || *name == '%')
       *to++= '\\';
     *to++= *name++;
   }
@@ -1139,6 +1141,7 @@
   FILE       *sql_file = md_result_file;
   int        len;
   DBUG_ENTER("get_table_structure");
+  DBUG_PRINT("enter", ("db: %s, table: %s", db, table));
 
   if (!insert_pat_inited)
   {
@@ -2327,27 +2330,60 @@
 
 static int dump_selected_tables(char *db, char **table_names, int tables)
 {
-  uint numrows;
-  int i;
+  uint numrows, i;
   char table_buff[NAME_LEN*+3];
+  char new_table_name[NAME_LEN];
+  DYNAMIC_STRING lock_tables_query;
+  HASH dump_tables;
+
+  DBUG_ENTER("dump_selected_tables");
 
   if (init_dumping(db))
     return 1;
-  if (lock_tables)
+
+  /* Init hash table for storing the actual name of tables to dump */
+  if (hash_init(&dump_tables, charset_info, 16, 0, 0,
+                (hash_get_key) get_table_key, 0, 0))
+    exit(EX_EOM);
+
+  init_dynamic_string(&lock_tables_query, "LOCK TABLES ", 256, 1024);
+  for (; tables > 0 ; tables-- , table_names++)
   {
-    DYNAMIC_STRING query;
+    /* the table name passed on commandline may be wrong case */
+    if (!get_actual_table_name( *table_names,
+                                new_table_name, sizeof(new_table_name) ))
+    {
+      /* Add found table name to lock_tables_query */
+      if (lock_tables)
+      {
+        dynstr_append(&lock_tables_query,
+                      quote_name(new_table_name, table_buff, 1));
+        dynstr_append(&lock_tables_query, " READ /*!32311 LOCAL */,");
+      }
 
-    init_dynamic_string(&query, "LOCK TABLES ", 256, 1024);
-    for (i=0 ; i < tables ; i++)
+      /* Add found table name to dump_tables list */
+      if (my_hash_insert(&dump_tables,
+                         (byte*)my_strdup(new_table_name, MYF(0))))
+        exit(EX_EOM);
+
+    }
+    else
     {
-      dynstr_append(&query, quote_name(table_names[i], table_buff, 1));
-      dynstr_append(&query, " READ /*!32311 LOCAL */,");
+       my_printf_error(0,"Couldn't find table: \"%s\"\n", MYF(0),
+                       *table_names);
+       safe_exit(EX_ILLEGAL_TABLE);
+       /* We shall countinue here, if --force was given */
     }
-    if (mysql_real_query(sock, query.str, query.length-1))
+  }
+
+  if (lock_tables)
+  {
+    if (mysql_real_query(sock, lock_tables_query.str,
+                         lock_tables_query.length-1))
       DB_error(sock, "when doing LOCK TABLES");
        /* We shall countinue here, if --force was given */
-    dynstr_free(&query);
   }
+  dynstr_free(&lock_tables_query);
   if (flush_logs)
   {
     if (mysql_refresh(sock, REFRESH_LOG))
@@ -2356,25 +2392,25 @@
   }
   if (opt_xml)
     print_xml_tag1(md_result_file, "", "database name=", db, "\n");
-  for (i=0 ; i < tables ; i++)
-  {
-    char new_table_name[NAME_LEN];
-
-    /* the table name passed on commandline may be wrong case */
-    if (!get_actual_table_name( table_names[i], new_table_name,
-                                sizeof(new_table_name)))
-    {
-      numrows= get_table_structure(new_table_name, db);
-      dump_table(numrows, new_table_name);
-    }
-    my_free(order_by, MYF(MY_ALLOW_ZERO_PTR));
-    order_by= 0;
+  /* Dump each selected table */
+  const char *table_name;
+  for (i= 0; i < dump_tables.records; i++)
+  {
+    table_name= hash_element(&dump_tables, i);
+    DBUG_PRINT("info",("Dumping table %s", table_name));
+    numrows = get_table_structure(table_name, db);
+    dump_table(numrows, table_name);
   }
   if (was_views)
   {
-    for (i=0 ; i < tables ; i++)
-      get_view_structure(table_names[i], db);
+    for(i=0; i < dump_tables.records; i++)
+    {
+      table_name= hash_element(&dump_tables, i);
+      get_view_structure(table_name, db);
   }
+  hash_free(&dump_tables);
+  my_free(order_by, MYF(MY_ALLOW_ZERO_PTR));
+  order_by= 0;
   if (opt_xml)
   {
     fputs("</database>\n", md_result_file);
@@ -2382,7 +2418,7 @@
   }
   if (lock_tables)
     mysql_query_with_error_report(sock, 0, "UNLOCK TABLES");
-  return 0;
+  DBUG_RETURN(0);
 } /* dump_selected_tables */
 
 

--- 1.271/mysql-test/mysql-test-run.sh	2005-06-16 18:30:15 +02:00
+++ 1.272/mysql-test/mysql-test-run.sh	2005-06-22 13:48:26 +02:00
@@ -707,6 +707,9 @@
 if [ "x$USE_EMBEDDED_SERVER" = "x1" ]; then
   MYSQL_CLIENT_TEST="$MYSQL_CLIENT_TEST -A --language=$LANGUAGE -A
--datadir=$SLAVE_MYDDIR -A --character-sets-dir=$CHARSETSDIR"
 fi
+# Save path and name of mysqldump
+MYSQL_DUMP_DIR="$MYSQL_DUMP"
+export MYSQL_DUMP_DIR
 MYSQL_DUMP="$MYSQL_DUMP --no-defaults -uroot --socket=$MASTER_MYSOCK --password=$DBPASSWD
$EXTRA_MYSQLDUMP_OPT"
 MYSQL_SHOW="$MYSQL_SHOW -uroot --socket=$MASTER_MYSOCK --password=$DBPASSWD
$EXTRA_MYSQLSHOW_OPT"
 MYSQL_BINLOG="$MYSQL_BINLOG --no-defaults --local-load=$MYSQL_TMP_DIR 
--character-sets-dir=$CHARSETSDIR $EXTRA_MYSQLBINLOG_OPT"

--- 1.175/sql/handler.cc	2005-06-17 23:14:27 +02:00
+++ 1.176/sql/handler.cc	2005-06-22 14:09:58 +02:00
@@ -1928,21 +1928,19 @@
 }
 
 /*
-  Try to discover table from engine and 
+  Try to discover table from engine and
   if found, write the frm file to disk.
-  
+
   RETURN VALUES:
-   0 : Table existed in engine and created 
-       on disk if so requested
-   1 : Table does not exist
-  >1 : error
+  -1 : Table did not exists
+   0 : Table created ok
+   > 0 : Error, table existed but could not be created
 
 */
 
-int ha_create_table_from_engine(THD* thd, 
-				const char *db, 
-				const char *name,
-				bool create_if_found)
+int ha_create_table_from_engine(THD* thd,
+				const char *db,
+				const char *name)
 {
   int error;
   const void *frmblob;
@@ -1951,45 +1949,47 @@
   HA_CREATE_INFO create_info;
   TABLE table;
   DBUG_ENTER("ha_create_table_from_engine");
-  DBUG_PRINT("enter", ("name '%s'.'%s'  create_if_found: %d",
-                       db, name, create_if_found));
+  DBUG_PRINT("enter", ("name '%s'.'%s'",
+                       db, name));
 
   bzero((char*) &create_info,sizeof(create_info));
 
-  if ((error= ha_discover(thd, db, name, &frmblob, &frmlen)))
-    DBUG_RETURN(error); 
+  if(error= ha_discover(thd, db, name, &frmblob, &frmlen))
+  {
+    // Table could not be discovered and thus not created
+    DBUG_RETURN(error);
+  }
+
   /*
-    Table exists in handler
-    frmblob and frmlen are set
+    Table exists in handler and could be discovered
+    frmblob and frmlen are set, write the frm to disk
   */
 
-  if (create_if_found)
+  (void)strxnmov(path,FN_REFLEN,mysql_data_home,"/",db,"/",name,NullS);
+  // Save the frm file
+  if (writefrm(path, frmblob, frmlen))
   {
-    (void)strxnmov(path,FN_REFLEN,mysql_data_home,"/",db,"/",name,NullS);
-    // Save the frm file    
-    if ((error = writefrm(path, frmblob, frmlen)))
-      goto err_end;
-
-    if (openfrm(thd, path,"",0,(uint) READ_ALL, 0, &table))
-      DBUG_RETURN(1);
-
-    update_create_info_from_table(&create_info, &table);
-    create_info.table_options|= HA_CREATE_FROM_ENGINE;
-
-    if (lower_case_table_names == 2 &&
-	!(table.file->table_flags() & HA_FILE_BASED))
-    {
-      /* Ensure that handler gets name in lower case */
-      my_casedn_str(files_charset_info, path);
-    }
-    
-    error=table.file->create(path,&table,&create_info);
-    VOID(closefrm(&table));
+    my_free((char*) frmblob, MYF(MY_ALLOW_ZERO_PTR));
+    DBUG_RETURN(2);
   }
 
-err_end:
+  if (openfrm(thd, path,"",0,(uint) READ_ALL, 0, &table))
+    DBUG_RETURN(3);
+
+  update_create_info_from_table(&create_info, &table);
+  create_info.table_options|= HA_CREATE_FROM_ENGINE;
+
+  if (lower_case_table_names == 2 &&
+      !(table.file->table_flags() & HA_FILE_BASED))
+  {
+    /* Ensure that handler gets name in lower case */
+    my_casedn_str(files_charset_info, path);
+  }
+  error=table.file->create(path,&table,&create_info);
+  VOID(closefrm(&table));
   my_free((char*) frmblob, MYF(MY_ALLOW_ZERO_PTR));
-  DBUG_RETURN(error);  
+
+  DBUG_RETURN(error != 0);
 }
 
 void st_ha_check_opt::init()
@@ -2092,14 +2092,15 @@
   Try to discover one table from handler(s)
 
   RETURN
-    0  ok. In this case *frmblob and *frmlen are set
-    1  error.  frmblob and frmlen may not be set
+   -1  : Table did not exists
+    0  : OK. In this case *frmblob and *frmlen are set
+    >0 : error.  frmblob and frmlen may not be set
 */
 
 int ha_discover(THD *thd, const char *db, const char *name,
 		const void **frmblob, uint *frmlen)
 {
-  int error= 1; // Table does not exist in any handler
+  int error= -1; // Table does not exist in any handler
   DBUG_ENTER("ha_discover");
   DBUG_PRINT("enter", ("db: %s, name: %s", db, name));
 #ifdef HAVE_NDBCLUSTER_DB
@@ -2131,11 +2132,8 @@
     error= ndbcluster_find_files(thd, db, path, wild, dir, files);
 #endif
   DBUG_RETURN(error);
-  
-  
 }
 
-#ifdef NOT_YET_USED
 
 /*
   Ask handler if the table exists in engine
@@ -2146,19 +2144,18 @@
     #                   Error code
 
  */
-int ha_table_exists(THD* thd, const char* db, const char* name)
+int ha_table_exists_in_engine(THD* thd, const char* db, const char* name)
 {
-  int error= 2;
-  DBUG_ENTER("ha_table_exists");
+  int error= 0;
+  DBUG_ENTER("ha_table_exists_in_engine");
   DBUG_PRINT("enter", ("db: %s, name: %s", db, name));
 #ifdef HAVE_NDBCLUSTER_DB
   if (have_ndbcluster == SHOW_OPTION_YES)
-    error= ndbcluster_table_exists(thd, db, name);
+    error= ndbcluster_table_exists_in_engine(thd, db, name);
 #endif
+  DBUG_PRINT("exit", ("error: %d", error));
   DBUG_RETURN(error);
 }
-
-#endif
 
 
 /*

--- 1.143/sql/handler.h	2005-06-17 23:14:27 +02:00
+++ 1.144/sql/handler.h	2005-06-22 14:09:59 +02:00
@@ -831,13 +831,12 @@
                     const char *alias, bool generate_warning);
 
 /* discovery */
-int ha_create_table_from_engine(THD* thd, const char *db, const char *name,
-				bool create_if_found);
+int ha_create_table_from_engine(THD* thd, const char *db, const char *name);
 int ha_discover(THD* thd, const char* dbname, const char* name,
                 const void** frmblob, uint* frmlen);
 int ha_find_files(THD *thd,const char *db,const char *path,
                   const char *wild, bool dir,List<char>* files);
-int ha_table_exists(THD* thd, const char* db, const char* name);
+int ha_table_exists_in_engine(THD* thd, const char* db, const char* name);
 
 /* key cache */
 int ha_init_key_cache(const char *name, KEY_CACHE *key_cache);

--- 1.233/sql/item_strfunc.cc	2005-06-17 16:27:43 +02:00
+++ 1.234/sql/item_strfunc.cc	2005-06-22 13:48:27 +02:00
@@ -363,6 +363,7 @@
 {
   DBUG_ASSERT(fixed == 1);
 #ifdef HAVE_OPENSSL
+  uint code= ER_WRONG_PARAMETERS_TO_PROCEDURE;
   DES_cblock ivec;
   struct st_des_keyblock keyblock;
   struct st_des_keyschedule keyschedule;
@@ -371,7 +372,7 @@
   String *res= args[0]->val_str(str);
 
   if ((null_value=args[0]->null_value))
-    return 0;
+    goto error;
   if ((res_length=res->length()) == 0)
     return &my_empty_string;
 
@@ -419,6 +420,7 @@
 
   tail=  (8-(res_length) % 8);			// 1..8 marking extra length
   res_length+=tail;
+  code= ER_OUT_OF_RESOURCES;
   if (tail && res->append(append_str, tail) || tmp_value.alloc(res_length+1))
     goto error;
   (*res)[res_length-1]=tail;			// save extra length
@@ -436,6 +438,13 @@
   return &tmp_value;
 
 error:
+  push_warning_printf(current_thd,MYSQL_ERROR::WARN_LEVEL_ERROR,
+                          code, ER(code),
+                          "des_encrypt");
+#else
+  push_warning_printf(current_thd,MYSQL_ERROR::WARN_LEVEL_ERROR,
+                      ER_FEATURE_DISABLED, ER(ER_FEATURE_DISABLED),
+                      "des_encrypt","--with-openssl");
 #endif	/* HAVE_OPENSSL */
   null_value=1;
   return 0;
@@ -446,6 +455,7 @@
 {
   DBUG_ASSERT(fixed == 1);
 #ifdef HAVE_OPENSSL
+  uint code= ER_WRONG_PARAMETERS_TO_PROCEDURE;
   DES_key_schedule ks1, ks2, ks3;
   DES_cblock ivec;
   struct st_des_keyblock keyblock;
@@ -454,7 +464,7 @@
   uint length=res->length(),tail;
 
   if ((null_value=args[0]->null_value))
-    return 0;
+    goto error;
   length=res->length();
   if (length < 9 || (length % 8) != 1 || !((*res)[0] & 128))
     return res;				// Skip decryption if not encrypted
@@ -485,6 +495,7 @@
     DES_set_key_unchecked(&keyblock.key2,&keyschedule.ks2);
     DES_set_key_unchecked(&keyblock.key3,&keyschedule.ks3);
   }
+  code= ER_OUT_OF_RESOURCES;
   if (tmp_value.alloc(length-1))
     goto error;
 
@@ -498,11 +509,19 @@
 		       &ivec, FALSE);
   /* Restore old length of key */
   if ((tail=(uint) (uchar) tmp_value[length-2]) > 8)
-    goto error;					// Wrong key
+    goto wrong_key;				     // Wrong key
   tmp_value.length(length-1-tail);
   return &tmp_value;
 
 error:
+  push_warning_printf(current_thd,MYSQL_ERROR::WARN_LEVEL_ERROR,
+                          code, ER(code),
+                          "des_decrypt");
+wrong_key:
+#else
+  push_warning_printf(current_thd,MYSQL_ERROR::WARN_LEVEL_ERROR,
+                      ER_FEATURE_DISABLED, ER(ER_FEATURE_DISABLED),
+                      "des_decrypt","--with-openssl");
 #endif	/* HAVE_OPENSSL */
   null_value=1;
   return 0;

--- 1.256/sql/sql_base.cc	2005-06-21 16:18:22 +02:00
+++ 1.257/sql/sql_base.cc	2005-06-22 14:09:59 +02:00
@@ -1611,8 +1611,18 @@
       */
       if (discover_retry_count++ != 0)
         goto err;
-      if (ha_create_table_from_engine(thd, db, name, TRUE) != 0)
+      if (ha_create_table_from_engine(thd, db, name) > 0)
+      {
+        /* Give right error message */
+        thd->clear_error();
+        DBUG_PRINT("error", ("Dicovery of %s/%s failed", db, name));
+        my_printf_error(ER_UNKNOWN_ERROR,
+                        "Failed to open '%-.64s', error while "
+                        "unpacking from engine",
+                        MYF(0), name);
+
         goto err;
+      }
 
       mysql_reset_errors(thd, 1);    // Clear warnings
       thd->clear_error();            // Clear error message

--- 1.253/sql/sql_table.cc	2005-06-17 23:14:28 +02:00
+++ 1.254/sql/sql_table.cc	2005-06-22 14:09:59 +02:00
@@ -256,16 +256,18 @@
       build_table_path(path, sizeof(path), db, alias, reg_ext);
     }
     if (drop_temporary ||
-        (access(path,F_OK) &&
-         ha_create_table_from_engine(thd,db,alias,TRUE)) ||
+       (access(path,F_OK) &&
+         ha_create_table_from_engine(thd,db,alias)) ||
         (!drop_view && mysql_frm_type(path) != FRMTYPE_TABLE))
     {
+      // Table was not found on disk and table can't be created from engine
       if (if_exists)
 	push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
 			    ER_BAD_TABLE_ERROR, ER(ER_BAD_TABLE_ERROR),
 			    table->table_name);
       else
-	error= 1;
+        error= 1;
+
     }
     else
     {
@@ -1604,15 +1606,14 @@
   {
     bool create_if_not_exists =
       create_info->options & HA_LEX_CREATE_IF_NOT_EXISTS;
-    if (!ha_create_table_from_engine(thd, db, table_name,
-				     create_if_not_exists))
+    if (ha_table_exists_in_engine(thd, db, table_name))
     {
-      DBUG_PRINT("info", ("Table already existed in handler"));
+      DBUG_PRINT("info", ("Table with same name already existed in handler"));
 
       if (create_if_not_exists)
       {
-       create_info->table_existed= 1;   // Mark that table existed
-       error= FALSE;
+        create_info->table_existed= 1;   // Mark that table existed
+        error= FALSE;
       }
       else
        my_error(ER_TABLE_EXISTS_ERROR, MYF(0), table_name);

--- 1.21/mysql-test/r/ndb_autodiscover.result	2005-03-23 09:32:40 +01:00
+++ 1.22/mysql-test/r/ndb_autodiscover.result	2005-06-22 14:09:58 +02:00
@@ -93,7 +93,7 @@
 ERROR 42S01: Table 't3' already exists
 show status like 'handler_discover%';
 Variable_name	Value
-Handler_discover	1
+Handler_discover	0
 create table IF NOT EXISTS t3(
 id int not null primary key,
 id2 int not null,
@@ -101,7 +101,7 @@
 ) engine=ndb;
 show status like 'handler_discover%';
 Variable_name	Value
-Handler_discover	2
+Handler_discover	0
 SHOW CREATE TABLE t3;
 Table	Create Table
 t3	CREATE TABLE `t3` (
@@ -114,7 +114,7 @@
 1	Explorer
 show status like 'handler_discover%';
 Variable_name	Value
-Handler_discover	2
+Handler_discover	1
 drop table t3;
 flush status;
 create table t7(
@@ -373,6 +373,20 @@
 drop table t2;
 drop database test2;
 use test;
+CREATE TABLE sys.SYSTAB_0 (a int);
+ERROR 42S01: Table 'SYSTAB_0' already exists
+select * from sys.SYSTAB_0;
+ERROR HY000: Failed to open 'SYSTAB_0', error while unpacking from engine
+CREATE TABLE IF NOT EXISTS sys.SYSTAB_0 (a int);
+show warnings;
+Level	Code	Message
+select * from sys.SYSTAB_0;
+ERROR HY000: Failed to open 'SYSTAB_0', error while unpacking from engine
+drop table sys.SYSTAB_0;
+ERROR 42S02: Unknown table 'SYSTAB_0'
+drop table IF EXISTS sys.SYSTAB_0;
+Warnings:
+Note	1051	Unknown table 'SYSTAB_0'
 drop database if exists test_only_ndb_tables;
 create database test_only_ndb_tables;
 use test_only_ndb_tables;

--- 1.19/mysql-test/t/ndb_autodiscover.test	2005-04-21 10:24:37 +02:00
+++ 1.20/mysql-test/t/ndb_autodiscover.test	2005-06-22 13:48:26 +02:00
@@ -494,6 +494,27 @@
 use test;
 drop database test_only_ndb_tables;
 
+#####################################################
+# Test that it's not possible to create tables
+# with same name as NDB internal tables
+# This will also test that it's not possible to create
+# a table with tha same name as a table that can't be
+# discovered( for example a table created via NDBAPI)
+
+--error 1050
+CREATE TABLE sys.SYSTAB_0 (a int);
+--error 1105
+select * from sys.SYSTAB_0;
+
+CREATE TABLE IF NOT EXISTS sys.SYSTAB_0 (a int);
+show warnings;
+--error 1105
+select * from sys.SYSTAB_0;
+
+--error 1051
+drop table sys.SYSTAB_0;
+drop table IF EXISTS sys.SYSTAB_0;
+
 ######################################################
 # Note! This should always be the last step in this 
 # file, the table t9 will be used and dropped 

--- 1.187/sql/ha_ndbcluster.cc	2005-06-20 18:02:43 +02:00
+++ 1.188/sql/ha_ndbcluster.cc	2005-06-22 14:09:58 +02:00
@@ -4445,7 +4445,7 @@
   {    
     const NdbError err= dict->getNdbError();
     if (err.code == 709)
-      DBUG_RETURN(1);
+      DBUG_RETURN(-1);
     ERR_RETURN(err);
   }
   DBUG_PRINT("info", ("Found table %s", tab->getName()));
@@ -4453,13 +4453,15 @@
   len= tab->getFrmLength();  
   if (len == 0 || tab->getFrmData() == NULL)
   {
-    DBUG_PRINT("No frm data found",
-               ("Table is probably created via NdbApi")); 
-    DBUG_RETURN(2);
+    DBUG_PRINT("error", ("No frm data found."));
+    DBUG_RETURN(1);
   }
   
   if (unpackfrm(&data, &len, tab->getFrmData()))
-    DBUG_RETURN(3);
+  {
+    DBUG_PRINT("error", ("Could not unpack table"));
+    DBUG_RETURN(1);
+  }
 
   *frmlen= len;
   *frmblob= data;
@@ -4472,11 +4474,11 @@
 
  */
 
-int ndbcluster_table_exists(THD* thd, const char *db, const char *name)
+int ndbcluster_table_exists_in_engine(THD* thd, const char *db, const char *name)
 {
   const NDBTAB* tab;
   Ndb* ndb;
-  DBUG_ENTER("ndbcluster_table_exists");
+  DBUG_ENTER("ndbcluster_table_exists_in_engine");
   DBUG_PRINT("enter", ("db: %s, name: %s", db, name));
 
   if (!(ndb= check_ndb_in_thd(thd)))
@@ -4655,7 +4657,7 @@
     DBUG_PRINT("info", ("%s existed on disk", name));     
     // The .ndb file exists on disk, but it's not in list of tables in ndb
     // Verify that handler agrees table is gone.
-    if (ndbcluster_table_exists(thd, db, file_name) == 0)    
+    if (ndbcluster_table_exists_in_engine(thd, db, file_name) == 0)    
     {
       DBUG_PRINT("info", ("NDB says %s does not exists", file_name));     
       it.remove();
@@ -4709,7 +4711,7 @@
   while ((file_name=it2++))
   {  
     DBUG_PRINT("info", ("Table %s need discovery", name));
-    if (ha_create_table_from_engine(thd, db, file_name, TRUE) == 0)
+    if (ha_create_table_from_engine(thd, db, file_name) == 0)
       files->push_back(thd->strdup(file_name)); 
   }
 

--- 1.85/sql/ha_ndbcluster.h	2005-05-18 14:34:39 +02:00
+++ 1.86/sql/ha_ndbcluster.h	2005-06-22 13:48:26 +02:00
@@ -681,7 +681,8 @@
                         const void** frmblob, uint* frmlen);
 int ndbcluster_find_files(THD *thd,const char *db,const char *path,
                           const char *wild, bool dir, List<char> *files);
-int ndbcluster_table_exists(THD* thd, const char *db, const char *name);
+int ndbcluster_table_exists_in_engine(THD* thd,
+                                      const char *db, const char *name);
 int ndbcluster_drop_database(const char* path);
 
 void ndbcluster_print_error(int error, const NdbOperation *error_op);

--- 1.144/client/mysqltest.c	2005-06-17 14:03:18 +02:00
+++ 1.145/client/mysqltest.c	2005-06-22 13:48:25 +02:00
@@ -986,9 +986,38 @@
       replace_dynstr_append(ds, buf);
   }
   error= pclose(res_file);
-
   if (error != 0)
-    die("command \"%s\" failed", cmd);
+  {
+    uint status= WEXITSTATUS(error);
+    if(q->abort_on_error)
+      die("At line %u: command \"%s\" failed", start_lineno, cmd);
+    else
+    {
+      DBUG_PRINT("info",
+                 ("error: %d, status: %d", error, status));
+      bool ok= 0;
+      uint i;
+      for (i=0 ; (uint) i < q->expected_errors ; i++)
+      {
+        DBUG_PRINT("info", ("expected error: %d", q->expected_errno[i].code.errnum));
+        if ((q->expected_errno[i].type == ERR_ERRNO) &&
+            (q->expected_errno[i].code.errnum == status))
+          ok= 1;
+        verbose_msg("At line %u: command \"%s\" failed with expected error: %d",
+                    start_lineno, cmd, status);
+      }
+      if (!ok)
+        die("At line: %u: command \"%s\" failed with wrong error: %d",
+            start_lineno, cmd, status);
+    }
+  }
+  else if (q->expected_errno[0].type == ERR_ERRNO &&
+           q->expected_errno[0].code.errnum != 0)
+  {
+    /* Error code we wanted was != 0, i.e. not an expected success */
+    die("At line: %u: command \"%s\" succeeded - should have failed with errno %d...",
+        start_lineno, cmd, q->expected_errno[0].code.errnum);
+  }
 
   if (!disable_result_log)
   {
Thread
bk commit into 5.0 tree (msvensson:1.1987)msvensson22 Jun