mirror of
https://github.com/MariaDB/server.git
synced 2025-01-18 04:53:01 +01:00
9e6784924a
Fixed compile-pentium64 scripts Fixed wrong estimate of update_with_key_prefix in sql-bench Merge bk-internal.mysql.com:/home/bk/mysql-5.1 into mysql.com:/home/my/mysql-5.1 Fixed unsafe define of uint4korr() Fixed that --extern works with mysql-test-run.pl Small trivial cleanups This also fixes a bug in counting number of rows that are updated when we have many simultanous queries Move all connection handling and command exectuion main loop from sql_parse.cc to sql_connection.cc Split handle_one_connection() into reusable sub functions. Split create_new_thread() into reusable sub functions. Added thread_scheduler; Preliminary interface code for future thread_handling code. Use 'my_thread_id' for internal thread id's Make thr_alarm_kill() to depend on thread_id instead of thread Make thr_abort_locks_for_thread() depend on thread_id instead of thread In store_globals(), set my_thread_var->id to be thd->thread_id. Use my_thread_var->id as basis for my_thread_name() The above changes makes the connection we have between THD and threads more soft. Added a lot of DBUG_PRINT() and DBUG_ASSERT() functions Fixed compiler warnings Fixed core dumps when running with --debug Removed setting of signal masks (was never used) Made event code call pthread_exit() (portability fix) Fixed that event code doesn't call DBUG_xxx functions before my_thread_init() is called. Made handling of thread_id and thd->variables.pseudo_thread_id uniform. Removed one common 'not freed memory' warning from mysqltest Fixed a couple of usage of not initialized warnings (unlikely cases) Suppress compiler warnings from bdb and (for the moment) warnings from ndb BitKeeper/deleted/.del-SETUP.sh.rej: Rename: BUILD/SETUP.sh.rej -> BitKeeper/deleted/.del-SETUP.sh.rej BitKeeper/deleted/.del-configure.in.rej: Rename: configure.in.rej -> BitKeeper/deleted/.del-configure.in.rej BitKeeper/deleted/.del-my_global.h.rej: Rename: include/my_global.h.rej -> BitKeeper/deleted/.del-my_global.h.rej BitKeeper/deleted/.del-my_pthread.h.rej: Rename: include/my_pthread.h.rej -> BitKeeper/deleted/.del-my_pthread.h.rej BitKeeper/deleted/.del-mysql_client_test.c.rej: Rename: tests/mysql_client_test.c.rej -> BitKeeper/deleted/.del-mysql_client_test.c.rej BitKeeper/deleted/.del-mysqld.cc.rej~35c1c438e11ebd89: Rename: sql/mysqld.cc.rej -> BitKeeper/deleted/.del-mysqld.cc.rej~35c1c438e11ebd89 BitKeeper/deleted/.del-sql_parse.cc.rej: Rename: sql/sql_parse.cc.rej -> BitKeeper/deleted/.del-sql_parse.cc.rej BitKeeper/deleted/.del-table.cc.rej: Rename: sql/table.cc.rej -> BitKeeper/deleted/.del-table.cc.rej BitKeeper/deleted/.del-thr_alarm.c.rej: Rename: mysys/thr_alarm.c.rej -> BitKeeper/deleted/.del-thr_alarm.c.rej BUILD/compile-pentium64: Update this to be in line with compile-pentium BUILD/compile-pentium: Send command line options to SETUP.sh BUILD/compile-solaris-sparc-debug: Update scripts BUILD/compile-solaris-sparc-forte: Update scripts BUILD/compile-solaris-sparc-purify: Update scripts BUILD/compile-solaris-sparc: Update scripts BitKeeper/deleted/.del-DbtupSystemRestart.cpp~15b54d7e4e75d2d: Removed compiler warning BitKeeper/deleted/.del-ha_berkeley.cc: Moved get_auto_primary_key() here as int5store() gives (wrong) compiler warnings in win64 configure.in: Added detection of port_create and port.h (for future)as --- manual merge BitKeeper/deleted/.del-ha_berkeley.h: Moved get_auto_primary_key() to ha_berkeley.cc BitKeeper/deleted/.del-mysqlmanager.c~e97636d71145a0b: Fixed compiler warnings BitKeeper/etc/ignore: added storage/ndb/src/ndbapi/ndberror_check client/mysqlbinlog.cc: Removed not needed 'static' (caused compiler warning) client/mysqldump.c: Fixed compiler warnings from 'max' build client/mysqltest.c: Free warning and query memory no abort. (Removes strange warnings on screen if mysql-test-run fails) Removed compiler warnings Portability fix for windows (windows doesn't have mode_t) client/sql_string.h: Removed compiler warning cmd-line-utils/readline/xmalloc.c: Fixed compiler warnings from 'max' build extra/charset2html.c: Fixed compiler warnings extra/comp_err.c: Fixed compiler warnings from 'max' build extra/yassl/include/lock.hpp: Fix for windows64 extra/yassl/include/openssl/ssl.h: Changed prototype for SSL_set_fd() to fix compiler warnings (and possible errors) on windows 64 bit extra/yassl/include/socket_wrapper.hpp: Moved socket_t to ssl.h, to be able to removed compiler warnings on windows 64 bit extra/yassl/include/yassl.hpp: Fix for windows64 extra/yassl/src/ssl.cpp: Removed compiler warning Detect wrong parameter (Happens when running test suite on solaris) Changed prototype for SSL_set_fd() to fix compiler warnings (and possible errors) on windows 64 bit extra/yassl/taocrypt/src/integer.cpp: Fixed compiler warnings extra/yassl/testsuite/testsuite.cpp: Removed compiler warning include/config-win.h: Added HAVE_WINSOCK2 (for future) include/my_dbug.h: Fixed DBUG_PROCESS() so that we don't get compiler warnings for it include/my_global.h: Fixed unsafe define of uint4korr() manual merge (ignore changes from 5.0) Fixed warnings on win64 when using int5store and int6store include/my_pthread.h: Added my_thread_id typedef Renamed 'my_thread_id() function to my_thead_dbug_id() include/thr_alarm.h: Make thr_alarm_kill() to depend on thread_id instead of thread include/thr_lock.h: Make thr_abort_locks_for_thread() depend on thread_id instead of thread libmysql/libmysql.def: Fixed compiler warnings on win64 libmysqld/CMakeLists.txt: Added missing files libmysqld/Makefile.am: Added new files libmysqld/lib_sql.cc: Remove not needed code (store_globals() now takes care of things) mysql-test/lib/mtr_report.pl: Removed wrong messages when using --extern mysql-test/mysql-test-run.pl: Fixed that --extern works Print help on stdout instead of stderr (make it easier to pipe it to less) Fixed typo that caused mysql-test-run.pl to fail on Solaris mysql-test/r/keywords.result: manual merge mysql-test/r/ndb_lock.result: After merge fixes mysql-test/r/ps.result: Portability fix mysql-test/t/disabled.def: Disabled ndb_alter_table as this very often fails for me (and have done it for a long time) mysql-test/t/keywords.test: manual merge mysql-test/t/ndb_lock.test: Added other possible error code mysql-test/t/ps.test: Portability fix (when compiling without DLOPEN) mysql-test/t/wait_timeout.test: Don't run this if we are not using a thread per connection (as other thread_handling code may not support timeouts) mysys/base64.c: Fixed compiler warnings on win64 mysys/mf_keycache.c: Fixed compiler warnings mysys/my_getopt.c: Fixed compiler warning mysys/my_init.c: Fixed compiler warning Re-indented long comment mysys/my_thr_init.c: Always use mysys_var->id to generate thread name (makes things uniform accross thread implementations and thread usage) Always generate my_thread_name() when using DBUG Ensure mysys_var->pthread_self is set Fixed compiler warnings mysys/ptr_cmp.c: Fixed compiler warnings from 'max' build mysys/thr_alarm.c: Change thr_alarm_kill() to use mysys_var->id instead of thread id Fixed compiler warning on windows mysys/thr_lock.c: Change thr_abort_locks_for_thread() to use mysys_var->id instead of thread id Add purecov statements around not tested code Fixed compiler warnings mysys/thr_mutex.c: my_thread_id() -> my_thread_dbug_id() server-tools/instance-manager/guardian.cc: Fixed compiler warning server-tools/instance-manager/instance.cc: Fixed compiler warning server-tools/instance-manager/mysql_connection.cc: Fixed compiler warnings server-tools/instance-manager/mysqlmanager.cc: Fixed compiler warnings sql/CMakeLists.txt: Added missing files sql/Makefile.am: Added new files sql/event_scheduler.cc: Added pthread_exit() calls Ensure DBUG_xxx calls are not made before my_thread_init() Use common functions to set up thread handling sql/field.h: manual merge sql/ha_ndbcluster.cc: Removed some trivial 'current_thd' calls sql/handler.cc: Avoid warnings on KILL_CONNECTION Don't print out null pointer with printf() (Causes crashes on Solaris) sql/item.cc: Fixed compiler warnings from 'max' build sql/item_cmpfunc.cc: After merge fixes sql/item_func.cc: Merge embedded and normal code usage (GET_LOCK, RELEASE_LOCK now works on my_thread_id instead of pthread_t) Fixed compiler warning sql/item_strfunc.cc: Fixed compiler warning sql/item_timefunc.cc: Fixed compiler warnings sql/lock.cc: Use (new) parameter to thr_abort_locks_for_thread() sql/log.cc: Fixed compiler warning sql/log_event.cc: Fixed compiler warnings about not used variable sql/mysql_priv.h: Remove TEST_NO_THREADS (not needed with new scheduler interface) Added functions from sql_connect.cc and new functions from sql_parse.cc sql/mysqld.cc: Use thread_scheduler structure to dispatch calls (make code more dynamic) Change --one-thread option to use thread_scheduler interface Made ONE_THREAD option independent of DBUG_BUILD --one-thread is now depricated. One should instead use '--thread-handling=no-threads' Remove not used uname() function. Split create_new_thread() into reusable sub functions. Preliminary interface code for future thread_handling code. Fixed compiler warnings sql/parse_file.cc: Don't send zero pointer to fn_format() (Causes crashes when using --debug) sql/repl_failsafe.cc: Setup pseudo_thread_id same way as other code sql/set_var.cc: Added variables 'thread_handling' Prepare for future variable 'thread_pool_size' Fixed compiler warnings sql/set_var.h: Fixed compiler warning sql/slave.cc: Setup pseudo_thread_id same way as other code Removed not used signal mask sql/sql_acl.cc: Fixed compiler warnings from 'max' build sql/sql_base.cc: Fixed long comments Normalized variable setup Don't destroy value of thd->variables.pseduo_thread_id More DBUG_PRINT()'s More DBUG_ASSERT()'s Fixed compiler warnings from 'max' build sql/sql_class.cc: Remove thd->real_id and thd->dbug_thread_id Added DBUG_ASSERT() Use thread_scheduler to signal threads to be killed. In THD::store_globals(), set my_thread_var->id to be thd->thread_id. Fixed compiler warnings sql/sql_class.h: Use 'my_thread_id' for internal thread id's Remove not needed THD elements: block_signals and dbug_thread_id Added 'thread_scheduler' scheduling extension element to THD sql/sql_insert.cc: After merge fixes (This actually fixes a bug in old code when many connections are in use) Setup pseudo_thread_id same way as other code Removed not used signal mask Initialize variable that may be used unitialized on error conditions (not fatal) sql/sql_parse.cc: Move connection related code to sql_connect.cc Remove setting of signal mask (not needed) Ensure TABLE_LIST->alias is set for generated TABLE_LIST elements (fixed core dumps when running with --debug) Added previous 'optional' element to reset_mgh() Removed not needed DBUG_PRINT call sql/sql_partition.cc: Fixed compiler warnings sql/sql_prepare.cc: Removed not needed casts Fixed compiler warnings from 'max' build sql/sql_select.cc: Fixed compiler warnings sql-bench/bench-init.pl.sh: Added --one-missing-tests sql-bench/example: Better example sql-bench/run-all-tests.sh: Added --only-missing-tests sql-bench/test-insert.sh: Fixed wrong estimate of update_with_key_prefix sql/sql_show.cc: Don't send pthread_kill() to threads to detect if they exists. (Not that useful and causes problems with future thread_handling code) Fixed compiler warnings sql/sql_table.cc: Simplify code Fixed compiler warnings sql/sql_test.cc: Remove dbug_thread_id from test output sql/sql_view.cc: Don't send zero pointer to fn_format() sql/tztime.cc: Fixed compiler warning sql/udf_example.def: Fixed compiler warnings on win64 sql/unireg.cc: Initialize variable that may be used unitialized on error conditions storage/archive/archive_test.c: Fixed compiler warnings storage/archive/azio.c: Fixed compiler warnings storage/innobase/dict/dict0crea.c: Fixed compiler warnings detected on windows64 storage/innobase/dict/dict0dict.c: Fixed compiler warnings detected on windows64 storage/innobase/dict/dict0load.c: Fixed compiler warnings detected on windows64 storage/innobase/dict/dict0mem.c: Fixed compiler warnings detected on windows64 storage/innobase/eval/eval0proc.c: Fixed compiler warnings detected on windows64 storage/innobase/handler/ha_innodb.cc: Fixed compiler warnings detected on windows64 storage/innobase/include/ut0byte.ic: Fixed compiler warnings on win64 storage/innobase/include/ut0ut.ic: Fixed compiler warnings on win64 storage/innobase/mtr/mtr0log.c: Fixed compiler warnings detected on windows64 storage/innobase/pars/pars0lex.l: Fixed warnings on win64 storage/innobase/rem/rem0cmp.c: Fixed compiler warnings detected on windows64 storage/innobase/row/row0mysql.c: Fixed compiler warnings detected on windows64 storage/innobase/row/row0sel.c: Fixed compiler warnings detected on windows64 storage/innobase/sync/sync0rw.c: Fixed compiler warnings detected on windows64 storage/innobase/trx/trx0trx.c: Fixed compiler warnings detected on windows64 storage/myisam/mi_log.c: my_thread_id() -> my_thread_debug_id() storage/myisam/mi_packrec.c: Fixed compiler warnings detected on windows64 storage/myisam/myisamchk.c: Fixed compiler warnings from 'max' build storage/ndb/src/common/debugger/EventLogger.cpp: Fixed compiler warnings storage/ndb/src/common/util/ConfigValues.cpp: Removed compiler warnings storage/ndb/src/common/util/NdbSqlUtil.cpp: Removed compiler warnings storage/ndb/src/cw/cpcd/CPCD.hpp: Fixed compiler warnings storage/ndb/src/kernel/blocks/backup/Backup.cpp: Fixed compiler warnings detected on windows64 storage/ndb/src/kernel/blocks/dbacc/Dbacc.hpp: Fixed compiler warnings detected on windows64 storage/ndb/src/kernel/blocks/dbacc/DbaccMain.cpp: Fixed compiler warnings detected on windows64 storage/ndb/src/kernel/blocks/dbdict/Dbdict.cpp: Fixed compiler warnings storage/ndb/src/kernel/blocks/dbdict/Dbdict.hpp: Fixed compiler warnings storage/ndb/src/kernel/blocks/dbdih/DbdihMain.cpp: Fixed compiler warnings storage/ndb/src/kernel/blocks/dblqh/DblqhMain.cpp: Fixed compiler warnings storage/ndb/src/kernel/blocks/dbtc/DbtcMain.cpp: Fixed compiler warnings storage/ndb/src/kernel/blocks/dbtup/Dbtup.hpp: Fixed compiler warnings storage/ndb/src/kernel/blocks/dbtup/DbtupDiskAlloc.cpp: Fixed compiler warnings storage/ndb/src/kernel/blocks/dbtup/DbtupExecQuery.cpp: Fixed compiler warnings storage/ndb/src/kernel/blocks/dbtup/DbtupFixAlloc.cpp: Fixed compiler warnings storage/ndb/src/kernel/blocks/dbtup/DbtupMeta.cpp: Fixed compiler warnings storage/ndb/src/kernel/blocks/dbtup/DbtupRoutines.cpp: Fixed compiler warnings storage/ndb/src/kernel/blocks/dbtup/DbtupScan.cpp: Fixed compiler warnings storage/ndb/src/kernel/blocks/dbtup/DbtupVarAlloc.cpp: Fixed compiler warnings storage/ndb/src/kernel/blocks/dbtup/tuppage.cpp: Fixed compiler warnings storage/ndb/src/kernel/blocks/dbtup/tuppage.hpp: Fixed compiler warnings storage/ndb/src/kernel/blocks/dbtux/DbtuxStat.cpp: Fixed compiler warnings storage/ndb/src/kernel/blocks/diskpage.hpp: Fixed compiler warnings storage/ndb/src/kernel/vm/ndbd_malloc.cpp: Fixed compiler warnings storage/ndb/src/kernel/vm/ndbd_malloc_impl.cpp: Fixed compiler warnings storage/ndb/src/mgmclient/main.cpp: Fixed compiler warnings storage/ndb/src/ndbapi/NdbEventOperationImpl.cpp: Fixed compiler warnings storage/ndb/src/ndbapi/NdbOperationExec.cpp: Fixed compiler warnings storage/ndb/src/ndbapi/SignalSender.cpp: Fixed compiler warnings storage/ndb/tools/restore/consumer_restore.cpp: Fixed compiler warnings strings/ctype-ucs2.c: Fixed compiler warnings strings/ctype-utf8.c: Fixed compiler warnings strings/decimal.c: Fixed compiler warnings strings/my_strchr.c: Fixed conflict between function and prototype support-files/compiler_warnings.supp: Ignore warnings from sql_yacc.cc that are hard to remove Ignore some not important warnings from windows 64 bit build Suppress warnings from bdb and (for the moment) warnings from ndb Suppress all warnings for all pushbuild platforms (should make all trees green) vio/viosslfactories.c: Added DBUG_PRINT BUILD/compile-pentium64-max: New BitKeeper file ``BUILD/compile-pentium64-max'' libmysqld/scheduler.cc: New BitKeeper file ``libmysqld/scheduler.cc'' libmysqld/sql_connect.cc: New BitKeeper file ``libmysqld/sql_connect.cc'' mysql-test/include/one_thread_per_connection.inc: New BitKeeper file ``mysql-test/include/one_thread_per_connection.inc'' mysql-test/r/no-threads.result: New BitKeeper file ``mysql-test/r/no-threads.result'' mysql-test/r/one_thread_per_connection.require: New BitKeeper file ``mysql-test/r/one_thread_per_connection.require'' mysql-test/t/no-threads-master.opt: New BitKeeper file ``mysql-test/t/no-threads-master.opt'' mysql-test/t/no-threads.test: New BitKeeper file ``mysql-test/t/no-threads.test'' sql/scheduler.cc: New BitKeeper file ``sql/scheduler.cc'' sql/scheduler.h: New BitKeeper file ``sql/scheduler.h'' sql/sql_connect.cc: New BitKeeper file ``sql/sql_connect.cc''
975 lines
30 KiB
C++
975 lines
30 KiB
C++
/* Copyright (C) 2000-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
|
|
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 */
|
|
|
|
|
|
/*
|
|
Functions to create a unireg form-file from a FIELD and a fieldname-fieldinfo
|
|
struct.
|
|
In the following functions FIELD * is an ordinary field-structure with
|
|
the following exeptions:
|
|
sc_length,typepos,row,kol,dtype,regnr and field need not to be set.
|
|
str is a (long) to record position where 0 is the first position.
|
|
*/
|
|
|
|
#include "mysql_priv.h"
|
|
#include <m_ctype.h>
|
|
#include <assert.h>
|
|
|
|
#define FCOMP 17 /* Bytes for a packed field */
|
|
|
|
static uchar * pack_screens(List<create_field> &create_fields,
|
|
uint *info_length, uint *screens, bool small_file);
|
|
static uint pack_keys(uchar *keybuff,uint key_count, KEY *key_info,
|
|
ulong data_offset);
|
|
static bool pack_header(uchar *forminfo,enum legacy_db_type table_type,
|
|
List<create_field> &create_fields,
|
|
uint info_length, uint screens, uint table_options,
|
|
ulong data_offset, handler *file);
|
|
static uint get_interval_id(uint *int_count,List<create_field> &create_fields,
|
|
create_field *last_field);
|
|
static bool pack_fields(File file, List<create_field> &create_fields,
|
|
ulong data_offset);
|
|
static bool make_empty_rec(THD *thd, int file, enum legacy_db_type table_type,
|
|
uint table_options,
|
|
List<create_field> &create_fields,
|
|
uint reclength, ulong data_offset,
|
|
handler *handler);
|
|
|
|
/*
|
|
Create a frm (table definition) file
|
|
|
|
SYNOPSIS
|
|
mysql_create_frm()
|
|
thd Thread handler
|
|
file_name Path for file (including database and .frm)
|
|
db Name of database
|
|
table Name of table
|
|
create_info create info parameters
|
|
create_fields Fields to create
|
|
keys number of keys to create
|
|
key_info Keys to create
|
|
db_file Handler to use. May be zero, in which case we use
|
|
create_info->db_type
|
|
RETURN
|
|
0 ok
|
|
1 error
|
|
*/
|
|
|
|
bool mysql_create_frm(THD *thd, const char *file_name,
|
|
const char *db, const char *table,
|
|
HA_CREATE_INFO *create_info,
|
|
List<create_field> &create_fields,
|
|
uint keys, KEY *key_info,
|
|
handler *db_file)
|
|
{
|
|
LEX_STRING str_db_type;
|
|
uint reclength, info_length, screens, key_info_length, maxlength, tmp_len, i;
|
|
ulong key_buff_length;
|
|
File file;
|
|
ulong filepos, data_offset;
|
|
uchar fileinfo[64],forminfo[288],*keybuff;
|
|
TYPELIB formnames;
|
|
uchar *screen_buff;
|
|
char buff[128];
|
|
#ifdef WITH_PARTITION_STORAGE_ENGINE
|
|
partition_info *part_info= thd->work_part_info;
|
|
#endif
|
|
DBUG_ENTER("mysql_create_frm");
|
|
|
|
DBUG_ASSERT(*fn_rext((char*)file_name)); // Check .frm extension
|
|
formnames.type_names=0;
|
|
if (!(screen_buff=pack_screens(create_fields,&info_length,&screens,0)))
|
|
DBUG_RETURN(1);
|
|
DBUG_ASSERT(db_file != NULL);
|
|
|
|
/* If fixed row records, we need one bit to check for deleted rows */
|
|
if (!(create_info->table_options & HA_OPTION_PACK_RECORD))
|
|
create_info->null_bits++;
|
|
data_offset= (create_info->null_bits + 7) / 8;
|
|
|
|
if (pack_header(forminfo, ha_legacy_type(create_info->db_type),
|
|
create_fields,info_length,
|
|
screens, create_info->table_options,
|
|
data_offset, db_file))
|
|
{
|
|
my_free((gptr) screen_buff,MYF(0));
|
|
if (thd->net.last_errno != ER_TOO_MANY_FIELDS)
|
|
DBUG_RETURN(1);
|
|
|
|
// Try again without UNIREG screens (to get more columns)
|
|
thd->net.last_error[0]=0;
|
|
if (!(screen_buff=pack_screens(create_fields,&info_length,&screens,1)))
|
|
DBUG_RETURN(1);
|
|
if (pack_header(forminfo, ha_legacy_type(create_info->db_type),
|
|
create_fields,info_length,
|
|
screens, create_info->table_options, data_offset, db_file))
|
|
{
|
|
my_free((gptr) screen_buff,MYF(0));
|
|
DBUG_RETURN(1);
|
|
}
|
|
}
|
|
reclength=uint2korr(forminfo+266);
|
|
|
|
/* Calculate extra data segment length */
|
|
str_db_type.str= (char *) ha_resolve_storage_engine_name(create_info->db_type);
|
|
str_db_type.length= strlen(str_db_type.str);
|
|
/* str_db_type */
|
|
create_info->extra_size= (2 + str_db_type.length +
|
|
2 + create_info->connect_string.length);
|
|
/*
|
|
Partition:
|
|
Length of partition info = 4 byte
|
|
Potential NULL byte at end of partition info string = 1 byte
|
|
Indicator if auto-partitioned table = 1 byte
|
|
=> Total 6 byte
|
|
*/
|
|
create_info->extra_size+= 6;
|
|
#ifdef WITH_PARTITION_STORAGE_ENGINE
|
|
if (part_info)
|
|
{
|
|
create_info->extra_size+= part_info->part_info_len;
|
|
}
|
|
#endif
|
|
|
|
for (i= 0; i < keys; i++)
|
|
{
|
|
if (key_info[i].parser_name)
|
|
create_info->extra_size+= key_info[i].parser_name->length + 1;
|
|
}
|
|
|
|
if ((file=create_frm(thd, file_name, db, table, reclength, fileinfo,
|
|
create_info, keys)) < 0)
|
|
{
|
|
my_free((gptr) screen_buff,MYF(0));
|
|
DBUG_RETURN(1);
|
|
}
|
|
|
|
key_buff_length= uint4korr(fileinfo+47);
|
|
keybuff=(uchar*) my_malloc(key_buff_length, MYF(0));
|
|
key_info_length= pack_keys(keybuff, keys, key_info, data_offset);
|
|
VOID(get_form_pos(file,fileinfo,&formnames));
|
|
if (!(filepos=make_new_entry(file,fileinfo,&formnames,"")))
|
|
goto err;
|
|
maxlength=(uint) next_io_size((ulong) (uint2korr(forminfo)+1000));
|
|
int2store(forminfo+2,maxlength);
|
|
int4store(fileinfo+10,(ulong) (filepos+maxlength));
|
|
fileinfo[26]= (uchar) test((create_info->max_rows == 1) &&
|
|
(create_info->min_rows == 1) && (keys == 0));
|
|
int2store(fileinfo+28,key_info_length);
|
|
|
|
tmp_len= system_charset_info->cset->charpos(system_charset_info,
|
|
create_info->comment.str,
|
|
create_info->comment.str +
|
|
create_info->comment.length, 60);
|
|
if (tmp_len < create_info->comment.length)
|
|
{
|
|
(void) my_snprintf(buff, sizeof(buff), "Too long comment for table '%s'",
|
|
table);
|
|
if ((thd->variables.sql_mode &
|
|
(MODE_STRICT_TRANS_TABLES | MODE_STRICT_ALL_TABLES)))
|
|
{
|
|
my_message(ER_UNKNOWN_ERROR, buff, MYF(0));
|
|
goto err;
|
|
}
|
|
push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
|
|
ER_UNKNOWN_ERROR, ER(ER_UNKNOWN_ERROR), buff);
|
|
create_info->comment.length= tmp_len;
|
|
}
|
|
|
|
strmake((char*) forminfo+47, create_info->comment.str ?
|
|
create_info->comment.str : "", create_info->comment.length);
|
|
forminfo[46]=(uchar) create_info->comment.length;
|
|
#ifdef WITH_PARTITION_STORAGE_ENGINE
|
|
if (part_info)
|
|
{
|
|
fileinfo[61]= (uchar) ha_legacy_type(part_info->default_engine_type);
|
|
DBUG_PRINT("info", ("part_db_type = %d", fileinfo[61]));
|
|
}
|
|
#endif
|
|
int2store(fileinfo+59,db_file->extra_rec_buf_length());
|
|
|
|
if (my_pwrite(file,(byte*) fileinfo,64,0L,MYF_RW) ||
|
|
my_pwrite(file,(byte*) keybuff,key_info_length,
|
|
(ulong) uint2korr(fileinfo+6),MYF_RW))
|
|
goto err;
|
|
VOID(my_seek(file,
|
|
(ulong) uint2korr(fileinfo+6)+ (ulong) key_buff_length,
|
|
MY_SEEK_SET,MYF(0)));
|
|
if (make_empty_rec(thd,file,ha_legacy_type(create_info->db_type),
|
|
create_info->table_options,
|
|
create_fields,reclength, data_offset, db_file))
|
|
goto err;
|
|
|
|
int2store(buff, create_info->connect_string.length);
|
|
if (my_write(file, (const byte*)buff, 2, MYF(MY_NABP)) ||
|
|
my_write(file, (const byte*)create_info->connect_string.str,
|
|
create_info->connect_string.length, MYF(MY_NABP)))
|
|
goto err;
|
|
|
|
int2store(buff, str_db_type.length);
|
|
if (my_write(file, (const byte*)buff, 2, MYF(MY_NABP)) ||
|
|
my_write(file, (const byte*)str_db_type.str,
|
|
str_db_type.length, MYF(MY_NABP)))
|
|
goto err;
|
|
|
|
#ifdef WITH_PARTITION_STORAGE_ENGINE
|
|
if (part_info)
|
|
{
|
|
char auto_partitioned= part_info->is_auto_partitioned ? 1 : 0;
|
|
int4store(buff, part_info->part_info_len);
|
|
if (my_write(file, (const byte*)buff, 4, MYF_RW) ||
|
|
my_write(file, (const byte*)part_info->part_info_string,
|
|
part_info->part_info_len + 1, MYF_RW) ||
|
|
my_write(file, (const byte*)&auto_partitioned, 1, MYF_RW))
|
|
goto err;
|
|
}
|
|
else
|
|
#endif
|
|
{
|
|
bzero(buff, 6);
|
|
if (my_write(file, (byte*) buff, 6, MYF_RW))
|
|
goto err;
|
|
}
|
|
for (i= 0; i < keys; i++)
|
|
{
|
|
if (key_info[i].parser_name)
|
|
{
|
|
if (my_write(file, (const byte*)key_info[i].parser_name->str,
|
|
key_info[i].parser_name->length + 1, MYF(MY_NABP)))
|
|
goto err;
|
|
}
|
|
}
|
|
|
|
VOID(my_seek(file,filepos,MY_SEEK_SET,MYF(0)));
|
|
if (my_write(file,(byte*) forminfo,288,MYF_RW) ||
|
|
my_write(file,(byte*) screen_buff,info_length,MYF_RW) ||
|
|
pack_fields(file, create_fields, data_offset))
|
|
goto err;
|
|
|
|
#ifdef HAVE_CRYPTED_FRM
|
|
if (create_info->password)
|
|
{
|
|
char tmp=2,*disk_buff=0;
|
|
SQL_CRYPT *crypted=new SQL_CRYPT(create_info->password);
|
|
if (!crypted || my_pwrite(file,&tmp,1,26,MYF_RW)) // Mark crypted
|
|
goto err;
|
|
uint read_length=uint2korr(forminfo)-256;
|
|
VOID(my_seek(file,filepos+256,MY_SEEK_SET,MYF(0)));
|
|
if (read_string(file,(gptr*) &disk_buff,read_length))
|
|
goto err;
|
|
crypted->encode(disk_buff,read_length);
|
|
delete crypted;
|
|
if (my_pwrite(file,disk_buff,read_length,filepos+256,MYF_RW))
|
|
{
|
|
my_free(disk_buff,MYF(0));
|
|
goto err;
|
|
}
|
|
my_free(disk_buff,MYF(0));
|
|
}
|
|
#endif
|
|
|
|
my_free((gptr) screen_buff,MYF(0));
|
|
my_free((gptr) keybuff, MYF(0));
|
|
|
|
if (opt_sync_frm && !(create_info->options & HA_LEX_CREATE_TMP_TABLE) &&
|
|
my_sync(file, MYF(MY_WME)))
|
|
goto err2;
|
|
if (my_close(file,MYF(MY_WME)))
|
|
goto err3;
|
|
|
|
{
|
|
/*
|
|
Restore all UCS2 intervals.
|
|
HEX representation of them is not needed anymore.
|
|
*/
|
|
List_iterator<create_field> it(create_fields);
|
|
create_field *field;
|
|
while ((field=it++))
|
|
{
|
|
if (field->save_interval)
|
|
{
|
|
field->interval= field->save_interval;
|
|
field->save_interval= 0;
|
|
}
|
|
}
|
|
}
|
|
DBUG_RETURN(0);
|
|
|
|
err:
|
|
my_free((gptr) screen_buff,MYF(0));
|
|
my_free((gptr) keybuff, MYF(0));
|
|
err2:
|
|
VOID(my_close(file,MYF(MY_WME)));
|
|
err3:
|
|
my_delete(file_name,MYF(0));
|
|
DBUG_RETURN(1);
|
|
} /* mysql_create_frm */
|
|
|
|
|
|
/*
|
|
Create a frm (table definition) file and the tables
|
|
|
|
SYNOPSIS
|
|
rea_create_table()
|
|
thd Thread handler
|
|
path Name of file (including database, without .frm)
|
|
db Data base name
|
|
table_name Table name
|
|
create_info create info parameters
|
|
create_fields Fields to create
|
|
keys number of keys to create
|
|
key_info Keys to create
|
|
file Handler to use
|
|
|
|
RETURN
|
|
0 ok
|
|
1 error
|
|
*/
|
|
|
|
int rea_create_table(THD *thd, const char *path,
|
|
const char *db, const char *table_name,
|
|
HA_CREATE_INFO *create_info,
|
|
List<create_field> &create_fields,
|
|
uint keys, KEY *key_info, handler *file)
|
|
{
|
|
DBUG_ENTER("rea_create_table");
|
|
|
|
char frm_name[FN_REFLEN];
|
|
strxmov(frm_name, path, reg_ext, NullS);
|
|
if (mysql_create_frm(thd, frm_name, db, table_name, create_info,
|
|
create_fields, keys, key_info, file))
|
|
|
|
DBUG_RETURN(1);
|
|
|
|
// Make sure mysql_create_frm din't remove extension
|
|
DBUG_ASSERT(*fn_rext(frm_name));
|
|
if (file->create_handler_files(path, NULL, CHF_CREATE_FLAG, create_info))
|
|
goto err_handler;
|
|
if (!create_info->frm_only && ha_create_table(thd, path, db, table_name,
|
|
create_info,0))
|
|
goto err_handler;
|
|
DBUG_RETURN(0);
|
|
|
|
err_handler:
|
|
VOID(file->create_handler_files(path, NULL, CHF_DELETE_FLAG, create_info));
|
|
my_delete(frm_name, MYF(0));
|
|
DBUG_RETURN(1);
|
|
} /* rea_create_table */
|
|
|
|
|
|
/* Pack screens to a screen for save in a form-file */
|
|
|
|
static uchar *pack_screens(List<create_field> &create_fields,
|
|
uint *info_length, uint *screens,
|
|
bool small_file)
|
|
{
|
|
reg1 uint i;
|
|
uint row,start_row,end_row,fields_on_screen;
|
|
uint length,cols;
|
|
uchar *info,*pos,*start_screen;
|
|
uint fields=create_fields.elements;
|
|
List_iterator<create_field> it(create_fields);
|
|
DBUG_ENTER("pack_screens");
|
|
|
|
start_row=4; end_row=22; cols=80; fields_on_screen=end_row+1-start_row;
|
|
|
|
*screens=(fields-1)/fields_on_screen+1;
|
|
length= (*screens) * (SC_INFO_LENGTH+ (cols>> 1)+4);
|
|
|
|
create_field *field;
|
|
while ((field=it++))
|
|
length+=(uint) strlen(field->field_name)+1+TE_INFO_LENGTH+cols/2;
|
|
|
|
if (!(info=(uchar*) my_malloc(length,MYF(MY_WME))))
|
|
DBUG_RETURN(0);
|
|
|
|
start_screen=0;
|
|
row=end_row;
|
|
pos=info;
|
|
it.rewind();
|
|
for (i=0 ; i < fields ; i++)
|
|
{
|
|
create_field *cfield=it++;
|
|
if (row++ == end_row)
|
|
{
|
|
if (i)
|
|
{
|
|
length=(uint) (pos-start_screen);
|
|
int2store(start_screen,length);
|
|
start_screen[2]=(uchar) (fields_on_screen+1);
|
|
start_screen[3]=(uchar) (fields_on_screen);
|
|
}
|
|
row=start_row;
|
|
start_screen=pos;
|
|
pos+=4;
|
|
pos[0]= (uchar) start_row-2; /* Header string */
|
|
pos[1]= (uchar) (cols >> 2);
|
|
pos[2]= (uchar) (cols >> 1) +1;
|
|
strfill((my_string) pos+3,(uint) (cols >> 1),' ');
|
|
pos+=(cols >> 1)+4;
|
|
}
|
|
length=(uint) strlen(cfield->field_name);
|
|
if (length > cols-3)
|
|
length=cols-3;
|
|
|
|
if (!small_file)
|
|
{
|
|
pos[0]=(uchar) row;
|
|
pos[1]=0;
|
|
pos[2]=(uchar) (length+1);
|
|
pos=(uchar*) strmake((char*) pos+3,cfield->field_name,length)+1;
|
|
}
|
|
cfield->row=(uint8) row;
|
|
cfield->col=(uint8) (length+1);
|
|
cfield->sc_length=(uint8) min(cfield->length,cols-(length+2));
|
|
}
|
|
length=(uint) (pos-start_screen);
|
|
int2store(start_screen,length);
|
|
start_screen[2]=(uchar) (row-start_row+2);
|
|
start_screen[3]=(uchar) (row-start_row+1);
|
|
|
|
*info_length=(uint) (pos-info);
|
|
DBUG_RETURN(info);
|
|
} /* pack_screens */
|
|
|
|
|
|
/* Pack keyinfo and keynames to keybuff for save in form-file. */
|
|
|
|
static uint pack_keys(uchar *keybuff, uint key_count, KEY *keyinfo,
|
|
ulong data_offset)
|
|
{
|
|
uint key_parts,length;
|
|
uchar *pos, *keyname_pos;
|
|
KEY *key,*end;
|
|
KEY_PART_INFO *key_part,*key_part_end;
|
|
DBUG_ENTER("pack_keys");
|
|
|
|
pos=keybuff+6;
|
|
key_parts=0;
|
|
for (key=keyinfo,end=keyinfo+key_count ; key != end ; key++)
|
|
{
|
|
int2store(pos, (key->flags ^ HA_NOSAME));
|
|
int2store(pos+2,key->key_length);
|
|
pos[4]= (uchar) key->key_parts;
|
|
pos[5]= (uchar) key->algorithm;
|
|
int2store(pos+6, key->block_size);
|
|
pos+=8;
|
|
key_parts+=key->key_parts;
|
|
DBUG_PRINT("loop", ("flags: %d key_parts: %d at 0x%lx",
|
|
key->flags, key->key_parts,
|
|
(long) key->key_part));
|
|
for (key_part=key->key_part,key_part_end=key_part+key->key_parts ;
|
|
key_part != key_part_end ;
|
|
key_part++)
|
|
|
|
{
|
|
uint offset;
|
|
DBUG_PRINT("loop",("field: %d startpos: %lu length: %d",
|
|
key_part->fieldnr, key_part->offset + data_offset,
|
|
key_part->length));
|
|
int2store(pos,key_part->fieldnr+1+FIELD_NAME_USED);
|
|
offset= (uint) (key_part->offset+data_offset+1);
|
|
int2store(pos+2, offset);
|
|
pos[4]=0; // Sort order
|
|
int2store(pos+5,key_part->key_type);
|
|
int2store(pos+7,key_part->length);
|
|
pos+=9;
|
|
}
|
|
}
|
|
/* Save keynames */
|
|
keyname_pos=pos;
|
|
*pos++=(uchar) NAMES_SEP_CHAR;
|
|
for (key=keyinfo ; key != end ; key++)
|
|
{
|
|
uchar *tmp=(uchar*) strmov((char*) pos,key->name);
|
|
*tmp++= (uchar) NAMES_SEP_CHAR;
|
|
*tmp=0;
|
|
pos=tmp;
|
|
}
|
|
*(pos++)=0;
|
|
|
|
if (key_count > 127 || key_parts > 127)
|
|
{
|
|
keybuff[0]= (key_count & 0x7f) | 0x80;
|
|
keybuff[1]= key_count >> 7;
|
|
int2store(keybuff+2,key_parts);
|
|
}
|
|
else
|
|
{
|
|
keybuff[0]=(uchar) key_count;
|
|
keybuff[1]=(uchar) key_parts;
|
|
keybuff[2]= keybuff[3]= 0;
|
|
}
|
|
length=(uint) (pos-keyname_pos);
|
|
int2store(keybuff+4,length);
|
|
DBUG_RETURN((uint) (pos-keybuff));
|
|
} /* pack_keys */
|
|
|
|
|
|
/* Make formheader */
|
|
|
|
static bool pack_header(uchar *forminfo, enum legacy_db_type table_type,
|
|
List<create_field> &create_fields,
|
|
uint info_length, uint screens, uint table_options,
|
|
ulong data_offset, handler *file)
|
|
{
|
|
uint length,int_count,int_length,no_empty, int_parts;
|
|
uint time_stamp_pos,null_fields;
|
|
ulong reclength, totlength, n_length, com_length;
|
|
DBUG_ENTER("pack_header");
|
|
|
|
if (create_fields.elements > MAX_FIELDS)
|
|
{
|
|
my_message(ER_TOO_MANY_FIELDS, ER(ER_TOO_MANY_FIELDS), MYF(0));
|
|
DBUG_RETURN(1);
|
|
}
|
|
|
|
totlength= 0L;
|
|
reclength= data_offset;
|
|
no_empty=int_count=int_parts=int_length=time_stamp_pos=null_fields=
|
|
com_length=0;
|
|
n_length=2L;
|
|
|
|
/* Check fields */
|
|
|
|
List_iterator<create_field> it(create_fields);
|
|
create_field *field;
|
|
while ((field=it++))
|
|
{
|
|
uint tmp_len= system_charset_info->cset->charpos(system_charset_info,
|
|
field->comment.str,
|
|
field->comment.str +
|
|
field->comment.length,
|
|
255);
|
|
if (tmp_len < field->comment.length)
|
|
{
|
|
char buff[128];
|
|
(void) my_snprintf(buff,sizeof(buff), "Too long comment for field '%s'",
|
|
field->field_name);
|
|
if ((current_thd->variables.sql_mode &
|
|
(MODE_STRICT_TRANS_TABLES | MODE_STRICT_ALL_TABLES)))
|
|
{
|
|
my_message(ER_UNKNOWN_ERROR, buff, MYF(0));
|
|
DBUG_RETURN(1);
|
|
}
|
|
push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN,
|
|
ER_UNKNOWN_ERROR, ER(ER_UNKNOWN_ERROR), buff);
|
|
field->comment.length= tmp_len;
|
|
}
|
|
|
|
totlength+= field->length;
|
|
com_length+= field->comment.length;
|
|
if (MTYP_TYPENR(field->unireg_check) == Field::NOEMPTY ||
|
|
field->unireg_check & MTYP_NOEMPTY_BIT)
|
|
{
|
|
field->unireg_check= (Field::utype) ((uint) field->unireg_check |
|
|
MTYP_NOEMPTY_BIT);
|
|
no_empty++;
|
|
}
|
|
/*
|
|
We mark first TIMESTAMP field with NOW() in DEFAULT or ON UPDATE
|
|
as auto-update field.
|
|
*/
|
|
if (field->sql_type == MYSQL_TYPE_TIMESTAMP &&
|
|
MTYP_TYPENR(field->unireg_check) != Field::NONE &&
|
|
!time_stamp_pos)
|
|
time_stamp_pos= (uint) field->offset+ (uint) data_offset + 1;
|
|
length=field->pack_length;
|
|
/* Ensure we don't have any bugs when generating offsets */
|
|
DBUG_ASSERT(reclength == field->offset + data_offset);
|
|
if ((uint) field->offset+ (uint) data_offset+ length > reclength)
|
|
reclength=(uint) (field->offset+ data_offset + length);
|
|
n_length+= (ulong) strlen(field->field_name)+1;
|
|
field->interval_id=0;
|
|
field->save_interval= 0;
|
|
if (field->interval)
|
|
{
|
|
uint old_int_count=int_count;
|
|
|
|
if (field->charset->mbminlen > 1)
|
|
{
|
|
/*
|
|
Escape UCS2 intervals using HEX notation to avoid
|
|
problems with delimiters between enum elements.
|
|
As the original representation is still needed in
|
|
the function make_empty_rec to create a record of
|
|
filled with default values it is saved in save_interval
|
|
The HEX representation is created from this copy.
|
|
*/
|
|
field->save_interval= field->interval;
|
|
field->interval= (TYPELIB*) sql_alloc(sizeof(TYPELIB));
|
|
*field->interval= *field->save_interval;
|
|
field->interval->type_names=
|
|
(const char **) sql_alloc(sizeof(char*) *
|
|
(field->interval->count+1));
|
|
field->interval->type_names[field->interval->count]= 0;
|
|
field->interval->type_lengths=
|
|
(uint *) sql_alloc(sizeof(uint) * field->interval->count);
|
|
|
|
for (uint pos= 0; pos < field->interval->count; pos++)
|
|
{
|
|
char *dst;
|
|
const char *src= field->save_interval->type_names[pos];
|
|
uint hex_length;
|
|
length= field->save_interval->type_lengths[pos];
|
|
hex_length= length * 2;
|
|
field->interval->type_lengths[pos]= hex_length;
|
|
field->interval->type_names[pos]= dst= sql_alloc(hex_length + 1);
|
|
octet2hex(dst, src, length);
|
|
}
|
|
}
|
|
|
|
field->interval_id=get_interval_id(&int_count,create_fields,field);
|
|
if (old_int_count != int_count)
|
|
{
|
|
for (const char **pos=field->interval->type_names ; *pos ; pos++)
|
|
int_length+=(uint) strlen(*pos)+1; // field + suffix prefix
|
|
int_parts+=field->interval->count+1;
|
|
}
|
|
}
|
|
if (f_maybe_null(field->pack_flag))
|
|
null_fields++;
|
|
}
|
|
int_length+=int_count*2; // 255 prefix + 0 suffix
|
|
|
|
/* Save values in forminfo */
|
|
|
|
if (reclength > (ulong) file->max_record_length())
|
|
{
|
|
my_error(ER_TOO_BIG_ROWSIZE, MYF(0), (uint) file->max_record_length());
|
|
DBUG_RETURN(1);
|
|
}
|
|
/* Hack to avoid bugs with small static rows in MySQL */
|
|
reclength=max(file->min_record_length(table_options),reclength);
|
|
if (info_length+(ulong) create_fields.elements*FCOMP+288+
|
|
n_length+int_length+com_length > 65535L || int_count > 255)
|
|
{
|
|
my_message(ER_TOO_MANY_FIELDS, ER(ER_TOO_MANY_FIELDS), MYF(0));
|
|
DBUG_RETURN(1);
|
|
}
|
|
|
|
bzero((char*)forminfo,288);
|
|
length=(info_length+create_fields.elements*FCOMP+288+n_length+int_length+
|
|
com_length);
|
|
int2store(forminfo,length);
|
|
forminfo[256] = (uint8) screens;
|
|
int2store(forminfo+258,create_fields.elements);
|
|
int2store(forminfo+260,info_length);
|
|
int2store(forminfo+262,totlength);
|
|
int2store(forminfo+264,no_empty);
|
|
int2store(forminfo+266,reclength);
|
|
int2store(forminfo+268,n_length);
|
|
int2store(forminfo+270,int_count);
|
|
int2store(forminfo+272,int_parts);
|
|
int2store(forminfo+274,int_length);
|
|
int2store(forminfo+276,time_stamp_pos);
|
|
int2store(forminfo+278,80); /* Columns needed */
|
|
int2store(forminfo+280,22); /* Rows needed */
|
|
int2store(forminfo+282,null_fields);
|
|
int2store(forminfo+284,com_length);
|
|
/* Up to forminfo+288 is free to use for additional information */
|
|
DBUG_RETURN(0);
|
|
} /* pack_header */
|
|
|
|
|
|
/* get each unique interval each own id */
|
|
|
|
static uint get_interval_id(uint *int_count,List<create_field> &create_fields,
|
|
create_field *last_field)
|
|
{
|
|
List_iterator<create_field> it(create_fields);
|
|
create_field *field;
|
|
TYPELIB *interval=last_field->interval;
|
|
|
|
while ((field=it++) != last_field)
|
|
{
|
|
if (field->interval_id && field->interval->count == interval->count)
|
|
{
|
|
const char **a,**b;
|
|
for (a=field->interval->type_names, b=interval->type_names ;
|
|
*a && !strcmp(*a,*b);
|
|
a++,b++) ;
|
|
|
|
if (! *a)
|
|
{
|
|
return field->interval_id; // Re-use last interval
|
|
}
|
|
}
|
|
}
|
|
return ++*int_count; // New unique interval
|
|
}
|
|
|
|
|
|
/* Save fields, fieldnames and intervals */
|
|
|
|
static bool pack_fields(File file, List<create_field> &create_fields,
|
|
ulong data_offset)
|
|
{
|
|
reg2 uint i;
|
|
uint int_count, comment_length=0;
|
|
uchar buff[MAX_FIELD_WIDTH];
|
|
create_field *field;
|
|
DBUG_ENTER("pack_fields");
|
|
|
|
/* Write field info */
|
|
|
|
List_iterator<create_field> it(create_fields);
|
|
|
|
int_count=0;
|
|
while ((field=it++))
|
|
{
|
|
uint recpos;
|
|
buff[0]= (uchar) field->row;
|
|
buff[1]= (uchar) field->col;
|
|
buff[2]= (uchar) field->sc_length;
|
|
int2store(buff+3, field->length);
|
|
/* The +1 is here becasue the col offset in .frm file have offset 1 */
|
|
recpos= field->offset+1 + (uint) data_offset;
|
|
int3store(buff+5,recpos);
|
|
int2store(buff+8,field->pack_flag);
|
|
int2store(buff+10,field->unireg_check);
|
|
buff[12]= (uchar) field->interval_id;
|
|
buff[13]= (uchar) field->sql_type;
|
|
if (field->sql_type == MYSQL_TYPE_GEOMETRY)
|
|
{
|
|
buff[14]= (uchar) field->geom_type;
|
|
#ifndef HAVE_SPATIAL
|
|
DBUG_ASSERT(0); // Should newer happen
|
|
#endif
|
|
}
|
|
else if (field->charset)
|
|
buff[14]= (uchar) field->charset->number;
|
|
else
|
|
buff[14]= 0; // Numerical
|
|
int2store(buff+15, field->comment.length);
|
|
comment_length+= field->comment.length;
|
|
set_if_bigger(int_count,field->interval_id);
|
|
if (my_write(file,(byte*) buff,FCOMP,MYF_RW))
|
|
DBUG_RETURN(1);
|
|
}
|
|
|
|
/* Write fieldnames */
|
|
buff[0]=(uchar) NAMES_SEP_CHAR;
|
|
if (my_write(file,(byte*) buff,1,MYF_RW))
|
|
DBUG_RETURN(1);
|
|
i=0;
|
|
it.rewind();
|
|
while ((field=it++))
|
|
{
|
|
char *pos= strmov((char*) buff,field->field_name);
|
|
*pos++=NAMES_SEP_CHAR;
|
|
if (i == create_fields.elements-1)
|
|
*pos++=0;
|
|
if (my_write(file,(byte*) buff,(uint) (pos-(char*) buff),MYF_RW))
|
|
DBUG_RETURN(1);
|
|
i++;
|
|
}
|
|
|
|
/* Write intervals */
|
|
if (int_count)
|
|
{
|
|
String tmp((char*) buff,sizeof(buff), &my_charset_bin);
|
|
tmp.length(0);
|
|
it.rewind();
|
|
int_count=0;
|
|
while ((field=it++))
|
|
{
|
|
if (field->interval_id > int_count)
|
|
{
|
|
unsigned char sep= 0;
|
|
unsigned char occ[256];
|
|
uint i;
|
|
unsigned char *val= NULL;
|
|
|
|
bzero(occ, sizeof(occ));
|
|
|
|
for (i=0; (val= (unsigned char*) field->interval->type_names[i]); i++)
|
|
for (uint j = 0; j < field->interval->type_lengths[i]; j++)
|
|
occ[(unsigned int) (val[j])]= 1;
|
|
|
|
if (!occ[(unsigned char)NAMES_SEP_CHAR])
|
|
sep= (unsigned char) NAMES_SEP_CHAR;
|
|
else if (!occ[(unsigned int)','])
|
|
sep= ',';
|
|
else
|
|
{
|
|
for (uint i=1; i<256; i++)
|
|
{
|
|
if(!occ[i])
|
|
{
|
|
sep= i;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if(!sep) /* disaster, enum uses all characters, none left as separator */
|
|
{
|
|
my_message(ER_WRONG_FIELD_TERMINATORS,ER(ER_WRONG_FIELD_TERMINATORS),
|
|
MYF(0));
|
|
DBUG_RETURN(1);
|
|
}
|
|
}
|
|
|
|
int_count= field->interval_id;
|
|
tmp.append(sep);
|
|
for (const char **pos=field->interval->type_names ; *pos ; pos++)
|
|
{
|
|
tmp.append(*pos);
|
|
tmp.append(sep);
|
|
}
|
|
tmp.append('\0'); // End of intervall
|
|
}
|
|
}
|
|
if (my_write(file,(byte*) tmp.ptr(),tmp.length(),MYF_RW))
|
|
DBUG_RETURN(1);
|
|
}
|
|
if (comment_length)
|
|
{
|
|
it.rewind();
|
|
int_count=0;
|
|
while ((field=it++))
|
|
{
|
|
if (field->comment.length)
|
|
if (my_write(file, (byte*) field->comment.str, field->comment.length,
|
|
MYF_RW))
|
|
DBUG_RETURN(1);
|
|
}
|
|
}
|
|
DBUG_RETURN(0);
|
|
}
|
|
|
|
|
|
/* save an empty record on start of formfile */
|
|
|
|
static bool make_empty_rec(THD *thd, File file,enum legacy_db_type table_type,
|
|
uint table_options,
|
|
List<create_field> &create_fields,
|
|
uint reclength,
|
|
ulong data_offset,
|
|
handler *handler)
|
|
{
|
|
int error= 0;
|
|
Field::utype type;
|
|
uint null_count;
|
|
uchar *buff,*null_pos;
|
|
TABLE table;
|
|
TABLE_SHARE share;
|
|
create_field *field;
|
|
enum_check_fields old_count_cuted_fields= thd->count_cuted_fields;
|
|
DBUG_ENTER("make_empty_rec");
|
|
|
|
/* We need a table to generate columns for default values */
|
|
bzero((char*) &table, sizeof(table));
|
|
bzero((char*) &share, sizeof(share));
|
|
table.s= &share;
|
|
|
|
if (!(buff=(uchar*) my_malloc((uint) reclength,MYF(MY_WME | MY_ZEROFILL))))
|
|
{
|
|
DBUG_RETURN(1);
|
|
}
|
|
|
|
table.in_use= thd;
|
|
table.s->db_low_byte_first= handler->low_byte_first();
|
|
table.s->blob_ptr_size= portable_sizeof_char_ptr;
|
|
|
|
null_count=0;
|
|
if (!(table_options & HA_OPTION_PACK_RECORD))
|
|
{
|
|
null_count++; // Need one bit for delete mark
|
|
*buff|= 1;
|
|
}
|
|
null_pos= buff;
|
|
|
|
List_iterator<create_field> it(create_fields);
|
|
thd->count_cuted_fields= CHECK_FIELD_WARN; // To find wrong default values
|
|
while ((field=it++))
|
|
{
|
|
/*
|
|
regfield don't have to be deleted as it's allocated with sql_alloc()
|
|
*/
|
|
Field *regfield= make_field(&share,
|
|
(char*) buff+field->offset + data_offset,
|
|
field->length,
|
|
null_pos + null_count / 8,
|
|
null_count & 7,
|
|
field->pack_flag,
|
|
field->sql_type,
|
|
field->charset,
|
|
field->geom_type,
|
|
field->unireg_check,
|
|
field->save_interval ? field->save_interval :
|
|
field->interval,
|
|
field->field_name);
|
|
if (!regfield)
|
|
{
|
|
error= 1;
|
|
goto err; // End of memory
|
|
}
|
|
|
|
/* save_in_field() will access regfield->table->in_use */
|
|
regfield->init(&table);
|
|
|
|
if (!(field->flags & NOT_NULL_FLAG))
|
|
{
|
|
*regfield->null_ptr|= regfield->null_bit;
|
|
null_count++;
|
|
}
|
|
|
|
if (field->sql_type == MYSQL_TYPE_BIT && !f_bit_as_char(field->pack_flag))
|
|
null_count+= field->length & 7;
|
|
|
|
type= (Field::utype) MTYP_TYPENR(field->unireg_check);
|
|
|
|
if (field->def &&
|
|
(regfield->real_type() != MYSQL_TYPE_YEAR ||
|
|
field->def->val_int() != 0))
|
|
{
|
|
if (field->def->save_in_field(regfield, 1))
|
|
{
|
|
my_error(ER_INVALID_DEFAULT, MYF(0), regfield->field_name);
|
|
error= 1;
|
|
delete regfield; //To avoid memory leak
|
|
goto err;
|
|
}
|
|
}
|
|
else if (regfield->real_type() == MYSQL_TYPE_ENUM &&
|
|
(field->flags & NOT_NULL_FLAG))
|
|
{
|
|
regfield->set_notnull();
|
|
regfield->store((longlong) 1, TRUE);
|
|
}
|
|
else if (type == Field::YES) // Old unireg type
|
|
regfield->store(ER(ER_YES),(uint) strlen(ER(ER_YES)),system_charset_info);
|
|
else if (type == Field::NO) // Old unireg type
|
|
regfield->store(ER(ER_NO), (uint) strlen(ER(ER_NO)),system_charset_info);
|
|
else
|
|
regfield->reset();
|
|
}
|
|
DBUG_ASSERT(data_offset == ((null_count + 7) / 8));
|
|
|
|
/*
|
|
We need to set the unused bits to 1. If the number of bits is a multiple
|
|
of 8 there are no unused bits.
|
|
*/
|
|
if (null_count & 7)
|
|
*(null_pos + null_count / 8)|= ~(((uchar) 1 << (null_count & 7)) - 1);
|
|
|
|
error=(int) my_write(file,(byte*) buff, (uint) reclength,MYF_RW);
|
|
|
|
err:
|
|
my_free((gptr) buff,MYF(MY_FAE));
|
|
thd->count_cuted_fields= old_count_cuted_fields;
|
|
DBUG_RETURN(error);
|
|
} /* make_empty_rec */
|