MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:Jonas Oreland Date:April 30 2010 9:41am
Subject:bzr commit into mysql-5.1-telco-7.0-spj branch (jonas:3144)
View as plain text  
#At file:///home/jonas/src/70-spj/ based on revid:jonas@stripped

 3144 Jonas Oreland	2010-04-30 [merge]
      ndb spj - merge 70-main

    added:
      mysql-test/include/ndb_desc_print.inc
      mysql-test/std_data/ndb_backup_before_native_default/
      mysql-test/std_data/ndb_backup_before_native_default/BACKUP-1-0.1.Data
      mysql-test/std_data/ndb_backup_before_native_default/BACKUP-1-0.2.Data
      mysql-test/std_data/ndb_backup_before_native_default/BACKUP-1.1.ctl
      mysql-test/std_data/ndb_backup_before_native_default/BACKUP-1.1.log
      mysql-test/std_data/ndb_backup_before_native_default/BACKUP-1.2.ctl
      mysql-test/std_data/ndb_backup_before_native_default/BACKUP-1.2.log
      mysql-test/suite/ndb/r/ndb_native_default_support.result
      mysql-test/suite/ndb/t/ndb_native_default_support.test
      storage/ndb/test/ndbapi/testNativeDefault.cpp
    renamed:
      include/my_socket.h => storage/ndb/include/portlib/ndb_socket.h
      include/my_socket_posix.h => storage/ndb/include/portlib/ndb_socket_posix.h
      include/my_socket_win32.h => storage/ndb/include/portlib/ndb_socket_win32.h
      mysys/my_socket.c => storage/ndb/src/common/portlib/ndb_socket.cpp
    modified:
      extra/yassl/include/openssl/ssl.h
      include/Makefile.am
      include/config-win.h
      include/my_global.h
      include/my_net.h
      include/mysql.h
      include/mysql.h.pp
      include/mysql_com.h
      include/violite.h
      libmysql/manager.c
      libmysqld/libmysqld.c
      mysql-test/Makefile.am
      mysql-test/include/wait_for_slave_param.inc
      mysql-test/suite/ndb/r/ndb_restore_promotion.result
      mysql-test/suite/ndb/t/ndb_restore_promotion.test
      mysql-test/suite/rpl/r/rpl_change_master.result
      mysql-test/suite/rpl_ndb/r/rpl_ndb_2ndb.result
      mysql-test/suite/rpl_ndb/r/rpl_ndb_extraCol.result
      mysys/CMakeLists.txt
      mysys/Makefile.am
      server-tools/instance-manager/listener.cc
      server-tools/instance-manager/listener.h
      sql-common/client.c
      sql/ha_ndbcluster.cc
      sql/ha_ndbcluster.h
      sql/hostname.cc
      sql/log_event.cc
      sql/mysqld.cc
      sql/net_serv.cc
      sql/sql_connect.cc
      storage/ndb/include/kernel/ndb_limits.h
      storage/ndb/include/kernel/signaldata/DictTabInfo.hpp
      storage/ndb/include/kernel/signaldata/LqhFrag.hpp
      storage/ndb/include/kernel/signaldata/TupFrag.hpp
      storage/ndb/include/ndb_version.h.in
      storage/ndb/include/ndbapi/NdbDictionary.hpp
      storage/ndb/include/ndbapi/NdbRecAttr.hpp
      storage/ndb/include/portlib/NdbTCP.h
      storage/ndb/include/util/SocketAuthenticator.hpp
      storage/ndb/include/util/UtilBuffer.hpp
      storage/ndb/src/common/debugger/signaldata/DictTabInfo.cpp
      storage/ndb/src/common/portlib/CMakeLists.txt
      storage/ndb/src/common/portlib/Makefile.am
      storage/ndb/src/common/portlib/NdbTCP.cpp
      storage/ndb/src/common/transporter/TCP_Transporter.cpp
      storage/ndb/src/common/transporter/Transporter.hpp
      storage/ndb/src/common/transporter/TransporterRegistry.cpp
      storage/ndb/src/common/util/SocketAuthenticator.cpp
      storage/ndb/src/common/util/SocketClient.cpp
      storage/ndb/src/common/util/SocketServer.cpp
      storage/ndb/src/kernel/blocks/ERROR_codes.txt
      storage/ndb/src/kernel/blocks/dbdict/Dbdict.cpp
      storage/ndb/src/kernel/blocks/dblqh/Dblqh.hpp
      storage/ndb/src/kernel/blocks/dblqh/DblqhMain.cpp
      storage/ndb/src/kernel/blocks/dblqh/DblqhProxy.cpp
      storage/ndb/src/kernel/blocks/dbtup/Dbtup.hpp
      storage/ndb/src/kernel/blocks/dbtup/DbtupDebug.cpp
      storage/ndb/src/kernel/blocks/dbtup/DbtupExecQuery.cpp
      storage/ndb/src/kernel/blocks/dbtup/DbtupGen.cpp
      storage/ndb/src/kernel/blocks/dbtup/DbtupMeta.cpp
      storage/ndb/src/kernel/blocks/dbtup/DbtupVarAlloc.cpp
      storage/ndb/src/mgmapi/mgmapi.cpp
      storage/ndb/src/mgmapi/ndb_logevent.cpp
      storage/ndb/src/ndbapi/NdbDictionary.cpp
      storage/ndb/src/ndbapi/NdbDictionaryImpl.cpp
      storage/ndb/src/ndbapi/NdbDictionaryImpl.hpp
      storage/ndb/src/ndbapi/NdbRecAttr.cpp
      storage/ndb/src/ndbapi/ndberror.c
      storage/ndb/test/include/NDBT_Table.hpp
      storage/ndb/test/ndbapi/CMakeLists.txt
      storage/ndb/test/ndbapi/Makefile.am
      storage/ndb/test/ndbapi/testBasic.cpp
      storage/ndb/test/ndbapi/testBitfield.cpp
      storage/ndb/test/ndbapi/testDict.cpp
      storage/ndb/test/ndbapi/testLcp.cpp
      storage/ndb/test/ndbapi/testMgm.cpp
      storage/ndb/test/ndbapi/testUpgrade.cpp
      storage/ndb/test/run-test/atrt-setup.sh
      storage/ndb/test/run-test/daily-basic-tests.txt
      storage/ndb/test/src/NDBT_Tables.cpp
      storage/ndb/tools/ndb_config.cpp
      support-files/compiler_warnings.supp
      vio/vio.c
      vio/vio_priv.h
      vio/viosocket.c
      vio/viossl.c
      storage/ndb/include/portlib/ndb_socket.h
      storage/ndb/include/portlib/ndb_socket_posix.h
      storage/ndb/include/portlib/ndb_socket_win32.h
      storage/ndb/src/common/portlib/ndb_socket.cpp
=== modified file 'extra/yassl/include/openssl/ssl.h'
--- a/extra/yassl/include/openssl/ssl.h	2009-05-27 15:21:45 +0000
+++ b/extra/yassl/include/openssl/ssl.h	2010-04-13 16:01:38 +0000
@@ -192,17 +192,10 @@ enum {  /* ERR Constants */
 };
 
 /*
-  Use platform default type for sockets except
-  if user explicitly request use of "int" to be
-  OpenSSL compatible
-*/
-#if !defined(YASSL_SET_FD_INT) && defined(_WIN32)
-#if defined(_WIN64)
-typedef unsigned __int64 YASSL_SOCKET_T;
-#else
-typedef unsigned int YASSL_SOCKET_T;
-#endif
-#else
+  Allow type used by SSL_set_fd to be changed, default to int
+  in order to be compatible with OpenSSL
+ */
+#ifndef YASSL_SOCKET_T_DEFINED
 typedef int YASSL_SOCKET_T;
 #endif
 

=== modified file 'include/Makefile.am'
--- a/include/Makefile.am	2010-04-01 15:22:57 +0000
+++ b/include/Makefile.am	2010-04-13 16:01:38 +0000
@@ -27,7 +27,6 @@ pkginclude_HEADERS =	$(HEADERS_ABI) my_d
 			decimal.h errmsg.h my_global.h my_net.h \
 			my_getopt.h sslopt-longopts.h my_dir.h \
 			sslopt-vars.h sslopt-case.h sql_common.h keycache.h \
-			my_socket.h my_socket_win32.h my_socket_posix.h \
 			m_ctype.h my_attribute.h $(HEADERS_GEN_CONFIGURE) \
 			$(HEADERS_GEN_MAKE)
 

=== modified file 'include/config-win.h'
--- a/include/config-win.h	2010-03-12 11:56:09 +0000
+++ b/include/config-win.h	2010-04-13 17:24:50 +0000
@@ -157,14 +157,8 @@ typedef unsigned int size_t;
 typedef uint rf_SetTimer;
 #endif
 
-#define ssize_t SSIZE_T
-
 #define Socket_defined
-#ifndef __cplusplus
-#define bool BOOL
-#define true ((BOOL)1)
-#define false ((BOOL)0)
-#endif
+#define my_socket SOCKET
 #define SIGPIPE SIGINT
 #define RETQSORTTYPE void
 #define QSORT_TYPE_IS_VOID

=== modified file 'include/my_global.h'
--- a/include/my_global.h	2010-03-12 11:56:09 +0000
+++ b/include/my_global.h	2010-04-13 16:01:38 +0000
@@ -668,9 +668,9 @@ C_MODE_END
 /* Some types that is different between systems */
 
 typedef int	File;		/* File descriptor */
-#include <my_socket.h>
 #ifndef Socket_defined
-#define INVALID_SOCKET MY_INVALID_SOCKET
+typedef int    my_socket;      /* File descriptor for sockets */
+#define INVALID_SOCKET -1
 #endif
 /* Type for fuctions that handles signals */
 #define sig_handler RETSIGTYPE
@@ -806,7 +806,7 @@ typedef SOCKET_SIZE_TYPE size_socket;
 
 #undef remove		/* Crashes MySQL on SCO 5.0.0 */
 #ifndef __WIN__
-#define closesocket(A)	my_socket_close(A)
+#define closesocket(A)	close(A)
 #ifndef ulonglong2double
 #define ulonglong2double(A) ((double) (ulonglong) (A))
 #define my_off_t2double(A)  ((double) (my_off_t) (A))
@@ -1082,18 +1082,17 @@ typedef off_t os_off_t;
 #endif
 
 #if defined(__WIN__)
-#define socket_errno	my_socket_errno()
+#define socket_errno	WSAGetLastError()
 #define SOCKET_EINTR	WSAEINTR
 #define SOCKET_EAGAIN	WSAEINPROGRESS
 #define SOCKET_ETIMEDOUT WSAETIMEDOUT
 #define SOCKET_EWOULDBLOCK WSAEWOULDBLOCK
 #define SOCKET_EADDRINUSE WSAEADDRINUSE
-#define SOCKET_ECONNREFUSED WSAECONNREFUSED
 #define SOCKET_ENFILE	ENFILE
 #define SOCKET_EMFILE	EMFILE
 #else /* Unix */
-#define socket_errno	my_socket_errno()
-#define closesocket(A)	my_socket_close(A)
+#define socket_errno	errno
+#define closesocket(A)	close(A)
 #define SOCKET_EINTR	EINTR
 #define SOCKET_EAGAIN	EAGAIN
 #define SOCKET_ETIMEDOUT SOCKET_EINTR

=== modified file 'include/my_net.h'
--- a/include/my_net.h	2009-05-27 15:21:45 +0000
+++ b/include/my_net.h	2010-04-13 16:01:38 +0000
@@ -84,9 +84,6 @@ C_MODE_START
 /* Thread safe or portable version of some functions */
 
 void my_inet_ntoa(struct in_addr in, char *buf);
-#ifdef __WIN__
-typedef int socklen_t;
-#endif
 
 /*
   Handling of gethostbyname_r()

=== modified file 'include/mysql.h'
--- a/include/mysql.h	2010-03-12 11:56:09 +0000
+++ b/include/mysql.h	2010-04-13 16:01:38 +0000
@@ -61,6 +61,13 @@ typedef char my_bool;
 #define STDCALL __stdcall
 #endif
 
+#ifndef my_socket_defined
+#ifdef __WIN__
+#define my_socket SOCKET
+#else
+typedef int my_socket;
+#endif /* __WIN__ */
+#endif /* my_socket_defined */
 #endif /* _global_h */
 
 #include "mysql_version.h"

=== modified file 'include/mysql.h.pp'
--- a/include/mysql.h.pp	2010-03-12 11:56:09 +0000
+++ b/include/mysql.h.pp	2010-04-13 16:01:38 +0000
@@ -1,5 +1,6 @@
 #include <sys/types.h>
 typedef char my_bool;
+typedef int my_socket;
 #include "mysql_version.h"
 #include "mysql_com.h"
 enum enum_server_command
@@ -18,7 +19,7 @@ typedef struct st_vio Vio;
 typedef struct st_net {
   Vio *vio;
   unsigned char *buff,*buff_end,*write_pos,*read_pos;
-  int fd;
+  my_socket fd;
   unsigned long remain_in_buf,length, buf_length, where_b;
   unsigned long max_packet,max_packet_size;
   unsigned int pkt_nr,compress_pkt_nr;
@@ -96,7 +97,7 @@ my_bool net_write_command(NET *net,unsig
 int net_real_write(NET *net,const unsigned char *packet, size_t len);
 unsigned long my_net_read(NET *net);
 struct sockaddr;
-int my_connect(int s, const struct sockaddr *name, unsigned int namelen,
+int my_connect(my_socket s, const struct sockaddr *name, unsigned int namelen,
         unsigned int timeout);
 struct rand_struct {
   unsigned long seed1,seed2,max_value;

=== modified file 'include/mysql_com.h'
--- a/include/mysql_com.h	2009-05-27 15:21:45 +0000
+++ b/include/mysql_com.h	2010-04-13 16:01:38 +0000
@@ -245,11 +245,7 @@ typedef struct st_net {
 #if !defined(CHECK_EMBEDDED_DIFFERENCES) || !defined(EMBEDDED_LIBRARY)
   Vio *vio;
   unsigned char *buff,*buff_end,*write_pos,*read_pos;
-#ifdef __WIN__
-  SOCKET fd;
-#else
-  int fd;					/* For Perl DBI/dbd */
-#endif
+  my_socket fd;					/* For Perl DBI/dbd */
   /*
     The following variable is set if we are doing several queries in one
     command ( as in LOAD TABLE ... FROM MASTER ),
@@ -423,13 +419,8 @@ void my_net_set_read_timeout(NET *net, u
   Currently it's used internally by manager.c
 */
 struct sockaddr;
-#ifdef __WIN__
-int my_connect(SOCKET s, const struct sockaddr *name, unsigned int namelen,
-	       unsigned int timeout);
-#else
-int my_connect(int s,    const struct sockaddr *name, unsigned int namelen,
+int my_connect(my_socket s, const struct sockaddr *name, unsigned int namelen,
 	       unsigned int timeout);
-#endif
 
 struct rand_struct {
   unsigned long seed1,seed2,max_value;

=== modified file 'include/violite.h'
--- a/include/violite.h	2010-03-12 11:56:09 +0000
+++ b/include/violite.h	2010-04-13 16:01:38 +0000
@@ -112,6 +112,9 @@ int vio_getnameinfo(const struct sockadd
 #ifndef YASSL_PREFIX
 #define YASSL_PREFIX
 #endif
+/* Set yaSSL to use same type as MySQL do for socket handles */
+typedef my_socket YASSL_SOCKET_T;
+#define YASSL_SOCKET_T_DEFINED
 #include <openssl/ssl.h>
 #include <openssl/err.h>
 

=== modified file 'libmysql/manager.c'
--- a/libmysql/manager.c	2009-05-27 15:21:45 +0000
+++ b/libmysql/manager.c	2010-04-13 16:01:38 +0000
@@ -1,10 +1,12 @@
-/*
-   Copyright (C) 2000-2004 MySQL AB
-    All rights reserved. Use is subject to license terms.
+/* Copyright (C) 2000-2004 MySQL AB
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; version 2 of the License.
+   the Free Software Foundation.
+
+   There are special exceptions to the terms and conditions of the GPL as it
+   is applied to this software. View the full text of the exception in file
+   EXCEPTIONS-CLIENT in the directory of this software distribution.
 
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -13,10 +15,7 @@
 
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
-
-
-*/
+   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
 #include <my_global.h>
 #if defined(THREAD)
@@ -105,8 +104,7 @@ MYSQL_MANAGER*  STDCALL mysql_manager_co
   if (!passwd)
     passwd="";
 
-  sock= my_socket_create(AF_INET, SOCK_STREAM, 0);
-  if (!my_socket_valid(sock))
+  if ((sock=(my_socket)socket(AF_INET,SOCK_STREAM,0)) == INVALID_SOCKET)
   {
     con->last_errno=errno;
     strmov(con->last_error,"Cannot create socket");
@@ -144,7 +142,7 @@ MYSQL_MANAGER*  STDCALL mysql_manager_co
     my_gethostbyname_r_free();
   }
   sock_addr.sin_port = (ushort) htons((ushort) port);
-  if (my_connect(MY_SOCKET_FORMAT_VALUE(sock),(struct sockaddr *) &sock_addr, sizeof(sock_addr),
+  if (my_connect(sock,(struct sockaddr *) &sock_addr, sizeof(sock_addr),
 		 0))
   {
     con->last_errno=errno;

=== modified file 'libmysqld/libmysqld.c'
--- a/libmysqld/libmysqld.c	2009-12-18 06:43:04 +0000
+++ b/libmysqld/libmysqld.c	2010-04-15 12:22:43 +0000
@@ -63,6 +63,8 @@ extern ulong max_allowed_packet;
 #else
 #include <errno.h>
 #define ERRNO errno
+#define SOCKET_ERROR -1
+#define closesocket(A) close(A)
 #endif
 
 #ifdef HAVE_GETPWUID
@@ -100,7 +102,7 @@ mysql_real_connect(MYSQL *mysql,const ch
   char name_buff[USERNAME_LENGTH];
 
   DBUG_ENTER("mysql_real_connect");
-  DBUG_PRINT("enter",("host: %s  db: %s  user: %s",
+  DBUG_PRINT("enter",("host: %s  db: %s  user: %s (libmysqld)",
 		      host ? host : "(Null)",
 		      db ? db : "(Null)",
 		      user ? user : "(Null)"));

=== modified file 'mysql-test/Makefile.am'
--- a/mysql-test/Makefile.am	2010-03-15 14:37:37 +0000
+++ b/mysql-test/Makefile.am	2010-04-29 14:52:05 +0000
@@ -84,6 +84,7 @@ TEST_DIRS = t r include std_data std_dat
 	std_data/ndb_backup51_undolog_be \
 	std_data/ndb_backup51_undolog_le \
 	std_data/ndb_backup_hashmap \
+	std_data/ndb_backup_before_native_default \
 	std_data/funcs_1 \
 	extra/binlog_tests/ extra/rpl_tests \
 	suite/binlog suite/binlog/t suite/binlog/r suite/binlog/std_data \

=== added file 'mysql-test/include/ndb_desc_print.inc'
--- a/mysql-test/include/ndb_desc_print.inc	1970-01-01 00:00:00 +0000
+++ b/mysql-test/include/ndb_desc_print.inc	2010-04-29 14:52:05 +0000
@@ -0,0 +1,5 @@
+# Use replace_regex to remove non-deterministic values from the
+# ndb_desc output
+#
+--replace_regex /Version: [0-9]*/Version: Any/  /t2_unique_index\(j\) - OrderedIndex/Index/ /t2_unique_index\$unique\(j\) - UniqueHashIndex/Index/ /PRIMARY\(i\) - OrderedIndex/Index/  /BT=NDB\$BLOB_[0-9]*_/BT=NDB$BLOB_XX_/ 
+--exec $NDB_DESC --no-defaults $ndb_desc_opts

=== modified file 'mysql-test/include/wait_for_slave_param.inc'
--- a/mysql-test/include/wait_for_slave_param.inc	2009-01-09 14:12:31 +0000
+++ b/mysql-test/include/wait_for_slave_param.inc	2010-04-15 11:38:10 +0000
@@ -49,6 +49,8 @@ if (!$_slave_timeout_counter)
 {
   let $_slave_timeout_counter= 3000;
 }
+# Save resulting counter for later use.
+let $slave_tcnt= $_slave_timeout_counter;
 
 let $_slave_param_comparison= $slave_param_comparison;
 if (`SELECT '$_slave_param_comparison' = ''`)
@@ -70,7 +72,7 @@ while (`SELECT NOT('$_show_slave_status_
 # This has to be outside the loop until BUG#41913 has been fixed
 if (!$_slave_timeout_counter)
 {
-  --echo **** ERROR: timeout after $slave_timeout seconds while waiting for slave parameter $slave_param $_slave_param_comparison $slave_param_value ****
+  --echo **** ERROR: timeout after $slave_tcnt deci-seconds while waiting for slave parameter $slave_param $_slave_param_comparison $slave_param_value ****
   if (`SELECT '$slave_error_message' != ''`)
   {
     --echo Message: $slave_error_message

=== added directory 'mysql-test/std_data/ndb_backup_before_native_default'
=== added file 'mysql-test/std_data/ndb_backup_before_native_default/BACKUP-1-0.1.Data'
Files a/mysql-test/std_data/ndb_backup_before_native_default/BACKUP-1-0.1.Data	1970-01-01 00:00:00 +0000 and b/mysql-test/std_data/ndb_backup_before_native_default/BACKUP-1-0.1.Data	2010-04-29 14:52:05 +0000 differ

=== added file 'mysql-test/std_data/ndb_backup_before_native_default/BACKUP-1-0.2.Data'
Files a/mysql-test/std_data/ndb_backup_before_native_default/BACKUP-1-0.2.Data	1970-01-01 00:00:00 +0000 and b/mysql-test/std_data/ndb_backup_before_native_default/BACKUP-1-0.2.Data	2010-04-29 14:52:05 +0000 differ

=== added file 'mysql-test/std_data/ndb_backup_before_native_default/BACKUP-1.1.ctl'
Files a/mysql-test/std_data/ndb_backup_before_native_default/BACKUP-1.1.ctl	1970-01-01 00:00:00 +0000 and b/mysql-test/std_data/ndb_backup_before_native_default/BACKUP-1.1.ctl	2010-04-29 14:52:05 +0000 differ

=== added file 'mysql-test/std_data/ndb_backup_before_native_default/BACKUP-1.1.log'
Files a/mysql-test/std_data/ndb_backup_before_native_default/BACKUP-1.1.log	1970-01-01 00:00:00 +0000 and b/mysql-test/std_data/ndb_backup_before_native_default/BACKUP-1.1.log	2010-04-29 14:52:05 +0000 differ

=== added file 'mysql-test/std_data/ndb_backup_before_native_default/BACKUP-1.2.ctl'
Files a/mysql-test/std_data/ndb_backup_before_native_default/BACKUP-1.2.ctl	1970-01-01 00:00:00 +0000 and b/mysql-test/std_data/ndb_backup_before_native_default/BACKUP-1.2.ctl	2010-04-29 14:52:05 +0000 differ

=== added file 'mysql-test/std_data/ndb_backup_before_native_default/BACKUP-1.2.log'
Files a/mysql-test/std_data/ndb_backup_before_native_default/BACKUP-1.2.log	1970-01-01 00:00:00 +0000 and b/mysql-test/std_data/ndb_backup_before_native_default/BACKUP-1.2.log	2010-04-29 14:52:05 +0000 differ

=== added file 'mysql-test/suite/ndb/r/ndb_native_default_support.result'
--- a/mysql-test/suite/ndb/r/ndb_native_default_support.result	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/ndb/r/ndb_native_default_support.result	2010-04-29 14:52:05 +0000
@@ -0,0 +1,574 @@
+DROP TABLE IF EXISTS t1,bit1;
+DROP DATABASE IF EXISTS mysqltest;
+CREATE DATABASE mysqltest;
+USE mysqltest;
+***************************************************************
+* BASIC SQL STATEMENT TEST FOR NDB NATIVE DEFAULT VALUE SUPPORT
+***************************************************************
+CREATE TABLE t1( 
+i INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
+j INT DEFAULT 6, 
+f FLOAT NOT NULL DEFAULT 6.6, 
+d DOUBLE DEFAULT 8.8,
+d2 DOUBLE NOT NULL,  #d2 gets 'data-type-specific default', i.e. 0.
+ch CHAR(19) DEFAULT "aaa",
+vch VARCHAR(19) DEFAULT "bbb", 
+b BINARY(19) DEFAULT "ccc",
+vb VARBINARY(19) DEFAULT  "ddd", 
+blob1 BLOB,
+text1 TEXT,
+timestamp_c TIMESTAMP DEFAULT CURRENT_TIMESTAMP
+)ENGINE=NDB;
+INSERT INTO t1 VALUES(),();
+INSERT INTO t1 VALUES(
+10, 10, 10.0, 10.0, 10.0,
+"nnnnn", "nnnnn", "nnnnn", "nnnnn", "nnnnn", "nnnnn", 
+"2008-11-16 08:13:32");
+INSERT INTO t1(i, ch) VALUES(11, "mmm");
+SELECT i, j, f, d, d2, ch, vch, HEX(b), HEX(vb), HEX(blob1), text1, timestamp_c FROM t1 ORDER BY i;
+i	j	f	d	d2	ch	vch	HEX(b)	HEX(vb)	HEX(blob1)	text1	timestamp_c
+1	6	6.6	8.8	0	aaa	bbb	63636300000000000000000000000000000000	646464	NULL	NULL	CURRENT_TIMESTAMP
+2	6	6.6	8.8	0	aaa	bbb	63636300000000000000000000000000000000	646464	NULL	NULL	CURRENT_TIMESTAMP
+10	10	10	10	10	nnnnn	nnnnn	6E6E6E6E6E0000000000000000000000000000	6E6E6E6E6E	6E6E6E6E6E	nnnnn	CURRENT_TIMESTAMP
+11	6	6.6	8.8	0	mmm	bbb	63636300000000000000000000000000000000	646464	NULL	NULL	CURRENT_TIMESTAMP
+UPDATE t1 SET ch = "xxx" WHERE i = 10;
+SELECT i, j, f, d, d2, ch, vch, HEX(b), HEX(vb), HEX(blob1), text1, timestamp_c FROM t1 ORDER BY i;
+i	j	f	d	d2	ch	vch	HEX(b)	HEX(vb)	HEX(blob1)	text1	timestamp_c
+1	6	6.6	8.8	0	aaa	bbb	63636300000000000000000000000000000000	646464	NULL	NULL	CURRENT_TIMESTAMP
+2	6	6.6	8.8	0	aaa	bbb	63636300000000000000000000000000000000	646464	NULL	NULL	CURRENT_TIMESTAMP
+10	10	10	10	10	xxx	nnnnn	6E6E6E6E6E0000000000000000000000000000	6E6E6E6E6E	6E6E6E6E6E	nnnnn	CURRENT_TIMESTAMP
+11	6	6.6	8.8	0	mmm	bbb	63636300000000000000000000000000000000	646464	NULL	NULL	CURRENT_TIMESTAMP
+UPDATE t1 SET blob1 = "yyy" WHERE j = 10;
+SELECT i, j, f, d, d2, ch, vch, HEX(b), HEX(vb), HEX(blob1), text1, timestamp_c FROM t1 ORDER BY i;
+i	j	f	d	d2	ch	vch	HEX(b)	HEX(vb)	HEX(blob1)	text1	timestamp_c
+1	6	6.6	8.8	0	aaa	bbb	63636300000000000000000000000000000000	646464	NULL	NULL	CURRENT_TIMESTAMP
+2	6	6.6	8.8	0	aaa	bbb	63636300000000000000000000000000000000	646464	NULL	NULL	CURRENT_TIMESTAMP
+10	10	10	10	10	xxx	nnnnn	6E6E6E6E6E0000000000000000000000000000	6E6E6E6E6E	797979	nnnnn	CURRENT_TIMESTAMP
+11	6	6.6	8.8	0	mmm	bbb	63636300000000000000000000000000000000	646464	NULL	NULL	CURRENT_TIMESTAMP
+REPLACE INTO t1(i, j, ch) VALUES(1, 1, "zzz");
+REPLACE INTO t1(i, j, ch) VALUES(20, 20, "www");
+SELECT i, j, f, d, d2, ch, vch, HEX(b), HEX(vb), HEX(blob1), text1, timestamp_c FROM t1 ORDER BY i;
+i	j	f	d	d2	ch	vch	HEX(b)	HEX(vb)	HEX(blob1)	text1	timestamp_c
+1	1	6.6	8.8	0	zzz	bbb	63636300000000000000000000000000000000	646464	NULL	NULL	CURRENT_TIMESTAMP
+2	6	6.6	8.8	0	aaa	bbb	63636300000000000000000000000000000000	646464	NULL	NULL	CURRENT_TIMESTAMP
+10	10	10	10	10	xxx	nnnnn	6E6E6E6E6E0000000000000000000000000000	6E6E6E6E6E	797979	nnnnn	CURRENT_TIMESTAMP
+11	6	6.6	8.8	0	mmm	bbb	63636300000000000000000000000000000000	646464	NULL	NULL	CURRENT_TIMESTAMP
+20	20	6.6	8.8	0	www	bbb	63636300000000000000000000000000000000	646464	NULL	NULL	CURRENT_TIMESTAMP
+DELETE FROM t1 WHERE i > 9;
+SELECT i, j, f, d, d2, ch, vch, HEX(b), HEX(vb), HEX(blob1), text1, timestamp_c FROM t1 ORDER BY i;
+i	j	f	d	d2	ch	vch	HEX(b)	HEX(vb)	HEX(blob1)	text1	timestamp_c
+1	1	6.6	8.8	0	zzz	bbb	63636300000000000000000000000000000000	646464	NULL	NULL	CURRENT_TIMESTAMP
+2	6	6.6	8.8	0	aaa	bbb	63636300000000000000000000000000000000	646464	NULL	NULL	CURRENT_TIMESTAMP
+CREATE TABLE bit1(
+pk INT AUTO_INCREMENT NOT NULL PRIMARY KEY,
+b1 BIT(3) DEFAULT B'111',
+b2 BIT(9) DEFAULT B'101',
+b3 BIT(23) DEFAULT B'110',
+b4 BIT(37) DEFAULT B'011',
+b5 BIT(63) DEFAULT B'101011'
+)ENGINE = NDB;
+INSERT INTO bit1 VALUES();
+INSERT INTO bit1(b1,b4) VALUES(B'101',B'111');
+SELECT pk,BIN(b1),BIN(b2),BIN(b3),BIN(b4),BIN(b5) FROM bit1 ORDER BY pk;
+pk	BIN(b1)	BIN(b2)	BIN(b3)	BIN(b4)	BIN(b5)
+1	111	101	110	11	101011
+2	101	101	110	111	101011
+UPDATE bit1 SET b5=B'11111' WHERE pk = 1;
+REPLACE INTO bit1(pk, b3) VALUES(2, B'1');
+REPLACE INTO bit1(pk, b3) VALUES(6, B'101');
+SELECT pk,BIN(b1),BIN(b2),BIN(b3),BIN(b4),BIN(b5) FROM bit1 ORDER BY pk;
+pk	BIN(b1)	BIN(b2)	BIN(b3)	BIN(b4)	BIN(b5)
+1	111	101	110	11	11111
+2	111	101	1	11	101011
+6	111	101	101	11	101011
+DELETE FROM bit1 WHERE pk = 2;
+SELECT pk,BIN(b1),BIN(b2),BIN(b3),BIN(b4),BIN(b5) FROM bit1 ORDER BY pk;
+pk	BIN(b1)	BIN(b2)	BIN(b3)	BIN(b4)	BIN(b5)
+1	111	101	110	11	11111
+6	111	101	101	11	101011
+********************************************************
+* Alter table to add column with default value
+********************************************************
+ALTER TABLE t1 ADD COLUMN ch2 CHAR(30) DEFAULT "alter table";
+SELECT i, j, f, d, d2, ch, vch, HEX(b), HEX(vb), HEX(blob1), text1, timestamp_c, ch2 FROM t1 ORDER BY i;
+i	j	f	d	d2	ch	vch	HEX(b)	HEX(vb)	HEX(blob1)	text1	timestamp_c	ch2
+1	1	6.6	8.8	0	zzz	bbb	63636300000000000000000000000000000000	646464	NULL	NULL	CURRENT_TIMESTAMP	alter table
+2	6	6.6	8.8	0	aaa	bbb	63636300000000000000000000000000000000	646464	NULL	NULL	CURRENT_TIMESTAMP	alter table
+INSERT INTO t1 VALUES();
+SELECT i, j, f, d, d2, ch, vch, HEX(b), HEX(vb), HEX(blob1), text1, timestamp_c, ch2 FROM t1 ORDER BY i;
+i	j	f	d	d2	ch	vch	HEX(b)	HEX(vb)	HEX(blob1)	text1	timestamp_c	ch2
+1	1	6.6	8.8	0	zzz	bbb	63636300000000000000000000000000000000	646464	NULL	NULL	CURRENT_TIMESTAMP	alter table
+2	6	6.6	8.8	0	aaa	bbb	63636300000000000000000000000000000000	646464	NULL	NULL	CURRENT_TIMESTAMP	alter table
+21	6	6.6	8.8	0	aaa	bbb	63636300000000000000000000000000000000	646464	NULL	NULL	CURRENT_TIMESTAMP	alter table
+********************************************************
+* Alter table with default value can fail safely
+********************************************************
+ALTER TABLE t1 ADD COLUMN ch2 CHAR(30) DEFAULT "alter table";
+ERROR 42S21: Duplicate column name 'ch2'
+ALTER TABLE t1 ADD COLUMN ch3 CHAR(3) DEFAULT "alter table";
+ERROR 42000: Invalid default value for 'ch3'
+INSERT INTO t1 VALUES();
+SELECT i, j, f, d, d2, ch, vch, HEX(b), HEX(vb), HEX(blob1), text1, timestamp_c, ch2 FROM t1 ORDER BY i;
+i	j	f	d	d2	ch	vch	HEX(b)	HEX(vb)	HEX(blob1)	text1	timestamp_c	ch2
+1	1	6.6	8.8	0	zzz	bbb	63636300000000000000000000000000000000	646464	NULL	NULL	CURRENT_TIMESTAMP	alter table
+2	6	6.6	8.8	0	aaa	bbb	63636300000000000000000000000000000000	646464	NULL	NULL	CURRENT_TIMESTAMP	alter table
+21	6	6.6	8.8	0	aaa	bbb	63636300000000000000000000000000000000	646464	NULL	NULL	CURRENT_TIMESTAMP	alter table
+22	6	6.6	8.8	0	aaa	bbb	63636300000000000000000000000000000000	646464	NULL	NULL	CURRENT_TIMESTAMP	alter table
+********************************************************
+* The tables with default values BACKUP and RESTORE test
+********************************************************
+DROP TABLE IF EXISTS t1, bit1;
+********************************************************
+* Begin to restore data from backup 
+********************************************************
+SHOW TABLES;
+Tables_in_mysqltest
+bit1
+t1
+-- t1 --
+Version: Any
+Fragment type: 9
+K Value: 6
+Min load factor: 78
+Max load factor: 80
+Temporary table: no
+Number of attributes: 13
+Number of primary keys: 1
+Length of frm data: 518
+Row Checksum: 1
+Row GCI: 1
+SingleUserMode: 0
+ForceVarPart: 1
+FragmentCount: 2
+TableStatus: Retrieved
+-- Attributes -- 
+i Int PRIMARY KEY DISTRIBUTION KEY AT=FIXED ST=MEMORY AUTO_INCR
+j Int NULL AT=FIXED ST=MEMORY DEFAULT 6
+f Float NOT NULL AT=FIXED ST=MEMORY DEFAULT 6.600000
+d Double NULL AT=FIXED ST=MEMORY DEFAULT 8.800000
+d2 Double NOT NULL AT=FIXED ST=MEMORY
+ch Char(19;latin1_swedish_ci) NULL AT=FIXED ST=MEMORY DEFAULT "aaa"
+vch Varchar(19;latin1_swedish_ci) NULL AT=SHORT_VAR ST=MEMORY DEFAULT "bbb"
+b Binary(19) NULL AT=FIXED ST=MEMORY DEFAULT 0x636363
+vb Varbinary(19) NULL AT=SHORT_VAR ST=MEMORY DEFAULT 0x646464
+blob1 Blob(256,2000,0) NULL AT=MEDIUM_VAR ST=MEMORY BV=2 BT=NDB$BLOB_XX_9
+text1 Text(256,2000,0;latin1_swedish_ci) NULL AT=MEDIUM_VAR ST=MEMORY BV=2 BT=NDB$BLOB_XX_10
+timestamp_c Timestamp NOT NULL AT=FIXED ST=MEMORY DEFAULT 0
+ch2 Char(30;latin1_swedish_ci) NULL AT=FIXED ST=MEMORY DEFAULT "alter table"
+
+-- Indexes -- 
+PRIMARY KEY(i) - UniqueHashIndex
+Index
+
+
+NDBT_ProgramExit: 0 - OK
+
+-- bit1 --
+Version: Any
+Fragment type: 9
+K Value: 6
+Min load factor: 78
+Max load factor: 80
+Temporary table: no
+Number of attributes: 6
+Number of primary keys: 1
+Length of frm data: 324
+Row Checksum: 1
+Row GCI: 1
+SingleUserMode: 0
+ForceVarPart: 1
+FragmentCount: 2
+TableStatus: Retrieved
+-- Attributes -- 
+pk Int PRIMARY KEY DISTRIBUTION KEY AT=FIXED ST=MEMORY AUTO_INCR
+b1 Bit(3) NULL AT=FIXED ST=MEMORY DEFAULT H'0x7
+b2 Bit(9) NULL AT=FIXED ST=MEMORY DEFAULT H'0x5
+b3 Bit(23) NULL AT=FIXED ST=MEMORY DEFAULT H'0x6
+b4 Bit(37) NULL AT=FIXED ST=MEMORY DEFAULT H'0x3
+b5 Bit(63) NULL AT=FIXED ST=MEMORY DEFAULT H'0x2B
+
+-- Indexes -- 
+PRIMARY KEY(pk) - UniqueHashIndex
+PRIMARY(pk) - OrderedIndex
+
+
+NDBT_ProgramExit: 0 - OK
+
+SELECT pk,BIN(b1),BIN(b2),BIN(b3),BIN(b4),BIN(b5) FROM bit1 ORDER BY pk;
+pk	BIN(b1)	BIN(b2)	BIN(b3)	BIN(b4)	BIN(b5)
+1	111	101	110	11	11111
+6	111	101	101	11	101011
+SELECT i, j, f, d, d2, ch, vch, HEX(b), HEX(vb), HEX(blob1), text1, timestamp_c, ch2 FROM t1 ORDER BY i;
+i	j	f	d	d2	ch	vch	HEX(b)	HEX(vb)	HEX(blob1)	text1	timestamp_c	ch2
+1	1	6.6	8.8	0	zzz	bbb	63636300000000000000000000000000000000	646464	NULL	NULL	CURRENT_TIMESTAMP	alter table
+2	6	6.6	8.8	0	aaa	bbb	63636300000000000000000000000000000000	646464	NULL	NULL	CURRENT_TIMESTAMP	alter table
+21	6	6.6	8.8	0	aaa	bbb	63636300000000000000000000000000000000	646464	NULL	NULL	CURRENT_TIMESTAMP	alter table
+22	6	6.6	8.8	0	aaa	bbb	63636300000000000000000000000000000000	646464	NULL	NULL	CURRENT_TIMESTAMP	alter table
+INSERT INTO t1(i, ch) VALUES(99, "restore");
+INSERT INTO bit1(pk, b5) VALUES(99, B'11111111');
+SELECT pk,BIN(b1),BIN(b2),BIN(b3),BIN(b4),BIN(b5) FROM bit1 ORDER BY pk;
+pk	BIN(b1)	BIN(b2)	BIN(b3)	BIN(b4)	BIN(b5)
+1	111	101	110	11	11111
+6	111	101	101	11	101011
+99	111	101	110	11	11111111
+SELECT i, j, f, d, d2, ch, vch, HEX(b), HEX(vb), HEX(blob1), text1, timestamp_c, ch2 FROM t1 ORDER BY i;
+i	j	f	d	d2	ch	vch	HEX(b)	HEX(vb)	HEX(blob1)	text1	timestamp_c	ch2
+1	1	6.6	8.8	0	zzz	bbb	63636300000000000000000000000000000000	646464	NULL	NULL	CURRENT_TIMESTAMP	alter table
+2	6	6.6	8.8	0	aaa	bbb	63636300000000000000000000000000000000	646464	NULL	NULL	CURRENT_TIMESTAMP	alter table
+21	6	6.6	8.8	0	aaa	bbb	63636300000000000000000000000000000000	646464	NULL	NULL	CURRENT_TIMESTAMP	alter table
+22	6	6.6	8.8	0	aaa	bbb	63636300000000000000000000000000000000	646464	NULL	NULL	CURRENT_TIMESTAMP	alter table
+99	6	6.6	8.8	0	restore	bbb	63636300000000000000000000000000000000	646464	NULL	NULL	CURRENT_TIMESTAMP	alter table
+DROP TABLE IF EXISTS t1, bit1;
+SHOW TABLES;
+Tables_in_mysqltest
+bit1
+t1
+SELECT i, j, f, d, d2, ch, vch, HEX(b), HEX(vb), HEX(blob1), text1, timestamp_c, ch2 FROM t1 WHERE i >= (SELECT MAX(i) FROM t1) ORDER BY i;
+i	j	f	d	d2	ch	vch	HEX(b)	HEX(vb)	HEX(blob1)	text1	timestamp_c	ch2
+MAX_VALUE	6	6.6	8.8	0	aaa	bbb	63636300000000000000000000000000000000	646464	NULL	NULL	CURRENT_TIMESTAMP	alter table
+DROP TABLE IF EXISTS t1, bit1;
+DROP DATABASE mysqltest;
+******************************************************************************
+* Restore the backup from 6.3 or 6.4, which don't support native default value
+******************************************************************************
+USE test;
+SHOW TABLES;
+Tables_in_test
+bit1
+t1
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `i` int(11) NOT NULL AUTO_INCREMENT,
+  `j` int(11) DEFAULT '6',
+  `f` float NOT NULL DEFAULT '6.6',
+  `d` double DEFAULT '8.8',
+  `d2` double NOT NULL,
+  `ch` char(19) DEFAULT 'aaa',
+  `vch` varchar(19) DEFAULT 'bbb',
+  `b` binary(19) DEFAULT 'ccc\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0',
+  `vb` varbinary(19) DEFAULT 'ddd',
+  `blob1` blob,
+  `text1` text,
+  `timestamp_c` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
+  PRIMARY KEY (`i`)
+) ENGINE=ndbcluster AUTO_INCREMENT=12 DEFAULT CHARSET=latin1
+SHOW CREATE TABLE bit1;
+Table	Create Table
+bit1	CREATE TABLE `bit1` (
+  `pk` int(11) NOT NULL AUTO_INCREMENT,
+  `b1` bit(3) DEFAULT b'111',
+  `b2` bit(9) DEFAULT b'101',
+  `b3` bit(23) DEFAULT b'110',
+  `b4` bit(37) DEFAULT b'11',
+  `b5` bit(63) DEFAULT b'101011',
+  PRIMARY KEY (`pk`)
+) ENGINE=ndbcluster AUTO_INCREMENT=3 DEFAULT CHARSET=latin1
+SELECT i, j, f, d, d2, ch, vch, HEX(b), HEX(vb), HEX(blob1), text1, timestamp_c FROM t1 ORDER BY i;
+i	j	f	d	d2	ch	vch	HEX(b)	HEX(vb)	HEX(blob1)	text1	timestamp_c
+1	6	6.6	8.8	0	aaa	bbb	63636300000000000000000000000000000000	646464	NULL	NULL	CURRENT_TIMESTAMP
+2	6	6.6	8.8	0	aaa	bbb	63636300000000000000000000000000000000	646464	NULL	NULL	CURRENT_TIMESTAMP
+10	10	10	10	10	nnnnn	nnnnn	6E6E6E6E6E0000000000000000000000000000	6E6E6E6E6E	6E6E6E6E6E	nnnnn	CURRENT_TIMESTAMP
+11	6	6.6	8.8	0	mmm	bbb	63636300000000000000000000000000000000	646464	NULL	NULL	CURRENT_TIMESTAMP
+SELECT pk,BIN(b1),BIN(b2),BIN(b3),BIN(b4),BIN(b5) FROM bit1 ORDER BY pk;
+pk	BIN(b1)	BIN(b2)	BIN(b3)	BIN(b4)	BIN(b5)
+1	111	101	110	11	101011
+2	101	101	110	111	101011
+INSERT INTO t1 VALUES();
+UPDATE t1 SET ch = "RESTORE FROM 6.3" WHERE i = 12;
+REPLACE INTO t1(i, j, ch) VALUES(20, 20, "RESTORE FROM 6.3");
+SELECT i, j, f, d, d2, ch, vch, HEX(b), HEX(vb), HEX(blob1), text1, timestamp_c FROM t1 ORDER BY i;
+i	j	f	d	d2	ch	vch	HEX(b)	HEX(vb)	HEX(blob1)	text1	timestamp_c
+1	6	6.6	8.8	0	aaa	bbb	63636300000000000000000000000000000000	646464	NULL	NULL	CURRENT_TIMESTAMP
+2	6	6.6	8.8	0	aaa	bbb	63636300000000000000000000000000000000	646464	NULL	NULL	CURRENT_TIMESTAMP
+10	10	10	10	10	nnnnn	nnnnn	6E6E6E6E6E0000000000000000000000000000	6E6E6E6E6E	6E6E6E6E6E	nnnnn	CURRENT_TIMESTAMP
+11	6	6.6	8.8	0	mmm	bbb	63636300000000000000000000000000000000	646464	NULL	NULL	CURRENT_TIMESTAMP
+12	6	6.6	8.8	0	RESTORE FROM 6.3	bbb	63636300000000000000000000000000000000	646464	NULL	NULL	CURRENT_TIMESTAMP
+20	20	6.6	8.8	0	RESTORE FROM 6.3	bbb	63636300000000000000000000000000000000	646464	NULL	NULL	CURRENT_TIMESTAMP
+INSERT INTO bit1 VALUES();
+UPDATE bit1 SET b5=b'1111111' WHERE pk = 1;
+REPLACE INTO bit1(pk, b3) VALUES(6, B'110011');
+SELECT pk,BIN(b1),BIN(b2),BIN(b3),BIN(b4),BIN(b5) FROM bit1 ORDER BY pk;
+pk	BIN(b1)	BIN(b2)	BIN(b3)	BIN(b4)	BIN(b5)
+1	111	101	110	11	1111111
+2	101	101	110	111	101011
+3	111	101	110	11	101011
+6	111	101	110011	11	101011
+********************************************************************************
+* Alter table restoring from 6.3 backup to new table with native default support
+********************************************************************************
+-- t1 --
+Version: Any
+Fragment type: 5
+K Value: 6
+Min load factor: 78
+Max load factor: 80
+Temporary table: no
+Number of attributes: 12
+Number of primary keys: 1
+Length of frm data: 484
+Row Checksum: 1
+Row GCI: 1
+SingleUserMode: 0
+ForceVarPart: 1
+FragmentCount: 2
+TableStatus: Retrieved
+-- Attributes -- 
+i Int PRIMARY KEY DISTRIBUTION KEY AT=FIXED ST=MEMORY AUTO_INCR
+j Int NULL AT=FIXED ST=MEMORY
+f Float NOT NULL AT=FIXED ST=MEMORY
+d Double NULL AT=FIXED ST=MEMORY
+d2 Double NOT NULL AT=FIXED ST=MEMORY
+ch Char(19;latin1_swedish_ci) NULL AT=FIXED ST=MEMORY
+vch Varchar(19;latin1_swedish_ci) NULL AT=SHORT_VAR ST=MEMORY
+b Binary(19) NULL AT=FIXED ST=MEMORY
+vb Varbinary(19) NULL AT=SHORT_VAR ST=MEMORY
+blob1 Blob(256,2000,0) NULL AT=MEDIUM_VAR ST=MEMORY BV=2 BT=NDB$BLOB_XX_9
+text1 Text(256,2000,0;latin1_swedish_ci) NULL AT=MEDIUM_VAR ST=MEMORY BV=2 BT=NDB$BLOB_XX_10
+timestamp_c Timestamp NOT NULL AT=FIXED ST=MEMORY
+
+-- Indexes -- 
+PRIMARY KEY(i) - UniqueHashIndex
+Index
+
+
+NDBT_ProgramExit: 0 - OK
+
+ALTER TABLE t1 CHANGE COLUMN j j INT DEFAULT 6;
+-- t1 --
+Version: Any
+Fragment type: 9
+K Value: 6
+Min load factor: 78
+Max load factor: 80
+Temporary table: no
+Number of attributes: 12
+Number of primary keys: 1
+Length of frm data: 487
+Row Checksum: 1
+Row GCI: 1
+SingleUserMode: 0
+ForceVarPart: 1
+FragmentCount: 2
+TableStatus: Retrieved
+-- Attributes -- 
+i Int PRIMARY KEY DISTRIBUTION KEY AT=FIXED ST=MEMORY AUTO_INCR
+j Int NULL AT=FIXED ST=MEMORY DEFAULT 6
+f Float NOT NULL AT=FIXED ST=MEMORY DEFAULT 6.600000
+d Double NULL AT=FIXED ST=MEMORY DEFAULT 8.800000
+d2 Double NOT NULL AT=FIXED ST=MEMORY
+ch Char(19;latin1_swedish_ci) NULL AT=FIXED ST=MEMORY DEFAULT "aaa"
+vch Varchar(19;latin1_swedish_ci) NULL AT=SHORT_VAR ST=MEMORY DEFAULT "bbb"
+b Binary(19) NULL AT=FIXED ST=MEMORY DEFAULT 0x636363
+vb Varbinary(19) NULL AT=SHORT_VAR ST=MEMORY DEFAULT 0x646464
+blob1 Blob(256,2000,0) NULL AT=MEDIUM_VAR ST=MEMORY BV=2 BT=NDB$BLOB_XX_9
+text1 Text(256,2000,0;latin1_swedish_ci) NULL AT=MEDIUM_VAR ST=MEMORY BV=2 BT=NDB$BLOB_XX_10
+timestamp_c Timestamp NOT NULL AT=FIXED ST=MEMORY DEFAULT 0
+
+-- Indexes -- 
+PRIMARY KEY(i) - UniqueHashIndex
+Index
+
+
+NDBT_ProgramExit: 0 - OK
+
+INSERT INTO t1(i, ch) VALUES(99, "native default support");
+SELECT i, j, f, d, d2, ch, vch, HEX(b), HEX(vb), HEX(blob1), text1, timestamp_c FROM t1 ORDER BY i;
+i	j	f	d	d2	ch	vch	HEX(b)	HEX(vb)	HEX(blob1)	text1	timestamp_c
+1	6	6.6	8.8	0	aaa	bbb	63636300000000000000000000000000000000	646464	NULL	NULL	CURRENT_TIMESTAMP
+2	6	6.6	8.8	0	aaa	bbb	63636300000000000000000000000000000000	646464	NULL	NULL	CURRENT_TIMESTAMP
+10	10	10	10	10	nnnnn	nnnnn	6E6E6E6E6E0000000000000000000000000000	6E6E6E6E6E	6E6E6E6E6E	nnnnn	CURRENT_TIMESTAMP
+11	6	6.6	8.8	0	mmm	bbb	63636300000000000000000000000000000000	646464	NULL	NULL	CURRENT_TIMESTAMP
+12	6	6.6	8.8	0	RESTORE FROM 6.3	bbb	63636300000000000000000000000000000000	646464	NULL	NULL	CURRENT_TIMESTAMP
+20	20	6.6	8.8	0	RESTORE FROM 6.3	bbb	63636300000000000000000000000000000000	646464	NULL	NULL	CURRENT_TIMESTAMP
+99	6	6.6	8.8	0	native default supp	bbb	63636300000000000000000000000000000000	646464	NULL	NULL	CURRENT_TIMESTAMP
+DROP TABLE IF EXISTS t1, bit1;
+*************************************************************
+* Test adding a unique index to a column with a default value
+*************************************************************
+CREATE TABLE t2(
+i INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
+j INT DEFAULT 6,
+f FLOAT NOT NULL DEFAULT 6.6,
+d DOUBLE DEFAULT 8.8,
+UNIQUE INDEX t2_unique_index(j) 
+)ENGINE =NDB;
+INSERT INTO t2 VALUES();
+INSERT INTO t2 VALUES();
+ERROR 23000: Duplicate entry '6' for key 't2_unique_index'
+INSERT INTO t2 VALUES(10, 10, 10.0, 10.0);
+SELECT * FROM t2 ORDER BY i;
+i	j	f	d
+1	6	6.6	8.8
+10	10	10	10
+*************************************************************
+* Test offline alter of default values
+*************************************************************
+ALTER TABLE t2 MODIFY COLUMN j INT DEFAULT 666;
+-- t2 --
+Version: Any
+Fragment type: 9
+K Value: 6
+Min load factor: 78
+Max load factor: 80
+Temporary table: no
+Number of attributes: 4
+Number of primary keys: 1
+Length of frm data: 331
+Row Checksum: 1
+Row GCI: 1
+SingleUserMode: 0
+ForceVarPart: 1
+FragmentCount: 2
+TableStatus: Retrieved
+-- Attributes -- 
+i Int PRIMARY KEY DISTRIBUTION KEY AT=FIXED ST=MEMORY AUTO_INCR
+j Int NULL AT=FIXED ST=MEMORY DEFAULT 666
+f Float NOT NULL AT=FIXED ST=MEMORY DEFAULT 6.600000
+d Double NULL AT=FIXED ST=MEMORY DEFAULT 8.800000
+
+-- Indexes -- 
+PRIMARY KEY(i) - UniqueHashIndex
+Index
+Index
+Index
+
+
+NDBT_ProgramExit: 0 - OK
+
+INSERT INTO t2 VALUES();
+SELECT * FROM t2 ORDER BY i;
+i	j	f	d
+1	6	6.6	8.8
+10	10	10	10
+11	666	6.6	8.8
+*************************************************************
+* Test that online alter of default values fails
+*************************************************************
+ALTER ONLINE TABLE t2 MODIFY COLUMN j INT DEFAULT 888;
+ERROR 42000: This version of MySQL doesn't yet support 'ALTER ONLINE TABLE t2 MODIFY COLUMN j INT DEFAULT 888'
+DROP TABLE IF EXISTS t2;
+**************************************************************
+* Test not null-after-defaults example that failed previously
+**************************************************************
+CREATE TABLE t1 (a int primary key, b int default 12, c char not null) engine=ndb;
+-- t1 --
+Version: Any
+Fragment type: 9
+K Value: 6
+Min load factor: 78
+Max load factor: 80
+Temporary table: no
+Number of attributes: 3
+Number of primary keys: 1
+Length of frm data: 267
+Row Checksum: 1
+Row GCI: 1
+SingleUserMode: 0
+ForceVarPart: 1
+FragmentCount: 2
+TableStatus: Retrieved
+-- Attributes -- 
+a Int PRIMARY KEY DISTRIBUTION KEY AT=FIXED ST=MEMORY
+b Int NULL AT=FIXED ST=MEMORY DEFAULT 12
+c Char(1;latin1_swedish_ci) NOT NULL AT=FIXED ST=MEMORY
+
+-- Indexes -- 
+PRIMARY KEY(a) - UniqueHashIndex
+PRIMARY(a) - OrderedIndex
+
+
+NDBT_ProgramExit: 0 - OK
+
+DROP TABLE t1;
+**************************************************************
+* Test mix of null, not-null, default etc..
+**************************************************************
+CREATE TABLE t1 (a int primary key, 
+b int default 12, 
+c char not null, 
+d varchar(6) default 'Daniel',
+e char(3) default 'Stu',
+f enum('NBFry','Kebab') default 'NBFry',
+g set('Chips','Pie','Fish') default 'Fish,Chips',
+h enum('Pig','Lion') not null,
+i char(2) default '66') engine=ndb;
+-- t1 --
+Version: Any
+Fragment type: 9
+K Value: 6
+Min load factor: 78
+Max load factor: 80
+Temporary table: no
+Number of attributes: 9
+Number of primary keys: 1
+Length of frm data: 409
+Row Checksum: 1
+Row GCI: 1
+SingleUserMode: 0
+ForceVarPart: 1
+FragmentCount: 2
+TableStatus: Retrieved
+-- Attributes -- 
+a Int PRIMARY KEY DISTRIBUTION KEY AT=FIXED ST=MEMORY
+b Int NULL AT=FIXED ST=MEMORY DEFAULT 12
+c Char(1;latin1_swedish_ci) NOT NULL AT=FIXED ST=MEMORY
+d Varchar(6;latin1_swedish_ci) NULL AT=SHORT_VAR ST=MEMORY DEFAULT "Daniel"
+e Char(3;latin1_swedish_ci) NULL AT=FIXED ST=MEMORY DEFAULT "Stu"
+f Char(1;binary) NULL AT=FIXED ST=MEMORY DEFAULT "0x01"
+g Char(1;binary) NULL AT=FIXED ST=MEMORY DEFAULT "0x05"
+h Char(1;binary) NOT NULL AT=FIXED ST=MEMORY
+i Char(2;latin1_swedish_ci) NULL AT=FIXED ST=MEMORY DEFAULT "66"
+
+-- Indexes -- 
+PRIMARY KEY(a) - UniqueHashIndex
+PRIMARY(a) - OrderedIndex
+
+
+NDBT_ProgramExit: 0 - OK
+
+DROP TABLE t1;
+******************************************
+* Test binary default with null char value
+******************************************
+CREATE TABLE t1 (a int primary key,
+b binary(10) default 0x4142430045464748494a,
+c varbinary(100) default 0x4142430045464748494a) engine=ndb;
+SHOW CREATE TABLE t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) NOT NULL,
+  `b` binary(10) DEFAULT 'ABC\0EFGHIJ',
+  `c` varbinary(100) DEFAULT 'ABC\0EFGHIJ',
+  PRIMARY KEY (`a`)
+) ENGINE=ndbcluster DEFAULT CHARSET=latin1
+-- t1 --
+Version: Any
+Fragment type: 9
+K Value: 6
+Min load factor: 78
+Max load factor: 80
+Temporary table: no
+Number of attributes: 3
+Number of primary keys: 1
+Length of frm data: 284
+Row Checksum: 1
+Row GCI: 1
+SingleUserMode: 0
+ForceVarPart: 1
+FragmentCount: 2
+TableStatus: Retrieved
+-- Attributes -- 
+a Int PRIMARY KEY DISTRIBUTION KEY AT=FIXED ST=MEMORY
+b Binary(10) NULL AT=FIXED ST=MEMORY DEFAULT 0x4142430045464748494A
+c Varbinary(100) NULL AT=SHORT_VAR ST=MEMORY DEFAULT 0x4142430045464748494A
+
+-- Indexes -- 
+PRIMARY KEY(a) - UniqueHashIndex
+PRIMARY(a) - OrderedIndex
+
+
+NDBT_ProgramExit: 0 - OK
+
+DROP TABLE t1;
+End of ndb native default support test

=== modified file 'mysql-test/suite/ndb/r/ndb_restore_promotion.result'
--- a/mysql-test/suite/ndb/r/ndb_restore_promotion.result	2009-08-18 13:02:20 +0000
+++ b/mysql-test/suite/ndb/r/ndb_restore_promotion.result	2010-04-29 14:52:05 +0000
@@ -197,3 +197,40 @@ a	c	d	e
 3	c	D	e
 4	c	d	E
 drop table t1;
+create table subject(pk int primary key, band varchar(50), pos int) engine=ndb;
+insert into subject values (1, 'Elbow', 1), (2, 'Franz Ferdinand', 2), (3, 'Proclaimers', 3);
+insert into subject values (4, 'David Bowie', 4), (5, 'Rufus Wainwright', 1);
+select * from subject order by pk;
+pk	band	pos
+1	Elbow	1
+2	Franz Ferdinand	2
+3	Proclaimers	3
+4	David Bowie	4
+5	Rufus Wainwright	1
+**************************
+Performing backup of table
+**************************
+******************
+Throwing away data
+******************
+delete from subject;
+select * from subject order by pk;
+pk	band	pos
+*******************************************************
+Modifying table to include new, native defaulted column
+*******************************************************
+alter table subject add column song varchar(50) default 'Unknown';
+***********************************************************
+Restoring data back into table and picking up default value
+***********************************************************
+****************************************************
+All restored entries should have song name 'Unknown'
+****************************************************
+select * from subject order by pk;
+pk	band	pos	song
+1	Elbow	1	Unknown
+2	Franz Ferdinand	2	Unknown
+3	Proclaimers	3	Unknown
+4	David Bowie	4	Unknown
+5	Rufus Wainwright	1	Unknown
+drop table subject;

=== added file 'mysql-test/suite/ndb/t/ndb_native_default_support.test'
--- a/mysql-test/suite/ndb/t/ndb_native_default_support.test	1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/ndb/t/ndb_native_default_support.test	2010-04-29 14:52:05 +0000
@@ -0,0 +1,314 @@
+#############################################################
+# Author: Guangbao Ni
+# Date: 2008-12
+# Purpose: ndb native default support test
+##############################################################
+
+-- source include/have_ndb.inc
+-- source include/ndb_default_cluster.inc
+
+--disable_warnings
+DROP TABLE IF EXISTS t1,bit1;
+DROP DATABASE IF EXISTS mysqltest;
+--enable_warnings
+
+CREATE DATABASE mysqltest;
+USE mysqltest;
+###############################################################
+# BASIC SQL STATEMENT TEST FOR NDB NATIVE DEFAULT VALUE SUPPORT
+###############################################################
+# Create table with default values for some types.
+# Create table for bit type.
+# Test cases include:
+# 1. Create table with default values
+# 2. Insert statement:
+#  --Insert default values into, the default values can be inserted into table correctly
+#  --Insert record supplied by client, it can inserted correctly
+#  --Insert record (including default value and value supplied by client)
+# 3. Update statement:
+#  --Update with primary key condition
+#  --Update with non-primary key condtion
+# 4. Replace statement:
+#  --Replace with default values when the record isn't existed in table
+#  --Replace with part default values and part value supplied by client when the record isn't existed in table.
+#  --Replace with part default values and part value suppliced by client when the record already existed in table.
+# 5. Delete statement:
+
+--echo ***************************************************************
+--echo * BASIC SQL STATEMENT TEST FOR NDB NATIVE DEFAULT VALUE SUPPORT
+--echo ***************************************************************
+
+CREATE TABLE t1( 
+  i INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
+  j INT DEFAULT 6, 
+  f FLOAT NOT NULL DEFAULT 6.6, 
+  d DOUBLE DEFAULT 8.8,
+  d2 DOUBLE NOT NULL,  #d2 gets 'data-type-specific default', i.e. 0.
+  ch CHAR(19) DEFAULT "aaa",
+  vch VARCHAR(19) DEFAULT "bbb", 
+  b BINARY(19) DEFAULT "ccc",
+  vb VARBINARY(19) DEFAULT  "ddd", 
+  blob1 BLOB,
+  text1 TEXT,
+  timestamp_c TIMESTAMP DEFAULT CURRENT_TIMESTAMP
+)ENGINE=NDB;
+
+--disable_warnings
+INSERT INTO t1 VALUES(),();
+
+INSERT INTO t1 VALUES(
+  10, 10, 10.0, 10.0, 10.0,
+  "nnnnn", "nnnnn", "nnnnn", "nnnnn", "nnnnn", "nnnnn", 
+  "2008-11-16 08:13:32");
+INSERT INTO t1(i, ch) VALUES(11, "mmm");
+--replace_column 12 CURRENT_TIMESTAMP
+SELECT i, j, f, d, d2, ch, vch, HEX(b), HEX(vb), HEX(blob1), text1, timestamp_c FROM t1 ORDER BY i;
+
+UPDATE t1 SET ch = "xxx" WHERE i = 10;
+--replace_column 12 CURRENT_TIMESTAMP
+SELECT i, j, f, d, d2, ch, vch, HEX(b), HEX(vb), HEX(blob1), text1, timestamp_c FROM t1 ORDER BY i;
+
+UPDATE t1 SET blob1 = "yyy" WHERE j = 10;
+--replace_column 12 CURRENT_TIMESTAMP
+SELECT i, j, f, d, d2, ch, vch, HEX(b), HEX(vb), HEX(blob1), text1, timestamp_c FROM t1 ORDER BY i;
+
+REPLACE INTO t1(i, j, ch) VALUES(1, 1, "zzz");
+REPLACE INTO t1(i, j, ch) VALUES(20, 20, "www");
+--enable_warnings
+--replace_column 12 CURRENT_TIMESTAMP
+SELECT i, j, f, d, d2, ch, vch, HEX(b), HEX(vb), HEX(blob1), text1, timestamp_c FROM t1 ORDER BY i;
+DELETE FROM t1 WHERE i > 9;
+--replace_column 12 CURRENT_TIMESTAMP
+SELECT i, j, f, d, d2, ch, vch, HEX(b), HEX(vb), HEX(blob1), text1, timestamp_c FROM t1 ORDER BY i;
+
+#Test BIT TYPE
+CREATE TABLE bit1(
+  pk INT AUTO_INCREMENT NOT NULL PRIMARY KEY,
+  b1 BIT(3) DEFAULT B'111',
+  b2 BIT(9) DEFAULT B'101',
+  b3 BIT(23) DEFAULT B'110',
+  b4 BIT(37) DEFAULT B'011',
+  b5 BIT(63) DEFAULT B'101011'
+)ENGINE = NDB;
+
+INSERT INTO bit1 VALUES();
+INSERT INTO bit1(b1,b4) VALUES(B'101',B'111');
+SELECT pk,BIN(b1),BIN(b2),BIN(b3),BIN(b4),BIN(b5) FROM bit1 ORDER BY pk;
+
+UPDATE bit1 SET b5=B'11111' WHERE pk = 1;
+REPLACE INTO bit1(pk, b3) VALUES(2, B'1');
+REPLACE INTO bit1(pk, b3) VALUES(6, B'101');
+SELECT pk,BIN(b1),BIN(b2),BIN(b3),BIN(b4),BIN(b5) FROM bit1 ORDER BY pk;
+
+DELETE FROM bit1 WHERE pk = 2;
+SELECT pk,BIN(b1),BIN(b2),BIN(b3),BIN(b4),BIN(b5) FROM bit1 ORDER BY pk; 
+
+#############################################################
+# ALTER TABLE WITH DEFAULT VALUES TEST
+#############################################################
+--echo ********************************************************
+--echo * Alter table to add column with default value
+--echo ********************************************************
+ALTER TABLE t1 ADD COLUMN ch2 CHAR(30) DEFAULT "alter table";
+--replace_column 12 CURRENT_TIMESTAMP
+SELECT i, j, f, d, d2, ch, vch, HEX(b), HEX(vb), HEX(blob1), text1, timestamp_c, ch2 FROM t1 ORDER BY i;
+--disable_warnings
+INSERT INTO t1 VALUES();
+--enable_warnings
+--replace_column 12 CURRENT_TIMESTAMP
+SELECT i, j, f, d, d2, ch, vch, HEX(b), HEX(vb), HEX(blob1), text1, timestamp_c, ch2 FROM t1 ORDER BY i;
+
+--echo ********************************************************
+--echo * Alter table with default value can fail safely
+--echo ********************************************************
+--disable_warnings
+--error 1060
+ALTER TABLE t1 ADD COLUMN ch2 CHAR(30) DEFAULT "alter table";
+--error 1067
+ALTER TABLE t1 ADD COLUMN ch3 CHAR(3) DEFAULT "alter table";
+INSERT INTO t1 VALUES();
+--enable_warnings
+--replace_column 12 CURRENT_TIMESTAMP
+SELECT i, j, f, d, d2, ch, vch, HEX(b), HEX(vb), HEX(blob1), text1, timestamp_c, ch2 FROM t1 ORDER BY i;
+
+##############################################################
+# BACKUP AND RESTORE TEST FOR TABLE WITH DEFAULT VALUES
+##############################################################
+#the above two tables are backuped, they can restore correctly.
+#The default values can be inserted correctly after restored.
+--echo ********************************************************
+--echo * The tables with default values BACKUP and RESTORE test
+--echo ********************************************************
+--source include/ndb_backup.inc
+DROP TABLE IF EXISTS t1, bit1;
+
+--echo ********************************************************
+--echo * Begin to restore data from backup 
+--echo ********************************************************
+--exec $NDB_RESTORE --no-defaults -b $the_backup_id -n 1 -A -m  -r --print --print_meta $NDB_BACKUPS-$the_backup_id >> $NDB_TOOLS_OUTPUT
+--exec $NDB_RESTORE --no-defaults -b $the_backup_id -n 2 -A -r --print --print_meta $NDB_BACKUPS-$the_backup_id >> $NDB_TOOLS_OUTPUT
+
+--sorted_result
+SHOW TABLES;
+--let ndb_desc_opts= -d mysqltest t1
+--source include/ndb_desc_print.inc
+--let ndb_desc_opts= -d mysqltest bit1
+--source include/ndb_desc_print.inc
+SELECT pk,BIN(b1),BIN(b2),BIN(b3),BIN(b4),BIN(b5) FROM bit1 ORDER BY pk;
+--replace_column 12 CURRENT_TIMESTAMP
+SELECT i, j, f, d, d2, ch, vch, HEX(b), HEX(vb), HEX(blob1), text1, timestamp_c, ch2 FROM t1 ORDER BY i;
+
+--disable_warnings
+INSERT INTO t1(i, ch) VALUES(99, "restore");
+--enable_warnings
+INSERT INTO bit1(pk, b5) VALUES(99, B'11111111');
+SELECT pk,BIN(b1),BIN(b2),BIN(b3),BIN(b4),BIN(b5) FROM bit1 ORDER BY pk;
+--replace_column 12 CURRENT_TIMESTAMP
+SELECT i, j, f, d, d2, ch, vch, HEX(b), HEX(vb), HEX(blob1), text1, timestamp_c, ch2 FROM t1 ORDER BY i;
+DROP TABLE IF EXISTS t1, bit1;
+
+
+--exec $NDB_RESTORE --no-defaults -b $the_backup_id -n 1 -A -m  -r --print_meta $NDB_BACKUPS-$the_backup_id >> $NDB_TOOLS_OUTPUT
+--exec $NDB_RESTORE --no-defaults -b $the_backup_id -n 2 -A -r --print_meta $NDB_BACKUPS-$the_backup_id >> $NDB_TOOLS_OUTPUT
+--sorted_result
+SHOW TABLES;
+--replace_column 1 MAX_VALUE 12 CURRENT_TIMESTAMP
+SELECT i, j, f, d, d2, ch, vch, HEX(b), HEX(vb), HEX(blob1), text1, timestamp_c, ch2 FROM t1 WHERE i >= (SELECT MAX(i) FROM t1) ORDER BY i;
+
+DROP TABLE IF EXISTS t1, bit1;
+DROP DATABASE mysqltest;
+
+###############################################################################
+# RESTORE THE BACKUP FROM 6.3 OR 6.4, WHICH DON'T SUPPORT NATIVE DEFAULT VALUE
+# SO DEFAULT VALUES AREN'T STORED IN NDBD KERNEL
+###############################################################################
+--echo ******************************************************************************
+--echo * Restore the backup from 6.3 or 6.4, which don't support native default value
+--echo ******************************************************************************
+
+--exec $NDB_RESTORE --no-defaults -b 1 -n 1 -m -r $MYSQL_TEST_DIR/std_data/ndb_backup_before_native_default >> $NDB_TOOLS_OUTPUT
+--exec $NDB_RESTORE --no-defaults -b 1 -n 2 -r $MYSQL_TEST_DIR/std_data/ndb_backup_before_native_default >> $NDB_TOOLS_OUTPUT
+
+USE test;
+--sorted_result
+SHOW TABLES;
+SHOW CREATE TABLE t1;
+SHOW CREATE TABLE bit1;
+--replace_column 12 CURRENT_TIMESTAMP
+SELECT i, j, f, d, d2, ch, vch, HEX(b), HEX(vb), HEX(blob1), text1, timestamp_c FROM t1 ORDER BY i;
+SELECT pk,BIN(b1),BIN(b2),BIN(b3),BIN(b4),BIN(b5) FROM bit1 ORDER BY pk;
+--disable_warnings
+INSERT INTO t1 VALUES();
+UPDATE t1 SET ch = "RESTORE FROM 6.3" WHERE i = 12;
+REPLACE INTO t1(i, j, ch) VALUES(20, 20, "RESTORE FROM 6.3");
+--enable_warnings
+--replace_column 12 CURRENT_TIMESTAMP
+SELECT i, j, f, d, d2, ch, vch, HEX(b), HEX(vb), HEX(blob1), text1, timestamp_c FROM t1 ORDER BY i;
+
+INSERT INTO bit1 VALUES();
+UPDATE bit1 SET b5=b'1111111' WHERE pk = 1;
+REPLACE INTO bit1(pk, b3) VALUES(6, B'110011');
+SELECT pk,BIN(b1),BIN(b2),BIN(b3),BIN(b4),BIN(b5) FROM bit1 ORDER BY pk;
+
+#########################################################################
+# OFFLINE ALTER OF 'OLD' TABLE WITH NO DEFAULTS TO 'NEW' TABLE 
+# WITH NATIVE DEFAULTS.
+#########################################################################
+--echo ********************************************************************************
+--echo * Alter table restoring from 6.3 backup to new table with native default support
+--echo ********************************************************************************
+--let ndb_desc_opts= -d test t1
+--source include/ndb_desc_print.inc
+
+ALTER TABLE t1 CHANGE COLUMN j j INT DEFAULT 6;
+
+--let ndb_desc_opts= -d test t1
+--source include/ndb_desc_print.inc
+
+--disable_warnings
+INSERT INTO t1(i, ch) VALUES(99, "native default support");
+--enable_warnings
+--replace_column 12 CURRENT_TIMESTAMP
+SELECT i, j, f, d, d2, ch, vch, HEX(b), HEX(vb), HEX(blob1), text1, timestamp_c FROM t1 ORDER BY i;
+
+DROP TABLE IF EXISTS t1, bit1;
+--echo *************************************************************
+--echo * Test adding a unique index to a column with a default value
+--echo *************************************************************
+CREATE TABLE t2(
+  i INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
+  j INT DEFAULT 6,
+  f FLOAT NOT NULL DEFAULT 6.6,
+  d DOUBLE DEFAULT 8.8,
+  UNIQUE INDEX t2_unique_index(j) 
+)ENGINE =NDB;
+INSERT INTO t2 VALUES();
+--error 1062
+INSERT INTO t2 VALUES();
+INSERT INTO t2 VALUES(10, 10, 10.0, 10.0);
+SELECT * FROM t2 ORDER BY i;
+
+--echo *************************************************************
+--echo * Test offline alter of default values
+--echo *************************************************************
+ALTER TABLE t2 MODIFY COLUMN j INT DEFAULT 666;
+
+--let ndb_desc_opts= -d test t2
+--source include/ndb_desc_print.inc
+INSERT INTO t2 VALUES();
+SELECT * FROM t2 ORDER BY i;
+
+--echo *************************************************************
+--echo * Test that online alter of default values fails
+--echo *************************************************************
+--error 1235
+ALTER ONLINE TABLE t2 MODIFY COLUMN j INT DEFAULT 888;
+
+DROP TABLE IF EXISTS t2;
+
+--echo **************************************************************
+--echo * Test not null-after-defaults example that failed previously
+--echo **************************************************************
+
+CREATE TABLE t1 (a int primary key, b int default 12, c char not null) engine=ndb;
+--let ndb_desc_opts= -d test t1
+--source include/ndb_desc_print.inc
+
+DROP TABLE t1;
+
+--echo **************************************************************
+--echo * Test mix of null, not-null, default etc..
+--echo **************************************************************
+
+CREATE TABLE t1 (a int primary key, 
+                 b int default 12, 
+                 c char not null, 
+                 d varchar(6) default 'Daniel',
+                 e char(3) default 'Stu',
+                 f enum('NBFry','Kebab') default 'NBFry',
+                 g set('Chips','Pie','Fish') default 'Fish,Chips',
+                 h enum('Pig','Lion') not null,
+                 i char(2) default '66') engine=ndb;
+--let ndb_desc_opts= -d test t1
+--source include/ndb_desc_print.inc
+
+DROP TABLE t1;
+
+--echo ******************************************
+--echo * Test binary default with null char value
+--echo ******************************************
+
+CREATE TABLE t1 (a int primary key,
+                 b binary(10) default 0x4142430045464748494a,
+                 c varbinary(100) default 0x4142430045464748494a) engine=ndb;
+
+SHOW CREATE TABLE t1;
+
+--let ndb_desc_opts= -d test t1
+--source include/ndb_desc_print.inc
+
+DROP TABLE t1;
+
+
+
+--echo End of ndb native default support test

=== modified file 'mysql-test/suite/ndb/t/ndb_restore_promotion.test'
--- a/mysql-test/suite/ndb/t/ndb_restore_promotion.test	2009-08-18 13:21:50 +0000
+++ b/mysql-test/suite/ndb/t/ndb_restore_promotion.test	2010-04-29 14:52:05 +0000
@@ -256,3 +256,46 @@ create table t1(c char(1),
 
 select a,c,d,e from t1 order by a;
 drop table t1;
+ 
+# Testcase for restore with native default added to table (WL4197)
+create table subject(pk int primary key, band varchar(50), pos int) engine=ndb;
+
+insert into subject values (1, 'Elbow', 1), (2, 'Franz Ferdinand', 2), (3, 'Proclaimers', 3);
+insert into subject values (4, 'David Bowie', 4), (5, 'Rufus Wainwright', 1);
+
+select * from subject order by pk;
+
+--echo **************************
+--echo Performing backup of table
+--echo **************************
+
+--source include/ndb_backup.inc
+
+--echo ******************
+--echo Throwing away data
+--echo ******************
+delete from subject;
+
+select * from subject order by pk;
+
+--echo *******************************************************
+--echo Modifying table to include new, native defaulted column
+--echo *******************************************************
+alter table subject add column song varchar(50) default 'Unknown';
+
+--echo ***********************************************************
+--echo Restoring data back into table and picking up default value
+--echo ***********************************************************
+
+# Note testcase nastily assumes 2 nodes, called 1 + 2.
+--exec $NDB_RESTORE --no-defaults -b $the_backup_id -n 1 -r --print --print_meta --skip-table-check $NDB_BACKUPS-$the_backup_id >> $NDB_TOOLS_OUTPUT
+--exec $NDB_RESTORE --no-defaults -b $the_backup_id -n 2 -r --print --print_meta --skip-table-check $NDB_BACKUPS-$the_backup_id >> $NDB_TOOLS_OUTPUT
+
+--echo ****************************************************
+--echo All restored entries should have song name 'Unknown'
+--echo ****************************************************
+
+select * from subject order by pk;
+
+drop table subject;
+# End of testcase for WL4197
\ No newline at end of file

=== modified file 'mysql-test/suite/rpl/r/rpl_change_master.result'
--- a/mysql-test/suite/rpl/r/rpl_change_master.result	2009-12-16 14:19:40 +0000
+++ b/mysql-test/suite/rpl/r/rpl_change_master.result	2010-04-13 16:01:38 +0000
@@ -278,7 +278,7 @@ Master_SSL_Cipher	
 Master_SSL_Key	
 Seconds_Behind_Master	NULL
 Master_SSL_Verify_Server_Cert	No
-Last_IO_Errno	2004
+Last_IO_Errno	2003
 Last_IO_Error	error connecting to master 'root@stripped:MASTER_PORT' - retry-time: 1  retries: 10
 Last_SQL_Errno	0
 Last_SQL_Error	

=== modified file 'mysql-test/suite/rpl_ndb/r/rpl_ndb_2ndb.result'
--- a/mysql-test/suite/rpl_ndb/r/rpl_ndb_2ndb.result	2008-02-11 14:06:07 +0000
+++ b/mysql-test/suite/rpl_ndb/r/rpl_ndb_2ndb.result	2010-04-29 14:52:05 +0000
@@ -266,14 +266,14 @@ select *
 from t1 
 order by id;
 id	b1	vc	bc	d	f	total	y	t	u	v
-2	1	Testing MySQL databases is a cool 	Must make it bug free for the customer	654321.4321	15.21	0	1965	1965-11-14	NULL	NULL
+2	1	Testing MySQL databases is a cool 	Must make it bug free for the customer	654321.4321	15.21	0	1965	1965-11-14	NULL	default
 3	1	Testing MySQL databases is a cool 	Must make it bug free for the customer	654321.4321	15.21	0	1965	1905-11-14	7	default
-4	1	Testing MySQL databases is a cool 	Must make it bug free for the customer	654321.4321	15.21	0	1965	1985-11-14	NULL	NULL
+4	1	Testing MySQL databases is a cool 	Must make it bug free for the customer	654321.4321	15.21	0	1965	1985-11-14	NULL	default
 20	1	Testing MySQL databases is a cool 	Must make it bug free for the customer	654321.4321	15.21	0	1965	1965-11-14	7	explicit
-42	1	Testing MySQL databases is a cool 	Must make it bug free for the customer	654321.4321	15.21	0	1965	1905-11-14	NULL	NULL
+42	1	Testing MySQL databases is a cool 	Must make it bug free for the customer	654321.4321	15.21	0	1965	1905-11-14	NULL	default
 50	1	Testing MySQL databases is a cool 	Must make it bug free for the customer	654321.4321	15.21	0	1965	1985-11-14	NULL	explicit
-142	1	Testing MySQL databases is a cool 	Must make it bug free for the customer	654321.4321	15.21	0	1965	1995-11-14	NULL	NULL
-412	1	Testing MySQL databases is a cool 	Must make it bug free for the customer	654321.4321	15.21	0	1965	2005-11-14	NULL	NULL
+142	1	Testing MySQL databases is a cool 	Must make it bug free for the customer	654321.4321	15.21	0	1965	1995-11-14	NULL	default
+412	1	Testing MySQL databases is a cool 	Must make it bug free for the customer	654321.4321	15.21	0	1965	2005-11-14	NULL	default
 --- Perform basic operation on master ---
 --- and ensure replicated correctly ---
 --- Update t1 on master --
@@ -298,11 +298,11 @@ FROM t1 
 WHERE id < 100
 ORDER BY id;
 id	b1	vc	bc	d	f	total	y	t	u	v
-2	0	Testing MySQL databases is a cool 	updated	654321.4321	15.21	0	1965	2006-02-22	NULL	NULL
+2	0	Testing MySQL databases is a cool 	updated	654321.4321	15.21	0	1965	2006-02-22	NULL	default
 3	0	Testing MySQL databases is a cool 	updated	654321.4321	15.21	0	1965	2006-02-22	7	default
-4	0	Testing MySQL databases is a cool 	updated	654321.4321	15.21	0	1965	2006-02-22	NULL	NULL
+4	0	Testing MySQL databases is a cool 	updated	654321.4321	15.21	0	1965	2006-02-22	NULL	default
 20	0	Testing MySQL databases is a cool 	updated	654321.4321	15.21	0	1965	2006-02-22	7	explicit
-42	0	Testing MySQL databases is a cool 	updated	654321.4321	15.21	0	1965	2006-02-22	NULL	NULL
+42	0	Testing MySQL databases is a cool 	updated	654321.4321	15.21	0	1965	2006-02-22	NULL	default
 50	0	Testing MySQL databases is a cool 	updated	654321.4321	15.21	0	1965	2006-02-22	NULL	explicit
 --- Remove a record from t1 on master ---
 DELETE FROM t1 WHERE id = 412;

=== modified file 'mysql-test/suite/rpl_ndb/r/rpl_ndb_extraCol.result'
--- a/mysql-test/suite/rpl_ndb/r/rpl_ndb_extraCol.result	2010-03-16 07:53:04 +0000
+++ b/mysql-test/suite/rpl_ndb/r/rpl_ndb_extraCol.result	2010-04-29 14:52:05 +0000
@@ -31,9 +31,9 @@ a	b	c
 *** Select from slave ***
 SELECT * FROM t1 ORDER BY a;
 a	b	c	d	e
-1	2	TEXAS	NULL	NULL
-2	1	AUSTIN	NULL	NULL
-3	4	QA	NULL	NULL
+1	2	TEXAS	2	TEST
+2	1	AUSTIN	2	TEST
+3	4	QA	2	TEST
 SET GLOBAL SLAVE_TYPE_CONVERSIONS = @saved_slave_type_conversions;
 *** Drop t1  ***
 DROP TABLE t1;
@@ -395,9 +395,9 @@ a	b	c
 *** Select from slave ***
 SELECT * FROM t7 ORDER BY a;
 a	b	c	d	e
-1	b1b1	Kyle	NULL	NULL
-2	b1b1	JOE	NULL	NULL
-3	b1b1	QA	NULL	NULL
+1	b1b1	Kyle	0000-00-00 00:00:00	Extra Column Testing
+2	b1b1	JOE	0000-00-00 00:00:00	Extra Column Testing
+3	b1b1	QA	0000-00-00 00:00:00	Extra Column Testing
 *** Drop t7  ***
 DROP TABLE t7;
 *** Create t8 on slave  ***
@@ -592,9 +592,9 @@ a	b	c
 *** Select on Slave ***
 SELECT * FROM t12 ORDER BY a;
 a	b	f	c	e
-1	b1b1b1b1b1b1b1b1	Kyle	NULL	NULL
-2	b1b1b1b1b1b1b1b1	JOE	NULL	NULL
-3	b1b1b1b1b1b1b1b1	QA	NULL	NULL
+1	b1b1b1b1b1b1b1b1	Kyle	test	1
+2	b1b1b1b1b1b1b1b1	JOE	test	1
+3	b1b1b1b1b1b1b1b1	QA	test	1
 *** Drop t12  ***
 DROP TABLE t12;
 **** Extra Colums End ****
@@ -624,9 +624,9 @@ a	b	c
 *** Select on Slave ****
 SELECT * FROM t13 ORDER BY a;
 a	b	c	d	e
-1	b1b1b1b1b1b1b1b1	Kyle	NULL	CURRENT_TIMESTAMP
-2	b1b1b1b1b1b1b1b1	JOE	NULL	CURRENT_TIMESTAMP
-3	b1b1b1b1b1b1b1b1	QA	NULL	CURRENT_TIMESTAMP
+1	b1b1b1b1b1b1b1b1	Kyle	1	CURRENT_TIMESTAMP
+2	b1b1b1b1b1b1b1b1	JOE	1	CURRENT_TIMESTAMP
+3	b1b1b1b1b1b1b1b1	QA	1	CURRENT_TIMESTAMP
 *** Drop t13  ***
 DROP TABLE t13;
 *** 22117 END *** 
@@ -660,9 +660,9 @@ c1	c2	c3	c4	c5
 *** Select on Slave ****
 SELECT * FROM t14 ORDER BY c1;
 c1	c2	c3	c4	c5	c6	c7
-1	1.00	Replication Testing Extra Col	b1b1b1b1b1b1b1b1	Kyle	NULL	CURRENT_TIMESTAMP
-2	2.00	This Test Should work	b1b1b1b1b1b1b1b1	JOE	NULL	CURRENT_TIMESTAMP
-3	3.00	If is does not, I will open a bug	b1b1b1b1b1b1b1b1	QA	NULL	CURRENT_TIMESTAMP
+1	1.00	Replication Testing Extra Col	b1b1b1b1b1b1b1b1	Kyle	1	CURRENT_TIMESTAMP
+2	2.00	This Test Should work	b1b1b1b1b1b1b1b1	JOE	1	CURRENT_TIMESTAMP
+3	3.00	If is does not, I will open a bug	b1b1b1b1b1b1b1b1	QA	1	CURRENT_TIMESTAMP
 *** Create t14a on slave  ***
 STOP SLAVE;
 RESET SLAVE;
@@ -690,9 +690,9 @@ c1	c4	c5
 *** Select on Slave ****
 SELECT * FROM t14a ORDER BY c1;
 c1	c4	c5	c6	c7
-1	b1b1b1b1b1b1b1b1	Kyle	NULL	CURRENT_TIMESTAMP
-2	b1b1b1b1b1b1b1b1	JOE	NULL	CURRENT_TIMESTAMP
-3	b1b1b1b1b1b1b1b1	QA	NULL	CURRENT_TIMESTAMP
+1	b1b1b1b1b1b1b1b1	Kyle	1	CURRENT_TIMESTAMP
+2	b1b1b1b1b1b1b1b1	JOE	1	CURRENT_TIMESTAMP
+3	b1b1b1b1b1b1b1b1	QA	1	CURRENT_TIMESTAMP
 STOP SLAVE;
 RESET SLAVE;
 *** Master Drop c5 ***
@@ -717,12 +717,12 @@ c1	c4
 *** Select on Slave ****
 SELECT * FROM t14a ORDER BY c1;
 c1	c4	c5	c6	c7
-1	b1b1b1b1b1b1b1b1	Kyle	NULL	CURRENT_TIMESTAMP
-2	b1b1b1b1b1b1b1b1	JOE	NULL	CURRENT_TIMESTAMP
-3	b1b1b1b1b1b1b1b1	QA	NULL	CURRENT_TIMESTAMP
-4	b1b1b1b1b1b1b1b1	NULL	NULL	CURRENT_TIMESTAMP
-5	b1b1b1b1b1b1b1b1	NULL	NULL	CURRENT_TIMESTAMP
-6	b1b1b1b1b1b1b1b1	NULL	NULL	CURRENT_TIMESTAMP
+1	b1b1b1b1b1b1b1b1	Kyle	1	CURRENT_TIMESTAMP
+2	b1b1b1b1b1b1b1b1	JOE	1	CURRENT_TIMESTAMP
+3	b1b1b1b1b1b1b1b1	QA	1	CURRENT_TIMESTAMP
+4	b1b1b1b1b1b1b1b1	NULL	1	CURRENT_TIMESTAMP
+5	b1b1b1b1b1b1b1b1	NULL	1	CURRENT_TIMESTAMP
+6	b1b1b1b1b1b1b1b1	NULL	1	CURRENT_TIMESTAMP
 *** connect to master and drop columns ***
 ALTER TABLE t14 DROP COLUMN c2;
 ALTER TABLE t14 DROP COLUMN c4;
@@ -735,9 +735,9 @@ c1	c3	c5
 *** Select from Slave ***
 SELECT * FROM t14 ORDER BY c1;
 c1	c3	c5	c6	c7
-1	Replication Testing Extra Col	Kyle	NULL	CURRENT_TIMESTAMP
-2	This Test Should work	JOE	NULL	CURRENT_TIMESTAMP
-3	If is does not, I will open a bug	QA	NULL	CURRENT_TIMESTAMP
+1	Replication Testing Extra Col	Kyle	1	CURRENT_TIMESTAMP
+2	This Test Should work	JOE	1	CURRENT_TIMESTAMP
+3	If is does not, I will open a bug	QA	1	CURRENT_TIMESTAMP
 *** Drop t14  ***
 DROP TABLE t14;
 *** Create t15 on slave  ***
@@ -768,9 +768,9 @@ c1	c2	c3	c4	c5
 *** Select on Slave ****
 SELECT * FROM t15 ORDER BY c1;
 c1	c2	c3	c4	c5	c6	c7
-1	1.00	Replication Testing Extra Col	b1b1b1b1b1b1b1b1	Kyle	NULL	CURRENT_TIMESTAMP
-2	2.00	This Test Should work	b1b1b1b1b1b1b1b1	JOE	NULL	CURRENT_TIMESTAMP
-3	3.00	If is does not, I will open a bug	b1b1b1b1b1b1b1b1	QA	NULL	CURRENT_TIMESTAMP
+1	1.00	Replication Testing Extra Col	b1b1b1b1b1b1b1b1	Kyle	1	CURRENT_TIMESTAMP
+2	2.00	This Test Should work	b1b1b1b1b1b1b1b1	JOE	1	CURRENT_TIMESTAMP
+3	3.00	If is does not, I will open a bug	b1b1b1b1b1b1b1b1	QA	1	CURRENT_TIMESTAMP
 *** Add column on master that is a Extra on Slave ***
 ALTER TABLE t15 ADD COLUMN c6 INT AFTER c5;
 ********************************************
@@ -831,9 +831,9 @@ c1	c2	c3	c4	c5	c6
 *** Try to select from slave ****
 SELECT * FROM t15 ORDER BY c1;
 c1	c2	c3	c4	c5	c6	c7
-1	1.00	Replication Testing Extra Col	b1b1b1b1b1b1b1b1	Kyle	NULL	CURRENT_TIMESTAMP
-2	2.00	This Test Should work	b1b1b1b1b1b1b1b1	JOE	NULL	CURRENT_TIMESTAMP
-3	3.00	If is does not, I will open a bug	b1b1b1b1b1b1b1b1	QA	NULL	CURRENT_TIMESTAMP
+1	1.00	Replication Testing Extra Col	b1b1b1b1b1b1b1b1	Kyle	1	CURRENT_TIMESTAMP
+2	2.00	This Test Should work	b1b1b1b1b1b1b1b1	JOE	1	CURRENT_TIMESTAMP
+3	3.00	If is does not, I will open a bug	b1b1b1b1b1b1b1b1	QA	1	CURRENT_TIMESTAMP
 5	2.00	Replication Testing	b1b1b1b1b1b1b1b1	Buda	2	CURRENT_TIMESTAMP
 *** DROP TABLE t15 ***
 DROP TABLE t15;
@@ -865,9 +865,9 @@ c1	c2	c3	c4	c5
 *** Select on Slave ****
 SELECT * FROM t16 ORDER BY c1;
 c1	c2	c3	c4	c5	c6	c7
-1	1.00	Replication Testing Extra Col	b1b1b1b1b1b1b1b1	Kyle	NULL	CURRENT_TIMESTAMP
-2	2.00	This Test Should work	b1b1b1b1b1b1b1b1	JOE	NULL	CURRENT_TIMESTAMP
-3	3.00	If is does not, I will open a bug	b1b1b1b1b1b1b1b1	QA	NULL	CURRENT_TIMESTAMP
+1	1.00	Replication Testing Extra Col	b1b1b1b1b1b1b1b1	Kyle	1	CURRENT_TIMESTAMP
+2	2.00	This Test Should work	b1b1b1b1b1b1b1b1	JOE	1	CURRENT_TIMESTAMP
+3	3.00	If is does not, I will open a bug	b1b1b1b1b1b1b1b1	QA	1	CURRENT_TIMESTAMP
 *** Add Partition on master ***
 ALTER TABLE t16 PARTITION BY KEY(c1) PARTITIONS 4;
 INSERT INTO t16 () VALUES(4,1.00,'Replication Rocks',@b1,'Omer');

=== modified file 'mysys/CMakeLists.txt'
--- a/mysys/CMakeLists.txt	2010-04-01 15:22:57 +0000
+++ b/mysys/CMakeLists.txt	2010-04-13 16:01:38 +0000
@@ -42,8 +42,7 @@ SET(MYSYS_SOURCES  array.c charset-def.c
 				my_static.c my_symlink.c my_symlink2.c my_sync.c my_thr_init.c my_wincond.c
 				my_windac.c my_winthread.c my_write.c ptr_cmp.c queues.c stacktrace.c
 				rijndael.c safemalloc.c sha1.c string.c thr_alarm.c thr_lock.c thr_mutex.c
-				thr_rwlock.c tree.c typelib.c my_vle.c base64.c my_memmem.c my_getpagesize.c
-                                my_socket.c)
+				thr_rwlock.c tree.c typelib.c my_vle.c base64.c my_memmem.c my_getpagesize.c)
 
 IF(NOT SOURCE_SUBLIBS)
   ADD_LIBRARY(mysys ${MYSYS_SOURCES})

=== modified file 'mysys/Makefile.am'
--- a/mysys/Makefile.am	2010-04-01 15:22:57 +0000
+++ b/mysys/Makefile.am	2010-04-13 16:01:38 +0000
@@ -72,8 +72,7 @@ libmysyslt_la_SOURCES =	my_init.c my_get
 			thr_alarm.c thr_lock.c my_pthread.c my_thr_init.c \
 			thr_mutex.c thr_rwlock.c \
 			mf_soundex.c \
-			my_conio.c my_wincond.c my_winthread.c \
-			my_socket.c
+			my_conio.c my_wincond.c my_winthread.c
 
 if NEED_THREAD
 # mf_keycache is used only in the server, so it is safe to leave the file

=== modified file 'server-tools/instance-manager/listener.cc'
--- a/server-tools/instance-manager/listener.cc	2010-03-12 11:56:09 +0000
+++ b/server-tools/instance-manager/listener.cc	2010-04-13 16:01:38 +0000
@@ -1,6 +1,4 @@
-/*
-   Copyright (C) 2003-2006 MySQL AB
-    All rights reserved. Use is subject to license terms.
+/* Copyright (C) 2003-2006 MySQL AB
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -13,8 +11,7 @@
 
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
-*/
+   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
 #if defined(__GNUC__) && defined(USE_PRAGMA_IMPLEMENTATION)
 #pragma implementation
@@ -38,11 +35,24 @@
 #include "priv.h"
 #include "thread_registry.h"
 
-static void set_no_inherit(my_socket socket)
+
+static void set_non_blocking(int socket)
+{
+#ifndef __WIN__
+  int flags= fcntl(socket, F_GETFL, 0);
+  fcntl(socket, F_SETFL, flags | O_NONBLOCK);
+#else
+  u_long arg= 1;
+  ioctlsocket(socket, FIONBIO, &arg);
+#endif
+}
+
+
+static void set_no_inherit(int socket)
 {
 #ifndef __WIN__
-  int flags= fcntl(socket.fd, F_GETFD, 0);
-  fcntl(socket.fd, F_SETFD, flags | FD_CLOEXEC);
+  int flags= fcntl(socket, F_GETFD, 0);
+  fcntl(socket, F_SETFD, flags | FD_CLOEXEC);
 #endif
 }
 
@@ -93,7 +103,7 @@ void Listener::run()
 
   /* II. Listen sockets and spawn childs */
   for (i= 0; i < num_sockets; i++)
-    n= my_socket_nfds(sockets[i], n);
+    n= max(n, sockets[i]);
   n++;
 
   timeval tv;
@@ -126,11 +136,11 @@ void Listener::run()
     for (int socket_index= 0; socket_index < num_sockets; socket_index++)
     {
       /* Assuming that rc > 0 as we asked to wait forever */
-      if (my_FD_ISSET(sockets[socket_index], &read_fds_arg))
+      if (FD_ISSET(sockets[socket_index], &read_fds_arg))
       {
-        my_socket client_fd= my_accept(sockets[socket_index], 0, 0);
+        int client_fd= accept(sockets[socket_index], 0, 0);
         /* accept may return -1 (failure or spurious wakeup) */
-        if (my_socket_valid(client_fd)) // connection established
+        if (client_fd >= 0)                    // connection established
         {
           set_no_inherit(client_fd);
 
@@ -143,8 +153,8 @@ void Listener::run()
             handle_new_mysql_connection(vio);
           else
           {
-            my_shutdown(client_fd, SHUT_RDWR);
-            my_socket_close(client_fd);
+            shutdown(client_fd, SHUT_RDWR);
+            closesocket(client_fd);
           }
         }
       }
@@ -156,7 +166,7 @@ void Listener::run()
   log_info("Listener: shutdown requested, exiting...");
 
   for (i= 0; i < num_sockets; i++)
-    my_socket_close(sockets[i]);
+    closesocket(sockets[i]);
 
 #ifndef __WIN__
   unlink(unix_socket_address.sun_path);
@@ -172,7 +182,7 @@ err:
 
   // we have to close the ip sockets in case of error
   for (i= 0; i < num_sockets; i++)
-    my_socket_close(sockets[i]);
+    closesocket(sockets[i]);
 
   thread_registry->set_error_status();
   thread_registry->unregister_thread(&thread_info);
@@ -182,8 +192,11 @@ err:
 
 int Listener::create_tcp_socket()
 {
-  my_socket ip_socket= my_socket_create(AF_INET, SOCK_STREAM, 0);
-  if (!my_socket_valid(ip_socket))
+  /* value to be set by setsockopt */
+  int arg= 1;
+
+  int ip_socket= socket(AF_INET, SOCK_STREAM, 0);
+  if (ip_socket == INVALID_SOCKET)
   {
     log_error("Listener: socket(AF_INET) failed: %s.",
               (const char *) strerror(errno));
@@ -212,29 +225,31 @@ int Listener::create_tcp_socket()
   ip_socket_address.sin_port= (unsigned short)
     htons((unsigned short) im_port);
 
-  my_socket_reuseaddr(ip_socket, true);
-  if (my_bind_inet(ip_socket, &ip_socket_address))
+  setsockopt(ip_socket, SOL_SOCKET, SO_REUSEADDR, (char*) &arg, sizeof(arg));
+  if (bind(ip_socket, (struct sockaddr *) &ip_socket_address,
+           sizeof(ip_socket_address)))
   {
     log_error("Listener: bind(ip socket) failed: %s.",
               (const char *) strerror(errno));
-    my_socket_close(ip_socket);
+    closesocket(ip_socket);
     return -1;
   }
 
-  if (my_listen(ip_socket, LISTEN_BACK_LOG_SIZE))
+  if (listen(ip_socket, LISTEN_BACK_LOG_SIZE))
   {
     log_error("Listener: listen(ip socket) failed: %s.",
               (const char *) strerror(errno));
-    my_socket_close(ip_socket);
+    closesocket(ip_socket);
     return -1;
   }
 
-  my_socket_nonblock(ip_socket, true);
+  /* set the socket nonblocking */
+  set_non_blocking(ip_socket);
 
   /* make sure that instances won't be listening our sockets */
   set_no_inherit(ip_socket);
 
-  my_FD_SET(ip_socket, &read_fds);
+  FD_SET(ip_socket, &read_fds);
   sockets[num_sockets++]= ip_socket;
   log_info("Listener: accepting connections on ip socket (port: %d)...",
            (int) im_port);
@@ -245,8 +260,8 @@ int Listener::create_tcp_socket()
 int Listener::
 create_unix_socket(struct sockaddr_un &unix_socket_address)
 {
-  my_socket unix_socket= my_socket_create(AF_UNIX, SOCK_STREAM, 0);
-  if (!my_socket_valid(unix_socket))
+  int unix_socket= socket(AF_UNIX, SOCK_STREAM, 0);
+  if (unix_socket == INVALID_SOCKET)
   {
     log_error("Listener: socket(AF_UNIX) failed: %s.",
               (const char *) strerror(errno));
@@ -265,27 +280,28 @@ create_unix_socket(struct sockaddr_un &u
     to be 0777. We need everybody to have access to the socket.
   */
   mode_t old_mask= umask(0);
-  if (my_bind(unix_socket, (struct sockaddr *) &unix_socket_address,
+  if (bind(unix_socket, (struct sockaddr *) &unix_socket_address,
            sizeof(unix_socket_address)))
   {
     log_error("Listener: bind(unix socket) failed for '%s': %s.",
               (const char *) unix_socket_address.sun_path,
               (const char *) strerror(errno));
-    my_socket_close(unix_socket);
+    close(unix_socket);
     return -1;
   }
 
   umask(old_mask);
 
-  if (my_listen(unix_socket, LISTEN_BACK_LOG_SIZE))
+  if (listen(unix_socket, LISTEN_BACK_LOG_SIZE))
   {
     log_error("Listener: listen(unix socket) failed: %s.",
               (const char *) strerror(errno));
-    my_socket_close(unix_socket);
+    close(unix_socket);
     return -1;
   }
 
-  my_socket_nonblock(unix_socket, true);
+  /* set the socket nonblocking */
+  set_non_blocking(unix_socket);
 
   /* make sure that instances won't be listening our sockets */
   set_no_inherit(unix_socket);
@@ -293,7 +309,7 @@ create_unix_socket(struct sockaddr_un &u
   log_info("Listener: accepting connections on unix socket '%s'...",
            (const char *) unix_socket_address.sun_path);
   sockets[num_sockets++]= unix_socket;
-  my_FD_SET(unix_socket, &read_fds);
+  FD_SET(unix_socket, &read_fds);
   return 0;
 }
 #endif

=== modified file 'server-tools/instance-manager/listener.h'
--- a/server-tools/instance-manager/listener.h	2009-05-27 15:21:45 +0000
+++ b/server-tools/instance-manager/listener.h	2010-04-13 16:01:38 +0000
@@ -1,6 +1,4 @@
-/*
-   Copyright (C) 2003-2006 MySQL AB
-    All rights reserved. Use is subject to license terms.
+/* Copyright (C) 2003-2006 MySQL AB
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -13,8 +11,7 @@
 
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
-*/
+   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
 #ifndef INCLUDES_MYSQL_INSTANCE_MANAGER_LISTENER_H
 #define INCLUDES_MYSQL_INSTANCE_MANAGER_LISTENER_H
@@ -51,7 +48,7 @@ private:
 
   ulong total_connection_count;
 
-  my_socket sockets[2];
+  int sockets[2];
   int num_sockets;
   fd_set read_fds;
 

=== modified file 'sql-common/client.c'
--- a/sql-common/client.c	2009-12-18 06:43:04 +0000
+++ b/sql-common/client.c	2010-04-15 11:38:10 +0000
@@ -41,8 +41,6 @@
 
 #include "mysql.h"
 
-#include <my_socket.h>
-
 /* Remove client convenience wrappers */
 #undef max_allowed_packet
 #undef net_buffer_length
@@ -145,18 +143,16 @@ char mysql_server_last_error[MYSQL_ERRMS
 
   Base version coded by Steve Bernacki, Jr. <steve@stripped>
 *****************************************************************************/
-#ifdef __WIN__
-int my_connect(SOCKET fd, const struct sockaddr *name, uint namelen,
+int my_connect(my_socket fd, const struct sockaddr *name, uint namelen,
 	       uint timeout)
-#else
-int my_connect(int fd,    const struct sockaddr *name, uint namelen,
-	       uint timeout)
-#endif
 {
 #if defined(__WIN__) || defined(__NETWARE__)
-  return connect(fd, (struct sockaddr*) name, namelen);
+  DBUG_ENTER("my_connect");
+  DBUG_RETURN(connect(fd, (struct sockaddr*) name, namelen));
 #else
   int flags, res, s_err;
+  DBUG_ENTER("my_connect");
+  DBUG_PRINT("enter", ("fd: %d  timeout: %u", fd, timeout));
 
   /*
     If they passed us a timeout of zero, we should behave
@@ -164,26 +160,26 @@ int my_connect(int fd,    const struct s
   */
 
   if (timeout == 0)
-    return connect(fd, (struct sockaddr*) name, namelen);
+    DBUG_RETURN(connect(fd, (struct sockaddr*) name, namelen));
 
   flags = fcntl(fd, F_GETFL, 0);	  /* Set socket to not block */
 #ifdef O_NONBLOCK
   fcntl(fd, F_SETFL, flags | O_NONBLOCK);  /* and save the flags..  */
 #endif
 
+  DBUG_PRINT("info", ("connecting non-blocking"));
   res= connect(fd, (struct sockaddr*) name, namelen);
+  DBUG_PRINT("info", ("connect result: %d  errno: %d", res, errno));
   s_err= errno;			/* Save the error... */
   fcntl(fd, F_SETFL, flags);
   if ((res != 0) && (s_err != EINPROGRESS))
   {
     errno= s_err;			/* Restore it */
-    return(-1);
+    DBUG_RETURN(-1);
   }
   if (res == 0)				/* Connected quickly! */
-    return(0);
-  my_socket ms;
-  ms.fd= fd;
-  return wait_for_data(ms, timeout);
+    DBUG_RETURN(0);
+  DBUG_RETURN(wait_for_data(fd, timeout));
 #endif
 }
 
@@ -202,26 +198,58 @@ static int wait_for_data(my_socket fd, u
 #ifdef HAVE_POLL
   struct pollfd ufds;
   int res;
+  DBUG_ENTER("wait_for_data");
 
-  ufds.fd= fd.fd;
+  DBUG_PRINT("info", ("polling"));
+  ufds.fd= fd;
   ufds.events= POLLIN | POLLPRI;
   if (!(res= poll(&ufds, 1, (int) timeout*1000)))
   {
+    DBUG_PRINT("info", ("poll timed out"));
     errno= EINTR;
-    return -1;
+    DBUG_RETURN(-1);
   }
+  DBUG_PRINT("info",
+             ("poll result: %d  errno: %d  revents: 0x%02d  events: 0x%02d",
+              res, errno, ufds.revents, ufds.events));
   if (res < 0 || !(ufds.revents & (POLLIN | POLLPRI)))
-    return -1;
-  return 0;
+    DBUG_RETURN(-1);
+  /*
+    At this point, we know that something happened on the socket.
+    But this does not means that everything is alright.
+    The connect might have failed. We need to retrieve the error code
+    from the socket layer. We must return success only if we are sure
+    that it was really a success. Otherwise we might prevent the caller
+    from trying another address to connect to.
+  */
+  {
+    int         s_err;
+    socklen_t   s_len= sizeof(s_err);
+
+    DBUG_PRINT("info", ("Get SO_ERROR from non-blocked connected socket."));
+    res= getsockopt(fd, SOL_SOCKET, SO_ERROR, &s_err, &s_len);
+    DBUG_PRINT("info", ("getsockopt res: %d  s_err: %d", res, s_err));
+    if (res)
+      DBUG_RETURN(res);
+    /* getsockopt() was successful, check the retrieved status value. */
+    if (s_err)
+    {
+      errno= s_err;
+      DBUG_RETURN(-1);
+    }
+    /* Status from connect() is zero. Socket is successfully connected. */
+  }
+  DBUG_RETURN(0);
 #else
   SOCKOPT_OPTLEN_TYPE s_err_size = sizeof(uint);
   fd_set sfds;
   struct timeval tv;
   time_t start_time, now_time;
   int res, s_err;
+  DBUG_ENTER("wait_for_data");
 
   if (fd >= FD_SETSIZE)				/* Check if wrong error */
-    return 0;					/* Can't use timeout */
+    DBUG_RETURN(0);					/* Can't use timeout */
 
   /*
     Our connection is "in progress."  We can use the select() call to wait
@@ -240,7 +268,7 @@ static int wait_for_data(my_socket fd, u
   */
 
   FD_ZERO(&sfds);
-  my_FD_SET(fd, &sfds);
+  FD_SET(fd, &sfds);
   /*
     select could be interrupted by a signal, and if it is, 
     the timeout should be adjusted and the select restarted
@@ -254,18 +282,18 @@ static int wait_for_data(my_socket fd, u
     tv.tv_sec = (long) timeout;
     tv.tv_usec = 0;
 #if defined(HPUX10) && defined(THREAD)
-    if ((res = select(my_socket_nfds(fd,0)+1, NULL, (int*) &sfds, NULL, &tv)) > 0)
+    if ((res = select(fd+1, NULL, (int*) &sfds, NULL, &tv)) > 0)
       break;
 #else
-    if ((res = select(my_socket_nfds(fd,0)+1, NULL, &sfds, NULL, &tv)) > 0)
+    if ((res = select(fd+1, NULL, &sfds, NULL, &tv)) > 0)
       break;
 #endif
     if (res == 0)					/* timeout */
-      return -1;
+      DBUG_RETURN(-1);
     now_time= my_time(0);
     timeout-= (uint) (now_time - start_time);
     if (errno != EINTR || (int) timeout <= 0)
-      return -1;
+      DBUG_RETURN(-1);
   }
 
   /*
@@ -275,15 +303,15 @@ static int wait_for_data(my_socket fd, u
   */
 
   s_err=0;
-  if (my_getsockopt(fd, SOL_SOCKET, SO_ERROR, (char*) &s_err, &s_err_size) != 0)
-    return(-1);
+  if (getsockopt(fd, SOL_SOCKET, SO_ERROR, (char*) &s_err, &s_err_size) != 0)
+    DBUG_RETURN(-1);
 
   if (s_err)
   {						/* getsockopt could succeed */
     errno = s_err;
-    return(-1);					/* but return an error... */
+    DBUG_RETURN(-1);					/* but return an error... */
   }
-  return (0);					/* ok */
+  DBUG_RETURN(0);					/* ok */
 #endif /* HAVE_POLL */
 }
 #endif /* defined(__WIN__) || defined(__NETWARE__) */
@@ -1886,7 +1914,7 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,cons
   init_sigpipe_variables
   DBUG_ENTER("mysql_real_connect");
 
-  DBUG_PRINT("enter",("host: %s  db: %s  user: %s",
+  DBUG_PRINT("enter",("host: %s  db: %s  user: %s (client)",
 		      host ? host : "(Null)",
 		      db ? db : "(Null)",
 		      user ? user : "(Null)"));
@@ -1936,6 +1964,7 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,cons
     unix_socket=mysql->options.unix_socket;
 
   mysql->server_status=SERVER_STATUS_AUTOCOMMIT;
+  DBUG_PRINT("info", ("Connecting"));
 
   /*
     Part 0: Grab a socket and connect it to the server
@@ -1945,6 +1974,7 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,cons
        mysql->options.protocol == MYSQL_PROTOCOL_MEMORY) &&
       (!host || !strcmp(host,LOCAL_HOST)))
   {
+    DBUG_PRINT("info", ("Using shared memory"));
     if ((create_shared_memory(mysql,net, mysql->options.connect_timeout)) ==
 	INVALID_HANDLE_VALUE)
     {
@@ -1967,8 +1997,8 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,cons
     else
     {
       mysql->options.protocol=MYSQL_PROTOCOL_MEMORY;
-      my_socket_invalidate(&sock);
-      unix_socket=0;
+      sock=0;
+      unix_socket = 0;
       host=mysql->options.shared_memory_base_name;
       my_snprintf(host_info=buff, sizeof(buff)-1,
                   ER(CR_SHARED_MEMORY_CONNECTION), host);
@@ -1987,8 +2017,7 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,cons
       unix_socket=mysql_unix_port;
     host_info=(char*) ER(CR_LOCALHOST_CONNECTION);
     DBUG_PRINT("info",("Using UNIX sock '%s'",unix_socket));
-    sock = my_socket_create(AF_UNIX,SOCK_STREAM,0);
-    if (!my_socket_valid(sock))
+    if ((sock = socket(AF_UNIX,SOCK_STREAM,0)) == SOCKET_ERROR)
     {
       set_mysql_extended_error(mysql, CR_SOCKET_CREATE_ERROR,
                                unknown_sqlstate,
@@ -2001,7 +2030,7 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,cons
     bzero((char*) &UNIXaddr,sizeof(UNIXaddr));
     UNIXaddr.sun_family = AF_UNIX;
     strmake(UNIXaddr.sun_path, unix_socket, sizeof(UNIXaddr.sun_path)-1);
-    if (my_connect(MY_SOCKET_FORMAT_VALUE(sock),(struct sockaddr *) &UNIXaddr, sizeof(UNIXaddr),
+    if (my_connect(sock,(struct sockaddr *) &UNIXaddr, sizeof(UNIXaddr),
 		   mysql->options.connect_timeout))
     {
       DBUG_PRINT("error",("Got error %d on connect to local server",
@@ -2020,7 +2049,7 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,cons
        (host && !strcmp(host,LOCAL_HOST_NAMEDPIPE)) ||
        (! have_tcpip && (unix_socket || !host && is_NT()))))
   {
-    sock.s= 0;
+    sock=0;
     if ((hPipe= create_named_pipe(mysql, mysql->options.connect_timeout,
                                   (char**) &host, (char**) &unix_socket)) ==
 	INVALID_HANDLE_VALUE)
@@ -2044,16 +2073,17 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,cons
     }
   }
 #endif
+  DBUG_PRINT("info", ("net->vio: %p  protocol: %d",
+                      net->vio, mysql->options.protocol));
   if (!net->vio &&
       (!mysql->options.protocol ||
        mysql->options.protocol == MYSQL_PROTOCOL_TCP))
   {
-    struct addrinfo *res_lst= NULL, *client_bind_ai_lst= NULL, *t_res, hints;
+    struct addrinfo *res_lst, *client_bind_ai_lst= NULL, hints, *t_res;
     int gai_errno;
     char port_buf[NI_MAXSERV];
-    my_socket sock= my_socket_create_invalid();
+    my_socket sock= SOCKET_ERROR;
     int saved_error= 0, status= -1, bind_result= 0;
-    my_bool create_ok= 0, bind_ok= 0;
 
     unix_socket=0;				/* This is not used */
     if (!port)
@@ -2091,9 +2121,6 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,cons
       DBUG_PRINT("info",("getaddrinfo error %d", gai_errno));
       set_mysql_extended_error(mysql, CR_UNKNOWN_HOST, unknown_sqlstate,
                                ER(CR_UNKNOWN_HOST), host, errno);
-      
-      if (res_lst)
-        freeaddrinfo(res_lst);
 
       goto error;
     }
@@ -2112,48 +2139,43 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,cons
       {
         DBUG_PRINT("info",("client bind getaddrinfo error %d", bind_gai_errno));
         set_mysql_extended_error(mysql, CR_UNKNOWN_HOST, unknown_sqlstate,
-                                 ER(CR_UNKNOWN_HOST), mysql->options.bind_name, errno);
-        
-        if (client_bind_ai_lst)
-          freeaddrinfo(client_bind_ai_lst);
-        
+                                 ER(CR_UNKNOWN_HOST), mysql->options.bind_name,
+                                 errno);
+
         freeaddrinfo(res_lst);
         goto error;
       }
       DBUG_PRINT("info", ("  got address info for client bind name"));
     }
 
-    /* 
+    /*
       A hostname might map to multiple IP addresses (IPv4/IPv6). Go over the
       list of IP addresses until a successful connection can be established.
-      For each IP address, attempt to bind the socket to each client address 
+      For each IP address, attempt to bind the socket to each client address
       for the client-side bind hostname until the bind is successful.
     */
-    for (t_res= res_lst; t_res; t_res= t_res->ai_next)    
+    DBUG_PRINT("info", ("Try connect on all addresses for host."));
+    for (t_res= res_lst; t_res; t_res= t_res->ai_next)
     {
       DBUG_PRINT("info",("Creating socket : Family %d, Type %d, Protocol %d",
-                         t_res->ai_family, t_res->ai_socktype, t_res->ai_protocol));
-      create_ok= bind_ok= 0;
-      sock= my_socket_create(t_res->ai_family, t_res->ai_socktype, t_res->ai_protocol);
-      if (!my_socket_valid(sock))
+                         t_res->ai_family, t_res->ai_socktype,
+                         t_res->ai_protocol));
+
+      sock= socket(t_res->ai_family, t_res->ai_socktype, t_res->ai_protocol);
+      if (sock ==SOCKET_ERROR)
       {
         DBUG_PRINT("info",("Socket created was invalid"));
         /* Try next address if there is one */
         saved_error= socket_errno;
         continue;
       }
-      create_ok= 1;
 
-      if (client_bind_ai_lst) 
+      if (client_bind_ai_lst)
       {
-        /* TODOs for client bind:
-           - check error codes
-           - don't use socket for localhost if this option is given
-        */
         struct addrinfo* curr_bind_ai= NULL;
         DBUG_PRINT("info", ("Attempting to bind socket to bind address(es)"));
 
-        /* 
+        /*
            We'll attempt to bind to each of the addresses returned, until
            we find one that works.
            If none works, we'll try the next destination host address
@@ -2164,9 +2186,9 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,cons
         while (curr_bind_ai != NULL)
         {
           /* Attempt to bind the socket to the given address */
-          bind_result= my_bind(sock, 
-                               curr_bind_ai->ai_addr, 
-                               curr_bind_ai->ai_addrlen);
+          bind_result= bind(sock,
+                            curr_bind_ai->ai_addr,
+                            curr_bind_ai->ai_addrlen);
 
           if (!bind_result)
             break;   /* Success */
@@ -2178,28 +2200,28 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,cons
 
         if (bind_result)
         {
-          DBUG_PRINT("info", ("All bind attempts with this address failed"));
-          saved_error= errno;
-          my_socket_close(sock);
-          my_socket_invalidate(&sock);
-          
-          /* 
-             Could not bind to any client-side address with this destination
+          /*
+            Could not bind to any client-side address with this destination
              Try the next destination address (if any)
           */
+          DBUG_PRINT("info", ("All bind attempts with this address failed"));
+          saved_error= errno;
+          closesocket(sock);
           continue;
         }
         DBUG_PRINT("info", ("Successfully bound client side of socket"));
       }
-      bind_ok= 1;
 
-      status= my_connect(MY_SOCKET_FORMAT_VALUE(sock), t_res->ai_addr, t_res->ai_addrlen,
+      DBUG_PRINT("info", ("Connect socket"));
+      status= my_connect(sock, t_res->ai_addr, t_res->ai_addrlen,
                          mysql->options.connect_timeout);
-      
+      /*
+        Here we rely on my_connect() to return success only if the
+        connect attempt was really successful. Otherwise we would stop
+        trying another address, believing we were successful.
+      */
       if (!status)
-      {
-        break;    /* Success */
-      }
+        break;
 
       /*
         Save value as socket errno might be overwritten due to
@@ -2207,53 +2229,43 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,cons
       */
       saved_error= socket_errno;
 
-      my_socket_close(sock);
-      my_socket_invalidate(&sock);
+      DBUG_PRINT("info", ("No success, close socket, try next address."));
+      closesocket(sock);
     }
+    DBUG_PRINT("info",
+               ("End of connect attempts, sock: %d  status: %d  error: %d",
+                sock, status, saved_error));
 
     freeaddrinfo(res_lst);
     if (client_bind_ai_lst)
       freeaddrinfo(client_bind_ai_lst);
 
-    if (status != 0)
+    if (sock == SOCKET_ERROR)
     {
-      /* Some error creating socket, binding client side, or connecting */
-      assert(!my_socket_valid(sock));
-      if (!create_ok)
-      {
-        DBUG_PRINT("error",("Got error %d when attempting to create socket",
-                            saved_error));
-        set_mysql_extended_error(mysql, CR_IPSOCK_ERROR, unknown_sqlstate,
-                                 ER(CR_IPSOCK_ERROR), saved_error);
-      }
-      else if (!bind_ok)
-      {
-        DBUG_PRINT("error",("Got error %d when attempting client socket bind",
-                            saved_error));
-        set_mysql_extended_error(mysql, CR_IPSOCK_ERROR, unknown_sqlstate,
-                                 ER(CR_IPSOCK_ERROR), mysql->options.bind_name, saved_error);
-      }
-      else
-      {
-        DBUG_PRINT("error",("Got error %d on connect to '%s'", saved_error, host));
-        set_mysql_extended_error(mysql, CR_CONN_HOST_ERROR, unknown_sqlstate,
-                                 ER(CR_CONN_HOST_ERROR), host, saved_error);
-      }
+      set_mysql_extended_error(mysql, CR_IPSOCK_ERROR, unknown_sqlstate,
+                                ER(CR_IPSOCK_ERROR), saved_error);
+      goto error;
+    }
+
+    if (status)
+    {
+      DBUG_PRINT("error",("Got error %d on connect to '%s'", saved_error, host));
+      set_mysql_extended_error(mysql, CR_CONN_HOST_ERROR, unknown_sqlstate,
+                                ER(CR_CONN_HOST_ERROR), host, saved_error);
       goto error;
     }
 
-    /* Managed to connect if we get here, now setup VIO */
     net->vio= vio_new(sock, VIO_TYPE_TCPIP, VIO_BUFFERED_READ);
     if (! net->vio )
     {
       DBUG_PRINT("error",("Unknow protocol %d ", mysql->options.protocol));
       set_mysql_error(mysql, CR_CONN_UNKNOW_PROTOCOL, unknown_sqlstate);
-      my_socket_close(sock);
-      my_socket_invalidate(&sock);
+      closesocket(sock);
       goto error;
     }
   }
 
+  DBUG_PRINT("info", ("net->vio: %p", net->vio));
   if (!net->vio)
   {
     DBUG_PRINT("error",("Unknow protocol %d ",mysql->options.protocol));
@@ -2296,6 +2308,7 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,cons
   /*
     Part 1: Connection established, read and parse first packet
   */
+  DBUG_PRINT("info", ("Read first packet."));
 
   if ((pkt_length=cli_safe_read(mysql)) == packet_error)
   {

=== modified file 'sql/ha_ndbcluster.cc'
--- a/sql/ha_ndbcluster.cc	2010-04-28 19:21:29 +0000
+++ b/sql/ha_ndbcluster.cc	2010-04-30 09:41:04 +0000
@@ -48,6 +48,7 @@
 
 #include <mysql/plugin.h>
 #include <abstract_query_plan.h>
+#include <ndb_version.h>
 
 #ifdef ndb_dynamite
 #undef assert
@@ -2206,6 +2207,7 @@ ha_ndbcluster::set_blob_values(const Ndb
       ERR_RETURN(ndb_op->getNdbError());
     if (field->is_null_in_record_with_offset(row_offset))
     {
+      DBUG_PRINT("info", ("Setting Blob %d to NULL", field_no));
       if (ndb_blob->setNull() != 0)
         ERR_RETURN(ndb_op->getNdbError());
     }
@@ -2393,6 +2395,108 @@ int cmp_frm(const NDBTAB *ndbtab, const 
   DBUG_RETURN(0);
 }
 
+/*
+  Does type support a default value?
+*/
+static bool
+type_supports_default_value(enum_field_types mysql_type)
+{
+  bool ret = (mysql_type != MYSQL_TYPE_BLOB &&
+              mysql_type != MYSQL_TYPE_TINY_BLOB &&
+              mysql_type != MYSQL_TYPE_MEDIUM_BLOB &&
+              mysql_type != MYSQL_TYPE_LONG_BLOB &&
+              mysql_type != MYSQL_TYPE_GEOMETRY);
+
+  return ret;
+}
+
+/**
+   Check that Ndb data dictionary has the same default values
+   as MySQLD for the current table.
+   Called as part of a DBUG check as part of table open
+   
+   Returns
+     0  - Defaults are ok
+     -1 - Some default(s) are bad
+*/
+int ha_ndbcluster::check_default_values(const NDBTAB* ndbtab)
+{
+  /* Debug only method for checking table defaults aligned
+     between MySQLD and Ndb
+  */
+  bool defaults_aligned= true;
+
+  if (ndbtab->hasDefaultValues())
+  {
+    /* Ndb supports native defaults for non-pk columns */
+    my_bitmap_map *old_map= tmp_use_all_columns(table, table->read_set);
+
+    for (uint f=0; f < table_share->fields; f++)
+    {
+      Field* field= table->field[f]; // Use Field struct from MySQLD table rep
+      const NdbDictionary::Column* ndbCol= ndbtab->getColumn(field->field_index); 
+      if ((! (field->flags & (PRI_KEY_FLAG |
+                              NO_DEFAULT_VALUE_FLAG))) &&
+          (type_supports_default_value(field->real_type())))
+      {
+        /* We expect Ndb to have a native default for this
+         * column
+         */
+        my_ptrdiff_t src_offset= table_share->default_values - 
+          field->table->record[0];
+
+        /* Move field by offset to refer to default value */
+        field->move_field_offset(src_offset);
+        
+        const uchar* ndb_default= (const uchar*) ndbCol->getDefaultValue();
+
+        if (ndb_default == NULL)
+          /* MySQLD default must also be NULL */
+          defaults_aligned= field->is_null();
+        else
+        {
+          if (field->type() != MYSQL_TYPE_BIT)
+          {
+            defaults_aligned= (0 == field->cmp(ndb_default));
+          }
+          else
+          {
+            longlong value= (static_cast<Field_bit*>(field))->val_int();
+            defaults_aligned= (0 == memcmp(ndb_default, 
+                                           &value, 
+                                           field->used_length()));
+          }
+        }
+        
+        field->move_field_offset(-src_offset);
+
+        if (unlikely(!defaults_aligned))
+        {
+          DBUG_PRINT("info", ("Default values differ for column %u",
+                              field->field_index));
+          break;
+        }
+      }
+      else
+      {
+        /* We don't expect Ndb to have a native default for this column */
+        if (unlikely(ndbCol->getDefaultValue()))
+        {
+          /* Didn't expect that */
+          DBUG_PRINT("info", ("Column %u has native default, but shouldn't."
+                              " Flags=%u, type=%u",
+                              field->field_index, field->flags, field->real_type()));
+          defaults_aligned= false;
+          break;
+        }
+      }
+    } 
+    tmp_restore_column_map(table->read_set, old_map);
+  }
+
+  return (defaults_aligned? 0: -1);
+}
+
 int ha_ndbcluster::get_metadata(THD *thd, const char *path)
 {
   Ndb *ndb= get_thd_ndb(thd)->ndb;
@@ -2438,6 +2542,11 @@ int ha_ndbcluster::get_metadata(THD *thd
   my_free((char*)data, MYF(0));
   my_free((char*)pack_data, MYF(0));
 
+  /* Now check that any Ndb native defaults are aligned 
+     with MySQLD defaults
+  */
+  DBUG_ASSERT(check_default_values(tab) == 0);
+
   if (error)
     goto err;
 
@@ -3515,7 +3624,20 @@ int ha_ndbcluster::ndb_pk_update_row(THD
   {
     DBUG_RETURN(error);
   }
+
+  /*
+    We are mapping a MySQLD PK changing update to an NdbApi delete 
+    and insert.
+    The original PK changing update may not have written new values
+    to all columns, so the write set may be partial.
+    We set the write set to be all columns so that all values are
+    copied from the old row to the new row.
+  */
+  my_bitmap_map *old_map=
+    tmp_use_all_columns(table, table->write_set);
   error= ndb_write_row(new_data, TRUE, batched_update);
+  tmp_restore_column_map(table->write_set, old_map);
+
   if (error)
   {
     DBUG_PRINT("info", ("insert failed"));
@@ -4974,7 +5096,10 @@ int ha_ndbcluster::ndb_write_row(uchar *
   if (options.optionsPresent != 0)
     poptions=&options;
 
-  const MY_BITMAP *user_cols_written_bitmap;
+  const Uint32 bitmapSz= (NDB_MAX_ATTRIBUTES_IN_TABLE + 31)/32;
+  uint32 tmpBitmapSpace[bitmapSz];
+  MY_BITMAP tmpBitmap;
+  MY_BITMAP *user_cols_written_bitmap;
 #ifdef HAVE_NDB_BINLOG
   uchar* ex_data_buffer= NULL;
 #endif
@@ -4987,8 +5112,6 @@ int ha_ndbcluster::ndb_write_row(uchar *
 #endif
       )
   {
-    uchar *mask;
-    
     /* Should we use the supplied table writeset or not?
      * For a REPLACE command, we should ignore it, and write
      * all columns to get correct REPLACE behaviour.
@@ -5005,6 +5128,7 @@ int ha_ndbcluster::ndb_write_row(uchar *
      */
     useWriteSet |= thd->slave_thread;
 #endif
+    uchar* mask;
 
     if (useWriteSet)
     {
@@ -5092,10 +5216,54 @@ int ha_ndbcluster::ndb_write_row(uchar *
       poptions=&options;
     }
 #endif
-    /* Using insert, we write all user visible columns */
-    user_cols_written_bitmap= NULL;
+    uchar *mask;
+
+    /* Check whether Ndb table definition includes any default values. */
+    if (m_table->hasDefaultValues())
+    {
+      DBUG_PRINT("info", ("Not sending values for native defaulted columns"));
+
+      /*
+        If Ndb is unaware of the table's defaults, we must provide all column values to the insert.  
+        This is done using a NULL column mask.
+        If Ndb is aware of the table's defaults, we only need to provide 
+        the columns explicitly mentioned in the write set, 
+        plus any extra columns required due to bug#41616. 
+        plus the primary key columns required due to bug#42238.
+      */
+      /*
+        The following code for setting user_cols_written_bitmap
+        should be removed after BUG#41616 and Bug#42238 are fixed
+      */
+      /* Copy table write set so that we can add to it */
+      user_cols_written_bitmap= &tmpBitmap;
+      bitmap_init(user_cols_written_bitmap, tmpBitmapSpace,
+                  table->write_set->n_bits, false);
+      bitmap_copy(user_cols_written_bitmap, table->write_set);
+
+      for (uint i= 0; i < table->s->fields; i++)
+      {
+        Field *field= table->field[i];
+        if (field->flags & (NO_DEFAULT_VALUE_FLAG | // bug 41616
+                            PRI_KEY_FLAG))          // bug 42238
+        {
+          bitmap_set_bit(user_cols_written_bitmap, field->field_index);
+        }
+      }
+
+      mask= (uchar *)(user_cols_written_bitmap->bitmap);
+    }
+    else
+    {
+      /* No defaults in kernel, provide all columns ourselves */
+      DBUG_PRINT("info", ("No native defaults, sending all values"));
+      user_cols_written_bitmap= NULL;
+      mask = NULL;
+    }
+      
+    /* Using insert, we write all non default columns */
     op= trans->insertTuple(key_rec, (const char *)key_row, m_ndb_record,
-                           (char *)record, NULL, // No mask
+                           (char *)record, mask, // Default value should be masked
                            poptions, sizeof(NdbOperation::OperationOptions));
   }
   if (!(op))
@@ -6130,6 +6298,58 @@ void ha_ndbcluster::unpack_record(uchar 
   }
 }
 
+
+/**
+  Get the default value of the field from default_values of the table.
+*/
+static void get_default_value(void *def_val, Field *field)
+{
+  DBUG_ASSERT(field != NULL);
+
+  my_ptrdiff_t src_offset= field->table->s->default_values - field->table->record[0];
+
+  {
+    if (bitmap_is_set(field->table->read_set, field->field_index))
+    {
+      if (field->type() == MYSQL_TYPE_BIT)
+      {
+        Field_bit *field_bit= static_cast<Field_bit*>(field);
+        if (!field->is_null_in_record_with_offset(src_offset))
+        {
+          field->move_field_offset(src_offset);
+          longlong value= field_bit->val_int();
+          memcpy(def_val, &value, sizeof(longlong));
+         field->move_field_offset(-src_offset);
+        }
+      }
+      else if (field->flags & BLOB_FLAG)
+      {
+        assert(false);
+      }
+      else
+      {
+        field->move_field_offset(src_offset);
+        /* Normal field (not blob or bit type). */
+        if (!field->is_null())
+        {
+          /* Only copy actually used bytes of varstrings. */
+          uint32 actual_length= field->used_length();
+          uchar *src_ptr= field->ptr;
+          field->set_notnull();
+          memcpy(def_val, src_ptr, actual_length);
+#ifdef HAVE_purify
+          if (actual_length < field->pack_length())
+            bzero(((char*)def_val) + actual_length,
+                  field->pack_length() - actual_length);
+#endif
+        }
+        field->move_field_offset(-src_offset);
+        /* No action needed for a NULL field. */
+      }
+    }
+  }
+}
+
 /*
     DBUG_EXECUTE("value", print_results(););
 */
@@ -7975,6 +8195,7 @@ static int create_ndb_column(THD *thd,
   NDBCOL::StorageType type= NDBCOL::StorageTypeMemory;
   bool dynamic= FALSE;
 
+  char buf[MAX_ATTR_DEFAULT_VALUE_SIZE];
   DBUG_ENTER("create_ndb_column");
   // Set name
   if (col.setName(field->field_name))
@@ -7985,6 +8206,40 @@ static int create_ndb_column(THD *thd,
   CHARSET_INFO *cs= field->charset();
   // Set type and sizes
   const enum enum_field_types mysql_type= field->real_type();
+
+  {
+    /* Clear default value (col obj is reused for whole table def) */
+    col.setDefaultValue(NULL, 0); 
+
+    /* If the data nodes are capable then set native 
+     * default.
+     */
+    bool nativeDefaults =
+      ! (thd &&
+         (! ndb_native_default_support(get_thd_ndb(thd)->
+                                       ndb->getMinDbNodeVersion())));
+
+    if (likely( nativeDefaults ))
+    {
+      if ((!(field->flags & PRI_KEY_FLAG) ) &&
+          type_supports_default_value(mysql_type))
+      {
+        if (!(field->flags & NO_DEFAULT_VALUE_FLAG))
+        {
+          my_ptrdiff_t src_offset= field->table->s->default_values 
+            - field->table->record[0];
+          if ((! field->is_null_in_record_with_offset(src_offset)) ||
+              ((field->flags & NOT_NULL_FLAG)))
+          {
+            /* Set a non-null native default */
+            memset(buf, 0, MAX_ATTR_DEFAULT_VALUE_SIZE);
+            get_default_value(buf, field);
+            col.setDefaultValue(buf, field->used_length());
+          }
+        }
+      }
+    }
+  }
   switch (mysql_type) {
   // Numeric types
   case MYSQL_TYPE_TINY:        
@@ -8596,6 +8851,12 @@ int ha_ndbcluster::create(const char *na
   /*
     Setup columns
   */
+  my_bitmap_map *old_map;
+  {
+    restore_record(form, s->default_values);
+    old_map= tmp_use_all_columns(form, form->read_set);
+  }
+
   for (i= 0; i < form->s->fields; i++) 
   {
     Field *field= form->field[i];
@@ -8621,6 +8882,7 @@ int ha_ndbcluster::create(const char *na
       pk_length += (field->pack_length() + 3) / 4;
   }
 
+  tmp_restore_column_map(form->read_set, old_map);
   if (use_disk)
   { 
     tab.setLogging(TRUE);
@@ -8686,6 +8948,7 @@ int ha_ndbcluster::create(const char *na
     col.setNullable(FALSE);
     col.setPrimaryKey(TRUE);
     col.setAutoIncrement(TRUE);
+    col.setDefaultValue(NULL, 0);
     if (tab.addColumn(col))
     {
       my_errno= errno;

=== modified file 'sql/ha_ndbcluster.h'
--- a/sql/ha_ndbcluster.h	2010-03-24 12:44:05 +0000
+++ b/sql/ha_ndbcluster.h	2010-04-30 09:41:04 +0000
@@ -675,6 +675,7 @@ private:
   int add_hidden_pk_ndb_record(NdbDictionary::Dictionary *dict);
   int add_index_ndb_record(NdbDictionary::Dictionary *dict,
                            KEY *key_info, uint index_no);
+  int check_default_values(const NdbDictionary::Table* ndbtab);
   int get_metadata(THD *thd, const char* path);
   void release_metadata(THD *thd, Ndb *ndb);
   NDB_INDEX_TYPE get_index_type(uint idx_no) const;

=== modified file 'sql/hostname.cc'
--- a/sql/hostname.cc	2009-10-02 18:32:45 +0000
+++ b/sql/hostname.cc	2010-04-13 16:01:38 +0000
@@ -37,6 +37,7 @@ extern "C" {					// Because of SCO 3.2V4
 #ifdef HAVE_SYS_UN_H
 #include <sys/un.h>
 #endif
+#include <netdb.h>
 #include <sys/utsname.h>
 #endif // __WIN__
 #ifdef	__cplusplus

=== modified file 'sql/log_event.cc'
--- a/sql/log_event.cc	2010-03-12 10:36:52 +0000
+++ b/sql/log_event.cc	2010-04-28 13:54:56 +0000
@@ -1721,8 +1721,8 @@ log_event_print_value(IO_CACHE *file, co
     {
       uint32 tmp= uint3korr(ptr);
       int part;
-      char buf[10];
-      char *pos= &buf[10];
+      char buf[11];
+      char *pos= &buf[10];  // start from '\0' to the beginning
 
       /* Copied from field.cc */
       *pos--=0;					// End NULL

=== modified file 'sql/mysqld.cc'
--- a/sql/mysqld.cc	2010-04-27 09:35:50 +0000
+++ b/sql/mysqld.cc	2010-04-30 09:41:04 +0000
@@ -110,6 +110,7 @@ extern "C" {					// Because of SCO 3.2V4
 #ifdef HAVE_SYS_UN_H
 #  include <sys/un.h>
 #endif
+#include <netdb.h>
 #ifdef HAVE_SELECT_H
 #  include <select.h>
 #endif
@@ -890,11 +891,11 @@ static void close_connections(void)
   DBUG_PRINT("quit",("Closing sockets"));
   if (!opt_disable_networking )
   {
-    if (my_socket_valid(ip_sock))
+    if (ip_sock != INVALID_SOCKET)
     {
-      (void) my_shutdown(ip_sock, SHUT_RDWR);
-      (void) my_socket_close(ip_sock);
-      my_socket_invalidate(&ip_sock);
+      (void) shutdown(ip_sock, SHUT_RDWR);
+      (void) closesocket(ip_sock);
+      ip_sock= INVALID_SOCKET;
     }
   }
 #ifdef __NT__
@@ -922,12 +923,12 @@ static void close_connections(void)
   }
 #endif
 #ifdef HAVE_SYS_UN_H
-  if (my_socket_valid(unix_sock))
+  if (unix_sock != INVALID_SOCKET)
   {
-    (void) my_shutdown(unix_sock, SHUT_RDWR);
-    (void) my_socket_close(unix_sock);
+    (void) shutdown(unix_sock, SHUT_RDWR);
+    (void) closesocket(unix_sock);
     (void) unlink(mysqld_unix_port);
-    my_socket_invalidate(&unix_sock);
+    unix_sock= INVALID_SOCKET;
   }
 #endif
   end_thr_alarm(0);			 // Abort old alarms.
@@ -1025,33 +1026,33 @@ static void close_server_sock()
   DBUG_ENTER("close_server_sock");
   my_socket tmp_sock;
   tmp_sock=ip_sock;
-  if (my_socket_valid(tmp_sock))
+  if (tmp_sock != INVALID_SOCKET)
   {
-    my_socket_invalidate(&ip_sock);
+    ip_sock=INVALID_SOCKET;
     DBUG_PRINT("info",("calling shutdown on TCP/IP socket"));
-    VOID(my_shutdown(tmp_sock, SHUT_RDWR));
+    VOID(shutdown(tmp_sock, SHUT_RDWR));
 #if defined(__NETWARE__)
     /*
       The following code is disabled for normal systems as it causes MySQL
       to hang on AIX 4.3 during shutdown
     */
     DBUG_PRINT("info",("calling closesocket on TCP/IP socket"));
-    VOID(my_socket_close(tmp_sock));
+    VOID(closesocket(tmp_sock));
 #endif
   }
   tmp_sock=unix_sock;
-  if (my_socket_valid(tmp_sock))
+  if (tmp_sock != INVALID_SOCKET)
   {
-    my_socket_invalidate(&unix_sock);
+    unix_sock=INVALID_SOCKET;
     DBUG_PRINT("info",("calling shutdown on unix socket"));
-    VOID(my_shutdown(tmp_sock, SHUT_RDWR));
+    VOID(shutdown(tmp_sock, SHUT_RDWR));
 #if defined(__NETWARE__)
     /*
       The following code is disabled for normal systems as it may cause MySQL
       to hang on AIX 4.3 during shutdown
     */
     DBUG_PRINT("info",("calling closesocket on unix/IP socket"));
-    VOID(my_socket_close(tmp_sock));
+    VOID(closesocket(tmp_sock));
 #endif
     VOID(unlink(mysqld_unix_port));
   }
@@ -1631,6 +1632,7 @@ static void network_init(void)
 #ifdef HAVE_SYS_UN_H
   struct sockaddr_un	UNIXaddr;
 #endif
+  int	arg=1;
   int   ret;
   uint  waited;
   uint  this_wait;
@@ -1667,13 +1669,12 @@ static void network_init(void)
 
     for (addr = addrlist; addr != NULL; addr = addr->ai_next)
     {
-      ip_sock= my_socket_create(addr->ai_family, addr->ai_socktype,
-                                addr->ai_protocol);
-      if (my_socket_valid(ip_sock))
+      ip_sock= socket(addr->ai_family, addr->ai_socktype, addr->ai_protocol);
+      if (ip_sock != INVALID_SOCKET)
         break;
     }
 
-    if (!my_socket_valid(ip_sock))
+    if (ip_sock == INVALID_SOCKET)
     {
       DBUG_PRINT("error",("Got error: %d from socket()",socket_errno));
       sql_perror(ER(ER_IPSOCK_ERROR));		/* purecov: tested */
@@ -1685,7 +1686,7 @@ static void network_init(void)
       We should not use SO_REUSEADDR on windows as this would enable a
       user to open two mysqld servers with the same TCP/IP port.
     */
-    my_socket_reuseaddr(ip_sock, true);
+    (void) setsockopt(ip_sock,SOL_SOCKET,SO_REUSEADDR,(char*)&arg,sizeof(arg));
 #endif /* __WIN__ */
 #ifdef IPV6_V6ONLY
      /*
@@ -1695,10 +1696,9 @@ static void network_init(void)
      */
     if (addr->ai_family == AF_INET6)
     {
-      int enable= 0;
-      DBUG_PRINT("info",("Clearing IPV6_ONLY socket option"));
-      my_setsockopt(ip_sock, IPPROTO_IPV6, IPV6_V6ONLY,
-                    &enable, sizeof(enable));
+      arg= 0;
+      (void) setsockopt(ip_sock, IPPROTO_IPV6, IPV6_V6ONLY, (char*)&arg,
+                sizeof(arg));
     }
 #endif
     /*
@@ -1711,7 +1711,7 @@ static void network_init(void)
     */
     for (waited= 0, retry= 1; ; retry++, waited+= this_wait)
     {
-      if (((ret= my_bind(ip_sock, addr->ai_addr, addr->ai_addrlen)) >= 0 ) ||
+      if (((ret= bind(ip_sock, addr->ai_addr, addr->ai_addrlen)) >= 0 ) ||
           (socket_errno != SOCKET_EADDRINUSE) ||
           (waited >= mysqld_port_timeout))
         break;
@@ -1727,7 +1727,7 @@ static void network_init(void)
       sql_print_error("Do you already have another mysqld server running on port: %d ?",mysqld_port);
       unireg_abort(1);
     }
-    if (my_listen(ip_sock,(int) back_log) < 0)
+    if (listen(ip_sock,(int) back_log) < 0)
     {
       sql_perror("Can't start server: listen() on TCP/IP port");
       sql_print_error("listen() on TCP/IP failed with error %d",
@@ -1798,8 +1798,7 @@ static void network_init(void)
                       (uint) sizeof(UNIXaddr.sun_path) - 1, mysqld_unix_port);
       unireg_abort(1);
     }
-    unix_sock= my_socket_create(AF_UNIX, SOCK_STREAM, 0);
-    if (!my_socket_valid(unix_sock))
+    if ((unix_sock= socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
     {
       sql_perror("Can't start server : UNIX Socket "); /* purecov: inspected */
       unireg_abort(1);				/* purecov: inspected */
@@ -1808,9 +1807,10 @@ static void network_init(void)
     UNIXaddr.sun_family = AF_UNIX;
     strmov(UNIXaddr.sun_path, mysqld_unix_port);
     (void) unlink(mysqld_unix_port);
-    my_socket_reuseaddr(unix_sock, true);
+    (void) setsockopt(unix_sock,SOL_SOCKET,SO_REUSEADDR,(char*)&arg,
+                     sizeof(arg));
     umask(0);
-    if (my_bind(unix_sock, my_reinterpret_cast(struct sockaddr *) (&UNIXaddr),
+    if (bind(unix_sock, my_reinterpret_cast(struct sockaddr *) (&UNIXaddr),
 	     sizeof(UNIXaddr)) < 0)
     {
       sql_perror("Can't start server : Bind on unix socket"); /* purecov: tested */
@@ -1821,7 +1821,7 @@ static void network_init(void)
 #if defined(S_IFSOCK) && defined(SECURE_SOCKETS)
     (void) chmod(mysqld_unix_port,S_IFSOCK);	/* Fix solaris 2.6 bug */
 #endif
-    if (my_listen(unix_sock,(int) back_log) < 0)
+    if (listen(unix_sock,(int) back_log) < 0)
       sql_print_warning("listen() on Unix socket failed with error %d",
 		      socket_errno);
   }
@@ -4508,7 +4508,7 @@ we force server id to 2, but this MySQL 
     if (!opt_bootstrap)
       (void) my_delete(pidfile_name,MYF(MY_WME));	// Not needed anymore
 
-    if (my_socket_valid(unix_sock))
+    if (unix_sock != INVALID_SOCKET)
       unlink(mysqld_unix_port);
     exit(1);
   }
@@ -4587,7 +4587,7 @@ we force server id to 2, but this MySQL 
 #endif
 
   sql_print_information(ER(ER_STARTUP),my_progname,server_version,
-                        ((!my_socket_valid(unix_sock)) ? (char*) ""
+                        ((unix_sock == INVALID_SOCKET) ? (char*) ""
                                                        : mysqld_unix_port),
                          mysqld_port,
                          MYSQL_COMPILATION_COMMENT);
@@ -5061,9 +5061,9 @@ inline void kill_broken_server()
   /* hack to get around signals ignored in syscalls for problem OS's */
   if (
 #if !defined(__NETWARE__)
-      !my_socket_valid(unix_sock) ||
+      unix_sock == INVALID_SOCKET ||
 #endif
-      (!opt_disable_networking && !my_socket_valid(ip_sock)))
+      (!opt_disable_networking && ip_sock == INVALID_SOCKET))
   {
     select_thread_in_use = 0;
     /* The following call will never return */
@@ -5082,27 +5082,31 @@ pthread_handler_t handle_connections_soc
 {
   my_socket sock,new_sock;
   uint error_count=0;
-  int max_used_connection= 0;
+  uint max_used_connection= (uint) (max(ip_sock,unix_sock)+1);
   fd_set readFDs,clientFDs;
   THD *thd;
   struct sockaddr_storage cAddr;
+  int ip_flags=0,socket_flags=0,flags;
   st_vio *vio_tmp;
   DBUG_ENTER("handle_connections_sockets");
 
-  my_socket_invalidate(&new_sock);
-
-  max_used_connection= my_socket_nfds(ip_sock, max_used_connection);
-  max_used_connection= my_socket_nfds(unix_sock, max_used_connection);
+  LINT_INIT(new_sock);
 
   (void) my_pthread_getprio(pthread_self());		// For debugging
 
   FD_ZERO(&clientFDs);
-  if (my_socket_valid(ip_sock))
+  if (ip_sock != INVALID_SOCKET)
   {
-    my_FD_SET(ip_sock,&clientFDs);
+    FD_SET(ip_sock,&clientFDs);
+#ifdef HAVE_FCNTL
+    ip_flags = fcntl(ip_sock, F_GETFL, 0);
+#endif
   }
 #ifdef HAVE_SYS_UN_H
-  my_FD_SET(unix_sock,&clientFDs);
+  FD_SET(unix_sock,&clientFDs);
+#ifdef HAVE_FCNTL
+  socket_flags=fcntl(unix_sock, F_GETFL, 0);
+#endif
 #endif
 
   DBUG_PRINT("general",("Waiting for connections."));
@@ -5111,10 +5115,10 @@ pthread_handler_t handle_connections_soc
   {
     readFDs=clientFDs;
 #ifdef HPUX10
-    if (select(max_used_connection+1,(int*) &readFDs,0,0,0) < 0)
+    if (select(max_used_connection,(int*) &readFDs,0,0,0) < 0)
       continue;
 #else
-    if (select((int) max_used_connection+1,&readFDs,0,0,0) < 0)
+    if (select((int) max_used_connection,&readFDs,0,0,0) < 0)
     {
       if (socket_errno != SOCKET_EINTR)
       {
@@ -5133,35 +5137,41 @@ pthread_handler_t handle_connections_soc
 
     /* Is this a new connection request ? */
 #ifdef HAVE_SYS_UN_H
-    if (my_FD_ISSET(unix_sock,&readFDs))
+    if (FD_ISSET(unix_sock,&readFDs))
     {
       sock = unix_sock;
+      flags= socket_flags;
     }
     else
 #endif
     {
       sock = ip_sock;
+      flags= ip_flags;
     }
 
 #if !defined(NO_FCNTL_NONBLOCK)
     if (!(test_flags & TEST_BLOCKING))
     {
-      my_socket_nonblock(sock, true);
+#if defined(O_NONBLOCK)
+      fcntl(sock, F_SETFL, flags | O_NONBLOCK);
+#elif defined(O_NDELAY)
+      fcntl(sock, F_SETFL, flags | O_NDELAY);
+#endif
     }
 #endif /* NO_FCNTL_NONBLOCK */
     for (uint retry=0; retry < MAX_ACCEPT_RETRY; retry++)
     {
       size_socket length=sizeof(struct sockaddr_storage);
-      new_sock= my_accept(sock, my_reinterpret_cast(struct sockaddr *) (&cAddr),
+      new_sock = accept(sock, my_reinterpret_cast(struct sockaddr *) (&cAddr),
                           &length);
 #ifdef __NETWARE__ 
       // TODO: temporary fix, waiting for TCP/IP fix - DEFECT000303149
-      if ((!my_socket_valid(new_sock)) && (socket_errno == EINVAL))
+      if ((new_sock == INVALID_SOCKET) && (socket_errno == EINVAL))
       {
         kill_server(SIGTERM);
       }
 #endif
-      if (my_socket_valid(new_sock) ||
+      if (new_sock != INVALID_SOCKET ||
 	  (socket_errno != SOCKET_EINTR && socket_errno != SOCKET_EAGAIN))
 	break;
       MAYBE_BROKEN_SYSCALL;
@@ -5169,15 +5179,15 @@ pthread_handler_t handle_connections_soc
       if (!(test_flags & TEST_BLOCKING))
       {
 	if (retry == MAX_ACCEPT_RETRY - 1)
-	  my_socket_nonblock(sock, false);
+          fcntl(sock, F_SETFL, flags);          // Try without O_NONBLOCK
       }
 #endif
     }
 #if !defined(NO_FCNTL_NONBLOCK)
     if (!(test_flags & TEST_BLOCKING))
-      my_socket_nonblock(sock, false);
+      fcntl(sock, F_SETFL, flags);
 #endif
-    if (!my_socket_valid(new_sock))
+    if (new_sock == INVALID_SOCKET)
     {
       if ((error_count++ & 255) == 0)		// This can happen often
 	sql_perror("Error in accept");
@@ -5189,7 +5199,7 @@ pthread_handler_t handle_connections_soc
 
 #ifdef HAVE_LIBWRAP
     {
-      if (my_socket_equal(sock, ip_sock))
+      if (sock == ip_sock)
       {
 	struct request_info req;
 	signal(SIGCHLD, SIG_DFL);
@@ -5214,8 +5224,8 @@ pthread_handler_t handle_connections_soc
 	  if (req.sink)
 	    ((void (*)(int))req.sink)(req.fd);
 
-	  (void) my_shutdown(new_sock, SHUT_RDWR);
-	  (void) my_socket_close(new_sock);
+	  (void) shutdown(new_sock, SHUT_RDWR);
+	  (void) closesocket(new_sock);
 	  continue;
 	}
       }
@@ -5223,12 +5233,15 @@ pthread_handler_t handle_connections_soc
 #endif /* HAVE_LIBWRAP */
 
     {
-      unsigned short dummy;
-      if(my_socket_get_port(new_sock, &dummy) < 0)
+      size_socket dummyLen;
+      struct sockaddr_storage dummy;                           // WL#4562 IPV6
+      dummyLen = sizeof(dummy);                                // WL#4562 IPV6
+      if (getsockname(new_sock,(struct sockaddr *)&dummy,      // WL#4562 IPV6
+                (SOCKET_SIZE_TYPE *)&dummyLen) < 0)            // WL#4562 IPV6
       {
 	sql_perror("Error on new connection socket");
-	(void) my_shutdown(new_sock, SHUT_RDWR);
-	(void) my_socket_close(new_sock);
+	(void) shutdown(new_sock, SHUT_RDWR);
+	(void) closesocket(new_sock);
 	continue;
       }   
     }
@@ -5239,14 +5252,14 @@ pthread_handler_t handle_connections_soc
 
     if (!(thd= new THD))
     {
-      (void) my_shutdown(new_sock, SHUT_RDWR);
-      my_socket_close(new_sock);
+      (void) shutdown(new_sock, SHUT_RDWR);
+      VOID(closesocket(new_sock));
       continue;
     }
     if (!(vio_tmp=vio_new(new_sock,
-			  my_socket_equal(sock,unix_sock) ? VIO_TYPE_SOCKET :
+			  sock == unix_sock ? VIO_TYPE_SOCKET :
 			  VIO_TYPE_TCPIP,
-			  my_socket_equal(sock,unix_sock) ? VIO_LOCALHOST: 0))||
+			  sock == unix_sock ? VIO_LOCALHOST: 0))||
 	my_net_init(&thd->net,vio_tmp))
     {
       /*
@@ -5258,13 +5271,13 @@ pthread_handler_t handle_connections_soc
         vio_delete(vio_tmp);
       else
       {
-	(void) my_shutdown(new_sock, SHUT_RDWR);
-	(void) my_socket_close(new_sock);
+	(void) shutdown(new_sock, SHUT_RDWR);
+	(void) closesocket(new_sock);
       }
       delete thd;
       continue;
     }
-    if (my_socket_equal(sock,unix_sock))
+    if (sock == unix_sock)
       thd->security_ctx->host=(char*) my_localhost;
 
     create_new_thread(thd);
@@ -7913,8 +7926,7 @@ static int mysql_init_variables(void)
   if (error)
     return 1;
   opt_specialflag= SPECIAL_ENGLISH;
-  my_socket_invalidate(&unix_sock);
-  my_socket_invalidate(&ip_sock);
+  unix_sock= ip_sock= INVALID_SOCKET;
   mysql_home_ptr= mysql_home;
   pidfile_name_ptr= pidfile_name;
   log_error_file_ptr= log_error_file;

=== modified file 'sql/net_serv.cc'
--- a/sql/net_serv.cc	2009-10-01 07:16:52 +0000
+++ b/sql/net_serv.cc	2010-04-13 16:01:38 +0000
@@ -48,7 +48,6 @@
 #include <my_sys.h>
 #include <m_string.h>
 #include <my_net.h>
-#include <my_socket.h>
 #include <violite.h>
 #include <signal.h>
 #include <errno.h>
@@ -143,8 +142,7 @@ my_bool my_net_init(NET *net, Vio* vio)
 
   if (vio != 0)					/* If real connection */
   {
-    /* Return native socket type in net->fd as is part of ABI */
-    net->fd  = MY_SOCKET_FORMAT_VALUE(vio_fd(vio));	/* For perl DBI/DBD */
+    net->fd  = vio_fd(vio);	/* For perl DBI/DBD */
 #if defined(MYSQL_SERVER) && !defined(__WIN__)
     if (!(test_flags & TEST_BLOCKING))
     {
@@ -232,7 +230,7 @@ static int net_data_is_ready(my_socket s
   struct pollfd ufds;
   int res;
 
-  ufds.fd= sd.fd;
+  ufds.fd= sd;
   ufds.events= POLLIN | POLLPRI;
   if (!(res= poll(&ufds, 1, 0)))
     return 0;
@@ -252,14 +250,14 @@ static int net_data_is_ready(my_socket s
 #endif
 
   FD_ZERO(&sfds);
-  my_FD_SET(sd, &sfds);
+  FD_SET(sd, &sfds);
 
   tv.tv_sec= tv.tv_usec= 0;
 
-  if ((res= select(my_socket_nfds(sd,0)+1, &sfds, NULL, NULL, &tv)) < 0)
+  if ((res= select((int) (sd + 1), &sfds, NULL, NULL, &tv)) < 0)
     return 0;
   else
-    return test(res ? my_FD_ISSET(sd, &sfds) : 0);
+    return test(res ? FD_ISSET(sd, &sfds) : 0);
 #endif /* HAVE_POLL */
 }
 

=== modified file 'sql/sql_connect.cc'
--- a/sql/sql_connect.cc	2010-03-12 11:56:09 +0000
+++ b/sql/sql_connect.cc	2010-04-13 16:01:38 +0000
@@ -22,6 +22,9 @@
 */
 
 #include "mysql_priv.h"
+#ifndef __WIN__
+#include <netdb.h>
+#endif
 
 #ifdef HAVE_OPENSSL
 /*

=== modified file 'storage/ndb/include/kernel/ndb_limits.h'
--- a/storage/ndb/include/kernel/ndb_limits.h	2009-06-22 14:29:27 +0000
+++ b/storage/ndb/include/kernel/ndb_limits.h	2010-04-30 09:41:04 +0000
@@ -74,7 +74,7 @@
 #define NDB_MAX_TABLES 20320                /* SchemaFile.hpp */
 #define MAX_TAB_NAME_SIZE 128
 #define MAX_ATTR_NAME_SIZE NAME_LEN       /* From mysql_com.h */
-#define MAX_ATTR_DEFAULT_VALUE_SIZE 128
+#define MAX_ATTR_DEFAULT_VALUE_SIZE ((MAX_TUPLE_SIZE_IN_WORDS + 1) * 4)  //Add 1 word for AttributeHeader
 #define MAX_ATTRIBUTES_IN_TABLE 128
 #define MAX_ATTRIBUTES_IN_INDEX 32
 #define MAX_TUPLE_SIZE_IN_WORDS 2013

=== modified file 'storage/ndb/include/kernel/signaldata/DictTabInfo.hpp'
--- a/storage/ndb/include/kernel/signaldata/DictTabInfo.hpp	2009-05-27 15:21:45 +0000
+++ b/storage/ndb/include/kernel/signaldata/DictTabInfo.hpp	2010-04-29 14:52:05 +0000
@@ -166,8 +166,14 @@ public:
     AttributeExtScale      = 1015, //Default 0
     AttributeExtLength     = 1016, //Default 0
     AttributeAutoIncrement = 1017, //Default false
-    AttributeDefaultValue  = 1018, //Default value (printable string),
     AttributeArrayType     = 1019, //Default NDB_ARRAYTYPE_FIXED
+    AttributeDefaultValueLen = 1020, //Actual Length saved in AttributeDefaultValue
+    /* Default value (Binary type, not printable as string),
+     * For backward compatibility, the new keyValue
+     * (not use the old keyValue 1018) is added
+       when restoring data from low backup version data.
+    */
+    AttributeDefaultValue = 1021,
     AttributeEnd           = 1999  //
   };
   // ----------------------------------------------------------------------
@@ -434,7 +440,8 @@ public:
     Uint32 AttributeAutoIncrement;
     Uint32 AttributeStorageType;
     Uint32 AttributeDynamic;
-    char   AttributeDefaultValue[MAX_ATTR_DEFAULT_VALUE_SIZE];
+    Uint32 AttributeDefaultValueLen;  //byte sizes
+    Uint8  AttributeDefaultValue[MAX_ATTR_DEFAULT_VALUE_SIZE];
     
     Attribute() {}
     void init();
@@ -588,8 +595,11 @@ public:
       fprintf(out, "AttributeExtPrecision = %d\n", AttributeExtPrecision);
       fprintf(out, "AttributeExtScale = %d\n", AttributeExtScale);
       fprintf(out, "AttributeExtLength = %d\n", AttributeExtLength);
-      fprintf(out, "AttributeDefaultValue = \"%s\"\n",
-        AttributeDefaultValue ? AttributeDefaultValue : "");
+      fprintf(out, "AttributeDefaultValueLen = %d\n",
+              AttributeDefaultValueLen);
+      fprintf(out, "AttributeDefaultValue: \n");
+      for (unsigned int i = 0; i < AttributeDefaultValueLen; i++)
+        fprintf(out, "0x%x", AttributeDefaultValue[i]);
     }
   };
   

=== modified file 'storage/ndb/include/kernel/signaldata/LqhFrag.hpp'
--- a/storage/ndb/include/kernel/signaldata/LqhFrag.hpp	2009-05-27 15:21:45 +0000
+++ b/storage/ndb/include/kernel/signaldata/LqhFrag.hpp	2010-04-29 14:52:05 +0000
@@ -215,6 +215,7 @@ public:
   STATIC_CONST( HeaderLength = 4 );
   STATIC_CONST( EntryLength = 3 );
   STATIC_CONST( MAX_ATTRIBUTES = 6 );
+  STATIC_CONST( DEFAULT_VALUE_SECTION_NUM = 0 );
   struct Entry {
     Uint32 attrId;              // for index, includes primary attr id << 16
     Uint32 attrDescriptor;      // 2 words type info

=== modified file 'storage/ndb/include/kernel/signaldata/TupFrag.hpp'
--- a/storage/ndb/include/kernel/signaldata/TupFrag.hpp	2009-05-27 15:21:45 +0000
+++ b/storage/ndb/include/kernel/signaldata/TupFrag.hpp	2010-04-29 14:52:05 +0000
@@ -123,6 +123,7 @@ class TupAddAttrReq {
   friend class Dbtux;
 public:
   STATIC_CONST( SignalLength = 5 );
+  STATIC_CONST( DEFAULT_VALUE_SECTION_NUM = 0 );
 private:
   Uint32 tupConnectPtr;
   Uint32 notused1;

=== modified file 'storage/ndb/include/ndb_version.h.in'
--- a/storage/ndb/include/ndb_version.h.in	2010-03-02 15:37:59 +0000
+++ b/storage/ndb/include/ndb_version.h.in	2010-04-29 14:52:05 +0000
@@ -386,4 +386,21 @@ ndb_route_exec_frag(Uint32 x)
   return x >= NDBD_ROUTE_EXEC_FRAG;
 }
 
+#define NDBD_NATIVE_DEFAULT_SUPPORT_70 NDB_MAKE_VERSION(7,0,15)
+#define NDBD_NATIVE_DEFAULT_SUPPORT_71 NDB_MAKE_VERSION(7,1,4)
+
+static
+inline
+int
+ndb_native_default_support(Uint32 x)
+{
+  const Uint32 major = (x >> 16) & 0xFF;
+  const Uint32 minor = (x >>  8) & 0xFF;
+
+  if (major == 7 && minor == 0)
+    return x >= NDBD_NATIVE_DEFAULT_SUPPORT_70;
+  
+  return x >= NDBD_NATIVE_DEFAULT_SUPPORT_71;
+}
+
 #endif

=== modified file 'storage/ndb/include/ndbapi/NdbDictionary.hpp'
--- a/storage/ndb/include/ndbapi/NdbDictionary.hpp	2010-03-01 14:13:01 +0000
+++ b/storage/ndb/include/ndbapi/NdbDictionary.hpp	2010-04-29 14:52:05 +0000
@@ -565,14 +565,32 @@ public:
 
     /** @} *******************************************************************/
 
+#ifndef DOXYGEN_SHOULD_SKIP_DEPRECATED
+    int setDefaultValue(const char*);
+#endif
+    /* setDefaultValue
+     * Set buf to NULL for no default value, or null default value for
+     * NULLABLE column, otherwise set buf to pointer to default value.
+     * The len parameter is the number of significant bytes of default
+     * value supplied, which is the type size for fixed size types.
+     * For variable length types, the leading 1 or 2 bytes pointed to 
+     * by buf also contain length information as normal for the type.
+     */
+    int setDefaultValue(const void* buf, unsigned int len);
+
+    /* getDefaultValue
+     * Get the default value data for this column.
+     * Optional int len* will be updated with the significant length 
+     * of the default value, or set to 0 for NULL or no default.
+     */
+    const void* getDefaultValue(unsigned int* len = 0) const;
+
 #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
     const Table * getBlobTable() const;
 
     void setAutoIncrement(bool);
     bool getAutoIncrement() const;
     void setAutoIncrementInitialValue(Uint64 val);
-    int setDefaultValue(const char*);   
-    const char* getDefaultValue() const;
 
     static const Column * FRAGMENT;
     static const Column * FRAGMENT_FIXED_MEMORY;
@@ -1063,6 +1081,12 @@ public:
      */
     Uint32 getPartitionId(Uint32 hashvalue) const ;
 
+    /*
+     * Return TRUE if any of the columns in the table have a 
+     * non NULL default value defined
+     */ 
+    bool hasDefaultValues() const;
+
   private:
 #ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
     friend class Ndb;
@@ -2518,8 +2542,32 @@ public:
       createRecord
     */
     void releaseRecord(NdbRecord *rec);
+  }; // class Dictionary
+
+  class NdbDataPrintFormat
+  {
+  public:
+    NdbDataPrintFormat();
+    virtual ~NdbDataPrintFormat();
+    const char *lines_terminated_by;
+    const char *fields_terminated_by;
+    const char *start_array_enclosure;
+    const char *end_array_enclosure;
+    const char *fields_enclosed_by;
+    const char *fields_optionally_enclosed_by;
+    const char *hex_prefix;
+    const char *null_string;
+    int hex_format;
   };
-};
+
+  static 
+  class NdbOut& printFormattedValue(class NdbOut& out, 
+                                    const NdbDataPrintFormat& format,
+                                    const NdbDictionary::Column* c,
+                                    const void* val);
+  
+
+}; // class NdbDictionary
 
 class NdbOut& operator <<(class NdbOut& out, const NdbDictionary::Column& col);
 

=== modified file 'storage/ndb/include/ndbapi/NdbRecAttr.hpp'
--- a/storage/ndb/include/ndbapi/NdbRecAttr.hpp	2009-09-02 07:15:55 +0000
+++ b/storage/ndb/include/ndbapi/NdbRecAttr.hpp	2010-04-30 09:41:04 +0000
@@ -464,21 +464,15 @@ NdbRecAttr::setUNDEFINED()
 
 class NdbOut& operator <<(class NdbOut&, const NdbRecAttr &);
 
-class NdbRecordPrintFormat
+class NdbRecordPrintFormat : public NdbDictionary::NdbDataPrintFormat
 {
 public:
-  NdbRecordPrintFormat();
-  virtual ~NdbRecordPrintFormat();
-  const char *lines_terminated_by;
-  const char *fields_terminated_by;
-  const char *start_array_enclosure;
-  const char *end_array_enclosure;
-  const char *fields_enclosed_by;
-  const char *fields_optionally_enclosed_by;
-  const char *hex_prefix;
-  const char *null_string;
-  int hex_format;
+  NdbRecordPrintFormat() : NdbDataPrintFormat() {};
+  virtual ~NdbRecordPrintFormat() {};
 };
+
+/* See also NdbDictionary::printFormattedValue() */
+
 NdbOut&
 ndbrecattr_print_formatted(NdbOut& out, const NdbRecAttr &r,
                            const NdbRecordPrintFormat &f);

=== modified file 'storage/ndb/include/portlib/NdbTCP.h'
--- a/storage/ndb/include/portlib/NdbTCP.h	2010-04-09 12:39:23 +0000
+++ b/storage/ndb/include/portlib/NdbTCP.h	2010-04-29 07:35:54 +0000
@@ -21,9 +21,9 @@
 
 #include <ndb_global.h>
 #include <ndb_net.h>
-#include <my_socket.h>
+#include <ndb_socket.h>
 
-#define NDB_SOCKET_TYPE my_socket
+#define NDB_SOCKET_TYPE ndb_socket_t
 #define _NDB_CLOSE_SOCKET(x) my_socket_close(x)
 
 #ifdef	__cplusplus
@@ -46,7 +46,7 @@ int Ndb_getInAddr(struct in_addr * dst, 
 #ifdef DBUG_OFF
 #define NDB_CLOSE_SOCKET(fd) _NDB_CLOSE_SOCKET(fd)
 #else
-int NDB_CLOSE_SOCKET(my_socket fd);
+int NDB_CLOSE_SOCKET(NDB_SOCKET_TYPE fd);
 #endif
 
 int Ndb_check_socket_hup(NDB_SOCKET_TYPE sock);

=== renamed file 'include/my_socket.h' => 'storage/ndb/include/portlib/ndb_socket.h'
--- a/include/my_socket.h	2009-10-20 14:44:42 +0000
+++ b/storage/ndb/include/portlib/ndb_socket.h	2010-04-13 16:01:38 +0000
@@ -4,9 +4,9 @@
 
 
 #ifdef __WIN__
-#include <my_socket_win32.h>
+#include <ndb_socket_win32.h>
 #else
-#include <my_socket_posix.h>
+#include <ndb_socket_posix.h>
 #endif
 
 C_MODE_START
@@ -14,7 +14,7 @@ C_MODE_START
 /*
   create a pair of connected sockets
 */
-int my_socketpair(my_socket s[2]);
+int my_socketpair(ndb_socket_t s[2]);
 
 C_MODE_END
 

=== renamed file 'include/my_socket_posix.h' => 'storage/ndb/include/portlib/ndb_socket_posix.h'
--- a/include/my_socket_posix.h	2010-03-01 21:51:49 +0000
+++ b/storage/ndb/include/portlib/ndb_socket_posix.h	2010-04-13 16:01:38 +0000
@@ -10,32 +10,32 @@
 #define MY_SOCKET_FORMAT "%d"
 #define MY_SOCKET_FORMAT_VALUE(x) (x.fd)
 
-typedef struct { int fd; } my_socket;
+typedef struct { int fd; } ndb_socket_t;
 
-static inline int my_socket_valid(my_socket s)
+static inline int my_socket_valid(ndb_socket_t s)
 {
   return (s.fd != -1);
 }
 
-static inline my_socket* my_socket_invalidate(my_socket *s)
+static inline ndb_socket_t* my_socket_invalidate(ndb_socket_t *s)
 {
   s->fd= -1;
   return s;
 }
 
-static inline my_socket my_socket_create_invalid()
+static inline ndb_socket_t my_socket_create_invalid()
 {
-  my_socket s;
+  ndb_socket_t s;
   my_socket_invalidate(&s);
   return s;
 }
 
-static inline int my_socket_get_fd(my_socket s)
+static inline int my_socket_get_fd(ndb_socket_t s)
 {
   return s.fd;
 }
 
-static inline int my_socket_close(my_socket s)
+static inline int my_socket_close(ndb_socket_t s)
 {
   return close(s.fd);
 }
@@ -50,40 +50,40 @@ static inline void my_socket_set_errno(i
   errno= error;
 }
 
-static inline my_socket my_socket_create(int domain, int type, int protocol)
+static inline ndb_socket_t my_socket_create(int domain, int type, int protocol)
 {
-  my_socket s;
+  ndb_socket_t s;
   s.fd= socket(domain, type, protocol);
 
   return s;
 }
 
-static inline int my_socket_nfds(my_socket s, int nfds)
+static inline int my_socket_nfds(ndb_socket_t s, int nfds)
 {
   if(s.fd > nfds)
     return s.fd;
   return nfds;
 }
 
-static inline size_t my_recv(my_socket s, char* buf, size_t len, int flags)
+static inline size_t my_recv(ndb_socket_t s, char* buf, size_t len, int flags)
 {
   return recv(s.fd, buf, len, flags);
 }
 
 static inline
-size_t my_send(my_socket s, const char* buf, size_t len, int flags)
+size_t my_send(ndb_socket_t s, const char* buf, size_t len, int flags)
 {
   return send(s.fd, buf, len, flags);
 }
 
-static inline int my_socket_reuseaddr(my_socket s, int enable)
+static inline int my_socket_reuseaddr(ndb_socket_t s, int enable)
 {
   const int on = enable;
   return setsockopt(s.fd, SOL_SOCKET, SO_REUSEADDR,
                     (const void*)&on, sizeof(on));
 }
 
-static inline int my_socket_nonblock(my_socket s, int enable)
+static inline int my_socket_nonblock(ndb_socket_t s, int enable)
 {
   int flags;
   flags = fcntl(s.fd, F_GETFL, 0);
@@ -108,18 +108,18 @@ static inline int my_socket_nonblock(my_
 #undef NONBLOCKFLAG
 }
 
-static inline int my_bind(my_socket s, const struct sockaddr *my_addr,
+static inline int my_bind(ndb_socket_t s, const struct sockaddr *my_addr,
                           SOCKET_SIZE_TYPE len)
 {
   return bind(s.fd, my_addr, len);
 }
 
-static inline int my_bind_inet(my_socket s, const struct sockaddr_in *my_addr)
+static inline int my_bind_inet(ndb_socket_t s, const struct sockaddr_in *my_addr)
 {
   return bind(s.fd, (struct sockaddr*)my_addr, sizeof(struct sockaddr_in));
 }
 
-static inline int my_socket_get_port(my_socket s, unsigned short *port)
+static inline int my_socket_get_port(ndb_socket_t s, unsigned short *port)
 {
   struct sockaddr_in servaddr;
   SOCKET_SIZE_TYPE sock_len = sizeof(servaddr);
@@ -131,41 +131,41 @@ static inline int my_socket_get_port(my_
   return 0;
 }
 
-static inline int my_listen(my_socket s, int backlog)
+static inline int my_listen(ndb_socket_t s, int backlog)
 {
   return listen(s.fd, backlog);
 }
 
 static inline
-my_socket my_accept(my_socket s, struct sockaddr *addr,
+ndb_socket_t my_accept(ndb_socket_t s, struct sockaddr *addr,
                     SOCKET_SIZE_TYPE *addrlen)
 {
-  my_socket r;
+  ndb_socket_t r;
   r.fd= accept(s.fd, addr, addrlen);
   return r;
 }
 
-static inline int my_connect_inet(my_socket s, const struct sockaddr_in *addr)
+static inline int my_connect_inet(ndb_socket_t s, const struct sockaddr_in *addr)
 {
   return connect(s.fd, (const struct sockaddr*)addr,
                  sizeof(struct sockaddr_in));
 }
 
 static inline
-int my_getsockopt(my_socket s, int level, int optname,
+int my_getsockopt(ndb_socket_t s, int level, int optname,
                   void *optval, SOCKET_SIZE_TYPE *optlen)
 {
   return getsockopt(s.fd, level, optname, optval, optlen);
 }
 
 static inline
-int my_setsockopt(my_socket s, int level, int optname,
+int my_setsockopt(ndb_socket_t s, int level, int optname,
                   void *optval, SOCKET_SIZE_TYPE optlen)
 {
   return setsockopt(s.fd, level, optname, optval, optlen);
 }
 
-static inline int my_socket_connect_address(my_socket s, struct in_addr *a)
+static inline int my_socket_connect_address(ndb_socket_t s, struct in_addr *a)
 {
   struct sockaddr_in addr;
   SOCKET_SIZE_TYPE addrlen= sizeof(addr);
@@ -176,7 +176,7 @@ static inline int my_socket_connect_addr
   return 0;
 }
 
-static inline int my_getpeername(my_socket s, struct sockaddr *a, SOCKET_SIZE_TYPE *addrlen)
+static inline int my_getpeername(ndb_socket_t s, struct sockaddr *a, SOCKET_SIZE_TYPE *addrlen)
 {
   if(getpeername(s.fd, a, addrlen))
     return my_socket_errno();
@@ -184,22 +184,22 @@ static inline int my_getpeername(my_sock
   return 0;
 }
 
-static inline int my_shutdown(my_socket s, int how)
+static inline int my_shutdown(ndb_socket_t s, int how)
 {
   return shutdown(s.fd, how);
 }
 
-static inline int my_socket_equal(my_socket s1, my_socket s2)
+static inline int my_socket_equal(ndb_socket_t s1, ndb_socket_t s2)
 {
   return s1.fd==s2.fd;
 }
 
-static inline ssize_t my_socket_readv(my_socket s, const struct iovec *iov,
+static inline ssize_t my_socket_readv(ndb_socket_t s, const struct iovec *iov,
                                       int iovcnt)
 {
   return readv(s.fd, iov, iovcnt);
 }
-static inline ssize_t my_socket_writev(my_socket s, const struct iovec *iov,
+static inline ssize_t my_socket_writev(ndb_socket_t s, const struct iovec *iov,
                                        int iovcnt)
 {
   return writev(s.fd, iov, iovcnt);

=== renamed file 'include/my_socket_win32.h' => 'storage/ndb/include/portlib/ndb_socket_win32.h'
--- a/include/my_socket_win32.h	2009-06-01 15:13:46 +0000
+++ b/storage/ndb/include/portlib/ndb_socket_win32.h	2010-04-13 16:01:38 +0000
@@ -2,37 +2,37 @@
 #include <winsock2.h>
 #include <ws2tcpip.h>
 
-#include <my_global.h>
+#include <ndb_global.h>
 
 #define MY_SOCKET_FORMAT "%p"
 #define MY_SOCKET_FORMAT_VALUE(x) (x.s)
 
-typedef struct { SOCKET s; } my_socket;
+typedef struct { SOCKET s; } ndb_socket_t;
 
-static inline int my_socket_valid(my_socket s)
+static inline int my_socket_valid(ndb_socket_t s)
 {
   return (s.s != INVALID_SOCKET);
 }
 
-static inline my_socket* my_socket_invalidate(my_socket *s)
+static inline ndb_socket_t* my_socket_invalidate(ndb_socket_t *s)
 {
   s->s= INVALID_SOCKET;
   return s;
 }
 
-static inline my_socket my_socket_create_invalid()
+static inline ndb_socket_t my_socket_create_invalid()
 {
-  my_socket s;
+  ndb_socket_t s;
   my_socket_invalidate(&s);
   return s;
 }
 
-static inline SOCKET my_socket_get_fd(my_socket s)
+static inline SOCKET my_socket_get_fd(ndb_socket_t s)
 {
   return s.s;
 }
 
-static inline int my_socket_close(my_socket s)
+static inline int my_socket_close(ndb_socket_t s)
 {
   return closesocket(s.s);
 }
@@ -47,21 +47,21 @@ static inline void my_socket_set_errno(i
   WSASetLastError(error);
 }
 
-static inline my_socket my_socket_create(int domain, int type, int protocol)
+static inline ndb_socket_t my_socket_create(int domain, int type, int protocol)
 {
-  my_socket s;
+  ndb_socket_t s;
   s.s= socket(domain, type, protocol);
 
   return s;
 }
 
-static inline int my_socket_nfds(my_socket s, int nfds)
+static inline int my_socket_nfds(ndb_socket_t s, int nfds)
 {
   (void)s;
   return nfds;
 }
 
-static inline size_t my_recv(my_socket s, char* buf, size_t len, int flags)
+static inline size_t my_recv(ndb_socket_t s, char* buf, size_t len, int flags)
 {
   int ret= recv(s.s, buf, len, flags);
   if (ret == SOCKET_ERROR)
@@ -70,7 +70,7 @@ static inline size_t my_recv(my_socket s
 }
 
 static inline
-size_t my_send(my_socket s, const char* buf, size_t len, int flags)
+size_t my_send(ndb_socket_t s, const char* buf, size_t len, int flags)
 {
   int ret= send(s.s, buf, len, flags);
   if (ret == SOCKET_ERROR)
@@ -78,14 +78,14 @@ size_t my_send(my_socket s, const char* 
   return ret;
 }
 
-static inline int my_socket_reuseaddr(my_socket s, int enable)
+static inline int my_socket_reuseaddr(ndb_socket_t s, int enable)
 {
   const int on = enable;
   return setsockopt(s.s, SOL_SOCKET, SO_REUSEADDR,
                     (const char*)&on, sizeof(on));
 }
 
-static inline int my_socket_nonblock(my_socket s, int enable)
+static inline int my_socket_nonblock(ndb_socket_t s, int enable)
 {
   unsigned long  ul = enable;
 
@@ -95,18 +95,18 @@ static inline int my_socket_nonblock(my_
   return 0;
 }
 
-static inline int my_bind(my_socket s, const struct sockaddr *my_addr,
+static inline int my_bind(ndb_socket_t s, const struct sockaddr *my_addr,
                           SOCKET_SIZE_TYPE len)
 {
   return bind(s.s, my_addr, len);
 }
 
-static inline int my_bind_inet(my_socket s, const struct sockaddr_in *my_addr)
+static inline int my_bind_inet(ndb_socket_t s, const struct sockaddr_in *my_addr)
 {
   return bind(s.s, (const struct sockaddr*)my_addr, sizeof(struct sockaddr_in));
 }
 
-static inline int my_socket_get_port(my_socket s, unsigned short *port)
+static inline int my_socket_get_port(ndb_socket_t s, unsigned short *port)
 {
   struct sockaddr_in servaddr;
   SOCKET_SIZE_TYPE sock_len = sizeof(servaddr);
@@ -118,41 +118,41 @@ static inline int my_socket_get_port(my_
   return 0;
 }
 
-static inline int my_listen(my_socket s, int backlog)
+static inline int my_listen(ndb_socket_t s, int backlog)
 {
   return listen(s.s, backlog);
 }
 
 static inline
-my_socket my_accept(my_socket s, struct sockaddr *addr,
+ndb_socket_t my_accept(ndb_socket_t s, struct sockaddr *addr,
                     SOCKET_SIZE_TYPE *addrlen)
 {
-  my_socket r;
+  ndb_socket_t r;
   r.s= accept(s.s, addr, addrlen);
   return r;
 }
 
-static inline int my_connect_inet(my_socket s, const struct sockaddr_in *addr)
+static inline int my_connect_inet(ndb_socket_t s, const struct sockaddr_in *addr)
 {
   return connect(s.s, (const struct sockaddr*) addr,
                  sizeof(struct sockaddr_in));
 }
 
 static inline
-int my_getsockopt(my_socket s, int level, int optname,
+int my_getsockopt(ndb_socket_t s, int level, int optname,
                   void *optval, SOCKET_SIZE_TYPE *optlen)
 {
   return getsockopt(s.s, level, optname, (char*)optval, optlen);
 }
 
 static inline
-int my_setsockopt(my_socket s, int level, int optname,
+int my_setsockopt(ndb_socket_t s, int level, int optname,
                   void *optval, SOCKET_SIZE_TYPE optlen)
 {
   return setsockopt(s.s, level, optname, (char*)optval, optlen);
 }
 
-static inline int my_socket_connect_address(my_socket s, struct in_addr *a)
+static inline int my_socket_connect_address(ndb_socket_t s, struct in_addr *a)
 {
   struct sockaddr_in addr;
   SOCKET_SIZE_TYPE addrlen= sizeof(addr);
@@ -163,7 +163,7 @@ static inline int my_socket_connect_addr
   return 0;
 }
 
-static inline int my_getpeername(my_socket s, struct sockaddr *a,
+static inline int my_getpeername(ndb_socket_t s, struct sockaddr *a,
                                  SOCKET_SIZE_TYPE *addrlen)
 {
   if(getpeername(s.s, a, addrlen))
@@ -172,12 +172,12 @@ static inline int my_getpeername(my_sock
   return 0;
 }
 
-static inline int my_shutdown(my_socket s, int how)
+static inline int my_shutdown(ndb_socket_t s, int how)
 {
   return shutdown(s.s, how);
 }
 
-static inline int my_socket_equal(my_socket s1, my_socket s2)
+static inline int my_socket_equal(ndb_socket_t s1, ndb_socket_t s2)
 {
   return s1.s==s2.s;
 }
@@ -192,7 +192,7 @@ struct iovec {
   void*  iov_base;  /* 'char*  buf' in WSABUF */
 };
 
-static inline ssize_t my_socket_readv(my_socket s, const struct iovec *iov,
+static inline ssize_t my_socket_readv(ndb_socket_t s, const struct iovec *iov,
                                       int iovcnt)
 {
   DWORD rv=0;
@@ -201,7 +201,7 @@ static inline ssize_t my_socket_readv(my
   return rv;
 }
 
-static inline ssize_t my_socket_writev(my_socket s, const struct iovec *iov,
+static inline ssize_t my_socket_writev(ndb_socket_t s, const struct iovec *iov,
                                        int iovcnt)
 {
   DWORD rv=0;

=== modified file 'storage/ndb/include/util/SocketAuthenticator.hpp'
--- a/storage/ndb/include/util/SocketAuthenticator.hpp	2009-05-27 15:21:45 +0000
+++ b/storage/ndb/include/util/SocketAuthenticator.hpp	2010-04-13 16:01:38 +0000
@@ -24,8 +24,8 @@ class SocketAuthenticator
 public:
   SocketAuthenticator() {}
   virtual ~SocketAuthenticator() {};
-  virtual bool client_authenticate(my_socket sockfd) = 0;
-  virtual bool server_authenticate(my_socket sockfd) = 0;
+  virtual bool client_authenticate(NDB_SOCKET_TYPE sockfd) = 0;
+  virtual bool server_authenticate(NDB_SOCKET_TYPE sockfd) = 0;
 };
 
 class SocketAuthSimple : public SocketAuthenticator
@@ -35,8 +35,8 @@ class SocketAuthSimple : public SocketAu
 public:
   SocketAuthSimple(const char *username, const char *passwd);
   virtual ~SocketAuthSimple();
-  virtual bool client_authenticate(my_socket sockfd);
-  virtual bool server_authenticate(my_socket sockfd);
+  virtual bool client_authenticate(NDB_SOCKET_TYPE sockfd);
+  virtual bool server_authenticate(NDB_SOCKET_TYPE sockfd);
 };
 
 #endif // SOCKET_AUTHENTICATOR_HPP

=== modified file 'storage/ndb/include/util/UtilBuffer.hpp'
--- a/storage/ndb/include/util/UtilBuffer.hpp	2009-05-26 18:53:34 +0000
+++ b/storage/ndb/include/util/UtilBuffer.hpp	2010-04-29 14:52:05 +0000
@@ -104,6 +104,14 @@ public:
     else
       return (memcmp(get_data(), cmp.get_data(), len) == 0);
   }
+
+  int assign(const UtilBuffer& buf) {
+    int ret = 0;
+    if(this != &buf) {
+      ret = assign(buf.get_data(), buf.length());
+    }
+    return ret;
+  }
 private:
   void *data;          /* Pointer to data storage */
   size_t len;          /* Size of the stored data */

=== modified file 'storage/ndb/src/common/debugger/signaldata/DictTabInfo.cpp'
--- a/storage/ndb/src/common/debugger/signaldata/DictTabInfo.cpp	2009-05-27 15:21:45 +0000
+++ b/storage/ndb/src/common/debugger/signaldata/DictTabInfo.cpp	2010-04-29 14:52:05 +0000
@@ -100,8 +100,12 @@ DictTabInfo::AttributeMapping[] = {
   DTIMAP(Attribute, AttributeExtScale, AttributeExtScale),
   DTIMAP(Attribute, AttributeExtLength, AttributeExtLength),
   DTIMAP2(Attribute, AttributeAutoIncrement, AttributeAutoIncrement, 0, 1),
-  DTIMAPS(Attribute, AttributeDefaultValue, AttributeDefaultValue,
-    0, MAX_ATTR_DEFAULT_VALUE_SIZE),
+
+  DTIMAP2(Attribute, AttributeDefaultValueLen, AttributeDefaultValueLen,
+          0, MAX_ATTR_DEFAULT_VALUE_SIZE),
+  DTIMAPB(Attribute, AttributeDefaultValue, AttributeDefaultValue,
+    0, MAX_ATTR_DEFAULT_VALUE_SIZE, AttributeDefaultValueLen),
+
   DTIBREAK(AttributeEnd)
 };
 
@@ -198,7 +202,8 @@ DictTabInfo::Attribute::init(){
   AttributeAutoIncrement = false;
   AttributeStorageType = 0;
   AttributeDynamic = 0;                         // Default is not dynamic
-  memset(AttributeDefaultValue, 0, sizeof(AttributeDefaultValue));//AttributeDefaultValue[0] = 0;
+  AttributeDefaultValueLen = 0;                 //Default byte sizes of binary default value is 0
+  memset(AttributeDefaultValue, 0, sizeof(AttributeDefaultValue));
 }
 
 //static 

=== modified file 'storage/ndb/src/common/portlib/CMakeLists.txt'
--- a/storage/ndb/src/common/portlib/CMakeLists.txt	2009-12-17 00:54:38 +0000
+++ b/storage/ndb/src/common/portlib/CMakeLists.txt	2010-04-13 16:01:38 +0000
@@ -23,7 +23,7 @@ IF(WIN32)
  SET(EXTRA_LIB wsock32 ws2_32)
 ENDIF(WIN32)
 ADD_LIBRARY(ndbportlib STATIC
-            NdbCondition.c NdbMutex.c
+            NdbCondition.c NdbMutex.c ndb_socket.cpp
             NdbEnv.c NdbThread.c NdbHost.c NdbTCP.cpp
             NdbMem.c NdbConfig.c NdbTick.c NdbDir.cpp NdbDaemon.c
             my_daemon.cc ${CMAKE_SOURCE_DIR}/sql/nt_servc.cc

=== modified file 'storage/ndb/src/common/portlib/Makefile.am'
--- a/storage/ndb/src/common/portlib/Makefile.am	2009-12-17 00:54:38 +0000
+++ b/storage/ndb/src/common/portlib/Makefile.am	2010-04-13 16:01:38 +0000
@@ -22,7 +22,7 @@ libportlib_la_SOURCES = \
 	NdbCondition.c NdbMutex.c NdbTick.c \
 	NdbEnv.c NdbThread.c NdbHost.c NdbTCP.cpp	    \
 	NdbDaemon.c my_daemon.cc NdbMem.c \
-	NdbConfig.c NdbDir.cpp
+	NdbConfig.c NdbDir.cpp ndb_socket.cpp
 
 include $(top_srcdir)/storage/ndb/config/common.mk.am
 include $(top_srcdir)/storage/ndb/config/type_util.mk.am

=== modified file 'storage/ndb/src/common/portlib/NdbTCP.cpp'
--- a/storage/ndb/src/common/portlib/NdbTCP.cpp	2009-05-27 15:21:45 +0000
+++ b/storage/ndb/src/common/portlib/NdbTCP.cpp	2010-04-13 16:01:38 +0000
@@ -60,7 +60,7 @@ Ndb_getInAddr(struct in_addr * dst, cons
 
 #ifndef DBUG_OFF
 extern "C"
-int NDB_CLOSE_SOCKET(my_socket fd)
+int NDB_CLOSE_SOCKET(NDB_SOCKET_TYPE fd)
 {
   DBUG_PRINT("info", ("NDB_CLOSE_SOCKET(" MY_SOCKET_FORMAT ")",
                       MY_SOCKET_FORMAT_VALUE(fd)));

=== renamed file 'mysys/my_socket.c' => 'storage/ndb/src/common/portlib/ndb_socket.cpp'
--- a/mysys/my_socket.c	2010-03-09 09:18:50 +0000
+++ b/storage/ndb/src/common/portlib/ndb_socket.cpp	2010-04-13 16:01:38 +0000
@@ -18,7 +18,7 @@
 
 #include "my_global.h"
 #include "m_string.h"
-#include "my_socket.h"
+#include "ndb_socket.h"
 
 
 /*
@@ -27,11 +27,11 @@
 
 #if defined _WIN32
 
-int my_socketpair(my_socket s[2])
+int my_socketpair(ndb_socket_t s[2])
 {
   struct sockaddr_in addr;
   SOCKET_SIZE_TYPE addrlen = sizeof(addr);
-  my_socket listener;
+  ndb_socket_t listener;
 
   my_socket_invalidate(&listener);
   my_socket_invalidate(&s[0]);
@@ -96,7 +96,7 @@ err:
 
 #else
 
-int my_socketpair(my_socket s[2])
+int my_socketpair(ndb_socket_t s[2])
 {
   int ret;
   int sock[2];

=== modified file 'storage/ndb/src/common/transporter/TCP_Transporter.cpp'
--- a/storage/ndb/src/common/transporter/TCP_Transporter.cpp	2010-03-11 19:47:09 +0000
+++ b/storage/ndb/src/common/transporter/TCP_Transporter.cpp	2010-04-13 16:01:38 +0000
@@ -244,7 +244,7 @@ TCP_Transporter::setSocketOptions(NDB_SO
   }
 }
 
-bool TCP_Transporter::setSocketNonBlocking(my_socket socket)
+bool TCP_Transporter::setSocketNonBlocking(NDB_SOCKET_TYPE socket)
 {
   if(my_socket_nonblock(socket, true)==0)
     return true;

=== modified file 'storage/ndb/src/common/transporter/Transporter.hpp'
--- a/storage/ndb/src/common/transporter/Transporter.hpp	2009-08-03 15:38:54 +0000
+++ b/storage/ndb/src/common/transporter/Transporter.hpp	2010-04-13 16:01:38 +0000
@@ -32,7 +32,7 @@
 #include <NdbThread.h>
 #include <NdbTick.h>
 
-#include <my_socket.h>
+#include <ndb_socket.h>
 
 class Transporter {
   friend class TransporterRegistry;

=== modified file 'storage/ndb/src/common/transporter/TransporterRegistry.cpp'
--- a/storage/ndb/src/common/transporter/TransporterRegistry.cpp	2009-10-21 19:08:32 +0000
+++ b/storage/ndb/src/common/transporter/TransporterRegistry.cpp	2010-04-13 16:01:38 +0000
@@ -1088,7 +1088,7 @@ TransporterRegistry::change_epoll(TCP_Tr
 {
   struct epoll_event event_poll;
   bzero(&event_poll, sizeof(event_poll));
-  my_socket sock_fd = t->getSocket();
+  NDB_SOCKET_TYPE sock_fd = t->getSocket();
   int node_id = t->getRemoteNodeId();
   int op = add ? EPOLL_CTL_ADD : EPOLL_CTL_DEL;
   int ret_val, error;
@@ -1955,7 +1955,7 @@ bool TransporterRegistry::connect_client
 NDB_SOCKET_TYPE TransporterRegistry::connect_ndb_mgmd(NdbMgmHandle *h)
 {
   struct ndb_mgm_reply mgm_reply;
-  my_socket sockfd;
+  NDB_SOCKET_TYPE sockfd;
   my_socket_invalidate(&sockfd);
 
   DBUG_ENTER("TransporterRegistry::connect_ndb_mgmd(NdbMgmHandle)");
@@ -2013,7 +2013,7 @@ NDB_SOCKET_TYPE TransporterRegistry::con
 NDB_SOCKET_TYPE TransporterRegistry::connect_ndb_mgmd(SocketClient *sc)
 {
   NdbMgmHandle h= ndb_mgm_create_handle();
-  my_socket s;
+  NDB_SOCKET_TYPE s;
   my_socket_invalidate(&s);
 
   DBUG_ENTER("TransporterRegistry::connect_ndb_mgmd(SocketClient)");

=== modified file 'storage/ndb/src/common/util/SocketAuthenticator.cpp'
--- a/storage/ndb/src/common/util/SocketAuthenticator.cpp	2010-01-18 19:20:01 +0000
+++ b/storage/ndb/src/common/util/SocketAuthenticator.cpp	2010-04-13 16:01:38 +0000
@@ -44,7 +44,7 @@ SocketAuthSimple::~SocketAuthSimple()
     free((void*)m_username);
 }
 
-bool SocketAuthSimple::client_authenticate(my_socket sockfd)
+bool SocketAuthSimple::client_authenticate(NDB_SOCKET_TYPE sockfd)
 {
   SocketOutputStream s_output(sockfd);
   SocketInputStream  s_input(sockfd);
@@ -60,7 +60,7 @@ bool SocketAuthSimple::client_authentica
   return false;
 }
 
-bool SocketAuthSimple::server_authenticate(my_socket sockfd)
+bool SocketAuthSimple::server_authenticate(NDB_SOCKET_TYPE sockfd)
 {
 
   SocketOutputStream s_output(sockfd);

=== modified file 'storage/ndb/src/common/util/SocketClient.cpp'
--- a/storage/ndb/src/common/util/SocketClient.cpp	2010-04-09 12:39:23 +0000
+++ b/storage/ndb/src/common/util/SocketClient.cpp	2010-04-29 07:35:54 +0000
@@ -218,7 +218,7 @@ done:
       return m_sockfd;
     }
   }
-  my_socket sockfd= m_sockfd;
+  NDB_SOCKET_TYPE sockfd = m_sockfd;
 
   my_socket_invalidate(&m_sockfd);
 

=== modified file 'storage/ndb/src/common/util/SocketServer.cpp'
--- a/storage/ndb/src/common/util/SocketServer.cpp	2009-09-29 10:26:01 +0000
+++ b/storage/ndb/src/common/util/SocketServer.cpp	2010-04-13 16:01:38 +0000
@@ -64,7 +64,7 @@ SocketServer::tryBind(unsigned short por
       return false;
   }
 
-  const NDB_SOCKET_TYPE sock  = my_socket_create(AF_INET, SOCK_STREAM, 0);
+  const NDB_SOCKET_TYPE sock = my_socket_create(AF_INET, SOCK_STREAM, 0);
   if (!my_socket_valid(sock))
     return false;
 
@@ -103,7 +103,7 @@ SocketServer::setup(SocketServer::Servic
       DBUG_RETURN(false);
   }
   
-  const my_socket sock  = my_socket_create(AF_INET, SOCK_STREAM, 0);
+  const NDB_SOCKET_TYPE sock = my_socket_create(AF_INET, SOCK_STREAM, 0);
   if (!my_socket_valid(sock))
   {
     DBUG_PRINT("error",("socket() - %d - %s",
@@ -191,7 +191,7 @@ SocketServer::doAccept(){
       ServiceInstance & si = m_services[i];
 
       if(my_FD_ISSET(si.m_socket, &readSet)){
-	my_socket childSock = my_accept(si.m_socket, 0, 0);
+	NDB_SOCKET_TYPE childSock = my_accept(si.m_socket, 0, 0);
 	if(!my_socket_valid(childSock))
         {
           m_services.unlock();

=== modified file 'storage/ndb/src/kernel/blocks/ERROR_codes.txt'
--- a/storage/ndb/src/kernel/blocks/ERROR_codes.txt	2010-03-11 09:44:08 +0000
+++ b/storage/ndb/src/kernel/blocks/ERROR_codes.txt	2010-04-29 14:52:05 +0000
@@ -2,7 +2,7 @@ Next QMGR 938
 Next NDBCNTR 1002
 Next NDBFS 2000
 Next DBACC 3002
-Next DBTUP 4032
+Next DBTUP 4035
 Next DBLQH 5055
 Next DBDICT 6025
 Next DBDIH 7221
@@ -531,6 +531,9 @@ Failed Create Table:
 4010 12004: Fail create last attribute in 1st fragment
 4011 12005: Fail create 1st attribute in 2nd fragment
 4012 12006: Fail create last attribute in 2nd fragment
+4032 : Fail to receive first default value
+4033 : Fail to receive last default value
+4034 : Fail to store default values in def values fragment
 
 Drop Table/Index:
 -----------------

=== modified file 'storage/ndb/src/kernel/blocks/dbdict/Dbdict.cpp'
--- a/storage/ndb/src/kernel/blocks/dbdict/Dbdict.cpp	2010-04-27 11:50:25 +0000
+++ b/storage/ndb/src/kernel/blocks/dbdict/Dbdict.cpp	2010-04-29 14:52:05 +0000
@@ -832,8 +832,9 @@ Dbdict::packTableIntoPages(SimplePropert
     
     ConstRope def(c_rope_pool, attrPtr.p->defaultValue);
     def.copy(defaultValue);
-    w.add(DictTabInfo::AttributeDefaultValue, defaultValue);
-    
+
+    w.add(DictTabInfo::AttributeDefaultValueLen, def.size());
+    w.add(DictTabInfo::AttributeDefaultValue, defaultValue, def.size());
     w.add(DictTabInfo::AttributeEnd, 1);
   }
   
@@ -5235,7 +5236,8 @@ void Dbdict::handleTabInfo(SimplePropert
     attrPtr.p->autoIncrement = attrDesc.AttributeAutoIncrement;
     {
       Rope defaultValue(c_rope_pool, attrPtr.p->defaultValue);
-      defaultValue.assign(attrDesc.AttributeDefaultValue);
+      defaultValue.assign((const char*)attrDesc.AttributeDefaultValue,
+                          attrDesc.AttributeDefaultValueLen);
     }
     
     keyCount += attrDesc.AttributeKeyFlag;
@@ -6115,6 +6117,9 @@ Dbdict::sendLQHADDATTRREQ(Signal* signal
 
   LqhAddAttrReq * const req = (LqhAddAttrReq*)signal->getDataPtrSend();
   Uint32 i = 0;
+  Uint32 startIndex = 25;
+  Uint32 *defVal_dst = &signal->theData[startIndex];
+  Uint32 defVal_length = 0;
   for(i = 0; i<LqhAddAttrReq::MAX_ATTRIBUTES && attributePtrI != RNIL; i++){
     jam();
     AttributeRecordPtr attrPtr;
@@ -6125,6 +6130,14 @@ Dbdict::sendLQHADDATTRREQ(Signal* signal
     entry.extTypeInfo = 0;
     // charset number passed to TUP, TUX in upper half
     entry.extTypeInfo |= (attrPtr.p->extPrecision & ~0xFFFF);
+
+    ConstRope def(c_rope_pool, attrPtr.p->defaultValue);
+    def.copy((char*)defVal_dst);
+
+    Uint32 defValueLen = def.size();
+    defVal_length += (defValueLen + 3)/4;
+    defVal_dst += (defValueLen + 3)/4;
+
     if (tabPtr.p->isIndex()) {
       Uint32 primaryAttrId;
       if (attrPtr.p->nextList != RNIL) {
@@ -6165,8 +6178,18 @@ Dbdict::sendLQHADDATTRREQ(Signal* signal
   req->senderAttrPtr = attributePtrI;
   req->noOfAttributes = i;
 
-  sendSignal(DBLQH_REF, GSN_LQHADDATTREQ, signal,
-	     LqhAddAttrReq::HeaderLength + LqhAddAttrReq::EntryLength * i, JBB);
+  if (defVal_length != 0)
+  {
+    LinearSectionPtr ptr[3];
+    ptr[0].p= &signal->theData[startIndex];
+    ptr[0].sz= defVal_length;
+
+    sendSignal(DBLQH_REF, GSN_LQHADDATTREQ, signal,
+       	       LqhAddAttrReq::HeaderLength + LqhAddAttrReq::EntryLength * i, JBB, ptr, 1);
+  }
+  else
+    sendSignal(DBLQH_REF, GSN_LQHADDATTREQ, signal,
+               LqhAddAttrReq::HeaderLength + LqhAddAttrReq::EntryLength * i, JBB);
 }
 
 void

=== modified file 'storage/ndb/src/kernel/blocks/dblqh/Dblqh.hpp'
--- a/storage/ndb/src/kernel/blocks/dblqh/Dblqh.hpp	2010-03-26 18:06:08 +0000
+++ b/storage/ndb/src/kernel/blocks/dblqh/Dblqh.hpp	2010-04-30 09:41:04 +0000
@@ -454,6 +454,8 @@ public:
     Uint16 attrReceived;
     Uint16 totalAttrReceived;
     Uint16 fragCopyCreation;
+    Uint16 defValNextPos;
+    Uint32 defValSectionI;
   };
   typedef Ptr<AddFragRecord> AddFragRecordPtr;
   

=== modified file 'storage/ndb/src/kernel/blocks/dblqh/DblqhMain.cpp'
--- a/storage/ndb/src/kernel/blocks/dblqh/DblqhMain.cpp	2010-03-26 18:06:08 +0000
+++ b/storage/ndb/src/kernel/blocks/dblqh/DblqhMain.cpp	2010-04-30 09:41:04 +0000
@@ -1432,6 +1432,21 @@ void Dblqh::execLQHADDATTREQ(Signal* sig
   addfragptr.p->m_addAttrReq = * req;
 
   const Uint32 tnoOfAttr = req->noOfAttributes;
+  const Uint32 numSections = signal->getNoOfSections();
+  bool isLongReq= ( numSections != 0 );
+  addfragptr.p->defValSectionI = RNIL;
+  addfragptr.p->defValNextPos = 0;
+
+  if (isLongReq)
+  {
+    SectionHandle handle(this, signal);
+    SegmentedSectionPtr defValSection;
+    handle.getSection(defValSection, LqhAddAttrReq::DEFAULT_VALUE_SECTION_NUM);
+    addfragptr.p->defValSectionI = defValSection.i;
+    addfragptr.p->defValNextPos = 0;
+    //Don't free Section here. Section is freed after default values are trasfered to TUP
+    handle.clear();
+  }
 
   ndbrequire(addfragptr.p->addfragStatus == AddFragRecord::WAIT_ADD_ATTR);
   ndbrequire((tnoOfAttr != 0) && (tnoOfAttr <= LqhAddAttrReq::MAX_ATTRIBUTES));
@@ -1504,6 +1519,13 @@ void Dblqh::execTUP_ADD_ATTCONF(Signal* 
       return;
     }
 
+    if (addfragptr.p->defValSectionI != RNIL)
+    {
+      releaseSection(addfragptr.p->defValSectionI);
+      addfragptr.p->defValNextPos = 0;
+      addfragptr.p->defValSectionI = RNIL;
+    }
+
     { // Reply
       LqhAddAttrConf *const conf = (LqhAddAttrConf*)signal->getDataPtrSend();
       conf->senderData = addfragptr.p->m_addAttrReq.senderData;
@@ -1562,6 +1584,13 @@ void Dblqh::execTUP_ADD_ATTRREF(Signal* 
     break;
   }
 
+  if (addfragptr.p->defValSectionI != RNIL)
+  {
+    releaseSection(addfragptr.p->defValSectionI);
+    addfragptr.p->defValNextPos = 0;
+    addfragptr.p->defValSectionI = RNIL;
+  }
+
   const Uint32 Ref = addfragptr.p->m_createTabReq.senderRef;
   const Uint32 senderData = addfragptr.p->m_addAttrReq.senderData;
 
@@ -1608,13 +1637,49 @@ Dblqh::sendAddAttrReq(Signal* signal)
       jam();
       TupAddAttrReq* const tupreq = (TupAddAttrReq*)signal->getDataPtrSend();
       tupreq->tupConnectPtr = addfragptr.p->tupConnectptr;
-      tupreq->notused1 = 0;
       tupreq->attrId = attrId;
       tupreq->attrDescriptor = entry.attrDescriptor;
       tupreq->extTypeInfo = entry.extTypeInfo;
       BlockReference tupRef = calcInstanceBlockRef(DBTUP);
-      sendSignal(tupRef, GSN_TUP_ADD_ATTRREQ,
-                 signal, TupAddAttrReq::SignalLength, JBB);
+
+      Uint32 sectionLen = 0;
+      Uint32 startIndex = TupAddAttrReq::SignalLength;
+      if (addfragptr.p->defValSectionI != RNIL)
+      {
+        SegmentedSectionPtr defValSection;
+        getSection(defValSection, addfragptr.p->defValSectionI);
+
+        SectionReader defValueReader(defValSection, getSectionSegmentPool());
+        Uint32 defSectionWords = defValueReader.getSize();
+
+        ndbrequire(defValueReader.step(addfragptr.p->defValNextPos));
+
+        Uint32 defValueHeader;
+        ndbrequire(defValueReader.peekWord(&defValueHeader));
+
+        AttributeHeader ah(defValueHeader);
+        Uint32 defValueLen = ah.getByteSize();
+        Uint32 defValueWords = ((defValueLen +3)/4) + 1;
+        Uint32 *dst = &signal->theData[startIndex];
+        ndbassert(defSectionWords >= (addfragptr.p->defValNextPos + defValueWords));
+        ndbrequire(defValueReader.getWords(dst, defValueWords));
+        addfragptr.p->defValNextPos += defValueWords;
+        sectionLen = defValueWords;
+      }
+
+      //A long section is attached when a default value is sent.
+      if (sectionLen != 0)
+      {
+        LinearSectionPtr ptr[3];
+        ptr[0].p= &signal->theData[startIndex];
+        ptr[0].sz= sectionLen;
+        sendSignal(tupRef, GSN_TUP_ADD_ATTRREQ,
+                   signal, TupAddAttrReq::SignalLength, JBB, ptr, 1);
+      }
+      else
+        sendSignal(tupRef, GSN_TUP_ADD_ATTRREQ,
+                   signal, TupAddAttrReq::SignalLength, JBB);
+
       return;
     }
     if (DictTabInfo::isOrderedIndex(tabptr.p->tableType) &&
@@ -20549,6 +20614,8 @@ void Dblqh::seizeAddfragrec(Signal* sign
   addfragptr.p->accConnectptr = RNIL;
   addfragptr.p->tupConnectptr = RNIL;
   addfragptr.p->tuxConnectptr = RNIL;
+  addfragptr.p->defValSectionI = RNIL;
+  addfragptr.p->defValNextPos = 0;
   bzero(&addfragptr.p->m_createTabReq, sizeof(addfragptr.p->m_createTabReq));
   bzero(&addfragptr.p->m_lqhFragReq, sizeof(addfragptr.p->m_lqhFragReq));
   bzero(&addfragptr.p->m_addAttrReq, sizeof(addfragptr.p->m_addAttrReq));

=== modified file 'storage/ndb/src/kernel/blocks/dblqh/DblqhProxy.cpp'
--- a/storage/ndb/src/kernel/blocks/dblqh/DblqhProxy.cpp	2010-04-27 09:35:50 +0000
+++ b/storage/ndb/src/kernel/blocks/dblqh/DblqhProxy.cpp	2010-04-30 09:41:04 +0000
@@ -271,6 +271,12 @@ DblqhProxy::execLQHADDATTREQ(Signal* sig
   ndbrequire(ss_main.m_req.noOfAttributes >= req->noOfAttributes);
   ss_main.m_req.noOfAttributes -= req->noOfAttributes;
 
+  /* Save long section(s) in ss for forwarding to 
+   * workers
+   */
+  SectionHandle handle(this, signal);
+  saveSections(ss, handle);
+  
   sendREQ(signal, ss);
 }
 

=== modified file 'storage/ndb/src/kernel/blocks/dbtup/Dbtup.hpp'
--- a/storage/ndb/src/kernel/blocks/dbtup/Dbtup.hpp	2010-03-16 11:44:14 +0000
+++ b/storage/ndb/src/kernel/blocks/dbtup/Dbtup.hpp	2010-04-30 09:41:04 +0000
@@ -241,6 +241,7 @@ inline const Uint32* ALIGN_WORD(const vo
 #define ZAI_INCONSISTENCY_ERROR 829
 #define ZNO_ILLEGAL_NULL_ATTR 839
 #define ZNOT_NULL_ATTR 840
+#define ZBAD_DEFAULT_VALUE_LEN 850
 #define ZNO_INSTRUCTION_ERROR 871
 #define ZOUTSIDE_OF_PROGRAM_ERROR 876
 #define ZSTORED_PROC_ID_ERROR 877
@@ -1101,6 +1102,7 @@ ArrayPool<TupTriggerData> c_triggerPool;
       } m_dropTable;
       struct {
         Uint32 m_fragOpPtrI;
+        Uint32 defValSectionI;
       } m_createTable;
       struct {
         Uint32 m_gci_hi;
@@ -1108,6 +1110,7 @@ ArrayPool<TupTriggerData> c_triggerPool;
     };
 
     State tableStatus;
+    Local_key m_default_value_location;
   };  
 
   /*
@@ -2515,6 +2518,8 @@ private:
 //------------------------------------------------------------------
 //------------------------------------------------------------------
 
+  int  store_default_record(const TablerecPtr& regTabPtr);
+  bool  receive_defvalue(Signal* signal, const TablerecPtr& regTabPtr);
 //------------------------------------------------------------------
 //------------------------------------------------------------------
   void bufferTRANSID_AI(Signal* signal, BlockReference aRef, Uint32 Tlen);
@@ -2844,6 +2849,7 @@ private:
   void initializeTablerec();
   void initializeTabDescr();
   void initializeUndoPage();
+  void initializeDefaultValuesFrag();
 
   void initTab(Tablerec* regTabPtr);
 
@@ -2987,6 +2993,7 @@ private:
 #endif
 
   Uint32 calculate_free_list_impl(Uint32) const ;
+  Uint64 calculate_used_var_words(Fragrecord* fragPtr);
   void remove_free_page(Fragrecord*, Var_page*, Uint32);
   void insert_free_page(Fragrecord*, Var_page*, Uint32);
 
@@ -2999,6 +3006,7 @@ private:
   Uint32* alloc_var_rec(Uint32 * err,
                         Fragrecord*, Tablerec*, Uint32, Local_key*, Uint32*);
   void free_var_rec(Fragrecord*, Tablerec*, Local_key*, Ptr<Page>);
+  void free_var_part(Fragrecord*, Tablerec*, Local_key*);
   Uint32* alloc_var_part(Uint32*err,Fragrecord*, Tablerec*, Uint32, Local_key*);
   Uint32 *realloc_var_part(Uint32 * err, Fragrecord*, Tablerec*,
                            PagePtr, Var_part_ref*, Uint32, Uint32);
@@ -3052,6 +3060,15 @@ private:
   Uint32 cnoOfFragrec;
   RSS_OP_COUNTER(cnoOfFreeFragrec);
   RSS_OP_SNAPSHOT(cnoOfFreeFragrec);
+  /*
+   * DefaultValuesFragment is a normal struct Fragrecord.
+   * It is TUP block-variable.
+   * There is only ONE DefaultValuesFragment shared
+   * among all table fragments stored by this TUP block.
+  */
+  FragrecordPtr DefaultValuesFragment;
+  RSS_OP_SNAPSHOT(defaultValueWordsHi);
+  RSS_OP_SNAPSHOT(defaultValueWordsLo);
 
   AlterTabOperation *alterTabOperRec;
   Uint32 cfirstfreeAlterTabOp;
@@ -3133,6 +3150,7 @@ private:
   Uint32* get_ptr(PagePtr*, Var_part_ref);
   Uint32* get_ptr(PagePtr*, const Local_key*, const Tablerec*);
   Uint32* get_dd_ptr(PagePtr*, const Local_key*, const Tablerec*);
+  Uint32* get_default_ptr(const Tablerec*, Uint32&);
   Uint32 get_len(Ptr<Page>* pagePtr, Var_part_ref ref);
 
   Tuple_header* alloc_copy_tuple(const Tablerec* tabPtrP, Local_key* ptr){
@@ -3401,6 +3419,20 @@ Dbtup::get_ptr(PagePtr* pagePtr, 
 
 inline
 Uint32*
+Dbtup::get_default_ptr(const Tablerec* regTabPtr, Uint32& default_len)
+{
+  Var_part_ref ref;
+  ref.assign(&regTabPtr->m_default_value_location);
+  Ptr<Page> page;
+
+  Uint32* default_data = get_ptr(&page, ref);
+  default_len = get_len(&page, ref);
+
+  return default_data;
+}
+
+inline
+Uint32*
 Dbtup::get_dd_ptr(PagePtr* pagePtr, 
 		  const Local_key* key, const Tablerec* regTabPtr)
 {

=== modified file 'storage/ndb/src/kernel/blocks/dbtup/DbtupDebug.cpp'
--- a/storage/ndb/src/kernel/blocks/dbtup/DbtupDebug.cpp	2010-03-05 15:03:09 +0000
+++ b/storage/ndb/src/kernel/blocks/dbtup/DbtupDebug.cpp	2010-04-29 14:52:05 +0000
@@ -379,6 +379,15 @@ Dbtup::execDUMP_STATE_ORD(Signal* signal
 
   if (signal->theData[0] == DumpStateOrd::SchemaResourceSnapshot)
   {
+    {
+      Uint64 defaultValueWords= 0;
+      if (DefaultValuesFragment.i != RNIL)
+        defaultValueWords= calculate_used_var_words(DefaultValuesFragment.p);
+      Uint32 defaultValueWordsHi= (Uint32) (defaultValueWords >> 32);
+      Uint32 defaultValueWordsLo= (Uint32) (defaultValueWords & 0xFFFFFFFF);
+      RSS_OP_SNAPSHOT_SAVE(defaultValueWordsHi);
+      RSS_OP_SNAPSHOT_SAVE(defaultValueWordsLo);
+    }
     RSS_OP_SNAPSHOT_SAVE(cnoOfFreeFragoprec);
     RSS_OP_SNAPSHOT_SAVE(cnoOfFreeFragrec);
     RSS_OP_SNAPSHOT_SAVE(cnoOfFreeTabDescrRec);
@@ -387,6 +396,15 @@ Dbtup::execDUMP_STATE_ORD(Signal* signal
 
   if (signal->theData[0] == DumpStateOrd::SchemaResourceCheckLeak)
   {
+    {
+      Uint64 defaultValueWords= 0;
+      if (DefaultValuesFragment.i != RNIL)
+        defaultValueWords= calculate_used_var_words(DefaultValuesFragment.p);
+      Uint32 defaultValueWordsHi= (Uint32) (defaultValueWords >> 32);
+      Uint32 defaultValueWordsLo= (Uint32) (defaultValueWords & 0xFFFFFFFF);
+      RSS_OP_SNAPSHOT_CHECK(defaultValueWordsHi);
+      RSS_OP_SNAPSHOT_CHECK(defaultValueWordsLo);
+    }
     RSS_OP_SNAPSHOT_CHECK(cnoOfFreeFragoprec);
     RSS_OP_SNAPSHOT_CHECK(cnoOfFreeFragrec);
     RSS_OP_SNAPSHOT_CHECK(cnoOfFreeTabDescrRec);

=== modified file 'storage/ndb/src/kernel/blocks/dbtup/DbtupExecQuery.cpp'
--- a/storage/ndb/src/kernel/blocks/dbtup/DbtupExecQuery.cpp	2010-03-26 18:06:08 +0000
+++ b/storage/ndb/src/kernel/blocks/dbtup/DbtupExecQuery.cpp	2010-04-30 09:41:04 +0000
@@ -1469,7 +1469,27 @@ int Dbtup::handleInsertReq(Signal* signa
     terrorCode = ZAI_INCONSISTENCY_ERROR;
     goto update_error;
   }
-
+  
+  if (!regTabPtr->m_default_value_location.isNull())
+  {
+    jam();
+    Uint32 default_values_len;
+    /* Get default values ptr + len for this table */
+    Uint32* default_values = get_default_ptr(regTabPtr, default_values_len);
+    ndbrequire(default_values_len != 0 && default_values != NULL);
+    /*
+     * Update default values into row first,
+     * next update with data received from the client.
+     */
+    if(unlikely((res = updateAttributes(req_struct, default_values,
+                                        default_values_len)) < 0))
+    {
+      jam();
+      terrorCode = Uint32(-res);
+      goto update_error;
+    }
+  }
+  
   if(unlikely((res = updateAttributes(req_struct, &cinBuffer[0],
                                       req_struct->attrinfo_len)) < 0))
   {

=== modified file 'storage/ndb/src/kernel/blocks/dbtup/DbtupGen.cpp'
--- a/storage/ndb/src/kernel/blocks/dbtup/DbtupGen.cpp	2010-03-05 15:03:09 +0000
+++ b/storage/ndb/src/kernel/blocks/dbtup/DbtupGen.cpp	2010-04-29 14:52:05 +0000
@@ -630,6 +630,7 @@ void Dbtup::execNDB_STTOR(Signal* signal
     jam();
     cownNodeId = ownNodeId;
     cownref = calcInstanceBlockRef(DBTUP);
+    initializeDefaultValuesFrag();
     break;
   case ZSTARTPHASE2:
     jam();
@@ -657,6 +658,30 @@ void Dbtup::startphase3Lab(Signal* signa
 {
 }//Dbtup::startphase3Lab()
 
+void Dbtup::initializeDefaultValuesFrag()
+{
+  /* Grab and initialize a fragment record for storing default
+   * values for the table fragments held by this TUP instance
+   */
+  seizeFragrecord(DefaultValuesFragment);
+  DefaultValuesFragment.p->fragStatus = Fragrecord::FS_ONLINE;
+  DefaultValuesFragment.p->m_undo_complete= false;
+  DefaultValuesFragment.p->m_lcp_scan_op = RNIL;
+  DefaultValuesFragment.p->m_lcp_keep_list = RNIL;
+  DefaultValuesFragment.p->noOfPages = 0;
+  DefaultValuesFragment.p->noOfVarPages = 0;
+  DefaultValuesFragment.p->m_max_page_no = 0;
+  DefaultValuesFragment.p->m_free_page_id_list = FREE_PAGE_RNIL;
+  ndbrequire(DefaultValuesFragment.p->m_page_map.isEmpty());
+  DefaultValuesFragment.p->m_restore_lcp_id = RNIL;
+  for (Uint32 i = 0; i<MAX_FREE_LIST+1; i++)
+    ndbrequire(DefaultValuesFragment.p->free_var_page_array[i].isEmpty());
+
+  DefaultValuesFragment.p->m_logfile_group_id = RNIL;
+
+  return;
+}
+
 void Dbtup::initializeFragoperrec() 
 {
   FragoperrecPtr fragoperPtr;
@@ -755,6 +780,7 @@ Dbtup::initTab(Tablerec* const regTabPtr
   regTabPtr->m_dropTable.tabUserPtr = RNIL;
   regTabPtr->m_dropTable.tabUserRef = 0;
   regTabPtr->tableStatus = NOT_DEFINED;
+  regTabPtr->m_default_value_location.setNull();
 
   // Clear trigger data
   if (!regTabPtr->afterInsertTriggers.isEmpty())

=== modified file 'storage/ndb/src/kernel/blocks/dbtup/DbtupMeta.cpp'
--- a/storage/ndb/src/kernel/blocks/dbtup/DbtupMeta.cpp	2010-01-13 13:28:03 +0000
+++ b/storage/ndb/src/kernel/blocks/dbtup/DbtupMeta.cpp	2010-04-29 14:52:05 +0000
@@ -38,6 +38,7 @@
 #include "AttributeOffset.hpp"
 #include <my_sys.h>
 #include <signaldata/LqhFrag.hpp>
+#include <signaldata/AttrInfo.hpp>
 
 #include <EventLogger.hpp>
 extern EventLogger * g_eventLogger;
@@ -78,6 +79,7 @@ Dbtup::execCREATE_TAB_REQ(Signal* signal
   fragOperPtr.p->lqhBlockrefFrag = req->senderRef;
 
   regTabPtr.p->m_createTable.m_fragOpPtrI = fragOperPtr.i;
+  regTabPtr.p->m_createTable.defValSectionI = RNIL;
   regTabPtr.p->tableStatus= DEFINING;
   regTabPtr.p->m_bits = 0;
   regTabPtr.p->m_bits |= (req->checksumIndicator ? Tablerec::TR_Checksum : 0);
@@ -297,6 +299,18 @@ void Dbtup::execTUP_ADD_ATTRREQ(Signal* 
     goto error;
   }
 
+  if (!receive_defvalue(signal, regTabPtr))
+    goto error;
+
+  if ((ERROR_INSERTED(4032) && (attrId == 0)) ||
+      (ERROR_INSERTED(4033) && lastAttr))
+  {
+    jam();
+    CLEAR_ERROR_INSERT_VALUE;
+    terrorCode = 1;
+    goto error;
+  }
+
   if (! lastAttr)
   {
     jam();
@@ -382,6 +396,12 @@ void Dbtup::execTUP_ADD_ATTRREQ(Signal* 
   }
 #endif
 
+  if (store_default_record(regTabPtr) < 0)
+  {
+    jam();
+    goto error;
+  }
+
   ndbrequire(regTabPtr.p->tableStatus == DEFINING);
   regTabPtr.p->tableStatus= DEFINED;
 
@@ -393,6 +413,17 @@ void Dbtup::execTUP_ADD_ATTRREQ(Signal* 
   releaseFragoperrec(fragOperPtr);
   return;
 error:
+  {
+    /* Release any unprocessed sections */
+    SectionHandle handle(this, signal);
+    releaseSections(handle);
+  }
+  /* Release segmented section used to receive Attr default value */
+  releaseSection(regTabPtr.p->m_createTable.defValSectionI);
+  regTabPtr.p->m_createTable.defValSectionI = RNIL;
+  free_var_part(DefaultValuesFragment.p, regTabPtr.p, &regTabPtr.p->m_default_value_location);
+  regTabPtr.p->m_default_value_location.setNull();
+
   signal->theData[0]= fragOperPtr.p->lqhPtrFrag;
   signal->theData[1]= terrorCode;
   sendSignal(fragOperPtr.p->lqhBlockrefFrag,
@@ -401,6 +432,156 @@ error:
   return;
 }
 
+bool Dbtup::receive_defvalue(Signal* signal, const TablerecPtr& regTabPtr)
+{
+  jam();
+  Uint32 defValueBytes = 0;
+  Uint32 defValueWords = 0;
+  Uint32 attrId = signal->theData[2];
+  Uint32 attrDescriptor = signal->theData[3];
+
+  Uint32 attrLen = AttributeDescriptor::getSize(attrDescriptor);
+  Uint32 arrayType = AttributeDescriptor::getArrayType(attrDescriptor);
+  Uint32 arraySize = AttributeDescriptor::getArraySize(attrDescriptor);
+
+  const Uint32 numSections = signal->getNoOfSections();
+
+  if (numSections == 0)
+    return true;
+
+  jam();
+  SectionHandle handle(this, signal);
+  SegmentedSectionPtr ptr;
+  handle.getSection(ptr, TupAddAttrReq::DEFAULT_VALUE_SECTION_NUM);
+
+  SimplePropertiesSectionReader r(ptr, getSectionSegmentPool());
+  r.reset();
+
+  Uint32 ahIn;
+  ndbrequire(r.getWord(&ahIn));
+
+  defValueBytes = AttributeHeader::getByteSize(ahIn);
+  defValueWords = (defValueBytes + 3) / 4;
+
+  Uint32 *dst = NULL;
+  AttributeHeader ah(attrId, defValueBytes);
+
+  if (defValueBytes == 0)
+  {
+    jam();
+    releaseSections(handle);
+    return true;
+  }
+
+  /* We have a default value, double check to be sure this is not
+   * a primary key
+   */
+  if (AttributeDescriptor::getPrimaryKey(attrDescriptor))
+  {
+    jam();
+    releaseSections(handle);
+    /* Default value for primary key column not supported */
+    terrorCode = 792;
+    return false;
+  }
+
+  Uint32 bytes;
+  if (attrLen)
+    bytes= AttributeDescriptor::getSizeInBytes(attrDescriptor);
+  else
+    bytes= ((arraySize + AD_SIZE_IN_WORDS_OFFSET)
+                              >> AD_SIZE_IN_WORDS_SHIFT) * 4;
+
+  terrorCode= 0;
+
+  if (attrLen)
+  {
+    if (arrayType == NDB_ARRAYTYPE_FIXED)
+    {
+      if (defValueBytes != bytes)
+      {
+        terrorCode = ZBAD_DEFAULT_VALUE_LEN;
+      }
+    }
+    else
+    {
+      if (defValueBytes > bytes)
+      {
+        terrorCode = ZBAD_DEFAULT_VALUE_LEN;
+      }
+    }
+  }
+  else
+  {
+    /*
+     * The condition is for BIT type.
+     * Even though it is fixed, the compare operator should be > rather than ==,
+     * for the 4-byte alignemnt, the space for BIT type occupied 4 bytes at least.
+     * yet the bytes of default value can be 1, 2, 3, 4, 5, 6, 7, 8 bytes.
+     */
+    if (defValueBytes > bytes)
+    {
+      terrorCode = ZBAD_DEFAULT_VALUE_LEN;
+    }
+  }
+  
+  jam();
+
+  if (likely( !terrorCode ))
+  {
+    dst = cinBuffer;
+    
+    ndbrequire(r.getWords(dst, defValueWords));
+    
+    /* Check that VAR types have valid inline length */
+    if ((attrLen) &&
+        (arrayType != NDB_ARRAYTYPE_FIXED))
+    {
+      jam();
+      const uchar* valPtr = (const uchar*) dst;
+      Uint32 internalVarSize = 0;
+      
+      if (arrayType == NDB_ARRAYTYPE_SHORT_VAR)
+      {
+        internalVarSize = 1 + valPtr[0];
+      }
+      else if (arrayType == NDB_ARRAYTYPE_MEDIUM_VAR)
+      {
+        internalVarSize = 2 + valPtr[0] + (256 * Uint32(valPtr[1]));
+      }
+      else
+      {
+        ndbrequire(false);
+      }
+      
+      if (unlikely(internalVarSize != defValueBytes))
+      {
+        jam();
+        terrorCode = ZBAD_DEFAULT_VALUE_LEN;
+        releaseSections(handle);
+        return false;
+      }
+    }
+
+    if (likely( appendToSection(regTabPtr.p->m_createTable.defValSectionI, 
+                                (const Uint32 *)&ah, 1) ))
+    {  
+      if (likely( appendToSection(regTabPtr.p->m_createTable.defValSectionI, 
+                                  (const Uint32*)dst, 
+                                  defValueWords)))
+      {
+        jam();
+        releaseSections(handle);
+        return true;
+      }
+    }
+    terrorCode = ZMEM_NOMEM_ERROR;
+  }
+
+  releaseSections(handle);
+  return false;
+}
+
 void Dbtup::execTUPFRAGREQ(Signal* signal)
 {
   jamEntry();
@@ -553,12 +734,75 @@ void Dbtup::execTUPFRAGREQ(Signal* signa
   return;
 
 sendref:
-
   signal->theData[0]= userptr;
   signal->theData[1]= terrorCode;
   sendSignal(userRef, GSN_TUPFRAGREF, signal, 2, JBB);
 }
 
+/*
+  Store the default values for a table, as the ATTRINFO "program"
+  (i.e AttributeHeader|Data AttributeHeader|Data...)
+  in varsize memory associated with the dummy fragment(DefaultValuesFragment).
+  There is a DBTUP global set of defaults records in DefaultValuesFragment.
+  One record per table stored on varsize pages.
+  
+  Each Table_record has a Local_key pointing to start of its default values
+  in TUP's default values fragment.
+*/
+int Dbtup::store_default_record(const TablerecPtr& regTabPtr)
+{
+  Uint32 RdefValSectionI = regTabPtr.p->m_createTable.defValSectionI;
+  jam();
+
+  if (RdefValSectionI == RNIL) //No default values are stored for the table
+  {
+    jam();
+    if (ERROR_INSERTED(4034))
+    {
+      jam();
+      CLEAR_ERROR_INSERT_VALUE;
+      terrorCode = 1;
+      return -1;
+    }
+
+    return 0;
+  }
+
+  SegmentedSectionPtr defValSection;
+  getSection(defValSection, RdefValSectionI);
+  Uint32 sizes = defValSection.p->m_sz;
+  /**
+   * Alloc var-length memory for storing defaults
+   */
+  Uint32* var_data_ptr= alloc_var_part(&terrorCode,
+                                       DefaultValuesFragment.p,
+                                       regTabPtr.p,
+                                       sizes,
+                                       &regTabPtr.p->m_default_value_location);
+  if (unlikely( var_data_ptr == 0 ))
+  {
+    jam();
+    /* Caller releases the default values section */
+    return -1;
+  }
+
+  if (ERROR_INSERTED(4034))
+  {
+    jam();
+    CLEAR_ERROR_INSERT_VALUE;
+    terrorCode = 1;
+    return -1;
+  }
+      
+  
+  copy(var_data_ptr, RdefValSectionI);
+  releaseSection(RdefValSectionI);
+  regTabPtr.p->m_createTable.defValSectionI= RNIL;
+
+  return 0;
+}
+
+
 bool Dbtup::addfragtotab(Tablerec* const regTabPtr,
                          Uint32 fragId,
                          Uint32 fragIndex)
@@ -1889,6 +2133,8 @@ Dbtup::drop_table_logsync_callback(Signa
              signal, DropTabConf::SignalLength, JBB);
   
   releaseTabDescr(tabPtr.p);
+  free_var_part(DefaultValuesFragment.p, tabPtr.p, &tabPtr.p->m_default_value_location);
+  tabPtr.p->m_default_value_location.setNull();
   initTab(tabPtr.p);
 }
 

=== modified file 'storage/ndb/src/kernel/blocks/dbtup/DbtupVarAlloc.cpp'
--- a/storage/ndb/src/kernel/blocks/dbtup/DbtupVarAlloc.cpp	2009-12-14 10:58:03 +0000
+++ b/storage/ndb/src/kernel/blocks/dbtup/DbtupVarAlloc.cpp	2010-04-29 14:52:05 +0000
@@ -139,6 +139,39 @@ Dbtup::alloc_var_part(Uint32 * err,
 }
 
 /*
+  free_var_part is used to free the variable length storage associated
+  with the passed local key.
+  It is not assumed that there is a corresponding fixed-length part.
+  // TODO : Any need for tabPtr?
+*/
+void Dbtup::free_var_part(Fragrecord* fragPtr,
+                          Tablerec* tabPtr,
+                          Local_key* key)
+{
+  Ptr<Page> pagePtr;
+  if (key->m_page_no != RNIL)
+  {
+    c_page_pool.getPtr(pagePtr, key->m_page_no);
+    ((Var_page*)pagePtr.p)->free_record(key->m_page_idx, Var_page::CHAIN);
+
+    ndbassert(pagePtr.p->free_space <= Var_page::DATA_WORDS);
+    if (pagePtr.p->free_space == Var_page::DATA_WORDS - 1)
+    {
+      jam();
+      Uint32 idx = pagePtr.p->list_index;
+      LocalDLList<Page> list(c_page_pool, fragPtr->free_var_page_array[idx]);
+      list.remove(pagePtr);
+      returnCommonArea(pagePtr.i, 1);
+      fragPtr->noOfVarPages --;
+    } else {
+      jam();
+      update_free_page_list(fragPtr, pagePtr);
+    }
+  }
+  return;
+}
+
+/*
   Deallocator for variable sized segments
   Part of the external interface for variable sized segments
 
@@ -474,6 +507,30 @@ Uint32 Dbtup::calculate_free_list_impl(U
   return 0;
 }
 
+Uint64 Dbtup::calculate_used_var_words(Fragrecord* fragPtr)
+{
+  /* Loop over all VarSize pages in this fragment, summing
+   * their used space
+   */
+  Uint64 totalUsed= 0;
+  for (Uint32 freeList= 0; freeList <= MAX_FREE_LIST; freeList++)
+  {
+    LocalDLList<Page> list(c_page_pool, 
+                           fragPtr->free_var_page_array[freeList]);
+    Ptr<Page> pagePtr;
+
+    if (list.first(pagePtr))
+    {
+      do
+      {
+        totalUsed+= (Tup_varsize_page::DATA_WORDS - pagePtr.p->free_space);
+      } while (list.next(pagePtr));
+    };
+  };
+
+  return totalUsed;
+}
+
 Uint32* 
 Dbtup::alloc_var_rowid(Uint32 * err,
                        Fragrecord* fragPtr,

=== modified file 'storage/ndb/src/mgmapi/mgmapi.cpp'
--- a/storage/ndb/src/mgmapi/mgmapi.cpp	2010-03-04 14:35:00 +0000
+++ b/storage/ndb/src/mgmapi/mgmapi.cpp	2010-04-13 16:01:38 +0000
@@ -568,7 +568,7 @@ ndb_mgm_connect(NdbMgmHandle handle, int
    * Do connect
    */
   LocalConfig &cfg= handle->cfg;
-  my_socket sockfd;
+  NDB_SOCKET_TYPE sockfd;
   my_socket_invalidate(&sockfd);
   Uint32 i;
   while (!my_socket_valid(sockfd))
@@ -1789,7 +1789,7 @@ ndb_mgm_set_loglevel_node(NdbMgmHandle h
 
 int
 ndb_mgm_listen_event_internal(NdbMgmHandle handle, const int filter[],
-			      int parsable, my_socket *sock)
+			      int parsable, NDB_SOCKET_TYPE* sock)
 {
   DBUG_ENTER("ndb_mgm_listen_event_internal");
   CHECK_HANDLE(handle, -1);
@@ -1849,7 +1849,7 @@ ndb_mgm_listen_event_internal(NdbMgmHand
     args.put("filter", tmp.c_str());
   }
 
-  my_socket tmp = handle->socket;
+  NDB_SOCKET_TYPE tmp = handle->socket;
   handle->socket = sockfd;
 
   const Properties *reply;
@@ -1880,7 +1880,7 @@ int
 #endif
 ndb_mgm_listen_event(NdbMgmHandle handle, const int filter[])
 {
-  my_socket s;
+  NDB_SOCKET_TYPE s;
   if(ndb_mgm_listen_event_internal(handle,filter,0,&s)<0)
     my_socket_invalidate(&s);
 #ifdef NDB_WIN

=== modified file 'storage/ndb/src/mgmapi/ndb_logevent.cpp'
--- a/storage/ndb/src/mgmapi/ndb_logevent.cpp	2010-03-02 09:16:27 +0000
+++ b/storage/ndb/src/mgmapi/ndb_logevent.cpp	2010-04-13 16:01:38 +0000
@@ -32,7 +32,8 @@
 #include "ndb_logevent.hpp"
 
 extern
-int ndb_mgm_listen_event_internal(NdbMgmHandle, const int filter[], int, my_socket*);
+int ndb_mgm_listen_event_internal(NdbMgmHandle, const int filter[],
+                                  int, NDB_SOCKET_TYPE*);
 
 struct ndb_logevent_error_msg {
   enum ndb_logevent_handle_error code;
@@ -74,7 +75,7 @@ NdbLogEventHandle
 ndb_mgm_create_logevent_handle(NdbMgmHandle mh,
 			       const int filter[])
 {
-  my_socket sock;
+  NDB_SOCKET_TYPE sock;
   if(ndb_mgm_listen_event_internal(mh, filter, 1, &sock) < 0)
     return 0;
 

=== modified file 'storage/ndb/src/ndbapi/NdbDictionary.cpp'
--- a/storage/ndb/src/ndbapi/NdbDictionary.cpp	2010-03-01 14:13:01 +0000
+++ b/storage/ndb/src/ndbapi/NdbDictionary.cpp	2010-04-29 14:52:05 +0000
@@ -20,6 +20,10 @@
 #include "NdbDictionaryImpl.hpp"
 #include <NdbOut.hpp>
 #include <signaldata/CreateHashMap.hpp>
+#include <NdbBlob.hpp>
+C_MODE_START
+#include <decimal.h>
+C_MODE_END
 
 /* NdbRecord static helper methods */
 
@@ -350,16 +354,37 @@ NdbDictionary::Column::setAutoIncrementI
   m_impl.m_autoIncrementInitialValue = val;
 }
 
+/*
+* setDefaultValue() with only one const char * parameter is reserved
+* for backward compatible api consideration, but is broken.
+*/
 int
 NdbDictionary::Column::setDefaultValue(const char* defaultValue)
 {
-  return !m_impl.m_defaultValue.assign(defaultValue);
+  return -1;
 }
 
-const char*
-NdbDictionary::Column::getDefaultValue() const
+/*
+  The significant length of a column can't easily be calculated before
+  the column type is fully defined, so the length of the default value 
+  is passed in as a parameter explicitly.
+*/
+int
+NdbDictionary::Column::setDefaultValue(const void* defaultValue, unsigned int n)
 {
-  return m_impl.m_defaultValue.c_str();
+  if (defaultValue == NULL)
+    return m_impl.m_defaultValue.assign(NULL, 0);
+
+  return m_impl.m_defaultValue.assign(defaultValue, n);
+}
+
+const void*
+NdbDictionary::Column::getDefaultValue(unsigned int* len) const
+{
+  if (len)
+   *len = m_impl.m_defaultValue.length();
+
+  return m_impl.m_defaultValue.get_data();
 }
 
 int
@@ -899,6 +924,11 @@ NdbDictionary::Table::getForceVarPart() 
   return m_impl.m_force_var_part;
 }
 
+bool
+NdbDictionary::Table::hasDefaultValues() const {
+  return m_impl.m_has_default_values;
+}
+
 const NdbRecord*
 NdbDictionary::Table::getDefaultRecord() const {
   return m_impl.m_ndbrecord;
@@ -1031,6 +1061,9 @@ NdbDictionary::Index::addColumn(const Co
   (* col) = NdbColumnImpl::getImpl(c);
 
   col->m_indexSourced=true;
+  
+  /* Remove defaults from indexed columns */
+  col->m_defaultValue.clear();
 
   if (m_impl.m_columns.push_back(col))
   {
@@ -2614,6 +2647,436 @@ NdbDictionary::Dictionary::getWarningFla
 
 // printers
 
+void
+pretty_print_string(NdbOut& out, 
+                    const NdbDictionary::NdbDataPrintFormat &f,
+                    const char *type, bool is_binary,
+                    const void *aref, unsigned sz)
+{
+  const unsigned char* ref = (const unsigned char*)aref;
+  int i, len, printable= 1;
+  // trailing zeroes are not printed
+  for (i=sz-1; i >= 0; i--)
+    if (ref[i] == 0) sz--;
+    else break;
+  if (!is_binary)
+  {
+    // trailing spaces are not printed
+    for (i=sz-1; i >= 0; i--)
+      if (ref[i] == 32) sz--;
+      else break;
+  }
+  if (is_binary && f.hex_format)
+  {
+    if (sz == 0)
+    {
+      out.print("0x0");
+      return;
+    }
+    out.print("0x");
+    for (len = 0; len < (int)sz; len++)
+      out.print("%02X", (int)ref[len]);
+    return;
+  }
+  if (sz == 0) return; // empty
+
+  for (len=0; len < (int)sz && ref[i] != 0; len++)
+    if (printable && !isprint((int)ref[i]))
+      printable= 0;
+
+  if (printable)
+    out.print("%.*s", len, ref);
+  else
+  {
+    out.print("0x");
+    for (i=0; i < len; i++)
+      out.print("%02X", (int)ref[i]);
+  }
+  if (len != (int)sz)
+  {
+    out.print("[");
+    for (i= len+1; ref[i] != 0; i++)
+    out.print("%u]",len-i);
+    assert((int)sz > i);
+    pretty_print_string(out,f,type,is_binary,ref+i,sz-i);
+  }
+}
+
+/* Three MySQL defs duplicated here : */ 
+static const int MaxMySQLDecimalPrecision= 65;
+static const int MaxMySQLDecimalScale= 30;
+static const int DigitsPerDigit_t= 9; // (Decimal digits in 2^32)
+
+/* Implications */
+/* Space for -, . and \0 */
+static const int MaxDecimalStrLen= MaxMySQLDecimalPrecision + 3;
+static const int IntPartDigit_ts= 
+  ((MaxMySQLDecimalPrecision - 
+    MaxMySQLDecimalScale) +
+   DigitsPerDigit_t -1) / DigitsPerDigit_t;
+static const int FracPartDigit_ts= 
+  (MaxMySQLDecimalScale + 
+   DigitsPerDigit_t - 1) / DigitsPerDigit_t;
+static const int DigitArraySize= IntPartDigit_ts + FracPartDigit_ts;
+
+NdbOut&
+NdbDictionary::printFormattedValue(NdbOut& out, 
+                                   const NdbDataPrintFormat& format,
+                                   const NdbDictionary::Column* c,
+                                   const void* val)
+{
+  if (val == NULL)
+  {
+    out << format.null_string;
+    return out;
+  }
+  
+  const unsigned char* val_p= (const unsigned char*) val;
+
+  uint length = c->getLength();
+  Uint32 j;
+  {
+    const char *fields_optionally_enclosed_by;
+    if (format.fields_enclosed_by[0] == '\0')
+      fields_optionally_enclosed_by=
+        format.fields_optionally_enclosed_by;
+    else
+      fields_optionally_enclosed_by= "";
+    out << format.fields_enclosed_by;
+
+    switch(c->getType()){
+    case NdbDictionary::Column::Bigunsigned:
+    {
+      Uint64 temp;
+      memcpy(&temp, val, 8); 
+      out << temp;
+      break;
+    }
+    case NdbDictionary::Column::Bit:
+    {
+      out << format.hex_prefix << "0x";
+      {
+        const Uint32 *buf = (const Uint32 *)val;
+        unsigned int k = (length+31)/32;
+        const unsigned int sigbits= length & 31;
+        Uint32 wordMask= (1 << sigbits) -1;
+        
+        /* Skip leading all-0 words */
+        while (k > 0)
+        {
+          const Uint32 v= buf[--k] & wordMask;
+          if (v != 0)
+            break;
+          /* Following words have all bits significant */
+          wordMask= ~0;
+        }
+        
+        /* Write first sig word with non-zero bits */
+        out.print("%X", (buf[k] & wordMask));
+        
+        /* Write remaining words (less significant) */
+        while (k > 0)
+          out.print("%.8X", buf[--k]);
+      }
+      break;
+    }
+    case NdbDictionary::Column::Unsigned:
+    {
+      if (length > 1)
+        out << format.start_array_enclosure;
+      out << *(const Uint32*)val;
+      for (j = 1; j < length; j++)
+        out << " " << *((const Uint32*)val) + j;
+      if (length > 1)
+        out << format.end_array_enclosure;
+      break;
+    }
+    case NdbDictionary::Column::Mediumunsigned:
+      out << (const Uint32) uint3korr(val_p);
+      break;
+    case NdbDictionary::Column::Smallunsigned:
+      out << *((const Uint16*) val);
+      break;
+    case NdbDictionary::Column::Tinyunsigned:
+      out << *((const Uint8*) val);
+      break;
+    case NdbDictionary::Column::Bigint:
+    {
+      Int64 temp;
+      memcpy(&temp, val, 8);
+      out << temp;
+      break;
+    }
+    case NdbDictionary::Column::Int:
+      out << *((Int32*)val);
+      break;
+    case NdbDictionary::Column::Mediumint:
+      out << sint3korr(val_p);
+      break;
+    case NdbDictionary::Column::Smallint:
+      out << *((const short*) val);
+      break;
+    case NdbDictionary::Column::Tinyint:
+      out << *((Int8*) val);
+      break;
+    case NdbDictionary::Column::Binary:
+      if (!format.hex_format)
+        out << fields_optionally_enclosed_by;
+      j = c->getLength();
+      pretty_print_string(out,format,"Binary", true, val, j);
+      if (!format.hex_format)
+        out << fields_optionally_enclosed_by;
+      break;
+    case NdbDictionary::Column::Char:
+      out << fields_optionally_enclosed_by;
+      j = c->getLength();
+      pretty_print_string(out,format,"Char", false, val, j);
+      out << fields_optionally_enclosed_by;
+      break;
+    case NdbDictionary::Column::Varchar:
+    {
+      out << fields_optionally_enclosed_by;
+      unsigned len = *val_p;
+      pretty_print_string(out,format,"Varchar", false, val_p+1,len);
+      j = length;
+      out << fields_optionally_enclosed_by;
+    }
+    break;
+    case NdbDictionary::Column::Varbinary:
+    {
+      if (!format.hex_format)
+        out << fields_optionally_enclosed_by;
+      unsigned len = *val_p;
+      pretty_print_string(out,format,"Varbinary", true, val_p+1,len);
+      j = length;
+      if (!format.hex_format)
+        out << fields_optionally_enclosed_by;
+    }
+    break;
+    case NdbDictionary::Column::Float:
+    {
+      float temp;
+      memcpy(&temp, val, sizeof(temp));
+      out << temp;
+      break;
+    }
+    case NdbDictionary::Column::Double:
+    {
+      double temp;
+      memcpy(&temp, val, sizeof(temp));
+      out << temp;
+      break;
+    }
+    case NdbDictionary::Column::Olddecimal:
+    {
+      short len = 1 + c->getPrecision() + (c->getScale() > 0);
+      out.print("%.*s", len, val_p);
+    }
+    break;
+    case NdbDictionary::Column::Olddecimalunsigned:
+    {
+      short len = 0 + c->getPrecision() + (c->getScale() > 0);
+      out.print("%.*s", len, val_p);
+    }
+    break;
+    case NdbDictionary::Column::Decimal:
+    case NdbDictionary::Column::Decimalunsigned:
+    {
+      int precision= c->getPrecision();
+      int scale= c->getScale();
+      
+      assert(precision <= MaxMySQLDecimalPrecision);
+      assert(scale <= MaxMySQLDecimalScale);
+      assert(decimal_size(precision, scale) <= DigitArraySize );
+      decimal_digit_t buff[ DigitArraySize ];
+      decimal_t tmpDec;
+      tmpDec.buf= buff;
+      tmpDec.len= DigitArraySize;
+      decimal_make_zero(&tmpDec);
+      int rc;
+
+      const uchar* data= (const uchar*) val_p;
+      if ((rc= bin2decimal(data, &tmpDec, precision, scale)))
+      {
+        out.print("***Error : Bad bin2decimal conversion %d ***",
+                  rc);
+        break;
+      }
+      
+      /* Get null terminated var-length string representation */
+      char decStr[MaxDecimalStrLen];
+      assert(decimal_string_size(&tmpDec) <= MaxDecimalStrLen);
+      int len= MaxDecimalStrLen;
+      if ((rc= decimal2string(&tmpDec, decStr, 
+                              &len,
+                              0,   // 0 = Var length output length
+                              0,   // 0 = Var length fractional part
+                              0))) // Filler char for fixed length
+      {
+        out.print("***Error : bad decimal2string conversion %d ***",
+                  rc);
+        break;
+      }
+
+      out.print("%s", decStr);
+      
+      break;
+    }
+      // for dates cut-and-paste from field.cc
+    case NdbDictionary::Column::Datetime:
+    {
+      ulonglong tmp;
+      memcpy(&tmp, val, 8);
+
+      long part1,part2,part3;
+      part1=(long) (tmp/LL(1000000));
+      part2=(long) (tmp - (ulonglong) part1*LL(1000000));
+      char buf[40];
+      char* pos=(char*) buf+19;
+      *pos--=0;
+      *pos--= (char) ('0'+(char) (part2%10)); part2/=10; 
+      *pos--= (char) ('0'+(char) (part2%10)); part3= (int) (part2 / 10);
+      *pos--= ':';
+      *pos--= (char) ('0'+(char) (part3%10)); part3/=10;
+      *pos--= (char) ('0'+(char) (part3%10)); part3/=10;
+      *pos--= ':';
+      *pos--= (char) ('0'+(char) (part3%10)); part3/=10;
+      *pos--= (char) ('0'+(char) part3);
+      *pos--= '/';
+      *pos--= (char) ('0'+(char) (part1%10)); part1/=10;
+      *pos--= (char) ('0'+(char) (part1%10)); part1/=10;
+      *pos--= '-';
+      *pos--= (char) ('0'+(char) (part1%10)); part1/=10;
+      *pos--= (char) ('0'+(char) (part1%10)); part3= (int) (part1/10);
+      *pos--= '-';
+      *pos--= (char) ('0'+(char) (part3%10)); part3/=10;
+      *pos--= (char) ('0'+(char) (part3%10)); part3/=10;
+      *pos--= (char) ('0'+(char) (part3%10)); part3/=10;
+      *pos=(char) ('0'+(char) part3);
+      out << buf;
+    }
+    break;
+    case NdbDictionary::Column::Date:
+    {
+      uint32 tmp=(uint32) uint3korr(val_p);
+      int part;
+      char buf[40];
+      char *pos=(char*) buf+10;
+      *pos--=0;
+      part=(int) (tmp & 31);
+      *pos--= (char) ('0'+part%10);
+      *pos--= (char) ('0'+part/10);
+      *pos--= '-';
+      part=(int) (tmp >> 5 & 15);
+      *pos--= (char) ('0'+part%10);
+      *pos--= (char) ('0'+part/10);
+      *pos--= '-';
+      part=(int) (tmp >> 9);
+      *pos--= (char) ('0'+part%10); part/=10;
+      *pos--= (char) ('0'+part%10); part/=10;
+      *pos--= (char) ('0'+part%10); part/=10;
+      *pos=   (char) ('0'+part);
+      out << buf;
+    }
+    break;
+    case NdbDictionary::Column::Time:
+    {
+      long tmp=(long) sint3korr(val_p);
+      int hour=(uint) (tmp/10000);
+      int minute=(uint) (tmp/100 % 100);
+      int second=(uint) (tmp % 100);
+      char buf[40];
+      sprintf(buf, "%02d:%02d:%02d", hour, minute, second);
+      out << buf;
+    }
+    break;
+    case NdbDictionary::Column::Year:
+    {
+      uint year = 1900 + *((const Uint8*) val);
+      char buf[40];
+      sprintf(buf, "%04d", year);
+      out << buf;
+    }
+    break;
+    case NdbDictionary::Column::Timestamp:
+    {
+      time_t time = *(const Uint32*) val;
+      out << (uint)time;
+    }
+    break;
+    case NdbDictionary::Column::Blob:
+    case NdbDictionary::Column::Text:
+    {
+      NdbBlob::Head head;
+      NdbBlob::unpackBlobHead(head, (const char*) val_p, c->getBlobVersion());
+      out << head.length << ":";
+      const unsigned char* p = val_p + head.headsize;
+      if ((unsigned int) c->getLength() < head.headsize)
+        out << "***error***"; // really cannot happen
+      else {
+        unsigned n = c->getLength() - head.headsize;
+        for (unsigned k = 0; k < n && k < head.length; k++) {
+          if (c->getType() == NdbDictionary::Column::Blob)
+            out.print("%02X", (int)p[k]);
+          else
+            out.print("%c", (int)p[k]);
+        }
+      }
+      j = length;
+    }
+    break;
+    case NdbDictionary::Column::Longvarchar:
+    {
+      out << fields_optionally_enclosed_by;
+      unsigned len = uint2korr(val_p);
+      pretty_print_string(out,format,"Longvarchar", false, 
+                          val_p+2,len);
+      j = length;
+      out << fields_optionally_enclosed_by;
+    }
+    break;
+    case NdbDictionary::Column::Longvarbinary:
+    {
+      if (!format.hex_format)
+        out << fields_optionally_enclosed_by;
+      unsigned len = uint2korr(val_p);
+      pretty_print_string(out,format,"Longvarbinary", true, 
+                          val_p+2,len);
+      j = length;
+      if (!format.hex_format)
+        out << fields_optionally_enclosed_by;
+    }
+    break;
+
+    default: /* no print functions for the rest, just print type */
+      out << "Unable to format type (" 
+          << (int) c->getType()
+          << ")";
+      if (length > 1)
+        out << " " << length << " times";
+      break;
+    }
+    out << format.fields_enclosed_by;
+  }
+  
+  return out;
+}
+
+NdbDictionary::NdbDataPrintFormat::NdbDataPrintFormat()
+{
+  fields_terminated_by= ";";
+  start_array_enclosure= "[";
+  end_array_enclosure= "]";
+  fields_enclosed_by= "";
+  fields_optionally_enclosed_by= "\"";
+  lines_terminated_by= "\n";
+  hex_prefix= "H'";
+  null_string= "[NULL]";
+  hex_format= 0;
+}
+NdbDictionary::NdbDataPrintFormat::~NdbDataPrintFormat() {};
+
+
 NdbOut&
 operator<<(NdbOut& out, const NdbDictionary::Column& col)
 {
@@ -2792,6 +3255,23 @@ operator<<(NdbOut& out, const NdbDiction
   if(col.getDynamic())
     out << " DYNAMIC";
 
+  const void *default_data = col.getDefaultValue();
+
+  if (default_data != NULL)
+  {
+    NdbDictionary::NdbDataPrintFormat f;
+
+    /* Display binary field defaults as hex */
+    f.hex_format = 1;
+
+    out << " DEFAULT ";
+    
+    NdbDictionary::printFormattedValue(out,
+                                       f,
+                                       &col,
+                                       default_data);
+  }
+  
   return out;
 }
 

=== modified file 'storage/ndb/src/ndbapi/NdbDictionaryImpl.cpp'
--- a/storage/ndb/src/ndbapi/NdbDictionaryImpl.cpp	2010-03-26 07:13:06 +0000
+++ b/storage/ndb/src/ndbapi/NdbDictionaryImpl.cpp	2010-04-29 14:52:05 +0000
@@ -101,7 +101,7 @@ NdbColumnImpl::operator=(const NdbColumn
   m_nullable = col.m_nullable;
   m_autoIncrement = col.m_autoIncrement;
   m_autoIncrementInitialValue = col.m_autoIncrementInitialValue;
-  m_defaultValue = col.m_defaultValue;
+  m_defaultValue.assign(col.m_defaultValue);
   m_attrSize = col.m_attrSize; 
   m_arraySize = col.m_arraySize;
   m_arrayType = col.m_arrayType;
@@ -307,7 +307,10 @@ NdbColumnImpl::equal(const NdbColumnImpl
   if (m_autoIncrement != col.m_autoIncrement){
     DBUG_RETURN(false);
   }
-  if(strcmp(m_defaultValue.c_str(), col.m_defaultValue.c_str()) != 0){
+  if (m_defaultValue.length() != col.m_defaultValue.length())
+    DBUG_RETURN(false);
+
+  if(memcmp(m_defaultValue.get_data(), col.m_defaultValue.get_data(), m_defaultValue.length()) != 0){
     DBUG_RETURN(false);
   }
 
@@ -585,6 +588,7 @@ NdbTableImpl::init(){
   m_row_gci = true;
   m_row_checksum = true;
   m_force_var_part = false;
+  m_has_default_values = false;
   m_kvalue= 6;
   m_minLoadFactor= 78;
   m_maxLoadFactor= 80;
@@ -858,6 +862,7 @@ NdbTableImpl::assign(const NdbTableImpl&
   m_row_gci = org.m_row_gci;
   m_row_checksum = org.m_row_checksum;
   m_force_var_part = org.m_force_var_part;
+  m_has_default_values = org.m_has_default_values;
   m_kvalue = org.m_kvalue;
   m_minLoadFactor = org.m_minLoadFactor;
   m_maxLoadFactor = org.m_maxLoadFactor;
@@ -2776,13 +2781,19 @@ NdbDictInterface::parseTableInfo(NdbTabl
     col->m_nullable = attrDesc.AttributeNullableFlag;
     col->m_autoIncrement = (attrDesc.AttributeAutoIncrement != 0);
     col->m_autoIncrementInitialValue = ~0;
-    if (!col->m_defaultValue.assign(attrDesc.AttributeDefaultValue))
+    AttributeHeader ah(*(Uint32*)attrDesc.AttributeDefaultValue);
+    Uint32 bytesize = ah.getByteSize();
+
+    if (col->m_defaultValue.assign((const char*)(attrDesc.AttributeDefaultValue + 4), bytesize))
     {
       delete col;
       delete impl;
       DBUG_RETURN(4000);
     }
 
+    if (bytesize > 0)
+      impl->m_has_default_values = true;
+
     col->m_column_no = impl->m_columns.size();
     impl->m_columns.push_back(col);
     it.next();
@@ -2867,6 +2878,12 @@ NdbDictionaryImpl::createTable(NdbTableI
       autoIncrement = true;
       initialValue = c->m_autoIncrementInitialValue;
     }
+
+    if (c->m_pk && (! c->m_defaultValue.empty())) {
+      /* Default value for primary key column not supported */
+      m_error.code = 792;
+      DBUG_RETURN(-1);
+    }
   }
  
   // create table
@@ -3461,9 +3478,31 @@ loop:
     }
 
     tmpAttr.AttributeAutoIncrement = col->m_autoIncrement;
-    BaseString::snprintf(tmpAttr.AttributeDefaultValue, 
-                         sizeof(tmpAttr.AttributeDefaultValue),
-                         "%s", col->m_defaultValue.c_str());
+    {
+      Uint32 ah;
+      Uint32 byteSize = col->m_defaultValue.length();
+
+      if (byteSize)
+      {
+        if (unlikely(! ndb_native_default_support(ndb.getMinDbNodeVersion())))
+        {
+          /* We can't create a table with native defaults with
+           * this kernel version
+           * Schema feature requires data node upgrade
+           */
+          m_error.code = 794;
+          DBUG_RETURN(-1);
+        }
+      }   
+
+      //The AttributeId of a column isn't decided now, so 0 is used.
+      AttributeHeader::init(&ah, 0, byteSize);
+
+      memcpy(tmpAttr.AttributeDefaultValue, &ah, 4);
+      memcpy(tmpAttr.AttributeDefaultValue + 4, col->m_defaultValue.get_data(), byteSize);
+
+      tmpAttr.AttributeDefaultValueLen = (((col->m_defaultValue.length() + 3) / 4) * 4) + 4;
+    }
     s = SimpleProperties::pack(w, 
 			       &tmpAttr,
 			       DictTabInfo::AttributeMapping, 

=== modified file 'storage/ndb/src/ndbapi/NdbDictionaryImpl.hpp'
--- a/storage/ndb/src/ndbapi/NdbDictionaryImpl.hpp	2010-03-01 14:13:01 +0000
+++ b/storage/ndb/src/ndbapi/NdbDictionaryImpl.hpp	2010-04-29 14:52:05 +0000
@@ -96,7 +96,7 @@ public:
   bool m_nullable;
   bool m_autoIncrement;
   Uint64 m_autoIncrementInitialValue;
-  BaseString m_defaultValue;
+  UtilBuffer m_defaultValue;
   /*
    * Table holding the blob parts.
    *
@@ -226,6 +226,7 @@ public:
   bool m_row_gci;
   bool m_row_checksum;
   bool m_force_var_part;
+  bool m_has_default_values; 
   int m_kvalue;
   int m_minLoadFactor;
   int m_maxLoadFactor;

=== modified file 'storage/ndb/src/ndbapi/NdbRecAttr.cpp'
--- a/storage/ndb/src/ndbapi/NdbRecAttr.cpp	2009-05-27 15:21:45 +0000
+++ b/storage/ndb/src/ndbapi/NdbRecAttr.cpp	2010-04-29 14:52:05 +0000
@@ -23,9 +23,6 @@
 #include <NdbBlob.hpp>
 #include "NdbDictionaryImpl.hpp"
 #include <NdbTCP.h>
-C_MODE_START
-#include <decimal.h>
-C_MODE_END
 
 NdbRecAttr::NdbRecAttr(Ndb*)
 {
@@ -177,390 +174,16 @@ NdbRecAttr::receive_data(const Uint32 * 
   return false;
 }
 
-NdbRecordPrintFormat::NdbRecordPrintFormat()
-{
-  fields_terminated_by= ";";
-  start_array_enclosure= "[";
-  end_array_enclosure= "]";
-  fields_enclosed_by= "";
-  fields_optionally_enclosed_by= "\"";
-  lines_terminated_by= "\n";
-  hex_prefix= "H'";
-  null_string= "[NULL]";
-  hex_format= 0;
-}
-NdbRecordPrintFormat::~NdbRecordPrintFormat() {}
 static const NdbRecordPrintFormat default_print_format;
 
-static void
-ndbrecattr_print_string(NdbOut& out, const NdbRecordPrintFormat &f,
-                        const char *type, bool is_binary,
-			const char *aref, unsigned sz)
-{
-  const unsigned char* ref = (const unsigned char*)aref;
-  int i, len, printable= 1;
-  // trailing zeroes are not printed
-  for (i=sz-1; i >= 0; i--)
-    if (ref[i] == 0) sz--;
-    else break;
-  if (!is_binary)
-  {
-    // trailing spaces are not printed
-    for (i=sz-1; i >= 0; i--)
-      if (ref[i] == 32) sz--;
-      else break;
-  }
-  if (is_binary && f.hex_format)
-  {
-    if (sz == 0)
-    {
-      out.print("0x0");
-      return;
-    }
-    out.print("0x");
-    for (len = 0; len < (int)sz; len++)
-      out.print("%02X", (int)ref[len]);
-    return;
-  }
-  if (sz == 0) return; // empty
-
-  for (len=0; len < (int)sz && ref[i] != 0; len++)
-    if (printable && !isprint((int)ref[i]))
-      printable= 0;
-
-  if (printable)
-    out.print("%.*s", len, ref);
-  else
-  {
-    out.print("0x");
-    for (i=0; i < len; i++)
-      out.print("%02X", (int)ref[i]);
-  }
-  if (len != (int)sz)
-  {
-    out.print("[");
-    for (i= len+1; ref[i] != 0; i++)
-    out.print("%u]",len-i);
-    assert((int)sz > i);
-    ndbrecattr_print_string(out,f,type,is_binary,aref+i,sz-i);
-  }
-}
-
-/* Three MySQL defs duplicated here : */ 
-static const int MaxMySQLDecimalPrecision= 65;
-static const int MaxMySQLDecimalScale= 30;
-static const int DigitsPerDigit_t= 9; // (Decimal digits in 2^32)
-
-/* Implications */
-/* Space for -, . and \0 */
-static const int MaxDecimalStrLen= MaxMySQLDecimalPrecision + 3;
-static const int IntPartDigit_ts= 
-  ((MaxMySQLDecimalPrecision - 
-    MaxMySQLDecimalScale) +
-   DigitsPerDigit_t -1) / DigitsPerDigit_t;
-static const int FracPartDigit_ts= 
-  (MaxMySQLDecimalScale + 
-   DigitsPerDigit_t - 1) / DigitsPerDigit_t;
-static const int DigitArraySize= IntPartDigit_ts + FracPartDigit_ts;
-
 NdbOut&
 ndbrecattr_print_formatted(NdbOut& out, const NdbRecAttr &r,
                            const NdbRecordPrintFormat &f)
 {
-  if (r.isNULL())
-  {
-    out << f.null_string;
-    return out;
-  }
-  
-  const NdbDictionary::Column* c = r.getColumn();
-  uint length = c->getLength();
-  {
-    const char *fields_optionally_enclosed_by;
-    if (f.fields_enclosed_by[0] == '\0')
-      fields_optionally_enclosed_by=
-        f.fields_optionally_enclosed_by;
-    else
-      fields_optionally_enclosed_by= "";
-    out << f.fields_enclosed_by;
-    Uint32 j;
-    switch(r.getType()){
-    case NdbDictionary::Column::Bigunsigned:
-      out << r.u_64_value();
-      break;
-    case NdbDictionary::Column::Bit:
-      out << f.hex_prefix << "0x";
-      {
-        const Uint32 *buf = (Uint32 *)r.aRef();
-        int k = (length+31)/32;
-        while (k > 0 && (buf[--k] == 0));
-        out.print("%X", buf[k]);
-        while (k > 0)
-          out.print("%.8X", buf[--k]);
-      }
-      break;
-    case NdbDictionary::Column::Unsigned:
-      if (length > 1)
-        out << f.start_array_enclosure;
-      out << *(Uint32*)r.aRef();
-      for (j = 1; j < length; j++)
-        out << " " << *((Uint32*)r.aRef() + j);
-      if (length > 1)
-        out << f.end_array_enclosure;
-      break;
-    case NdbDictionary::Column::Mediumunsigned:
-      out << r.u_medium_value();
-      break;
-    case NdbDictionary::Column::Smallunsigned:
-      out << r.u_short_value();
-      break;
-    case NdbDictionary::Column::Tinyunsigned:
-      out << (unsigned) r.u_8_value();
-      break;
-    case NdbDictionary::Column::Bigint:
-      out << r.int64_value();
-      break;
-    case NdbDictionary::Column::Int:
-      out << r.int32_value();
-      break;
-    case NdbDictionary::Column::Mediumint:
-      out << r.medium_value();
-      break;
-    case NdbDictionary::Column::Smallint:
-      out << r.short_value();
-      break;
-    case NdbDictionary::Column::Tinyint:
-      out << (int) r.int8_value();
-      break;
-    case NdbDictionary::Column::Binary:
-      if (!f.hex_format)
-        out << fields_optionally_enclosed_by;
-      j = r.get_size_in_bytes();
-      ndbrecattr_print_string(out,f,"Binary", true, r.aRef(), j);
-      if (!f.hex_format)
-        out << fields_optionally_enclosed_by;
-      break;
-    case NdbDictionary::Column::Char:
-      out << fields_optionally_enclosed_by;
-      j = r.get_size_in_bytes();
-      ndbrecattr_print_string(out,f,"Char", false, r.aRef(), j);
-      out << fields_optionally_enclosed_by;
-      break;
-    case NdbDictionary::Column::Varchar:
-    {
-      out << fields_optionally_enclosed_by;
-      unsigned len = *(const unsigned char*)r.aRef();
-      ndbrecattr_print_string(out,f,"Varchar", false, r.aRef()+1,len);
-      j = length;
-      out << fields_optionally_enclosed_by;
-    }
-    break;
-    case NdbDictionary::Column::Varbinary:
-    {
-      if (!f.hex_format)
-        out << fields_optionally_enclosed_by;
-      unsigned len = *(const unsigned char*)r.aRef();
-      ndbrecattr_print_string(out,f,"Varbinary", true, r.aRef()+1,len);
-      j = length;
-      if (!f.hex_format)
-        out << fields_optionally_enclosed_by;
-    }
-    break;
-    case NdbDictionary::Column::Float:
-      out << r.float_value();
-      break;
-    case NdbDictionary::Column::Double:
-      out << r.double_value();
-      break;
-    case NdbDictionary::Column::Olddecimal:
-    {
-      short len = 1 + c->getPrecision() + (c->getScale() > 0);
-      out.print("%.*s", len, r.aRef());
-    }
-    break;
-    case NdbDictionary::Column::Olddecimalunsigned:
-    {
-      short len = 0 + c->getPrecision() + (c->getScale() > 0);
-      out.print("%.*s", len, r.aRef());
-    }
-    break;
-    case NdbDictionary::Column::Decimal:
-    case NdbDictionary::Column::Decimalunsigned:
-    { 
-      int precision= c->getPrecision();
-      int scale= c->getScale();
-      
-      assert(precision <= MaxMySQLDecimalPrecision);
-      assert(scale <= MaxMySQLDecimalScale);
-      assert(decimal_size(precision, scale) <= DigitArraySize );
-      decimal_digit_t buff[ DigitArraySize ];
-      decimal_t tmpDec;
-      tmpDec.buf= buff;
-      tmpDec.len= DigitArraySize;
-      decimal_make_zero(&tmpDec);
-      int rc;
-
-      const uchar* data= (const uchar*) r.aRef();
-      if ((rc= bin2decimal(data, &tmpDec, precision, scale)))
-      {
-        out.print("***Error : Bad bin2decimal conversion %d ***",
-                  rc);
-        break;
-      }
-      
-      /* Get null terminated var-length string representation */
-      char decStr[MaxDecimalStrLen];
-      assert(decimal_string_size(&tmpDec) <= MaxDecimalStrLen);
-      int len= MaxDecimalStrLen;
-      if ((rc= decimal2string(&tmpDec, decStr, 
-                              &len,
-                              0,   // 0 = Var length output length
-                              0,   // 0 = Var length fractional part
-                              0))) // Filler char for fixed length
-      {
-        out.print("***Error : bad decimal2string conversion %d ***",
-                  rc);
-        break;
-      }
-
-      out.print("%s", decStr);
-      
-      break;
-    }
-      // for dates cut-and-paste from field.cc
-    case NdbDictionary::Column::Datetime:
-    {
-      ulonglong tmp=r.u_64_value();
-      long part1,part2,part3;
-      part1=(long) (tmp/LL(1000000));
-      part2=(long) (tmp - (ulonglong) part1*LL(1000000));
-      char buf[40];
-      char* pos=(char*) buf+19;
-      *pos--=0;
-      *pos--= (char) ('0'+(char) (part2%10)); part2/=10; 
-      *pos--= (char) ('0'+(char) (part2%10)); part3= (int) (part2 / 10);
-      *pos--= ':';
-      *pos--= (char) ('0'+(char) (part3%10)); part3/=10;
-      *pos--= (char) ('0'+(char) (part3%10)); part3/=10;
-      *pos--= ':';
-      *pos--= (char) ('0'+(char) (part3%10)); part3/=10;
-      *pos--= (char) ('0'+(char) part3);
-      *pos--= '/';
-      *pos--= (char) ('0'+(char) (part1%10)); part1/=10;
-      *pos--= (char) ('0'+(char) (part1%10)); part1/=10;
-      *pos--= '-';
-      *pos--= (char) ('0'+(char) (part1%10)); part1/=10;
-      *pos--= (char) ('0'+(char) (part1%10)); part3= (int) (part1/10);
-      *pos--= '-';
-      *pos--= (char) ('0'+(char) (part3%10)); part3/=10;
-      *pos--= (char) ('0'+(char) (part3%10)); part3/=10;
-      *pos--= (char) ('0'+(char) (part3%10)); part3/=10;
-      *pos=(char) ('0'+(char) part3);
-      out << buf;
-    }
-    break;
-    case NdbDictionary::Column::Date:
-    {
-      uint32 tmp=(uint32) uint3korr(r.aRef());
-      int part;
-      char buf[40];
-      char *pos=(char*) buf+10;
-      *pos--=0;
-      part=(int) (tmp & 31);
-      *pos--= (char) ('0'+part%10);
-      *pos--= (char) ('0'+part/10);
-      *pos--= '-';
-      part=(int) (tmp >> 5 & 15);
-      *pos--= (char) ('0'+part%10);
-      *pos--= (char) ('0'+part/10);
-      *pos--= '-';
-      part=(int) (tmp >> 9);
-      *pos--= (char) ('0'+part%10); part/=10;
-      *pos--= (char) ('0'+part%10); part/=10;
-      *pos--= (char) ('0'+part%10); part/=10;
-      *pos=   (char) ('0'+part);
-      out << buf;
-    }
-    break;
-    case NdbDictionary::Column::Time:
-    {
-      long tmp=(long) sint3korr(r.aRef());
-      int hour=(uint) (tmp/10000);
-      int minute=(uint) (tmp/100 % 100);
-      int second=(uint) (tmp % 100);
-      char buf[40];
-      sprintf(buf, "%02d:%02d:%02d", hour, minute, second);
-      out << buf;
-    }
-    break;
-    case NdbDictionary::Column::Year:
-    {
-      uint year = 1900 + r.u_8_value();
-      char buf[40];
-      sprintf(buf, "%04d", year);
-      out << buf;
-    }
-    break;
-    case NdbDictionary::Column::Timestamp:
-    {
-      time_t time = r.u_32_value();
-      out << (uint)time;
-    }
-    break;
-    case NdbDictionary::Column::Blob:
-    case NdbDictionary::Column::Text:
-    {
-      NdbBlob::Head head;
-      NdbBlob::unpackBlobHead(head, r.aRef(), c->getBlobVersion());
-      out << head.length << ":";
-      const unsigned char* p = (const unsigned char*)r.aRef() + head.headsize;
-      if (r.get_size_in_bytes() < head.headsize)
-        out << "***error***"; // really cannot happen
-      else {
-        unsigned n = r.get_size_in_bytes() - head.headsize;
-        for (unsigned k = 0; k < n && k < head.length; k++) {
-          if (r.getType() == NdbDictionary::Column::Blob)
-            out.print("%02X", (int)p[k]);
-          else
-            out.print("%c", (int)p[k]);
-        }
-      }
-      j = length;
-    }
-    break;
-    case NdbDictionary::Column::Longvarchar:
-    {
-      out << fields_optionally_enclosed_by;
-      unsigned len = uint2korr(r.aRef());
-      ndbrecattr_print_string(out,f,"Longvarchar", false, r.aRef()+2,len);
-      j = length;
-      out << fields_optionally_enclosed_by;
-    }
-    break;
-    case NdbDictionary::Column::Longvarbinary:
-    {
-      if (!f.hex_format)
-        out << fields_optionally_enclosed_by;
-      unsigned len = uint2korr(r.aRef());
-      ndbrecattr_print_string(out,f,"Longvarbinary", true, r.aRef()+2,len);
-      j = length;
-      if (!f.hex_format)
-        out << fields_optionally_enclosed_by;
-    }
-    break;
-
-    default: /* no print functions for the rest, just print type */
-      out << "Unable to format type (" 
-          << (int) r.getType()
-          << ")";
-      if (length > 1)
-        out << " " << length << " times";
-      break;
-    }
-    out << f.fields_enclosed_by;
-  }
-
-  return out;
+  return NdbDictionary::printFormattedValue(out,
+                                            f,
+                                            r.getColumn(),
+                                            r.aRef());
 }
 
 NdbOut& operator<<(NdbOut& out, const NdbRecAttr &r)

=== modified file 'storage/ndb/src/ndbapi/ndberror.c'
--- a/storage/ndb/src/ndbapi/ndberror.c	2010-04-27 09:35:50 +0000
+++ b/storage/ndb/src/ndbapi/ndberror.c	2010-04-30 09:41:04 +0000
@@ -318,6 +318,7 @@ ErrorBundle ErrorCodes[] = {
   { 823,  DMEC, AE, "Too much attrinfo from application in tuple manager" },
   { 829,  DMEC, AE, "Corrupt data received for insert/update" },
   { 831,  DMEC, AE, "Too many nullable/bitfields in table definition" },
+  { 850,  DMEC, AE, "Too long or too short default value"},
   { 876,  DMEC, AE, "876" },
   { 877,  DMEC, AE, "877" },
   { 878,  DMEC, AE, "878" },
@@ -473,6 +474,8 @@ ErrorBundle ErrorCodes[] = {
   { 777,  DMEC, AE, "Cannot create a temporary index on a non-temporary table" },
   { 778,  DMEC, AE, "A temporary table or index must be specified as not logging" },
   { 786,  DMEC, NR, "Schema transaction aborted due to node-failure" },
+  { 792,  DMEC, SE, "Default value for primary key column not supported" },
+  { 794,  DMEC, AE, "Schema feature requires data node upgrade" },
   
   /**
    * FunctionNotImplemented

=== modified file 'storage/ndb/test/include/NDBT_Table.hpp'
--- a/storage/ndb/test/include/NDBT_Table.hpp	2009-05-27 15:21:45 +0000
+++ b/storage/ndb/test/include/NDBT_Table.hpp	2010-04-29 14:52:05 +0000
@@ -33,7 +33,9 @@ public:
 		 bool _nullable = false,
 		 CHARSET_INFO *cs= 0,
 		 NdbDictionary::Column::StorageType storage = NdbDictionary::Column::StorageTypeMemory,
-                 bool dynamic = false):
+                 bool dynamic = false,
+                 const void* defaultVal = NULL,
+                 Uint32 defaultValBytes = 0):
     NdbDictionary::Column(_name)
   {
     assert(_name != 0);
@@ -48,6 +50,7 @@ public:
     }
     setStorageType(storage);
     setDynamic(dynamic);
+    setDefaultValue(defaultVal, defaultValBytes);
   }
 };
 

=== modified file 'storage/ndb/test/ndbapi/CMakeLists.txt'
--- a/storage/ndb/test/ndbapi/CMakeLists.txt	2010-04-16 12:25:53 +0000
+++ b/storage/ndb/test/ndbapi/CMakeLists.txt	2010-04-29 14:52:05 +0000
@@ -66,6 +66,7 @@ ADD_EXECUTABLE(DbAsyncGenerator bench/ma
 ADD_EXECUTABLE(testSRBank testSRBank.cpp)
 ADD_EXECUTABLE(test_event_merge test_event_merge.cpp)
 Add_EXECUTABLE(testNdbinfo testNdbinfo.cpp)
+ADD_EXECUTABLE(testNativeDefault testNativeDefault.cpp)
 ##testDict_INCLUDES = $(INCLUDES) -I$(top_srcdir)/ndb/include/kernel
 ##testIndex_INCLUDES = $(INCLUDES) -I$(top_srcdir)/ndb/include/kernel
 ##testSystemRestart_INCLUDES = $(INCLUDES) -I$(top_srcdir)/ndb/include/kernel

=== modified file 'storage/ndb/test/ndbapi/Makefile.am'
--- a/storage/ndb/test/ndbapi/Makefile.am	2009-11-08 12:52:27 +0000
+++ b/storage/ndb/test/ndbapi/Makefile.am	2010-04-29 14:52:05 +0000
@@ -37,6 +37,7 @@ testLimits \
 testMgm \
 testMgmd \
 testSingleUserMode \
+testNativeDefault \
 testNdbApi \
 testNodeRestart \
 testUpgrade \
@@ -104,6 +105,7 @@ testMgmd_SOURCES = testMgmd.cpp \
 testMgmd_LDFLAGS = -static
 testMgmd_CXXFLAGS = -I$(top_srcdir)/storage/ndb/src/mgmapi -I$(top_srcdir)/storage/ndb/include/debugger  
 testSingleUserMode_SOURCES = testSingleUserMode.cpp
+testNativeDefault_SOURCES = testNativeDefault.cpp
 testNdbApi_SOURCES = testNdbApi.cpp
 testNodeRestart_SOURCES = testNodeRestart.cpp
 testUpgrade_SOURCES = testUpgrade.cpp

=== modified file 'storage/ndb/test/ndbapi/testBasic.cpp'
--- a/storage/ndb/test/ndbapi/testBasic.cpp	2010-01-28 15:16:46 +0000
+++ b/storage/ndb/test/ndbapi/testBasic.cpp	2010-04-29 14:52:05 +0000
@@ -1497,19 +1497,19 @@ runBug20535(NDBT_Context* ctx, NDBT_Step
 {
   Ndb* pNdb = GETNDB(step);
   const NdbDictionary::Table * tab = ctx->getTab();
-  NdbDictionary::Dictionary * dict = pNdb->getDictionary();
 
-  bool null = false;
+  bool hasDefault = false;
   for (Uint32 i = 0; i<(Uint32)tab->getNoOfColumns(); i++)
   {
-    if (tab->getColumn(i)->getNullable())
+    if (tab->getColumn(i)->getNullable() ||
+        tab->getColumn(i)->getDefaultValue())
     {
-      null = true;
+      hasDefault = true;
       break;
     }
   }
   
-  if (!null)
+  if (!hasDefault)
     return NDBT_OK;
 
   HugoTransactions hugoTrans(* tab);
@@ -1528,7 +1528,8 @@ runBug20535(NDBT_Context* ctx, NDBT_Step
   for (Uint32 i = 0; i<(Uint32)tab->getNoOfColumns(); i++)
   {
     if (!tab->getColumn(i)->getPrimaryKey() &&
-        !tab->getColumn(i)->getNullable())
+        !tab->getColumn(i)->getNullable() &&
+        !tab->getColumn(i)->getDefaultValue())
     {
       hugoTrans.setValueForAttr(pOp, i, 0, 1);
     }
@@ -1547,7 +1548,8 @@ runBug20535(NDBT_Context* ctx, NDBT_Step
   for (Uint32 i = 0; i<(Uint32)tab->getNoOfColumns(); i++)
   {
     if (!tab->getColumn(i)->getPrimaryKey() &&
-        tab->getColumn(i)->getNullable())
+        (tab->getColumn(i)->getNullable() ||
+         tab->getColumn(i)->getDefaultValue()))
     {
       values.push_back(pOp->getValue(i));
     }
@@ -1556,19 +1558,48 @@ runBug20535(NDBT_Context* ctx, NDBT_Step
   if (pTrans->execute(Commit) != 0)
     return NDBT_FAILED;
 
-  null = true;
+  bool defaultOk = true;
   for (unsigned int i = 0; i<values.size(); i++)
   {
-    if (!values[i]->isNULL())
+    const NdbRecAttr* recAttr = values[i];
+    const NdbDictionary::Column* col = recAttr->getColumn();
+    unsigned int defaultLen = 0;
+    const char* def = (const char*) col->getDefaultValue(&defaultLen);
+      
+    if (def)
+    {
+      /* Column has a native default, check that it was set */
+
+      if (!recAttr->isNULL())
+      {
+        if (memcmp(def, recAttr->aRef(), defaultLen) != 0)
+        {
+          defaultOk = false;
+          ndbout_c("column %s does not have correct default value",
+                   recAttr->getColumn()->getName());
+        }
+      }
+      else
+      {
+        defaultOk = false;
+        ndbout_c("column %s is null, should have default value",
+                 recAttr->getColumn()->getName());
+      }
+    }
+    else
     {
-      null = false;
-      ndbout_c("column %s is not NULL", values[i]->getColumn()->getName());
+      /* Column has Null as its default */      
+      if (!recAttr->isNULL())
+      {
+        defaultOk = false;
+        ndbout_c("column %s is not NULL", recAttr->getColumn()->getName());
+      }
     }
   }
   
   pTrans->close();  
   
-  if (null)
+  if (defaultOk)
     return NDBT_OK;
   else
     return NDBT_FAILED;

=== modified file 'storage/ndb/test/ndbapi/testBitfield.cpp'
--- a/storage/ndb/test/ndbapi/testBitfield.cpp	2009-09-25 14:08:15 +0000
+++ b/storage/ndb/test/ndbapi/testBitfield.cpp	2010-04-29 14:52:05 +0000
@@ -69,7 +69,7 @@ main(int argc, char** argv){
   Ndb* pNdb;
   pNdb = new Ndb(&con, _dbname);  
   pNdb->init();
-  while (pNdb->waitUntilReady() != 0);
+  while (pNdb->waitUntilReady() != 0) {};
 
   NdbDictionary::Dictionary * dict = pNdb->getDictionary();
 
@@ -130,7 +130,9 @@ create_random_table(Ndb* pNdb)
   do {
     NdbDictionary::Table tab;
     Uint32 cols = 1 + (rand() % (NDB_MAX_ATTRIBUTES_IN_TABLE - 1));
-    Uint32 length = 4090;
+    const Uint32 maxLength = 4090;
+    Uint32 length = maxLength;
+    Uint8  defbuf[(maxLength + 7)/8];
     
     BaseString name; 
     name.assfmt("TAB_%d", rand() & 65535);
@@ -153,6 +155,10 @@ create_random_table(Ndb* pNdb)
       col.setType(NdbDictionary::Column::Bit);
       
       Uint32 len = 1 + (rand() % (length - 1));
+      memset(defbuf, 0, (length + 7)/8);
+      for (Uint32 j = 0; j < len/8; j++)
+        defbuf[j] = 0x63;
+      col.setDefaultValue(defbuf, (len + 7)/8);
       col.setLength(len); length -= len;
       int nullable = (rand() >> 16) & 1;
       col.setNullable(nullable); length -= nullable;

=== modified file 'storage/ndb/test/ndbapi/testDict.cpp'
--- a/storage/ndb/test/ndbapi/testDict.cpp	2010-01-18 11:12:17 +0000
+++ b/storage/ndb/test/ndbapi/testDict.cpp	2010-04-29 14:52:05 +0000
@@ -25,6 +25,7 @@
 #include <signaldata/DumpStateOrd.hpp>
 #include <../../include/kernel/ndb_limits.h>
 #include <../../include/kernel/trigger_definitions.h>
+#include <signaldata/DictTabInfo.hpp>
 #include <random.h>
 #include <NdbAutoPtr.hpp>
 #include <NdbMixRestarter.hpp>
@@ -1854,13 +1855,38 @@ runCreateDiskTable(NDBT_Context* ctx, ND
   return NDBT_OK;
 }
 
+int getColumnMaxLength(const NdbDictionary::Column* c)
+{
+  int length= c->getLength();
+  if (c->getArrayType() == NDB_ARRAYTYPE_FIXED)
+  {
+    /* Not yet set - need to calculate from type etc. */
+    DictTabInfo::Attribute attrDesc;
+
+    attrDesc.init();
+    attrDesc.AttributeExtType= c->getType();
+    attrDesc.AttributeExtLength= c->getLength();
+    attrDesc.AttributeExtPrecision= c->getPrecision();
+    attrDesc.AttributeExtScale= c->getScale();
+
+    if (!attrDesc.translateExtType())
+    {
+      return 0;
+    }
+
+    length= ((1 << attrDesc.AttributeSize) * c->getLength()) >> 3;
+  }
+
+  return length;
+}
+
 #include <NDBT_Tables.hpp>
 
 #define SAFTY 300
 
 int runFailAddFragment(NDBT_Context* ctx, NDBT_Step* step){
   static int acclst[] = { 3001, 6200, 6202 };
-  static int tuplst[] = { 4007, 4008, 4009, 4010 };
+  static int tuplst[] = { 4007, 4008, 4009, 4010, 4032, 4033, 4034 };
   static int tuxlst[] = { 12001, 12002, 12003, 12004, 
                           6201, 6203 };
   static unsigned acccnt = sizeof(acclst)/sizeof(acclst[0]);
@@ -1881,7 +1907,44 @@ int runFailAddFragment(NDBT_Context* ctx
     errNo = atoi(buf);
     ndbout_c("Using errno: %u", errNo);
   }
-  
+
+  const NdbDictionary::Table* origTab= ctx->getTab();
+  HugoCalculator calc(*origTab);
+
+  // Add defaults to some columns
+  for (int colNum= 0; colNum < tab.getNoOfColumns(); colNum++)
+  {
+    const NdbDictionary::Column* origCol= origTab->getColumn(colNum);
+    NdbDictionary::Column* col= tab.getColumn(colNum);
+    if (!origCol->getPrimaryKey())
+    {
+      if (myRandom48(2) == 0)
+      {
+        char defaultBuf[ NDB_MAX_TUPLE_SIZE ];
+        Uint32 real_len;
+        Uint32 updatesVal = myRandom48(1 << 16);
+        const char* def= calc.calcValue(0, colNum, updatesVal, 
+                                        defaultBuf,
+                                        getColumnMaxLength(origCol),
+                                        &real_len);
+        if (col->setDefaultValue(def, real_len) != 0)
+        {
+          ndbout_c("Error setting default value\n");
+          return NDBT_FAILED;
+        }
+        NdbDictionary::NdbDataPrintFormat dpf;
+        ndbout << "Set default for column " << origCol->getName()
+               << " to ";
+        
+        NdbDictionary::printFormattedValue(ndbout,
+                                           dpf,
+                                           col,
+                                           def);
+        ndbout << endl;
+      }
+    }
+  }
+
   // ordered index on first few columns
   NdbDictionary::Index idx("X");
   idx.setTable(tab.getName());

=== modified file 'storage/ndb/test/ndbapi/testLcp.cpp'
--- a/storage/ndb/test/ndbapi/testLcp.cpp	2010-03-11 19:47:09 +0000
+++ b/storage/ndb/test/ndbapi/testLcp.cpp	2010-04-13 16:01:38 +0000
@@ -361,7 +361,7 @@ static int pause_lcp(int error)
 
   int filter[] = { 15, NDB_MGM_EVENT_CATEGORY_INFO, 0 };
 
-  my_socket my_fd;
+  NDB_SOCKET_TYPE my_fd;
 #ifdef NDB_WIN
   SOCKET fd= ndb_mgm_listen_event(g_restarter.handle, filter);
   my_fd.s= fd;
@@ -460,7 +460,7 @@ static int do_op(int row)
 static int continue_lcp(int error)
 {
   int filter[] = { 15, NDB_MGM_EVENT_CATEGORY_INFO, 0 };
-  my_socket my_fd;
+  NDB_SOCKET_TYPE my_fd;
   my_socket_invalidate(&my_fd);
 #ifdef NDB_WIN
   SOCKET fd;

=== modified file 'storage/ndb/test/ndbapi/testMgm.cpp'
--- a/storage/ndb/test/ndbapi/testMgm.cpp	2010-03-16 15:56:18 +0000
+++ b/storage/ndb/test/ndbapi/testMgm.cpp	2010-04-13 16:01:38 +0000
@@ -454,7 +454,7 @@ int runTestMgmApiEventTimeout(NDBT_Conte
                      1, NDB_MGM_EVENT_CATEGORY_STARTUP,
                      0 };
 
-    my_socket my_fd;
+    NDB_SOCKET_TYPE my_fd;
 #ifdef NDB_WIN
     SOCKET fd= ndb_mgm_listen_event(h, filter);
     my_fd.s= fd;

=== added file 'storage/ndb/test/ndbapi/testNativeDefault.cpp'
--- a/storage/ndb/test/ndbapi/testNativeDefault.cpp	1970-01-01 00:00:00 +0000
+++ b/storage/ndb/test/ndbapi/testNativeDefault.cpp	2010-04-29 14:52:05 +0000
@@ -0,0 +1,810 @@
+/* Copyright (C) 2008 MySQL AB
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; version 2 of the License.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
+#include <NdbOut.hpp>
+#include <NdbApi.hpp>
+#include <NdbSleep.h>
+#include <NDBT.hpp>
+#include <NdbError.hpp>
+
+static Ndb_cluster_connection *g_cluster_connection= 0;
+static Ndb* g_ndb = 0;
+static const char* g_tablename1 = "T_DEF1"; //The normal table with default values
+static const char* g_tablename2 = "T_DEF2"; //The table for Test that maximum length defaults work
+//The table for Test that an attempt to insert to a table containing defaults 
+//without supplying a value for a not-null, non-defaulted column still fails
+static const char* g_tablename3 = "T_DEF3"; 
+static NdbDictionary::Dictionary* g_dict = 0;
+static const unsigned int column_count_table1 = 8;
+static const unsigned int column_count_table2 = 2;
+static const unsigned int column_count_table3 = 2;
+
+static int connect_ndb();
+static int disconnect_ndb();
+
+static struct NdbError g_ndberror;
+static int create_table();
+
+static int connect_ndb()
+{
+  g_cluster_connection = new Ndb_cluster_connection();
+  if(g_cluster_connection->connect(12, 5, 1) != 0)
+  {
+    return NDBT_FAILED;
+  }
+  g_ndb = new Ndb(g_cluster_connection, "TEST");
+  g_ndb->init();
+  if(g_ndb->waitUntilReady(30) == 0){
+    return NDBT_OK;
+  }
+  return NDBT_FAILED;
+}
+
+static int disconnect_ndb()                                            {
+  delete g_ndb;
+  delete g_cluster_connection;
+  g_ndb = 0;
+//  g_table = 0;
+  g_cluster_connection= 0;
+  return NDBT_OK;
+}
+
+#define PRINT_ERROR(error) \
+   ndbout << "Error in " << __FILE__ << ", line: " << __LINE__ \
+            << ", code: " << error.code \
+            << ", msg: " << error.message << "." << endl
+#define FAIL(error_msg) \
+  ndbout << error_msg << " at line " << __LINE__ << endl; \
+  return NDBT_FAILED
+
+static const int            tab1_c1_default= 6; 
+static const float          tab1_c2_default= float(1234.56);
+static const double         tab1_c3_default= 4567.89;
+static const char           tab1_c4_default[]= "aaaaaa      ";
+static const unsigned int   tab1_c4_default_siglen= 12;
+static const char           tab1_c5_default[]= "\x6" "aaaaaa\0\0\0\0";
+static const unsigned int   tab1_c5_default_siglen= 7;
+static const char           tab1_c6_default[]= "aaaaaa      ";
+static const unsigned int   tab1_c6_default_siglen= 0;
+static const char           tab1_c7_default[]= "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
+static const char           tab1_c7_default_siglen= 1;
+
+static const int            tab2_c1_default_len= 8052 - 4 - 2;
+/* Max row length minus 4 bytes for key, minus 2 bytes for length info */
+static const char           tab2_c1_default_char= 'V';
+
+static int 
+create_table()
+{
+  g_dict = g_ndb->getDictionary();
+  if ((g_dict->getTable(g_tablename1) != 0) &&
+      (g_dict->dropTable(g_tablename1) != 0))
+  {
+    PRINT_ERROR(g_dict->getNdbError());
+    return NDBT_FAILED;
+  }
+
+  if ((g_dict->getTable(g_tablename2) != 0) &&
+      (g_dict->dropTable(g_tablename2) != 0))
+  {
+    PRINT_ERROR(g_dict->getNdbError());
+    return NDBT_FAILED;
+  }
+
+  if ((g_dict->getTable(g_tablename3) != 0) &&
+      (g_dict->dropTable(g_tablename3) != 0))
+  {
+    PRINT_ERROR(g_dict->getNdbError());
+    return NDBT_FAILED;
+  }
+
+  NdbDictionary::Table tab(g_tablename1);
+  tab.setLogging(false);
+  
+  NdbDictionary::Table tab2(g_tablename2);
+  tab2.setLogging(false);
+
+  NdbDictionary::Table tab3(g_tablename3);
+  tab3.setLogging(false);
+
+  // col PK - Uint32
+  { NdbDictionary::Column col("PK");
+    col.setType(NdbDictionary::Column::Unsigned);
+    col.setPrimaryKey(true);
+    col.setNullable(FALSE);
+    col.setAutoIncrement(TRUE);
+    col.setDefaultValue(NULL);
+    tab.addColumn(col);
+  }
+ 
+  { 
+    NdbDictionary::Column col("C1");
+    col.setType(NdbDictionary::Column::Int);
+    col.setDefaultValue(&tab1_c1_default,sizeof(int));
+    tab.addColumn(col);
+  }
+  
+  { 
+    NdbDictionary::Column col("C2");
+    col.setType(NdbDictionary::Column::Float);
+    col.setDefaultValue(&tab1_c2_default, sizeof(float));
+    tab.addColumn(col);
+  }
+
+  { 
+    NdbDictionary::Column col("C3");
+    col.setType(NdbDictionary::Column::Double);
+    col.setDefaultValue(&tab1_c3_default, sizeof(double));
+    tab.addColumn(col);
+  }
+
+  { 
+    NdbDictionary::Column col("C4");
+    col.setType(NdbDictionary::Column::Char);
+    col.setLength(12);
+    col.setDefaultValue(tab1_c4_default, 12);
+    tab.addColumn(col);
+  }
+
+  { 
+    NdbDictionary::Column col("C5");
+    col.setType(NdbDictionary::Column::Varchar);
+    col.setLength(199);
+    col.setDefaultValue(tab1_c5_default, tab1_c5_default_siglen);
+    tab.addColumn(col);
+  }
+
+
+  { 
+    /* Test non-null pointer passed, but with zero length? */
+    NdbDictionary::Column col("C6");
+    col.setType(NdbDictionary::Column::Char);
+    col.setLength(12);
+    col.setNullable(TRUE);
+    col.setDefaultValue(tab1_c6_default, tab1_c6_default_siglen);
+    tab.addColumn(col);
+  }
+
+  //Test that a zero-length VARCHAR default works
+  { 
+    NdbDictionary::Column col("C7");
+    col.setType(NdbDictionary::Column::Varchar);
+    col.setLength(10);
+    col.setDefaultValue(tab1_c7_default, tab1_c7_default_siglen);
+    tab.addColumn(col);
+  }
+
+  //create table T_DEF2
+  { NdbDictionary::Column col("PK");
+    col.setType(NdbDictionary::Column::Unsigned);
+    col.setPrimaryKey(true);
+    col.setNullable(FALSE);
+    col.setAutoIncrement(FALSE);
+    col.setDefaultValue(NULL, 0);
+    tab2.addColumn(col);
+  }
+
+  //Test that maximum length defaults work
+  { 
+    char default_data[tab2_c1_default_len + 2];
+    default_data[0] = (tab2_c1_default_len >> 0) & 0xff;
+    default_data[1] = (tab2_c1_default_len >> 8) & 0xff;
+    memset(default_data + 2, tab2_c1_default_char, tab2_c1_default_len);
+    NdbDictionary::Column col("C1");
+    col.setType(NdbDictionary::Column::Longvarchar);
+    col.setLength(tab2_c1_default_len);
+    col.setDefaultValue(default_data, tab2_c1_default_len + 2);
+    tab2.addColumn(col);
+  }
+
+  //Create table T_DEF3
+  { NdbDictionary::Column col("PK");
+    col.setType(NdbDictionary::Column::Unsigned);
+    col.setPrimaryKey(true);
+    col.setNullable(FALSE);
+    col.setAutoIncrement(FALSE);
+    col.setDefaultValue(NULL, 0);
+    tab3.addColumn(col);
+  }
+
+  //For column without supplying a value for a not-null, non-defaulted column
+  { NdbDictionary::Column col("C1");
+    col.setType(NdbDictionary::Column::Unsigned);
+    col.setNullable(FALSE);
+    col.setDefaultValue(NULL, 0);
+    tab3.addColumn(col);
+  }
+  
+  // create table
+  if(g_dict->createTable(tab) != 0)
+  {
+    PRINT_ERROR(g_dict->getNdbError());
+    return NDBT_FAILED;
+  }
+
+  if(g_dict->createTable(tab2) != 0)
+  {
+    PRINT_ERROR(g_dict->getNdbError());
+    return NDBT_FAILED;
+  }
+
+  if(g_dict->createTable(tab3) != 0)
+  {
+    PRINT_ERROR(g_dict->getNdbError());
+    return NDBT_FAILED;
+  }
+
+  return NDBT_OK;
+}
+
+static int
+ndb_error_check(const struct NdbError& error, unsigned int line)
+{
+  if (error.code != 850)
+  {
+    PRINT_ERROR(error);
+    ndbout << " at line " << line << "\n";
+    return NDBT_FAILED;
+  }
+  return NDBT_OK;
+}
+
+#define CHECK_ERROR(error) {                           \
+  if (ndb_error_check(error, __LINE__) == NDBT_FAILED) \
+    return NDBT_FAILED;                                \
+  }
+
+static int
+create_table_error()
+{
+  g_dict = g_ndb->getDictionary();
+
+  /*
+   * 1. The following test case is for fixed columns that
+   *    there are too long or too short default values.
+   */
+  //for too long default value
+  NdbDictionary::Table tab1("T_DEF_TEST1");
+  tab1.setLogging(false);
+
+  { NdbDictionary::Column col("PK");
+    col.setType(NdbDictionary::Column::Unsigned);
+    col.setPrimaryKey(true);
+    col.setNullable(FALSE);
+    col.setDefaultValue(NULL);
+    tab1.addColumn(col);
+  }
+
+  { int default_data = 6;
+    NdbDictionary::Column col("C1");
+    col.setType(NdbDictionary::Column::Int);
+    col.setDefaultValue(&default_data, 8);
+    tab1.addColumn(col);
+  }
+
+  if(g_dict->createTable(tab1) != 0)
+  {
+    CHECK_ERROR(g_dict->getNdbError());
+  }
+  else
+  {
+    FAIL("Create table should not have succeeded");
+  }
+  
+  //for too short default value
+  NdbDictionary::Table tab2("T_DEF_TEST2");
+  tab2.setLogging(false);
+
+  { NdbDictionary::Column col("PK");
+    col.setType(NdbDictionary::Column::Unsigned);
+    col.setPrimaryKey(true);
+    col.setNullable(FALSE);
+    col.setAutoIncrement(TRUE);
+    col.setDefaultValue(NULL);
+    tab2.addColumn(col);
+  }
+
+  { const char default_data[] = "aaaaaa";
+    NdbDictionary::Column col("C4");
+    col.setType(NdbDictionary::Column::Char);
+    col.setLength(12);
+    col.setDefaultValue(default_data, 6);
+    tab2.addColumn(col);
+  }
+
+  if(g_dict->createTable(tab2) != 0)
+  {
+    CHECK_ERROR(g_dict->getNdbError());
+  }
+  else
+  {
+    FAIL("Create table should not have succeeded");
+  }
+
+  /*
+   * 2. The following test case is for Var-type columns that
+   *    there are too long default values.
+   */
+  NdbDictionary::Table tab3("T_DEF_TEST3");
+  tab3.setLogging(false);
+
+  { NdbDictionary::Column col("PK");
+    col.setType(NdbDictionary::Column::Unsigned);
+    col.setPrimaryKey(true);
+    col.setNullable(FALSE);
+    col.setAutoIncrement(TRUE);
+    col.setDefaultValue(NULL);
+    tab3.addColumn(col);
+  }
+
+  { char default_data[20];
+    memset(default_data, 0, 20);
+    Uint8 * p = (Uint8*)default_data;
+    *p = 10;
+    memcpy(default_data + 1, "aaaaaaaaaa", 10);
+    NdbDictionary::Column col("C5");
+    col.setType(NdbDictionary::Column::Varchar);
+    col.setLength(9);
+    col.setDefaultValue(default_data, 11);
+    tab3.addColumn(col);
+  }
+
+  if(g_dict->createTable(tab3) != 0)
+  {
+    CHECK_ERROR(g_dict->getNdbError());
+  }
+  else
+  {
+    FAIL("Create table should not have succeeded");
+  }
+
+
+  /*
+   * 3. Test attempt to set default value for primary key
+   */
+  NdbDictionary::Table tab4("T_DEF_TEST4");
+  tab4.setLogging(false);
+
+  { NdbDictionary::Column col("PK");
+    unsigned int default_val=22;
+    col.setType(NdbDictionary::Column::Unsigned);
+    col.setPrimaryKey(true);
+    col.setNullable(FALSE);
+    col.setAutoIncrement(TRUE);
+    col.setDefaultValue(&default_val, sizeof(default_val));
+    tab4.addColumn(col);
+  }
+
+  if(g_dict->createTable(tab4) == 0)
+  {
+    FAIL("Create table should not have succeeded");
+  }
+
+  if(g_dict->getNdbError().code != 792)
+  {
+    PRINT_ERROR(g_dict->getNdbError());
+    return NDBT_FAILED;
+  }
+ 
+  /*
+   * 4. The following test case is for Var-type columns that
+   *    there are too long default values, where the passed
+   *    value is short, but the implied value is too long
+   */
+  NdbDictionary::Table tab5("T_DEF_TEST5");
+  tab5.setLogging(false);
+
+  { NdbDictionary::Column col("PK");
+    col.setType(NdbDictionary::Column::Unsigned);
+    col.setPrimaryKey(true);
+    col.setNullable(FALSE);
+    col.setAutoIncrement(TRUE);
+    col.setDefaultValue(NULL);
+    tab5.addColumn(col);
+  }
+
+  { char default_data[20];
+    memset(default_data, 0, 20);
+    Uint8 * p = (Uint8*)default_data;
+    *p = 15;
+    memcpy(default_data + 1, "aaaaaaaaaa", 15);
+    NdbDictionary::Column col("C5");
+    col.setType(NdbDictionary::Column::Varchar);
+    col.setLength(9);
+    /* Within range, but contained VARCHAR is too long */
+    col.setDefaultValue(default_data, 10);
+    tab5.addColumn(col);
+  }
+
+  if(g_dict->createTable(tab5) != 0)
+  {
+    CHECK_ERROR(g_dict->getNdbError());
+  }
+  else
+  {
+    FAIL("Create table should not have succeeded");
+  }
+
+  return NDBT_OK;
+}
+
+static int 
+drop_table()
+{
+  if ((g_dict != 0) && ( g_dict->getTable(g_tablename1) != 0))
+  {
+    if(g_dict->dropTable(g_tablename1))
+      PRINT_ERROR(g_dict->getNdbError());
+  }
+
+  if ((g_dict != 0) && ( g_dict->getTable(g_tablename2) != 0))
+  {
+    if(g_dict->dropTable(g_tablename2))
+      PRINT_ERROR(g_dict->getNdbError());
+  }
+
+  if ((g_dict != 0) && ( g_dict->getTable(g_tablename3) != 0))
+  {
+    if(g_dict->dropTable(g_tablename3))
+      PRINT_ERROR(g_dict->getNdbError());
+  }
+
+  return NDBT_OK;
+}
+
+static int do_insert()
+{
+  const NdbDictionary::Table *myTable= g_dict->getTable(g_tablename1);
+
+  if (myTable == NULL)
+  {
+    PRINT_ERROR(g_dict->getNdbError());
+    return NDBT_FAILED; 
+  }
+
+  NdbTransaction *myTransaction= g_ndb->startTransaction(); 
+  if (myTransaction == NULL)
+  {
+    PRINT_ERROR(g_ndb->getNdbError());
+    return NDBT_FAILED;
+  }
+
+  NdbOperation *myOperation= myTransaction->getNdbOperation(myTable);
+  NdbOperation *myOperation1= myTransaction->getNdbOperation(myTable); 
+  if (myOperation == NULL || myOperation1 == NULL) 
+  {
+    PRINT_ERROR(myTransaction->getNdbError());
+    g_ndb->closeTransaction(myTransaction);
+    return NDBT_FAILED;
+  }
+
+  myOperation->insertTuple();
+  myOperation->equal("PK", 1);
+  myOperation1->insertTuple();
+  myOperation1->equal("PK", 2);
+
+  //insert the second table T_DEF2
+  const NdbDictionary::Table *myTable2= g_dict->getTable(g_tablename2);
+
+  if (myTable == NULL)
+  {
+    PRINT_ERROR(g_dict->getNdbError());
+    return NDBT_FAILED;
+  }
+  NdbOperation *myOperation2 = myTransaction->getNdbOperation(myTable2);
+  if (myOperation2 == NULL)
+  {
+    PRINT_ERROR(myTransaction->getNdbError());
+    g_ndb->closeTransaction(myTransaction);
+    return NDBT_FAILED;
+  }
+
+  myOperation2->insertTuple();
+  myOperation2->equal("PK", 1);
+
+
+  /* Test insert of max length tuple with max length default
+   * Could theoretically expose kernel overflow with default 
+   * + supplied value
+   */
+  myOperation2=myTransaction->getNdbOperation(myTable2);
+  if (myOperation2 == NULL)
+  {
+    PRINT_ERROR(myTransaction->getNdbError());
+    g_ndb->closeTransaction(myTransaction);
+    return NDBT_FAILED;
+  }
+  
+  myOperation2->insertTuple();
+  myOperation2->equal("PK", 2);
+
+  {
+    char default_data[tab2_c1_default_len + 2];
+    default_data[0] = (tab2_c1_default_len >> 0) & 0xff;
+    default_data[1] = (tab2_c1_default_len >> 8) & 0xff;
+    memset(default_data + 2, tab2_c1_default_char, tab2_c1_default_len);
+    
+    myOperation2->setValue("C1", default_data);
+  }
+
+  if (myTransaction->execute(NdbTransaction::Commit) == -1)
+  {
+    PRINT_ERROR(myTransaction->getNdbError());
+    g_ndb->closeTransaction(myTransaction);
+    return NDBT_FAILED;
+  }
+  
+  g_ndb->closeTransaction(myTransaction);
+
+  //The following insert should fail, and return error code
+  const NdbDictionary::Table *myTable3= g_dict->getTable(g_tablename3);
+
+  if (myTable3 == NULL)
+  {
+    PRINT_ERROR(g_dict->getNdbError());
+    return NDBT_FAILED;
+  }
+
+  NdbTransaction *myTransaction3 = g_ndb->startTransaction();
+  if (myTransaction3 == NULL)
+  {
+    PRINT_ERROR(g_ndb->getNdbError());
+    return NDBT_FAILED;
+  }
+
+  NdbOperation *myOperation3 = myTransaction3->getNdbOperation(myTable3);
+  if (myOperation3 == NULL)
+  {
+    PRINT_ERROR(myTransaction3->getNdbError());
+    g_ndb->closeTransaction(myTransaction3);
+    return NDBT_FAILED;
+  }
+  myOperation3->insertTuple();
+  myOperation3->equal("PK", 1);
+
+  /* It should return error code 839 ( msg: Illegal null attribute)
+   * for an attempt to insert to a table containing defaults 
+   * without supplying a value for a not-null, non-defaulted column
+  */
+  if (myTransaction3->execute(NdbTransaction::Commit) == -1)
+  {
+    PRINT_ERROR(myTransaction3->getNdbError());
+    
+    if (myTransaction3->getNdbError().code != 839)
+    {
+      ndbout << "Expected error 839" << endl;
+      g_ndb->closeTransaction(myTransaction3);
+      return NDBT_FAILED;
+    }
+  }
+  g_ndb->closeTransaction(myTransaction3);
+
+  return NDBT_OK;
+}
+
+#define CHECK_VAL_EQ(ref, test) {                \
+    if ((ref) != (test)) {                       \
+      ndbout << "Equality failed at line " << __LINE__ << "\n" \
+             << test << " != " << ref << "\n"; \
+      return NDBT_FAILED;                      \
+    } }
+
+#define CHECK_BYTES_EQ(ref, test, len) {        \
+    if (memcmp((ref), (test), (len))) {         \
+      ndbout << "Bytes differ at line " << __LINE__ << "\n"; \
+      return NDBT_FAILED;                                    \
+    }} 
+
+
+
+
+static int do_read()
+{
+  NdbRecAttr *myRecAttr[column_count_table1];
+  NdbRecAttr *myRecAttr2[column_count_table2];
+  NdbRecAttr *myRecAttr3[column_count_table3];
+
+  const NdbDictionary::Table *myTable= g_dict->getTable(g_tablename1);
+  const NdbDictionary::Table *myTable2 = g_dict->getTable(g_tablename2);
+  const NdbDictionary::Table *myTable3 = g_dict->getTable(g_tablename3);
+
+  if (myTable == NULL || myTable2 == NULL || myTable3 == NULL)
+  {
+    PRINT_ERROR(g_dict->getNdbError());
+    return NDBT_FAILED;
+  }
+
+  NdbTransaction *myTransaction= g_ndb->startTransaction();
+  if (myTransaction == NULL)
+  {
+    PRINT_ERROR(g_ndb->getNdbError());
+    return NDBT_FAILED;
+  }
+
+  //Define Scan Operation for T_DEF1
+  NdbScanOperation *myScanOp = myTransaction->getNdbScanOperation(myTable);
+  if (myScanOp == NULL)
+  {
+    PRINT_ERROR(myTransaction->getNdbError());
+    g_ndb->closeTransaction(myTransaction);
+    return NDBT_FAILED;
+  }
+
+  if(myScanOp->readTuples(NdbOperation::LM_CommittedRead) == -1)
+  {
+    PRINT_ERROR(myTransaction->getNdbError());
+    g_ndb->closeTransaction(myTransaction);
+    return NDBT_FAILED;
+  }
+
+  myRecAttr[0] = myScanOp->getValue("PK");
+  myRecAttr[1] = myScanOp->getValue("C1");
+  myRecAttr[2] = myScanOp->getValue("C2");
+  myRecAttr[3] = myScanOp->getValue("C3");
+  myRecAttr[4] = myScanOp->getValue("C4");
+  myRecAttr[5] = myScanOp->getValue("C5");
+  myRecAttr[6] = myScanOp->getValue("C6");
+  myRecAttr[7] = myScanOp->getValue("C7");
+
+  for (unsigned int i = 0; i < column_count_table1; i++)
+    if (myRecAttr[i] == NULL)
+    {
+      PRINT_ERROR(myTransaction->getNdbError());
+      g_ndb->closeTransaction(myTransaction);
+      return NDBT_FAILED;
+    }
+
+  //Define Scan Operation for T_DEF2
+  NdbScanOperation *myScanOp2 = myTransaction->getNdbScanOperation(myTable2);
+  if (myScanOp2 == NULL)
+  {
+    PRINT_ERROR(myTransaction->getNdbError());
+    g_ndb->closeTransaction(myTransaction);
+    return NDBT_FAILED;
+  }
+
+  if(myScanOp2->readTuples(NdbOperation::LM_CommittedRead) == -1)
+  {
+    PRINT_ERROR(myTransaction->getNdbError());
+    g_ndb->closeTransaction(myTransaction);
+    return NDBT_FAILED;
+  }
+
+  myRecAttr2[0] = myScanOp2->getValue("PK");
+  myRecAttr2[1] = myScanOp2->getValue("C1");
+  if (myRecAttr2[0] == NULL || myRecAttr2[1] == NULL)
+  {
+    PRINT_ERROR(myTransaction->getNdbError());
+    g_ndb->closeTransaction(myTransaction);
+    return NDBT_FAILED;
+  }
+
+  //Define Scan Operation for T_DEF3  
+  NdbScanOperation *myScanOp3 = myTransaction->getNdbScanOperation(myTable3);
+  if (myScanOp3 == NULL)
+  {
+    PRINT_ERROR(myTransaction->getNdbError());
+    g_ndb->closeTransaction(myTransaction);
+    return NDBT_FAILED;
+  }
+
+  if(myScanOp3->readTuples(NdbOperation::LM_CommittedRead) == -1)
+  {
+    PRINT_ERROR(myTransaction->getNdbError());
+    g_ndb->closeTransaction(myTransaction);
+    return NDBT_FAILED;
+  }
+
+  myRecAttr3[0] = myScanOp3->getValue("PK");
+  myRecAttr3[1] = myScanOp3->getValue("C1");
+  if (myRecAttr3[0] == NULL || myRecAttr3[1] == NULL)
+  {
+    PRINT_ERROR(myTransaction->getNdbError());
+    g_ndb->closeTransaction(myTransaction);
+    return NDBT_FAILED;
+  }
+
+  //Execute the Transcation for the 3 scan operations
+  if(myTransaction->execute(NdbTransaction::NoCommit) != 0)
+  {
+    PRINT_ERROR(myTransaction->getNdbError());
+    g_ndb->closeTransaction(myTransaction);
+    return NDBT_FAILED;
+  }
+
+  //The following print out the result
+  int check;
+  ndbout<< "Table: " << g_tablename1 << endl;
+//   ndbout << "PK";
+//   for (unsigned int i = 0; i < column_count_table1; i++)
+//     ndbout << "\tC" << i ;
+//   ndbout << endl;
+  while((check = myScanOp->nextResult(true)) == 0){
+    do {
+//       for (Uint32 i = 0; i < column_count_table1; i++)
+//         ndbout << *myRecAttr[i] << "\t";
+//       ndbout << endl;
+      
+      for (Uint32 i = 0; i < column_count_table1; i++)
+      {
+        /* Check that all columns are non NULL except c6 */
+        CHECK_VAL_EQ((i == 6), myRecAttr[i]->isNULL());
+      }
+
+      CHECK_VAL_EQ(tab1_c1_default, (int) myRecAttr[1]->int32_value());
+      CHECK_VAL_EQ(tab1_c2_default, myRecAttr[2]->float_value());
+      CHECK_VAL_EQ(tab1_c3_default, myRecAttr[3]->double_value());
+      CHECK_BYTES_EQ(tab1_c4_default, (const char*) myRecAttr[4]->aRef(), tab1_c4_default_siglen);
+      CHECK_BYTES_EQ(tab1_c5_default, (const char*) myRecAttr[5]->aRef(), tab1_c5_default_siglen); 
+      CHECK_BYTES_EQ(tab1_c6_default, (const char*) myRecAttr[6]->aRef(), tab1_c6_default_siglen);
+      CHECK_BYTES_EQ(tab1_c7_default, (const char*) myRecAttr[7]->aRef(), tab1_c7_default_siglen);
+    } while((check = myScanOp->nextResult(false)) == 0);
+
+    if(check == -1)
+    {
+      ndbout << "Error with transaction " << check << " " 
+             << myTransaction->getNdbError().code << "\n";
+      return NDBT_FAILED;
+    }
+  }
+
+  ndbout<< "Table: " << g_tablename2 << endl;
+  // ndbout << "PK\tC1" << endl;
+  while((check = myScanOp2->nextResult(true)) == 0){
+    do {
+//       for (Uint32 i = 0; i < column_count_table2; i++)
+//       {
+//         if (i == 1)
+//           ndbout << myRecAttr2[i]->get_size_in_bytes() << "  ";
+//         ndbout << *myRecAttr2[i] << "\t";
+//       }
+//       ndbout << endl;
+      const char* valPtr= (const char*)myRecAttr2[1]->aRef();
+      char default_data[tab2_c1_default_len + 2];
+      default_data[0] = (tab2_c1_default_len >> 0) & 0xff;
+      default_data[1] = (tab2_c1_default_len >> 8) & 0xff;
+      memset(default_data + 2, tab2_c1_default_char, tab2_c1_default_len);
+
+      CHECK_BYTES_EQ(default_data, valPtr, tab2_c1_default_len + 2);
+
+    } while((check = myScanOp2->nextResult(false)) == 0);
+  }
+
+
+  return NDBT_OK;
+}
+
+int main(int argc, char* argv[])
+{
+  int ret = NDBT_OK;
+  ndb_init();
+  connect_ndb();
+  if ((ret = create_table_error()) == NDBT_FAILED)
+   return ret;
+
+  if ((ret = create_table()) == NDBT_FAILED)
+    return ret;
+  if ((ret = do_insert()) == NDBT_FAILED)
+    return ret;
+  if ((ret = do_read()) == NDBT_FAILED)
+    return ret;
+
+  if ((ret = drop_table()) == NDBT_FAILED)
+    return ret;
+
+  disconnect_ndb();
+
+  ndbout << "All tests successful" << endl;
+  return NDBT_OK;
+}

=== modified file 'storage/ndb/test/ndbapi/testUpgrade.cpp'
--- a/storage/ndb/test/ndbapi/testUpgrade.cpp	2010-03-22 12:38:39 +0000
+++ b/storage/ndb/test/ndbapi/testUpgrade.cpp	2010-04-29 14:52:05 +0000
@@ -847,11 +847,14 @@ runPostUpgradeChecks(NDBT_Context* ctx, 
   ndbout << "done" << endl;
 
 
-  if (ctx->getProperty("NoDDL", Uint32(0)) == 0)
+  if ((ctx->getProperty("NoDDL", Uint32(0)) == 0) &&
+      (ctx->getProperty("KeepFS", Uint32(0)) != 0))
   {
     /**
      * Bug48227
-     *   
+     * Upgrade with FS 6.3->7.0, followed by table
+     * create, followed by Sys restart resulted in 
+     * table loss.
      */
     Ndb* pNdb = GETNDB(step);
     NdbDictionary::Dictionary *pDict = pNdb->getDictionary();
@@ -915,6 +918,17 @@ runWait(NDBT_Context* ctx, NDBT_Step* st
   return NDBT_OK;
 }
 
+bool versionsSpanBoundary(int verA, int verB, int incBoundaryVer)
+{
+  int minPeerVer = MIN(verA, verB);
+  int maxPeerVer = MAX(verA, verB);
+
+  return ( (minPeerVer <  incBoundaryVer) &&
+           (maxPeerVer >= incBoundaryVer) );
+}
+
+#define SchemaTransVersion NDB_MAKE_VERSION(6,4,0)
+
 int runPostUpgradeDecideDDL(NDBT_Context* ctx, NDBT_Step* step)
 {
   /* We are running post-upgrade, now examine the versions
@@ -923,10 +937,11 @@ int runPostUpgradeDecideDDL(NDBT_Context
    */
   /* DDL should be ok as long as
    *  1) All data nodes have the same version
-   *  2) We are at the same version as the data nodes
+   *  2) There is not some version specific exception
    */
   bool useDDL = true;
 
+  Ndb* pNdb = GETNDB(step);
   NdbRestarter restarter;
   int minNdbVer = 0;
   int maxNdbVer = 0;
@@ -945,14 +960,53 @@ int runPostUpgradeDecideDDL(NDBT_Context
     useDDL = false;
     ndbout << "Ndbd nodes have mixed versions, DDL not supported" << endl;
   }
-  if (myVer != minNdbVer)
+  if (versionsSpanBoundary(myVer, minNdbVer, SchemaTransVersion))
   {
     useDDL = false;
-    ndbout << "Api has different version to Ndbd nodes, DDL not supported" << endl;
+    ndbout << "Api and Ndbd versions span schema-trans boundary, DDL not supported" << endl;
   }
 
   ctx->setProperty("NoDDL", useDDL?0:1);
 
+  if (useDDL)
+  {
+    ndbout << "Dropping and recreating tables..." << endl;
+    
+    for (int i=0; i < NDBT_Tables::getNumTables(); i++)
+    {  
+      /* Drop table (ignoring rc if it doesn't exist etc...) */
+      pNdb->getDictionary()->dropTable(NDBT_Tables::getTable(i)->getName());
+      int ret= NDBT_Tables::createTable(pNdb, 
+                                        NDBT_Tables::getTable(i)->getName(),
+                                        false,   // temp
+                                        false);  // exists ok
+      if(ret)
+      {
+        NdbError err = pNdb->getDictionary()->getNdbError();
+
+        g_err << "Failed to create table "
+              << NDBT_Tables::getTable(i)->getName()
+              << " error : " 
+              << err
+              << endl;
+
+        /* Check for allowed exceptions during upgrade */
+        if (err.code == 794)
+        {
+          /* Schema feature requires data node upgrade */
+          if (minNdbVer >= myVer)
+          {
+            g_err << "Error 794 received, but data nodes are upgraded" << endl;
+            // TODO : Dump versions here
+            return NDBT_FAILED;
+          }
+          g_err << "Create table failure due to old version NDBDs, continuing" << endl;
+        }
+      }
+    }
+    ndbout << "Done" << endl;
+  }
+
   return NDBT_OK;
 }
 

=== modified file 'storage/ndb/test/run-test/atrt-setup.sh'
--- a/storage/ndb/test/run-test/atrt-setup.sh	2010-04-28 08:10:55 +0000
+++ b/storage/ndb/test/run-test/atrt-setup.sh	2010-04-30 09:12:28 +0000
@@ -3,21 +3,36 @@
 MACHINE=$1
 LOCAL_DIR=$2
 REMOTE_DIR=$3
+verbose=
+
+if uname | grep -iq cygwin
+then
+    verbose=1
+fi
 
 # Local copy
-if [ `uname -n` = "$MACHINE" ]; then
-  if [ "$REMOTE_DIR" = "$LOCAL_DIR" -o "$REMOTE_DIR/" = "$LOCAL_DIR" ]; then
-    echo "$0: Same directoty on local host. Skipping setup..."
-  else
-    echo "$0: Local machine setup from '$REMOTE_DIR' to '$LOCAL_DIR'..."
-    cp -r "$REMOTE_DIR" "$LOCAL_DIR"
-  fi
-  exit 0;
+if [ "$MACHINE" = "`uname -n`" -o "$MACHINE" = "localhost" ]
+then
+    if [ "$REMOTE_DIR" = "$LOCAL_DIR" -o "$REMOTE_DIR/" = "$LOCAL_DIR" ]
+    then
+	if [ "$verbose" ]
+	then
+	    echo "$0: Same directory on localhost. Skipping setup..."
+	fi
+    else
+	if [ "$verbose" ]
+	then
+	    echo "$0: Local machine setup from '$REMOTE_DIR' to '$LOCAL_DIR'..."
+	fi
+	cp -r "$REMOTE_DIR" "$LOCAL_DIR"
+    fi
+    exit 0;
 fi
 
-if uname | grep -iq cygwin; then
-  LOCAL_DIR=`cygpath -u $LOCAL_DIR`
-  REMOTE_DIR=`cygpath -u $REMOTE_DIR`
+if uname | grep -iq cygwin
+then
+    LOCAL_DIR=`cygpath -u $LOCAL_DIR`
+    REMOTE_DIR=`cygpath -u $REMOTE_DIR`
 fi
 
 set -e

=== modified file 'storage/ndb/test/run-test/daily-basic-tests.txt'
--- a/storage/ndb/test/run-test/daily-basic-tests.txt	2010-03-17 12:37:40 +0000
+++ b/storage/ndb/test/run-test/daily-basic-tests.txt	2010-04-29 14:52:05 +0000
@@ -1548,3 +1548,7 @@ max-time: 300
 cmd: testNodeRestart
 args: -n MixReadUnlockRestart T1
 
+mas-time: 500
+cmd: testNativeDefault
+args: 
+

=== modified file 'storage/ndb/test/src/NDBT_Tables.cpp'
--- a/storage/ndb/test/src/NDBT_Tables.cpp	2010-01-20 09:51:06 +0000
+++ b/storage/ndb/test/src/NDBT_Tables.cpp	2010-04-29 14:52:05 +0000
@@ -407,16 +407,42 @@ const
 NDBT_Table D1("D1", sizeof(D1Attribs)/sizeof(NDBT_Attribute), D1Attribs);
 
 static
+const char* BigVarDefault =
+  "\x80\x1"
+  "KOL7 default in table D2"
+  "KOL7 default in table D2"
+  "KOL7 default in table D2"
+  "KOL7 default in table D2"
+  "KOL7 default in table D2"
+  "KOL7 default in table D2"
+  "KOL7 default in table D2"
+  "KOL7 default in table D2"
+  "KOL7 default in table D2"
+  "KOL7 default in table D2"
+  "KOL7 default in table D2"
+  "KOL7 default in table D2"
+  "KOL7 default in table D2"
+  "KOL7 default in table D2"
+  "KOL7 default in table D2"
+  "KOL7 default in table D2";
+
+static unsigned smallUintDefault = 77;
+
+static
 const
 NDBT_Attribute D2Attribs[] = {
   NDBT_Attribute("KOL1", NdbDictionary::Column::Varbinary, 127, true), 
-  NDBT_Attribute("KOL2", NdbDictionary::Column::Unsigned, 1, false, false, 0, NdbDictionary::Column::StorageTypeDisk),
+  NDBT_Attribute("KOL2", NdbDictionary::Column::Unsigned, 1, false, false, 0, NdbDictionary::Column::StorageTypeDisk, false,
+                 &smallUintDefault, sizeof(unsigned)),
   NDBT_Attribute("KOL3", NdbDictionary::Column::Unsigned),
-  NDBT_Attribute("KOL4", NdbDictionary::Column::Varbinary, 133, false, true, 0, MM, true),
+  NDBT_Attribute("KOL4", NdbDictionary::Column::Varbinary, 133, false, true, 0, MM, true, 
+                 "\x1E" "A default value for KOL4 in D2", 31),
   NDBT_Attribute("KOL5", NdbDictionary::Column::Char, 199, false, true, 0, NdbDictionary::Column::StorageTypeDisk),
   NDBT_Attribute("KOL6", NdbDictionary::Column::Bit, 21, false, false, 0, NdbDictionary::Column::StorageTypeDisk),
-  NDBT_Attribute("KOL7", NdbDictionary::Column::Longvarbinary, 384, false, true, 0, NdbDictionary::Column::StorageTypeDisk),
-  NDBT_Attribute("KOL8", NdbDictionary::Column::Varbinary, 88, false, true, 0, NdbDictionary::Column::StorageTypeDisk)
+  NDBT_Attribute("KOL7", NdbDictionary::Column::Longvarbinary, 384, false, true, 0, NdbDictionary::Column::StorageTypeDisk, false, 
+                 BigVarDefault, 386),
+  NDBT_Attribute("KOL8", NdbDictionary::Column::Varbinary, 88, false, true, 0, NdbDictionary::Column::StorageTypeDisk, false, 
+                 "\x1E""A default value for KOL8 in D2", 31)
 
 };
 static

=== modified file 'storage/ndb/tools/ndb_config.cpp'
--- a/storage/ndb/tools/ndb_config.cpp	2009-12-15 16:00:47 +0000
+++ b/storage/ndb/tools/ndb_config.cpp	2010-04-13 16:01:38 +0000
@@ -32,6 +32,7 @@
 #include <mgmapi_configuration.hpp>
 #include <ConfigInfo.hpp>
 #include <NdbAutoPtr.hpp>
+#include <NdbTCP.h>
 
 static int g_verbose = 0;
 static int try_reconnect = 3;

=== modified file 'support-files/compiler_warnings.supp'
--- a/support-files/compiler_warnings.supp	2008-11-07 11:00:38 +0000
+++ b/support-files/compiler_warnings.supp	2010-04-27 17:43:23 +0000
@@ -80,3 +80,6 @@ mi_packrec.c : .*result of 32-bit shift 
 #
 .* : .*no matching operator delete found; memory will not be freed if initialization throws an exception.*
 ctype-simple.c : .*unary minus operator applied to unsigned type, result still unsigned.*
+
+# Ignore warnings in instance manager
+listener.cc : .*conversion from 'SOCKET' to 'int'.*

=== modified file 'vio/vio.c'
--- a/vio/vio.c	2010-03-12 11:56:09 +0000
+++ b/vio/vio.c	2010-04-13 16:01:38 +0000
@@ -33,8 +33,7 @@ static void vio_init(Vio* vio, enum enum
                      my_socket sd, HANDLE hPipe, uint flags)
 {
   DBUG_ENTER("vio_init");
-  DBUG_PRINT("enter", ("type: %d  sd: " MY_SOCKET_FORMAT "  flags: %d",
-                       type, MY_SOCKET_FORMAT_VALUE(sd), flags));
+  DBUG_PRINT("enter", ("type: %d  sd: %d  flags: %d", type, sd, flags));
 
 #ifndef HAVE_VIO_READ_BUFF
   flags&= ~VIO_BUFFERED_READ;
@@ -147,14 +146,13 @@ Vio *vio_new(my_socket sd, enum enum_vio
 {
   Vio *vio;
   DBUG_ENTER("vio_new");
-  DBUG_PRINT("enter", ("sd: " MY_SOCKET_FORMAT, MY_SOCKET_FORMAT_VALUE(sd)));
+  DBUG_PRINT("enter", ("sd: %d", sd));
   if ((vio = (Vio*) my_malloc(sizeof(*vio),MYF(MY_WME))))
   {
     vio_init(vio, type, sd, 0, flags);
     sprintf(vio->desc,
-	    (vio->type == VIO_TYPE_SOCKET ? "socket (" MY_SOCKET_FORMAT ")"
-             : "TCP/IP (" MY_SOCKET_FORMAT ")"),
-	    MY_SOCKET_FORMAT_VALUE(vio->sd));
+           (vio->type == VIO_TYPE_SOCKET ? "socket (%d)" : "TCP/IP (%d)"),
+           vio->sd);
 #if !defined(__WIN__)
 #if !defined(NO_FCNTL_NONBLOCK)
     /*
@@ -167,18 +165,18 @@ Vio *vio_new(my_socket sd, enum enum_vio
       reports that the socket is set for non-blocking when it really will
       block.
     */
-    fcntl(sd.fd, F_SETFL, 0);
-    vio->fcntl_mode= fcntl(sd.fd, F_GETFL);
+    fcntl(sd, F_SETFL, 0);
+    vio->fcntl_mode= fcntl(sd, F_GETFL);
 #elif defined(HAVE_SYS_IOCTL_H)			/* hpux */
     /* Non blocking sockets doesn't work good on HPUX 11.0 */
-    (void) ioctl(sd.fd,FIOSNBIO,0);
+    (void) ioctl(sd,FIOSNBIO,0);
     vio->fcntl_mode &= ~O_NONBLOCK;
 #endif
 #else /* !defined(__WIN__) */
     {
       /* set to blocking mode by default */
       ulong arg=0, r;
-      r = ioctlsocket(sd.s,FIONBIO,(void*) &arg);
+      r = ioctlsocket(sd,FIONBIO,(void*) &arg);
       vio->fcntl_mode &= ~O_NONBLOCK;
     }
 #endif
@@ -195,9 +193,7 @@ Vio *vio_new_win32pipe(HANDLE hPipe)
   DBUG_ENTER("vio_new_handle");
   if ((vio = (Vio*) my_malloc(sizeof(Vio),MYF(MY_WME))))
   {
-    my_socket s;
-	my_socket_invalidate(&s);
-    vio_init(vio, VIO_TYPE_NAMEDPIPE, s, hPipe, VIO_LOCALHOST);
+    vio_init(vio, VIO_TYPE_NAMEDPIPE, 0, hPipe, VIO_LOCALHOST);
     strmov(vio->desc, "named pipe");
   }
   DBUG_RETURN(vio);
@@ -213,9 +209,7 @@ Vio *vio_new_win32shared_memory(HANDLE h
   DBUG_ENTER("vio_new_win32shared_memory");
   if ((vio = (Vio*) my_malloc(sizeof(Vio),MYF(MY_WME))))
   {
-    my_socket s;
-	my_socket_invalidate(&s);
-    vio_init(vio, VIO_TYPE_SHARED_MEMORY, s, 0, VIO_LOCALHOST);
+    vio_init(vio, VIO_TYPE_SHARED_MEMORY, 0, 0, VIO_LOCALHOST);
     vio->handle_file_map= handle_file_map;
     vio->handle_map= handle_map;
     vio->event_server_wrote= event_server_wrote;

=== modified file 'vio/vio_priv.h'
--- a/vio/vio_priv.h	2009-12-17 10:14:52 +0000
+++ b/vio/vio_priv.h	2010-04-13 16:01:38 +0000
@@ -25,6 +25,11 @@
 #include <m_string.h>
 #include <violite.h>
 
+#ifndef __WIN__
+#include <sys/socket.h>
+#include <netdb.h>
+#endif
+
 #ifdef _WIN32
 void	vio_win32_timeout(Vio *vio, uint which, uint timeout);
 #endif

=== modified file 'vio/viosocket.c'
--- a/vio/viosocket.c	2010-03-12 11:56:09 +0000
+++ b/vio/viosocket.c	2010-04-13 16:01:38 +0000
@@ -27,7 +27,7 @@
 
 int vio_errno(Vio *vio __attribute__((unused)))
 {
-  return my_socket_errno();
+  return socket_errno;         /* On Win32 this mapped to WSAGetLastError() */
 }
 
 
@@ -35,21 +35,17 @@ size_t vio_read(Vio * vio, uchar* buf, s
 {
   size_t r;
   DBUG_ENTER("vio_read");
-  DBUG_PRINT("enter", ("sd: " MY_SOCKET_FORMAT "  buf: 0x%lx  size: %u",
-                       MY_SOCKET_FORMAT_VALUE(vio->sd), (long) buf,
+  DBUG_PRINT("enter", ("sd: %d  buf: 0x%lx  size: %u", vio->sd, (long) buf,
                        (uint) size));
 
   /* Ensure nobody uses vio_read_buff and vio_read simultaneously */
   DBUG_ASSERT(vio->read_end == vio->read_pos);
-
-  /*
-    Callers of 'vio_read' checks "errno" even if no system function
-    failed, to avoid false positives "errno" must be reset
-  */
-  my_socket_set_errno(0);
-
-  r = my_recv(vio->sd, buf, size, 0);
-
+#ifdef __WIN__
+  r = recv(vio->sd, buf, size,0);
+#else
+  errno=0;                                     /* For linux */
+  r = read(vio->sd, buf, size);
+#endif /* __WIN__ */
 #ifndef DBUG_OFF
   if (r == (size_t) -1)
   {
@@ -71,8 +67,7 @@ size_t vio_read_buff(Vio *vio, uchar* bu
   size_t rc;
 #define VIO_UNBUFFERED_READ_MIN_SIZE 2048
   DBUG_ENTER("vio_read_buff");
-  DBUG_PRINT("enter", ("sd: " MY_SOCKET_FORMAT "  buf: 0x%lx  size: %u",
-                       MY_SOCKET_FORMAT_VALUE(vio->sd), (long) buf,
+  DBUG_PRINT("enter", ("sd: %d  buf: 0x%lx  size: %u", vio->sd, (long) buf,
                        (uint) size));
 
   if (vio->read_pos < vio->read_end)
@@ -111,11 +106,13 @@ size_t vio_write(Vio * vio, const uchar*
 {
   size_t r;
   DBUG_ENTER("vio_write");
-  DBUG_PRINT("enter", ("sd: " MY_SOCKET_FORMAT "  buf: 0x%lx  size: %u",
-                       MY_SOCKET_FORMAT_VALUE(vio->sd), (long)buf, (uint)size));
-
-  r = my_send(vio->sd, buf, size, 0);
-
+  DBUG_PRINT("enter", ("sd: %d  buf: 0x%lx  size: %u", vio->sd, (long) buf,
+                       (uint) size));
+#ifdef __WIN__
+  r = send(vio->sd, buf, size,0);
+#else
+  r = write(vio->sd, buf, size);
+#endif /* __WIN__ */
 #ifndef DBUG_OFF
   if (r == (size_t) -1)
   {
@@ -138,7 +135,7 @@ int vio_blocking(Vio * vio __attribute__
 
 #if !defined(__WIN__)
 #if !defined(NO_FCNTL_NONBLOCK)
-  if (my_socket_valid(vio->sd))
+  if (vio->sd >= 0)
   {
     int old_fcntl=vio->fcntl_mode;
     if (set_blocking_mode)
@@ -147,10 +144,10 @@ int vio_blocking(Vio * vio __attribute__
       vio->fcntl_mode |= O_NONBLOCK; /* set bit */
     if (old_fcntl != vio->fcntl_mode)
     {
-      r= my_socket_nonblock(vio->sd, (vio->fcntl_mode & O_NONBLOCK));
-      if (r!=0)
+      r= fcntl(vio->sd, F_SETFL, vio->fcntl_mode);
+      if (r == -1)
       {
-        DBUG_PRINT("info", ("fcntl failed, errno %d", r));
+        DBUG_PRINT("info", ("fcntl failed, errno %d", errno));
         vio->fcntl_mode= old_fcntl;
       }
     }
@@ -174,7 +171,7 @@ int vio_blocking(Vio * vio __attribute__
       vio->fcntl_mode |= O_NONBLOCK; /* set bit */
     }
     if (old_fcntl != vio->fcntl_mode)
-      r = ioctlsocket(vio->sd.s,FIONBIO,(void*) &arg);
+      r = ioctlsocket(vio->sd,FIONBIO,(void*) &arg);
   }
   else
     r=  test(!(vio->fcntl_mode & O_NONBLOCK)) != set_blocking_mode;
@@ -202,7 +199,7 @@ int vio_fastsend(Vio * vio __attribute__
 #if defined(IPTOS_THROUGHPUT)
   {
     int tos = IPTOS_THROUGHPUT;
-    r= my_setsockopt(vio->sd, IPPROTO_IP, IP_TOS, (void *) &tos, sizeof(tos));
+    r= setsockopt(vio->sd, IPPROTO_IP, IP_TOS, (void *) &tos, sizeof(tos));
   }
 #endif                                    /* IPTOS_THROUGHPUT */
   if (!r)
@@ -213,8 +210,9 @@ int vio_fastsend(Vio * vio __attribute__
     int nodelay = 1;
 #endif
 
-    r= my_setsockopt(vio->sd, IPPROTO_TCP, TCP_NODELAY,
-                  &nodelay, sizeof(nodelay));
+    r= setsockopt(vio->sd, IPPROTO_TCP, TCP_NODELAY,
+                  IF_WIN(const char*, void*) &nodelay,
+                  sizeof(nodelay));
 
   }
   if (r)
@@ -231,13 +229,13 @@ int vio_keepalive(Vio* vio, my_bool set_
   int r=0;
   uint opt = 0;
   DBUG_ENTER("vio_keepalive");
-  DBUG_PRINT("enter", ("sd: " MY_SOCKET_FORMAT "  set_keep_alive: %d",
-                       MY_SOCKET_FORMAT_VALUE(vio->sd), (int)set_keep_alive));
+  DBUG_PRINT("enter", ("sd: %d  set_keep_alive: %d", vio->sd, (int)
+                      set_keep_alive));
   if (vio->type != VIO_TYPE_NAMEDPIPE)
   {
     if (set_keep_alive)
       opt = 1;
-    r = my_setsockopt(vio->sd, SOL_SOCKET, SO_KEEPALIVE, (char *) &opt,
+    r = setsockopt(vio->sd, SOL_SOCKET, SO_KEEPALIVE, (char *) &opt,
 		   sizeof(opt));
   }
   DBUG_RETURN(r);
@@ -273,10 +271,10 @@ int vio_close(Vio * vio)
       vio->type == VIO_TYPE_SOCKET ||
       vio->type == VIO_TYPE_SSL);
 
-    DBUG_ASSERT(my_socket_valid(vio->sd));
-    if (my_shutdown(vio->sd, SHUT_RDWR))
+    DBUG_ASSERT(vio->sd >= 0);
+    if (shutdown(vio->sd, SHUT_RDWR))
       r= -1;
-    if (my_socket_close(vio->sd))
+    if (closesocket(vio->sd))
       r= -1;
   }
   if (r)
@@ -285,7 +283,7 @@ int vio_close(Vio * vio)
     /* FIXME: error handling (not critical for MySQL) */
   }
   vio->type= VIO_CLOSED;
-  my_socket_invalidate(&(vio->sd));
+  vio->sd=   -1;
   DBUG_RETURN(r);
 }
 
@@ -397,8 +395,8 @@ my_bool vio_peer_addr(Vio * vio, char *i
                       size_t ip_buffer_size)
 {
   DBUG_ENTER("vio_peer_addr");
-  DBUG_PRINT("enter", ("Client socket fd: " MY_SOCKET_FORMAT,
-                       MY_SOCKET_FORMAT_VALUE(vio->sd)));
+  DBUG_PRINT("enter", ("Client socket fd: %d", (int) vio->sd));
+
   if (vio->localhost)
   {
     /*
@@ -429,7 +427,7 @@ my_bool vio_peer_addr(Vio * vio, char *i
 
     /* Get sockaddr by socked fd */
 
-    err_code= my_getpeername(vio->sd, addr, &addr_length);
+    err_code= getpeername(vio->sd, addr, &addr_length);
 
     if (err_code)
     {
@@ -476,7 +474,7 @@ my_bool vio_poll_read(Vio *vio,uint time
   struct pollfd fds;
   int res;
   DBUG_ENTER("vio_poll");
-  fds.fd=vio->sd.fd; /* FIXME: Vista has WSAPoll(), can emulate elsewhere */
+  fds.fd=vio->sd;
   fds.events=POLLIN;
   fds.revents=0;
   if ((res=poll(&fds,1,(int) timeout*1000)) <= 0)
@@ -505,8 +503,9 @@ void vio_timeout(Vio *vio, uint which, u
   wait_timeout.tv_usec= 0;
 #endif
 
-  r= my_setsockopt(vio->sd, SOL_SOCKET, which ? SO_SNDTIMEO : SO_RCVTIMEO,
-                   &wait_timeout, sizeof(wait_timeout));
+  r= setsockopt(vio->sd, SOL_SOCKET, which ? SO_SNDTIMEO : SO_RCVTIMEO,
+                IF_WIN(const char*, const void*)&wait_timeout,
+                sizeof(wait_timeout));
 
   }
 
@@ -632,7 +631,7 @@ int vio_close_pipe(Vio * vio)
     /* FIXME: error handling (not critical for MySQL) */
   }
   vio->type= VIO_CLOSED;
-  my_socket_invalidate(&(vio->sd));
+  vio->sd=   -1;
   DBUG_RETURN(r);
 }
 
@@ -824,7 +823,7 @@ int vio_close_shared_memory(Vio * vio)
     }
   }
   vio->type= VIO_CLOSED;
-  my_socket_invalidate(&(vio->sd));
+  vio->sd=   -1;
   DBUG_RETURN(error_count);
 }
 #endif /* HAVE_SMEM */

=== modified file 'vio/viossl.c'
--- a/vio/viossl.c	2009-05-27 15:21:45 +0000
+++ b/vio/viossl.c	2010-04-13 16:01:38 +0000
@@ -89,10 +89,8 @@ size_t vio_ssl_read(Vio *vio, uchar* buf
 {
   size_t r;
   DBUG_ENTER("vio_ssl_read");
-  DBUG_PRINT("enter", ("sd: " MY_SOCKET_FORMAT "  buf: 0x%lx  size: %u  "
-                       "ssl: 0x%lx",
-		       MY_SOCKET_FORMAT_VALUE(vio->sd), (long) buf,
-                       (uint) size, (long) vio->ssl_arg));
+  DBUG_PRINT("enter", ("sd: %d  buf: 0x%lx  size: %u  ssl: 0x%lx",
+                      vio->sd, (long) buf, (uint) size, (long) vio->ssl_arg));
 
   r= SSL_read((SSL*) vio->ssl_arg, buf, size);
 #ifndef DBUG_OFF
@@ -108,8 +106,7 @@ size_t vio_ssl_write(Vio *vio, const uch
 {
   size_t r;
   DBUG_ENTER("vio_ssl_write");
-  DBUG_PRINT("enter", ("sd: " MY_SOCKET_FORMAT "  buf: 0x%lx  size: %u",
-                       MY_SOCKET_FORMAT_VALUE(vio->sd),
+  DBUG_PRINT("enter", ("sd: %d  buf: 0x%lx  size: %u", vio->sd,
                        (long) buf, (uint) size));
 
   r= SSL_write((SSL*) vio->ssl_arg, buf, size);
@@ -187,9 +184,8 @@ static int ssl_do(struct st_VioSSLFd *pt
   my_bool was_blocking;
 
   DBUG_ENTER("ssl_do");
-  DBUG_PRINT("enter", ("ptr: 0x%lx, sd: " MY_SOCKET_FORMAT "  ctx: 0x%lx",
-                       (long) ptr, MY_SOCKET_FORMAT_VALUE(vio->sd),
-                       (long) ptr->ssl_context));
+  DBUG_PRINT("enter", ("ptr: 0x%lx, sd: %d  ctx: 0x%lx",
+                       (long) ptr, vio->sd, (long) ptr->ssl_context));
 
   /* Set socket to blocking if not already set */
   vio_blocking(vio, 1, &was_blocking);
@@ -204,7 +200,7 @@ static int ssl_do(struct st_VioSSLFd *pt
   DBUG_PRINT("info", ("ssl: 0x%lx timeout: %ld", (long) ssl, timeout));
   SSL_clear(ssl);
   SSL_SESSION_set_timeout(SSL_get_session(ssl), timeout);
-  SSL_set_fd(ssl, my_socket_get_fd(vio->sd));
+  SSL_set_fd(ssl, vio->sd);
 
   if (connect_accept_func(ssl) < 1)
   {
@@ -220,7 +216,7 @@ static int ssl_do(struct st_VioSSLFd *pt
     change type, set sd to the fd used when connecting
     and set pointer to the SSL structure
   */
-  vio_reset(vio, VIO_TYPE_SSL, vio->sd, 0, 0);
+  vio_reset(vio, VIO_TYPE_SSL, SSL_get_fd(ssl), 0, 0);
   vio->ssl_arg= (void*)ssl;
 
 #ifndef DBUG_OFF


Attachment: [text/bzr-bundle] bzr/jonas@mysql.com-20100430094104-ttjgn5wfxplp23gy.bundle
Thread
bzr commit into mysql-5.1-telco-7.0-spj branch (jonas:3144)Jonas Oreland30 Apr