List:Commits« Previous MessageNext Message »
From:John David Duncan Date:May 16 2011 6:07am
Subject:bzr commit into mysql-5.1-telco-7.2 branch (john.duncan:4175)
View as plain text  
#At file:///Users/jdd/bzr-repo/working/cluster-7.2-labs-memcached/ based on revid:john.duncan@stripped

 4175 John David Duncan	2011-05-15
      Support CHAR

    modified:
      storage/ndb/memcache/src/DataTypeHandler.cc
=== modified file 'storage/ndb/memcache/src/DataTypeHandler.cc'
--- a/storage/ndb/memcache/src/DataTypeHandler.cc	2011-05-16 05:49:22 +0000
+++ b/storage/ndb/memcache/src/DataTypeHandler.cc	2011-05-16 06:07:15 +0000
@@ -43,46 +43,65 @@ typedef int    impl_writeToNdb(WRITE_ARG
 /* Implementations for readFromNdb() */
 impl_readFromNdb dth_decode_varchar; 
 impl_readFromNdb dth_decode_longvarchar; 
+impl_readFromNdb dth_decode_char; 
+impl_readFromNdb dth_decode_char1; 
 impl_readFromNdb dth_decode_int; 
 impl_readFromNdb dth_decode_ubigint; 
-impl_readFromNdb dth_decode_char1; 
 
 /* Implementations for impl_getStringifiedLength() */
-impl_getStringifiedLength dth_sfdlen_varchar;
-impl_getStringifiedLength dth_sfdlen_longvarchar;
-impl_getStringifiedLength dth_sfdlen_int;
-impl_getStringifiedLength dth_sfdlen_ubigint;
-impl_getStringifiedLength dth_sfdlen_char1;
+impl_getStringifiedLength dth_length_varchar;
+impl_getStringifiedLength dth_length_longvarchar;
+impl_getStringifiedLength dth_length_char;
+impl_getStringifiedLength dth_length_char1;
+impl_getStringifiedLength dth_length_int;
+impl_getStringifiedLength dth_length_ubigint;
 
 /* Implementations for writeToNdb() */
 impl_writeToNdb dth_encode_varchar;
 impl_writeToNdb dth_encode_longvarchar;
+impl_writeToNdb dth_encode_char;
+impl_writeToNdb dth_encode_char1;
 impl_writeToNdb dth_encode_int;
 impl_writeToNdb dth_encode_ubigint;
-impl_writeToNdb dth_encode_char1;
 
 
 
 /***** Singleton Handlers *****/
 DataTypeHandler Handler_Varchar =  {
-  dth_decode_varchar,
-  dth_sfdlen_varchar,
-  dth_encode_varchar,
-  0,
-  true
+  dth_decode_varchar,      // readFromNdb()
+  dth_length_varchar,      // getStringifiedLength()
+  dth_encode_varchar,      // writeToNdb()
+  0,                       // direct_int_size
+  true                     // contains_string
 };
 
 DataTypeHandler Handler_LongVarchar = {
   dth_decode_longvarchar,
-  dth_sfdlen_longvarchar,
+  dth_length_longvarchar,
   dth_encode_longvarchar,
   0,
   true
 };
 
+DataTypeHandler Handler_Char =  {
+  dth_decode_char,        // readFromNdb()
+  dth_length_char,        // getStringifiedLength()
+  dth_encode_char,        // writeToNdb()
+  0,                      // direct_int_size
+  true                    // contains_string
+};
+
+DataTypeHandler Handler_enum = {   /* NDB sees ENUM columns as CHAR(1) */
+  dth_decode_char1,
+  dth_length_char1,
+  dth_encode_char1,
+  1,
+  false
+};
+
 DataTypeHandler Handler_Int = {
   dth_decode_int,
-  dth_sfdlen_int,
+  dth_length_int,
   dth_encode_int,
   4,
   false
@@ -90,19 +109,12 @@ DataTypeHandler Handler_Int = {
 
 DataTypeHandler Handler_BigIntUnsigned = {
   dth_decode_ubigint,
-  dth_sfdlen_ubigint,
+  dth_length_ubigint,
   dth_encode_ubigint,
   8,
   false
 };
 
-DataTypeHandler Handler_enum = {   /* NDB sees ENUM columns as CHAR(1) */
-  dth_decode_char1,
-  dth_sfdlen_char1,
-  dth_encode_char1,
-  1,
-  false
-};
 
 
 /*
@@ -128,7 +140,7 @@ DataTypeHandler * getDataTypeHandlerForC
       
     case NdbDictionary::Column::Char:
       if(col->getLength() == 1) return & Handler_enum;
-      /* fallthrough.  TODO: support CHAR */
+      else return & Handler_Char;
 
     default:
       return NULL;
@@ -173,13 +185,13 @@ size_t getColumnRecordSize(const NdbDict
 /***** VARCHAR *****/
 int dth_decode_varchar(const NdbDictionary::Column *col, 
                        char * &str, const void *buf) {    
-  size_t len = dth_sfdlen_varchar(col, buf);
+  size_t len = dth_length_varchar(col, buf);
   str = ((char *) buf) + 1;
   return len;
 }                       
 
 
-size_t dth_sfdlen_varchar(const NdbDictionary::Column *col, const void *buf) {
+size_t dth_length_varchar(const NdbDictionary::Column *col, const void *buf) {
   /* Return the actual length of the value string */
   uint8_t * length_byte = (uint8_t *) buf;  
   return (size_t) (*length_byte);
@@ -209,13 +221,13 @@ int dth_encode_varchar(const NdbDictiona
 /***** LONGVARCHAR *****/
 int dth_decode_longvarchar(const NdbDictionary::Column *col, 
                            char * &str, const void *buf) {  
-  size_t len = dth_sfdlen_longvarchar(col, buf);
+  size_t len = dth_length_longvarchar(col, buf);
   str = ((char *) buf) + 2;
   return len;
 } 
 
 
-size_t dth_sfdlen_longvarchar(const NdbDictionary::Column *col, const void *buf) {
+size_t dth_length_longvarchar(const NdbDictionary::Column *col, const void *buf) {
   /* Return the actual length of the value string */
   uint8_t * length_byte_1 = (uint8_t *) buf;
   uint8_t * length_byte_2 = ((uint8_t *) buf) + 1;
@@ -247,6 +259,29 @@ int dth_encode_longvarchar(const NdbDict
 }
 
 
+/***** CHAR *****/
+int dth_decode_char(const NdbDictionary::Column *col,
+                    char * &str, const void *buf) {
+  *str = * (char *) buf;  
+  // TODO: is it null-padded? space-padded?
+  return col->getLength();
+}
+
+size_t dth_length_char(const NdbDictionary::Column *col, const void *buf) {
+  return col->getLength();
+}
+
+int dth_encode_char(const NdbDictionary::Column *col, 
+                    size_t len, size_t offset, const char *str, void *buf) {
+  char *cbuf = ((char *) buf);
+  char *dest = cbuf + offset;
+
+  if(len > col->getLength()) return DTH_VALUE_TOO_LONG;
+
+  memcpy(dest, str, len);
+  return len;  
+}                    
+
 /***** INT *****/
 int dth_decode_int(const NdbDictionary::Column *col,
                    char * &str, const void *buf) {  
@@ -254,7 +289,7 @@ int dth_decode_int(const NdbDictionary::
 }
 
 
-size_t dth_sfdlen_int(const NdbDictionary::Column *col, const void *buf) {
+size_t dth_length_int(const NdbDictionary::Column *col, const void *buf) {
   int i = *((int *) buf);
   int len = ( i < 0) ? 2 : 1;  
   for( ; i > 0 ; len++) i = i / 10;
@@ -266,8 +301,8 @@ int dth_encode_int(const NdbDictionary::
                    size_t len, size_t offset, const char *str, void *buf) {
   assert(offset == 0); 
   int *ibuf = (int *) buf;
-  *ibuf = strtol(str, NULL, 10); 
-  
+  *ibuf = strtol(str, NULL, 10);
+
   return len;
 }                                 
 
@@ -275,11 +310,11 @@ int dth_encode_int(const NdbDictionary::
 /***** BIGINT UNSIGNED *****/
 int dth_decode_ubigint(const NdbDictionary::Column *col,  
                        char * &str, const void *buf) {
-  return sprintf(str, "%"PRIu64,* (uint64_t *) buf) + 1;  // +1 for null
+  return sprintf(str, "%"PRIu64,* (Uint64 *) buf) + 1;  // +1 for null
 }
 
 
-size_t dth_sfdlen_ubigint(const NdbDictionary::Column *col, const void *buf) {
+size_t dth_length_ubigint(const NdbDictionary::Column *col, const void *buf) {
   int i = *((uint64_t *) buf);
   int len = ( i < 0) ? 2 : 1;  
   for( ; i > 0 ; len++) i = i / 10;
@@ -305,8 +340,8 @@ int dth_decode_char1(const NdbDictionary
   return 1;
 }
 
-size_t dth_sfdlen_char1(const NdbDictionary::Column *col, const void *buf) {
-  return 1;  
+size_t dth_length_char1(const NdbDictionary::Column *col, const void *buf) {
+  return 1;
 }
 
 int dth_encode_char1(const NdbDictionary::Column *col, 


Attachment: [text/bzr-bundle] bzr/john.duncan@oracle.com-20110516060715-1awsj0s7rqq54fp0.bundle
Thread
bzr commit into mysql-5.1-telco-7.2 branch (john.duncan:4175) John David Duncan16 May