Commit d4338eb2 authored by unknown's avatar unknown

SCRUM

Including client code into embedded library
fixes


libmysql/libmysql.c:
  We should call this way
libmysqld/lib_sql.cc:
  Necessary initializations added
libmysqld/libmysqld.c:
  mysql_close can't be "virtual"
  mysqltest.c calls mysql_close before mysql_connect
sql-common/client.c:
  We have to redo fetch_lengths to count lengths looking at '\0' in string.
  It works slower, but is correct for both client and embedded libraries
parent 1023a084
......@@ -3388,7 +3388,7 @@ my_bool STDCALL mysql_stmt_reset(MYSQL_STMT *stmt)
mysql= stmt->mysql->last_used_con;
int4store(buff, stmt->stmt_id); /* Send stmt id to server */
if (advanced_command(mysql, COM_RESET_STMT,buff,MYSQL_STMT_HEADER,0,0,1))
if ((*mysql->methods->advanced_command)(mysql, COM_RESET_STMT,buff,MYSQL_STMT_HEADER,0,0,1))
{
set_stmt_errmsg(stmt, mysql->net.last_error, mysql->net.last_errno,
mysql->net.sqlstate);
......
......@@ -38,6 +38,7 @@ static char inited, org_my_init_done;
C_MODE_START
#include <mysql.h>
#include "errmsg.h"
#include <sql_common.h>
static int check_connections1(THD * thd);
static int check_connections2(THD * thd);
......@@ -66,8 +67,10 @@ emb_advanced_command(MYSQL *mysql, enum enum_server_command command,
/* Clear result variables */
thd->clear_error();
mysql->affected_rows= ~(my_ulonglong) 0;
mysql->field_count= 0;
thd->store_globals(); // Fix if more than one connect
free_old_query(mysql);
result= dispatch_command(command, thd, (char *) arg, arg_length + 1);
if (!skip_check)
......
......@@ -72,6 +72,8 @@ cli_mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
const char *passwd, const char *db,
uint port, const char *unix_socket,ulong client_flag);
void STDCALL cli_mysql_close(MYSQL *mysql);
#ifdef HAVE_GETPWUID
struct passwd *getpwuid(uid_t);
char* getlogin(void);
......@@ -166,14 +168,12 @@ static inline int mysql_init_charset(MYSQL *mysql)
** before calling mysql_real_connect !
*/
static void STDCALL emb_mysql_close(MYSQL *mysql);
static my_bool STDCALL emb_mysql_read_query_result(MYSQL *mysql);
static MYSQL_RES * STDCALL emb_mysql_store_result(MYSQL *mysql);
static MYSQL_RES * STDCALL emb_mysql_use_result(MYSQL *mysql);
static MYSQL_METHODS embedded_methods=
{
emb_mysql_close,
emb_mysql_read_query_result,
emb_advanced_command,
emb_mysql_store_result,
......@@ -276,9 +276,15 @@ mysql_real_connect(MYSQL *mysql,const char *host, const char *user,
** If handle is alloced by mysql connect free it.
*************************************************************************/
static void STDCALL emb_mysql_close(MYSQL *mysql)
void STDCALL mysql_close(MYSQL *mysql)
{
DBUG_ENTER("mysql_close");
if (mysql->methods != &embedded_methods)
{
cli_mysql_close(mysql);
DBUG_VOID_RETURN;
}
if (mysql) /* Some simple safety */
{
my_free(mysql->options.user,MYF(MY_ALLOW_ZERO_PTR));
......
......@@ -48,12 +48,14 @@
#endif
#define CLI_MYSQL_REAL_CONNECT cli_mysql_real_connect
#define CLI_MYSQL_CLOSE cli_mysql_close
#undef net_flush
my_bool net_flush(NET *net);
#else /*EMBEDDED_LIBRARY*/
#define CLI_MYSQL_REAL_CONNECT mysql_real_connect
#define CLI_MYSQL_CLOSE mysql_close
#endif /*EMBEDDED_LIBRARY*/
#if !defined(MYSQL_SERVER) && (defined(__WIN__) || defined(_WIN32) || defined(_WIN64))
......@@ -965,26 +967,11 @@ void mysql_read_default_options(struct st_mysql_options *options,
void fetch_lengths(ulong *to, MYSQL_ROW column, uint field_count)
{
ulong *prev_length;
byte *start=0;
MYSQL_ROW end;
prev_length=0; /* Keep gcc happy */
for (end=column + field_count + 1 ; column != end ; column++, to++)
{
if (!*column)
{
*to= 0; /* Null */
continue;
}
if (start) /* Found end of prev string */
*prev_length= (ulong) (*column-start-1);
start= *column;
prev_length= to;
}
for (end=column + field_count; column != end ; column++, to++)
*to= *column ? strlen(*column) : 0;
}
/***************************************************************************
Change field rows to field structs
***************************************************************************/
......@@ -1422,14 +1409,12 @@ my_bool mysql_autenticate(MYSQL *mysql, const char *passwd)
before calling mysql_real_connect !
*/
static void STDCALL cli_mysql_close(MYSQL *mysql);
static my_bool STDCALL cli_mysql_read_query_result(MYSQL *mysql);
static MYSQL_RES * STDCALL cli_mysql_store_result(MYSQL *mysql);
static MYSQL_RES * STDCALL cli_mysql_use_result(MYSQL *mysql);
static MYSQL_METHODS client_methods=
{
cli_mysql_close,
cli_mysql_read_query_result,
cli_advanced_command,
cli_mysql_store_result,
......@@ -2140,7 +2125,7 @@ static void mysql_close_free(MYSQL *mysql)
}
static void STDCALL cli_mysql_close(MYSQL *mysql)
void STDCALL CLI_MYSQL_CLOSE(MYSQL *mysql)
{
DBUG_ENTER("mysql_close");
if (mysql) /* Some simple safety */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment