I was able to create a simple new data type, MYTYPE as a similar data type to the CHAR type. The first thing to understand is the use of the sql_yacc.yy and the lex.h files. If you don't understand what these files are and how to generate their products, the sql_yacc.cc, sql_yacc.h and lex_hash.h files, read up on that first. That is step 1. I'm starting at step 2.
In the sql_yacc.yy file
1) Declare your token:
%token MYTYPE
Notice that the tokens are in alphabetic order. Keep yours this way.
2) Declare your type in the %type <NONE> area. You'll notice a few other 'non-primitive' field types such as varchar in there. Include MYTYPE in alphabetic order within this area near varchar. (NOTE: I'm not sure what this section's purpose is, but I needed to include my type for it to work.)
3) I based my type off of the char data type. As a result, I want to immulate the char data type in my data type. I found:
| char field_length opt_binary
{
$$=MYSQL_TYPE_STRING;
}
and beneath it included the definition for my data type
| mytype field_length opt_binary
{
$$=MYSQL_TYPE_STRING;
}
What this does is assigns the base string type defined in MySQL to my data type. I'm essentially inheriting.
4) Continued my search for the char data type and found:
char:
CHAR_SYM {}
;
so I included my data type specification right below it.
mytype:
MYTYPE {}
********* That's it for the sql_yacc.yy file *********
In the lex.h file
5) Within the "static SYMBOL symbols[]' array, include your data type. Notice that this is also in alphabetic order. Keep it this way.
{ "MYTYPE", SYM(MYTYPE)},
********* That's it for the lex.h file *********
6) Generate the sql_yacc.cc, sql_yacc.h and lex_hash.h files.
7) Because I am basically creating an 'alias' for the char type, all of the functionality I need comes from the MYSQL_TYPE_STRING defined inside of MySQL.
NOW:
I can start MySQL
I can 'alter table test add column myval mytype(124)' and the server accepts my data type. You'll notice that when you 'describe' the table, your new data type shows up as 'char'. That's because MySQL converts some fields 'under the covers'. Here's a reference:
http://dev.mysql.com/doc/refman/5.0/en/show-columns.html
Hope this helps.