diff options
author | unknown <holyfoot@deer.(none)> | 2006-01-04 14:20:28 +0400 |
---|---|---|
committer | unknown <holyfoot@deer.(none)> | 2006-01-04 14:20:28 +0400 |
commit | 6b27acbdf41dd3c990af4627ddaf8fbfcd8eb4e6 (patch) | |
tree | bcb306f8c631b6b3153296059aae11b7e290ded7 /sql | |
parent | 81ca15813bfc482ac98614de41a867e47dde07d3 (diff) | |
download | mariadb-git-6b27acbdf41dd3c990af4627ddaf8fbfcd8eb4e6.tar.gz |
Big patch to make embedded-server working in 5.x
Now it supports queries returning several results
(particularly important with the SP)
include/mysql.h:
embedded_query_result structure added
libmysql/libmysql.c:
embedded-server related fixes
libmysqld/emb_qcache.cc:
multiple-result support added
libmysqld/embedded_priv.h:
embedded_query_result struct implemented
libmysqld/lib_sql.cc:
multiple-result support added
libmysqld/libmysqld.c:
small fixes
mysql-test/t/backup.test:
test fixed
mysql-test/t/binlog_stm_binlog.test:
test fixed
mysql-test/t/binlog_stm_blackhole.test:
test fixed
mysql-test/t/binlog_stm_ctype_cp932.test:
test fixed
mysql-test/t/compress.test:
test fixed
mysql-test/t/delayed.test:
test fixed
mysql-test/t/federated.test:
test fixed
mysql-test/t/federated_archive.test:
test fixed
mysql-test/t/federated_bug_13118.test:
test fixed
mysql-test/t/federated_transactions.test:
test fixed
mysql-test/t/flush_table.test:
test fixed
mysql-test/t/handler.test:
test fixed
mysql-test/t/init_connect.test:
test fixed
mysql-test/t/innodb.test:
test fixed
mysql-test/t/mysql.test:
test fixed
mysql-test/t/mysql_client_test.test:
test fixed
mysql-test/t/mysqltest.test:
test fixed
mysql-test/t/query_cache.test:
test fixed
mysql-test/t/query_cache_notembedded.test:
test fixed
mysql-test/t/read_only.test:
test fixed
mysql-test/t/skip_grants.test:
test fixed
mysql-test/t/sp-destruct.test:
test fixed
mysql-test/t/sp-error.test:
test fixed
mysql-test/t/sp-threads.test:
test fixed
mysql-test/t/sp.test:
test fixed
mysql-test/t/view.test:
test fixed
mysql-test/t/wait_timeout.test:
test fixed
sql-common/client.c:
small fixes
sql/mysqld.cc:
embedded-server related fix
sql/protocol.cc:
embedded-server related fix
sql/protocol.h:
embedded-server related fix
sql/sql_class.cc:
embedded-server related fix
sql/sql_class.h:
embedded-server related fix
sql/sql_cursor.cc:
embedded-server related fix
sql/sql_parse.cc:
embedded-server related fix
sql/sql_prepare.cc:
embedded-server related fix
Diffstat (limited to 'sql')
-rw-r--r-- | sql/mysqld.cc | 2 | ||||
-rw-r--r-- | sql/protocol.cc | 82 | ||||
-rw-r--r-- | sql/protocol.h | 9 | ||||
-rw-r--r-- | sql/sql_class.cc | 6 | ||||
-rw-r--r-- | sql/sql_class.h | 12 | ||||
-rw-r--r-- | sql/sql_cursor.cc | 1 | ||||
-rw-r--r-- | sql/sql_parse.cc | 31 | ||||
-rw-r--r-- | sql/sql_prepare.cc | 11 |
8 files changed, 75 insertions, 79 deletions
diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 2a51afbee8d..3682f16613f 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -2449,9 +2449,7 @@ static int my_message_sql(uint error, const char *str, myf MyFlags) { NET *net= &thd->net; net->report_error= 1; -#ifndef EMBEDDED_LIBRARY /* TODO query cache in embedded library*/ query_cache_abort(net); -#endif if (!net->last_error[0]) // Return only first message { strmake(net->last_error, str, sizeof(net->last_error)-1); diff --git a/sql/protocol.cc b/sql/protocol.cc index 0a1b42f5236..98cded56871 100644 --- a/sql/protocol.cc +++ b/sql/protocol.cc @@ -29,6 +29,7 @@ static const unsigned int PACKET_BUFFER_EXTRA_ALLOC= 1024; static void write_eof_packet(THD *thd, NET *net); +void net_send_error_packet(THD *thd, uint sql_errno, const char *err); #ifndef EMBEDDED_LIBRARY bool Protocol::net_store_data(const char *from, uint length) @@ -56,10 +57,6 @@ bool Protocol_prep::net_store_data(const char *from, uint length) void net_send_error(THD *thd, uint sql_errno, const char *err) { -#ifndef EMBEDDED_LIBRARY - uint length; - char buff[MYSQL_ERRMSG_SIZE+2], *pos; -#endif NET *net= &thd->net; bool generate_warning= thd->killed != THD::KILL_CONNECTION; DBUG_ENTER("net_send_error"); @@ -106,42 +103,8 @@ void net_send_error(THD *thd, uint sql_errno, const char *err) push_warning(thd, MYSQL_ERROR::WARN_LEVEL_ERROR, sql_errno, err); } -#ifdef EMBEDDED_LIBRARY - net->last_errno= sql_errno; - strmake(net->last_error, err, sizeof(net->last_error)-1); - strmov(net->sqlstate, mysql_errno_to_sqlstate(sql_errno)); -#else - - if (net->vio == 0) - { - if (thd->bootstrap) - { - /* In bootstrap it's ok to print on stderr */ - fprintf(stderr,"ERROR: %d %s\n",sql_errno,err); - } - DBUG_VOID_RETURN; - } + net_send_error_packet(thd, sql_errno, err); - if (net->return_errno) - { // new client code; Add errno before message - int2store(buff,sql_errno); - pos= buff+2; - if (thd->client_capabilities & CLIENT_PROTOCOL_41) - { - /* The first # is to make the protocol backward compatible */ - buff[2]= '#'; - pos= strmov(buff+3, mysql_errno_to_sqlstate(sql_errno)); - } - length= (uint) (strmake(pos, err, MYSQL_ERRMSG_SIZE-1) - buff); - err=buff; - } - else - { - length=(uint) strlen(err); - set_if_smaller(length,MYSQL_ERRMSG_SIZE-1); - } - VOID(net_write_command(net,(uchar) 255, "", 0, (char*) err,length)); -#endif /* EMBEDDED_LIBRARY*/ thd->is_fatal_error=0; // Error message is given thd->net.report_error= 0; @@ -430,6 +393,47 @@ bool send_old_password_request(THD *thd) return my_net_write(net, eof_buff, 1) || net_flush(net); } + +void net_send_error_packet(THD *thd, uint sql_errno, const char *err) +{ + NET *net= &thd->net; + uint length; + char buff[MYSQL_ERRMSG_SIZE+2], *pos; + + DBUG_ENTER("send_error_packet"); + + if (net->vio == 0) + { + if (thd->bootstrap) + { + /* In bootstrap it's ok to print on stderr */ + fprintf(stderr,"ERROR: %d %s\n",sql_errno,err); + } + DBUG_VOID_RETURN; + } + + if (net->return_errno) + { // new client code; Add errno before message + int2store(buff,sql_errno); + pos= buff+2; + if (thd->client_capabilities & CLIENT_PROTOCOL_41) + { + /* The first # is to make the protocol backward compatible */ + buff[2]= '#'; + pos= strmov(buff+3, mysql_errno_to_sqlstate(sql_errno)); + } + length= (uint) (strmake(pos, err, MYSQL_ERRMSG_SIZE-1) - buff); + err=buff; + } + else + { + length=(uint) strlen(err); + set_if_smaller(length,MYSQL_ERRMSG_SIZE-1); + } + VOID(net_write_command(net,(uchar) 255, "", 0, (char*) err,length)); + DBUG_VOID_RETURN; +} + #endif /* EMBEDDED_LIBRARY */ /* diff --git a/sql/protocol.h b/sql/protocol.h index 8d9da5774b2..85c22724b74 100644 --- a/sql/protocol.h +++ b/sql/protocol.h @@ -91,6 +91,12 @@ public: virtual bool store_date(TIME *time)=0; virtual bool store_time(TIME *time)=0; virtual bool store(Field *field)=0; +#ifdef EMBEDDED_LIBRARY + int begin_dataset(); + virtual void remove_last_row() {} +#else + void remove_last_row() {} +#endif }; @@ -117,6 +123,9 @@ public: virtual bool store(float nr, uint32 decimals, String *buffer); virtual bool store(double from, uint32 decimals, String *buffer); virtual bool store(Field *field); +#ifdef EMBEDDED_LIBRARY + void remove_last_row(); +#endif }; diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 08d89228a72..4644145c856 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -951,7 +951,9 @@ bool select_send::send_data(List<Item> &items) thd->sent_row_count++; if (!thd->vio_ok()) DBUG_RETURN(0); - if (!thd->net.report_error) + if (thd->net.report_error) + protocol->remove_last_row(); + else DBUG_RETURN(protocol->write()); DBUG_RETURN(1); } @@ -1983,10 +1985,8 @@ void THD::reset_sub_statement_state(Sub_statement_state *backup, cuted_fields= 0; transaction.savepoints= 0; -#ifndef EMBEDDED_LIBRARY /* Surpress OK packets in case if we will execute statements */ net.no_send_ok= TRUE; -#endif } diff --git a/sql/sql_class.h b/sql/sql_class.h index 1ef3322bc8f..fc31742240b 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -801,13 +801,16 @@ public: #ifdef EMBEDDED_LIBRARY struct st_mysql *mysql; - struct st_mysql_data *data; unsigned long client_stmt_id; unsigned long client_param_count; struct st_mysql_bind *client_params; char *extra_data; ulong extra_length; - String query_rest; + struct st_mysql_data *cur_data; + struct st_mysql_data *first_data; + struct st_mysql_data **data_tail; + void clear_data_list(); + struct st_mysql_data *alloc_new_dataset(); #endif NET net; // client connection descriptor MEM_ROOT warn_root; // For warnings and errors @@ -1441,6 +1444,11 @@ public: */ virtual void cleanup(); void set_thd(THD *thd_arg) { thd= thd_arg; } +#ifdef EMBEDDED_LIBRARY + virtual void begin_dataset() {} +#else + void begin_dataset() {} +#endif }; diff --git a/sql/sql_cursor.cc b/sql/sql_cursor.cc index 89c160cd70a..33ad27b9d14 100644 --- a/sql/sql_cursor.cc +++ b/sql/sql_cursor.cc @@ -603,6 +603,7 @@ void Materialized_cursor::fetch(ulong num_rows) THD *thd= table->in_use; int res= 0; + result->begin_dataset(); for (fetch_limit+= num_rows; fetch_count < fetch_limit; fetch_count++) { if ((res= table->file->rnd_next(table->record[0]))) diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 4def568635d..5a3d25f9de7 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -1713,13 +1713,10 @@ bool dispatch_command(enum enum_server_command command, THD *thd, net->no_send_error= 0; /* Multiple queries exits, execute them individually - in embedded server - just store them to be executed later */ -#ifndef EMBEDDED_LIBRARY if (thd->lock || thd->open_tables || thd->derived_tables || thd->prelocked_mode) close_thread_tables(thd); -#endif ulong length= (ulong)(packet_end-packet); log_slow_statement(thd); @@ -1737,25 +1734,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, thd->set_time(); /* Reset the query start time. */ /* TODO: set thd->lex->sql_command to SQLCOM_END here */ VOID(pthread_mutex_unlock(&LOCK_thread_count)); -#ifndef EMBEDDED_LIBRARY mysql_parse(thd, packet, length); -#else - /* - 'packet' can point inside the query_rest's buffer - so we have to do memmove here - */ - if (thd->query_rest.length() > length) - { - memmove(thd->query_rest.c_ptr(), packet, length); - thd->query_rest.length(length); - } - else - thd->query_rest.copy(packet, length, thd->query_rest.charset()); - - thd->server_status&= ~ (SERVER_QUERY_NO_INDEX_USED | - SERVER_QUERY_NO_GOOD_INDEX_USED); - break; -#endif /*EMBEDDED_LIBRARY*/ } if (!(specialflag & SPECIAL_NO_PRIOR)) @@ -4242,10 +4221,8 @@ end_with_restore_list: goto error; } -#ifndef EMBEDDED_LIBRARY my_bool nsok= thd->net.no_send_ok; thd->net.no_send_ok= TRUE; -#endif if (sp->m_flags & sp_head::MULTI_RESULTS) { if (! (thd->client_capabilities & CLIENT_MULTI_RESULTS)) @@ -4255,9 +4232,7 @@ end_with_restore_list: back */ my_error(ER_SP_BADSELECT, MYF(0), sp->m_qname.str); -#ifndef EMBEDDED_LIBRARY thd->net.no_send_ok= nsok; -#endif goto error; } /* @@ -4274,18 +4249,14 @@ end_with_restore_list: sp->m_db.str, sp->m_name.str, TRUE, 0) || sp_change_security_context(thd, sp, &save_ctx)) { -#ifndef EMBEDDED_LIBRARY thd->net.no_send_ok= nsok; -#endif goto error; } if (save_ctx && check_routine_access(thd, EXECUTE_ACL, sp->m_db.str, sp->m_name.str, TRUE, 0)) { -#ifndef EMBEDDED_LIBRARY thd->net.no_send_ok= nsok; -#endif sp_restore_security_context(thd, save_ctx); goto error; } @@ -4317,9 +4288,7 @@ end_with_restore_list: sp_restore_security_context(thd, save_ctx); #endif -#ifndef EMBEDDED_LIBRARY thd->net.no_send_ok= nsok; -#endif thd->server_status&= ~bits_to_be_cleared; if (!res) diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc index 7b35f057217..78487dd965d 100644 --- a/sql/sql_prepare.cc +++ b/sql/sql_prepare.cc @@ -92,6 +92,12 @@ public: virtual bool send_fields(List<Item> &list, uint flags); virtual bool send_data(List<Item> &items); virtual bool send_eof(); +#ifdef EMBEDDED_LIBRARY + void begin_dataset() + { + protocol.begin_dataset(); + } +#endif }; /****************************************************************************** @@ -524,9 +530,10 @@ void set_param_time(Item_param *param, uchar **pos, ulong len) void set_param_datetime(Item_param *param, uchar **pos, ulong len) { - MYSQL_TIME *to= (MYSQL_TIME*)*pos; + MYSQL_TIME tm= *((MYSQL_TIME*)*pos); + tm.neg= 0; - param->set_time(to, MYSQL_TIMESTAMP_DATETIME, + param->set_time(&tm, MYSQL_TIMESTAMP_DATETIME, MAX_DATETIME_WIDTH * MY_CHARSET_BIN_MB_MAXLEN); } |