Drizzled Public API Documentation

data0type.cc
00001 /*****************************************************************************
00002 
00003 Copyright (C) 1996, 2009, Innobase Oy. All Rights Reserved.
00004 
00005 This program is free software; you can redistribute it and/or modify it under
00006 the terms of the GNU General Public License as published by the Free Software
00007 Foundation; version 2 of the License.
00008 
00009 This program is distributed in the hope that it will be useful, but WITHOUT
00010 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00011 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
00012 
00013 You should have received a copy of the GNU General Public License along with
00014 this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
00015 St, Fifth Floor, Boston, MA 02110-1301 USA
00016 
00017 *****************************************************************************/
00018 
00019 /**************************************************/
00026 #include "data0type.h"
00027 
00028 #ifdef UNIV_NONINL
00029 #include "data0type.ic"
00030 #endif
00031 
00032 #ifndef UNIV_HOTBACKUP
00033 # include "ha_prototypes.h"
00034 
00035 /* At the database startup we store the default-charset collation number of
00036 this MySQL installation to this global variable. If we have < 4.1.2 format
00037 column definitions, or records in the insert buffer, we use this
00038 charset-collation code for them. */
00039 
00040 UNIV_INTERN ulint data_mysql_default_charset_coll;
00041 
00042 /*********************************************************************/
00047 UNIV_INTERN
00048 ulint
00049 dtype_get_at_most_n_mbchars(
00050 /*========================*/
00051   ulint   prtype,   
00052   ulint   mbminmaxlen,  
00054   ulint   prefix_len, 
00057   ulint   data_len, 
00058   const char* str)    
00060 {
00061   ulint mbminlen = DATA_MBMINLEN(mbminmaxlen);
00062   ulint mbmaxlen = DATA_MBMAXLEN(mbminmaxlen);
00063 
00064   ut_a(data_len != UNIV_SQL_NULL);
00065   ut_ad(!mbmaxlen || !(prefix_len % mbmaxlen));
00066 
00067   if (mbminlen != mbmaxlen) {
00068     ut_a(!(prefix_len % mbmaxlen));
00069     return(innobase_get_at_most_n_mbchars(
00070       dtype_get_charset_coll(prtype),
00071       prefix_len, data_len, str));
00072   }
00073 
00074   if (prefix_len < data_len) {
00075 
00076     return(prefix_len);
00077 
00078   }
00079 
00080   return(data_len);
00081 }
00082 #endif /* UNIV_HOTBACKUP */
00083 
00084 /*********************************************************************/
00088 UNIV_INTERN
00089 ibool
00090 dtype_is_string_type(
00091 /*=================*/
00092   ulint mtype)  
00093 {
00094   if (mtype <= DATA_BLOB
00095       || mtype == DATA_MYSQL
00096       || mtype == DATA_VARMYSQL) {
00097 
00098     return(TRUE);
00099   }
00100 
00101   return(FALSE);
00102 }
00103 
00104 /*********************************************************************/
00109 UNIV_INTERN
00110 ibool
00111 dtype_is_binary_string_type(
00112 /*========================*/
00113   ulint mtype,  
00114   ulint prtype) 
00115 {
00116   if ((mtype == DATA_FIXBINARY)
00117       || (mtype == DATA_BINARY)
00118       || (mtype == DATA_BLOB && (prtype & DATA_BINARY_TYPE))) {
00119 
00120     return(TRUE);
00121   }
00122 
00123   return(FALSE);
00124 }
00125 
00126 /*********************************************************************/
00132 UNIV_INTERN
00133 ibool
00134 dtype_is_non_binary_string_type(
00135 /*============================*/
00136   ulint mtype,  
00137   ulint prtype) 
00138 {
00139   if (dtype_is_string_type(mtype) == TRUE
00140       && dtype_is_binary_string_type(mtype, prtype) == FALSE) {
00141 
00142     return(TRUE);
00143   }
00144 
00145   return(FALSE);
00146 }
00147 
00148 /*********************************************************************/
00152 UNIV_INTERN
00153 ulint
00154 dtype_form_prtype(
00155 /*==============*/
00156   ulint old_prtype, 
00158   ulint charset_coll) 
00159 {
00160   ut_a(old_prtype < 256 * 256);
00161   ut_a(charset_coll < 256);
00162 
00163   return(old_prtype + (charset_coll << 16));
00164 }
00165 
00166 /*********************************************************************/
00169 UNIV_INTERN
00170 ibool
00171 dtype_validate(
00172 /*===========*/
00173   const dtype_t*  type) 
00174 {
00175   ut_a(type);
00176   ut_a(type->mtype >= DATA_VARCHAR);
00177   ut_a(type->mtype <= DATA_MYSQL);
00178 
00179   if (type->mtype == DATA_SYS) {
00180     ut_a((type->prtype & DATA_MYSQL_TYPE_MASK) < DATA_N_SYS_COLS);
00181   }
00182 
00183 #ifndef UNIV_HOTBACKUP
00184   ut_a(dtype_get_mbminlen(type) <= dtype_get_mbmaxlen(type));
00185 #endif /* !UNIV_HOTBACKUP */
00186 
00187   return(TRUE);
00188 }
00189 
00190 #ifndef UNIV_HOTBACKUP
00191 /*********************************************************************/
00193 UNIV_INTERN
00194 void
00195 dtype_print(
00196 /*========*/
00197   const dtype_t*  type) 
00198 {
00199   ulint mtype;
00200   ulint prtype;
00201   ulint len;
00202 
00203   ut_a(type);
00204 
00205   mtype = type->mtype;
00206   prtype = type->prtype;
00207 
00208   switch (mtype) {
00209   case DATA_VARCHAR:
00210     fputs("DATA_VARCHAR", stderr);
00211     break;
00212 
00213   case DATA_CHAR:
00214     fputs("DATA_CHAR", stderr);
00215     break;
00216 
00217   case DATA_BINARY:
00218     fputs("DATA_BINARY", stderr);
00219     break;
00220 
00221   case DATA_FIXBINARY:
00222     fputs("DATA_FIXBINARY", stderr);
00223     break;
00224 
00225   case DATA_BLOB:
00226     fputs("DATA_BLOB", stderr);
00227     break;
00228 
00229   case DATA_INT:
00230     fputs("DATA_INT", stderr);
00231     break;
00232 
00233   case DATA_MYSQL:
00234     fputs("DATA_MYSQL", stderr);
00235     break;
00236 
00237   case DATA_SYS:
00238     fputs("DATA_SYS", stderr);
00239     break;
00240 
00241   case DATA_FLOAT:
00242     fputs("DATA_FLOAT", stderr);
00243     break;
00244 
00245   case DATA_DOUBLE:
00246     fputs("DATA_DOUBLE", stderr);
00247     break;
00248 
00249   case DATA_DECIMAL:
00250     fputs("DATA_DECIMAL", stderr);
00251     break;
00252 
00253   case DATA_VARMYSQL:
00254     fputs("DATA_VARMYSQL", stderr);
00255     break;
00256 
00257   default:
00258     fprintf(stderr, "type %lu", (ulong) mtype);
00259     break;
00260   }
00261 
00262   len = type->len;
00263 
00264   if ((type->mtype == DATA_SYS)
00265       || (type->mtype == DATA_VARCHAR)
00266       || (type->mtype == DATA_CHAR)) {
00267     putc(' ', stderr);
00268     if (prtype == DATA_ROW_ID) {
00269       fputs("DATA_ROW_ID", stderr);
00270       len = DATA_ROW_ID_LEN;
00271     } else if (prtype == DATA_ROLL_PTR) {
00272       fputs("DATA_ROLL_PTR", stderr);
00273       len = DATA_ROLL_PTR_LEN;
00274     } else if (prtype == DATA_TRX_ID) {
00275       fputs("DATA_TRX_ID", stderr);
00276       len = DATA_TRX_ID_LEN;
00277     } else if (prtype == DATA_ENGLISH) {
00278       fputs("DATA_ENGLISH", stderr);
00279     } else {
00280       fprintf(stderr, "prtype %lu", (ulong) prtype);
00281     }
00282   } else {
00283     if (prtype & DATA_UNSIGNED) {
00284       fputs(" DATA_UNSIGNED", stderr);
00285     }
00286 
00287     if (prtype & DATA_BINARY_TYPE) {
00288       fputs(" DATA_BINARY_TYPE", stderr);
00289     }
00290 
00291     if (prtype & DATA_NOT_NULL) {
00292       fputs(" DATA_NOT_NULL", stderr);
00293     }
00294   }
00295 
00296   fprintf(stderr, " len %lu", (ulong) len);
00297 }
00298 #endif /* !UNIV_HOTBACKUP */