2006-12-31 01:02:27 +01:00
|
|
|
/* Copyright (C) 2002-2006 MySQL AB
|
2002-12-11 08:17:51 +01:00
|
|
|
|
|
|
|
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
|
2006-12-23 20:17:15 +01:00
|
|
|
the Free Software Foundation; version 2 of the License.
|
2002-12-11 08:17:51 +01:00
|
|
|
|
|
|
|
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 */
|
|
|
|
|
2005-05-04 15:05:56 +02:00
|
|
|
#ifdef USE_PRAGMA_INTERFACE
|
2002-12-11 08:17:51 +01:00
|
|
|
#pragma interface /* gcc class implementation */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
class i_string;
|
|
|
|
class THD;
|
2003-01-20 15:47:25 +01:00
|
|
|
typedef struct st_mysql_field MYSQL_FIELD;
|
2003-04-23 16:37:33 +02:00
|
|
|
typedef struct st_mysql_rows MYSQL_ROWS;
|
|
|
|
|
2002-12-11 08:17:51 +01:00
|
|
|
class Protocol
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
THD *thd;
|
|
|
|
String *packet;
|
2004-05-25 00:03:49 +02:00
|
|
|
String *convert;
|
2002-12-11 08:17:51 +01:00
|
|
|
uint field_pos;
|
2005-11-22 23:50:37 +01:00
|
|
|
#ifndef DBUG_OFF
|
2002-12-11 08:17:51 +01:00
|
|
|
enum enum_field_types *field_types;
|
|
|
|
#endif
|
2003-01-15 09:11:44 +01:00
|
|
|
uint field_count;
|
2004-06-09 19:36:48 +02:00
|
|
|
#ifndef EMBEDDED_LIBRARY
|
2003-01-15 09:11:44 +01:00
|
|
|
bool net_store_data(const char *from, uint length);
|
2004-06-09 19:36:48 +02:00
|
|
|
#else
|
|
|
|
virtual bool net_store_data(const char *from, uint length);
|
2003-01-15 09:11:44 +01:00
|
|
|
char **next_field;
|
2003-01-20 15:47:25 +01:00
|
|
|
MYSQL_FIELD *next_mysql_field;
|
2003-01-15 09:11:44 +01:00
|
|
|
MEM_ROOT *alloc;
|
2002-12-17 16:33:25 +01:00
|
|
|
#endif
|
2004-05-25 00:03:49 +02:00
|
|
|
bool store_string_aux(const char *from, uint length,
|
|
|
|
CHARSET_INFO *fromcs, CHARSET_INFO *tocs);
|
2002-12-11 08:17:51 +01:00
|
|
|
public:
|
|
|
|
Protocol() {}
|
2003-11-28 11:18:13 +01:00
|
|
|
Protocol(THD *thd_arg) { init(thd_arg); }
|
2003-03-21 12:18:52 +01:00
|
|
|
virtual ~Protocol() {}
|
2003-11-28 11:18:13 +01:00
|
|
|
void init(THD* thd_arg);
|
2004-08-03 12:32:21 +02:00
|
|
|
|
2004-08-28 08:32:27 +02:00
|
|
|
enum { SEND_NUM_ROWS= 1, SEND_DEFAULTS= 2, SEND_EOF= 4 };
|
2004-11-03 11:39:38 +01:00
|
|
|
virtual bool send_fields(List<Item> *list, uint flags);
|
2004-08-03 12:32:21 +02:00
|
|
|
|
2002-12-11 08:17:51 +01:00
|
|
|
bool store(I_List<i_string> *str_list);
|
2003-03-17 10:14:04 +01:00
|
|
|
bool store(const char *from, CHARSET_INFO *cs);
|
2002-12-11 08:17:51 +01:00
|
|
|
String *storage_packet() { return packet; }
|
|
|
|
inline void free() { packet->free(); }
|
2003-09-17 17:48:53 +02:00
|
|
|
virtual bool write();
|
2006-12-22 02:59:27 +01:00
|
|
|
inline bool store(int from)
|
|
|
|
{ return store_long((longlong) from); }
|
2002-12-11 08:17:51 +01:00
|
|
|
inline bool store(uint32 from)
|
|
|
|
{ return store_long((longlong) from); }
|
|
|
|
inline bool store(longlong from)
|
|
|
|
{ return store_longlong((longlong) from, 0); }
|
|
|
|
inline bool store(ulonglong from)
|
|
|
|
{ return store_longlong((longlong) from, 1); }
|
2003-05-29 23:47:31 +02:00
|
|
|
inline bool store(String *str)
|
2003-08-19 15:00:12 +02:00
|
|
|
{ return store((char*) str->ptr(), str->length(), str->charset()); }
|
2002-12-17 16:33:25 +01:00
|
|
|
|
2003-01-15 09:11:44 +01:00
|
|
|
virtual bool prepare_for_send(List<Item> *item_list)
|
|
|
|
{
|
|
|
|
field_count=item_list->elements;
|
|
|
|
return 0;
|
|
|
|
}
|
2004-11-02 19:13:27 +01:00
|
|
|
virtual bool flush();
|
2002-12-11 08:17:51 +01:00
|
|
|
virtual void prepare_for_resend()=0;
|
|
|
|
|
|
|
|
virtual bool store_null()=0;
|
|
|
|
virtual bool store_tiny(longlong from)=0;
|
|
|
|
virtual bool store_short(longlong from)=0;
|
|
|
|
virtual bool store_long(longlong from)=0;
|
|
|
|
virtual bool store_longlong(longlong from, bool unsigned_flag)=0;
|
2005-02-08 23:50:45 +01:00
|
|
|
virtual bool store_decimal(const my_decimal *)=0;
|
2003-03-17 10:14:04 +01:00
|
|
|
virtual bool store(const char *from, uint length, CHARSET_INFO *cs)=0;
|
2003-04-07 10:52:48 +02:00
|
|
|
virtual bool store(const char *from, uint length,
|
|
|
|
CHARSET_INFO *fromcs, CHARSET_INFO *tocs)=0;
|
2002-12-11 08:17:51 +01:00
|
|
|
virtual bool store(float from, uint32 decimals, String *buffer)=0;
|
|
|
|
virtual bool store(double from, uint32 decimals, String *buffer)=0;
|
|
|
|
virtual bool store(TIME *time)=0;
|
|
|
|
virtual bool store_date(TIME *time)=0;
|
|
|
|
virtual bool store_time(TIME *time)=0;
|
|
|
|
virtual bool store(Field *field)=0;
|
2006-02-24 17:34:15 +01:00
|
|
|
#ifdef EMBEDDED_LIBRARY
|
|
|
|
int begin_dataset();
|
|
|
|
virtual void remove_last_row() {}
|
|
|
|
#else
|
|
|
|
void remove_last_row() {}
|
|
|
|
#endif
|
Fix for BUG#735 "Prepared Statements: there is no support for Query
Cache".
WL#1569 "Prepared Statements: implement support of Query Cache".
Prepared SELECTs did not look up in the query cache, and their results
were not stored in the query cache. This made them slower than
non-prepared SELECTs in some cases.
The fix is to re-use the expanded query (the prepared query where
"?" placeholders are replaced by their values, at execution time)
for searching/storing in the query cache.
It works fine for statements prepared via mysql_stmt_prepare(), which
are the most commonly used and were the scope of this bugfix and WL.
It works less fine for statements prepared via the SQL command
PREPARE...FROM, which are still not using the query cache if they
have at least one parameter (because then the expanded query contains
names of user variables, and user variables don't work with the
query cache, even in non-prepared queries).
Note that results from prepared SELECTs, which are in the binary
protocol, and results from normal SELECTs, which are in the text
protocol, ignore each other in the query cache, because a result in the
binary protocol should never be served to a SELECT expecting the text
protocol and vice-versa.
Note, after this patch, bug 25843 starts applying to query cache
("changing default database between PREPARE and EXECUTE of statement
breaks binlog"), we need to fix it.
2007-03-09 18:09:57 +01:00
|
|
|
enum enum_protocol_type
|
|
|
|
{
|
|
|
|
PROTOCOL_TEXT= 0, PROTOCOL_BINARY= 1
|
|
|
|
/*
|
|
|
|
before adding here or change the values, consider that it is cast to a
|
|
|
|
bit in sql_cache.cc.
|
|
|
|
*/
|
|
|
|
};
|
|
|
|
virtual enum enum_protocol_type type()= 0;
|
2002-12-11 08:17:51 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* Class used for the old (MySQL 4.0 protocol) */
|
|
|
|
|
2007-01-30 22:48:05 +01:00
|
|
|
class Protocol_text :public Protocol
|
2002-12-11 08:17:51 +01:00
|
|
|
{
|
|
|
|
public:
|
2007-01-30 22:48:05 +01:00
|
|
|
Protocol_text() {}
|
|
|
|
Protocol_text(THD *thd_arg) :Protocol(thd_arg) {}
|
2002-12-11 08:17:51 +01:00
|
|
|
virtual void prepare_for_resend();
|
|
|
|
virtual bool store_null();
|
|
|
|
virtual bool store_tiny(longlong from);
|
|
|
|
virtual bool store_short(longlong from);
|
|
|
|
virtual bool store_long(longlong from);
|
|
|
|
virtual bool store_longlong(longlong from, bool unsigned_flag);
|
2005-02-08 23:50:45 +01:00
|
|
|
virtual bool store_decimal(const my_decimal *);
|
2003-03-17 10:14:04 +01:00
|
|
|
virtual bool store(const char *from, uint length, CHARSET_INFO *cs);
|
2003-04-07 10:52:48 +02:00
|
|
|
virtual bool store(const char *from, uint length,
|
|
|
|
CHARSET_INFO *fromcs, CHARSET_INFO *tocs);
|
2002-12-11 08:17:51 +01:00
|
|
|
virtual bool store(TIME *time);
|
|
|
|
virtual bool store_date(TIME *time);
|
|
|
|
virtual bool store_time(TIME *time);
|
|
|
|
virtual bool store(float nr, uint32 decimals, String *buffer);
|
|
|
|
virtual bool store(double from, uint32 decimals, String *buffer);
|
|
|
|
virtual bool store(Field *field);
|
2006-02-24 17:34:15 +01:00
|
|
|
#ifdef EMBEDDED_LIBRARY
|
|
|
|
void remove_last_row();
|
|
|
|
#endif
|
Fix for BUG#735 "Prepared Statements: there is no support for Query
Cache".
WL#1569 "Prepared Statements: implement support of Query Cache".
Prepared SELECTs did not look up in the query cache, and their results
were not stored in the query cache. This made them slower than
non-prepared SELECTs in some cases.
The fix is to re-use the expanded query (the prepared query where
"?" placeholders are replaced by their values, at execution time)
for searching/storing in the query cache.
It works fine for statements prepared via mysql_stmt_prepare(), which
are the most commonly used and were the scope of this bugfix and WL.
It works less fine for statements prepared via the SQL command
PREPARE...FROM, which are still not using the query cache if they
have at least one parameter (because then the expanded query contains
names of user variables, and user variables don't work with the
query cache, even in non-prepared queries).
Note that results from prepared SELECTs, which are in the binary
protocol, and results from normal SELECTs, which are in the text
protocol, ignore each other in the query cache, because a result in the
binary protocol should never be served to a SELECT expecting the text
protocol and vice-versa.
Note, after this patch, bug 25843 starts applying to query cache
("changing default database between PREPARE and EXECUTE of statement
breaks binlog"), we need to fix it.
2007-03-09 18:09:57 +01:00
|
|
|
virtual enum enum_protocol_type type() { return PROTOCOL_TEXT; };
|
2002-12-11 08:17:51 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2007-01-30 22:48:05 +01:00
|
|
|
class Protocol_binary :public Protocol
|
2002-12-11 08:17:51 +01:00
|
|
|
{
|
|
|
|
private:
|
2003-01-15 09:11:44 +01:00
|
|
|
uint bit_fields;
|
2002-12-11 08:17:51 +01:00
|
|
|
public:
|
2007-01-30 22:48:05 +01:00
|
|
|
Protocol_binary() {}
|
|
|
|
Protocol_binary(THD *thd_arg) :Protocol(thd_arg) {}
|
2002-12-11 08:17:51 +01:00
|
|
|
virtual bool prepare_for_send(List<Item> *item_list);
|
|
|
|
virtual void prepare_for_resend();
|
2003-09-17 17:48:53 +02:00
|
|
|
#ifdef EMBEDDED_LIBRARY
|
|
|
|
virtual bool write();
|
2003-09-18 09:25:00 +02:00
|
|
|
bool net_store_data(const char *from, uint length);
|
2003-09-17 17:48:53 +02:00
|
|
|
#endif
|
2002-12-11 08:17:51 +01:00
|
|
|
virtual bool store_null();
|
|
|
|
virtual bool store_tiny(longlong from);
|
|
|
|
virtual bool store_short(longlong from);
|
|
|
|
virtual bool store_long(longlong from);
|
|
|
|
virtual bool store_longlong(longlong from, bool unsigned_flag);
|
2005-02-08 23:50:45 +01:00
|
|
|
virtual bool store_decimal(const my_decimal *);
|
2003-03-17 10:14:04 +01:00
|
|
|
virtual bool store(const char *from,uint length, CHARSET_INFO *cs);
|
2003-04-07 10:52:48 +02:00
|
|
|
virtual bool store(const char *from, uint length,
|
|
|
|
CHARSET_INFO *fromcs, CHARSET_INFO *tocs);
|
2002-12-11 08:17:51 +01:00
|
|
|
virtual bool store(TIME *time);
|
|
|
|
virtual bool store_date(TIME *time);
|
|
|
|
virtual bool store_time(TIME *time);
|
|
|
|
virtual bool store(float nr, uint32 decimals, String *buffer);
|
|
|
|
virtual bool store(double from, uint32 decimals, String *buffer);
|
|
|
|
virtual bool store(Field *field);
|
Fix for BUG#735 "Prepared Statements: there is no support for Query
Cache".
WL#1569 "Prepared Statements: implement support of Query Cache".
Prepared SELECTs did not look up in the query cache, and their results
were not stored in the query cache. This made them slower than
non-prepared SELECTs in some cases.
The fix is to re-use the expanded query (the prepared query where
"?" placeholders are replaced by their values, at execution time)
for searching/storing in the query cache.
It works fine for statements prepared via mysql_stmt_prepare(), which
are the most commonly used and were the scope of this bugfix and WL.
It works less fine for statements prepared via the SQL command
PREPARE...FROM, which are still not using the query cache if they
have at least one parameter (because then the expanded query contains
names of user variables, and user variables don't work with the
query cache, even in non-prepared queries).
Note that results from prepared SELECTs, which are in the binary
protocol, and results from normal SELECTs, which are in the text
protocol, ignore each other in the query cache, because a result in the
binary protocol should never be served to a SELECT expecting the text
protocol and vice-versa.
Note, after this patch, bug 25843 starts applying to query cache
("changing default database between PREPARE and EXECUTE of statement
breaks binlog"), we need to fix it.
2007-03-09 18:09:57 +01:00
|
|
|
virtual enum enum_protocol_type type() { return PROTOCOL_BINARY; };
|
2002-12-11 08:17:51 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
void send_warning(THD *thd, uint sql_errno, const char *err=0);
|
2004-10-20 15:06:54 +02:00
|
|
|
void net_printf_error(THD *thd, uint sql_errno, ...);
|
|
|
|
void net_send_error(THD *thd, uint sql_errno=0, const char *err=0);
|
2002-12-11 08:17:51 +01:00
|
|
|
void send_ok(THD *thd, ha_rows affected_rows=0L, ulonglong id=0L,
|
|
|
|
const char *info=0);
|
2005-06-30 14:17:10 +02:00
|
|
|
void send_eof(THD *thd);
|
2003-07-18 16:25:54 +02:00
|
|
|
bool send_old_password_request(THD *thd);
|
2002-12-11 08:17:51 +01:00
|
|
|
char *net_store_data(char *to,const char *from, uint length);
|
|
|
|
char *net_store_data(char *to,int32 from);
|
|
|
|
char *net_store_data(char *to,longlong from);
|
2003-09-17 17:48:53 +02:00
|
|
|
|