maria-developers team mailing list archive
-
maria-developers team
-
Mailing list archive
-
Message #12065
A cleanup for libmariadb
Hi Georg,
Can you please review this cleanup patch?
It's a prerequisite for:
MDEV-17832 Protocol: extensions for Pluggable types and JSON, GEOMETRY
The idea is that this patch introduces a new file
libmariadb/mariadb_priv.h and adds prototypes of these functions:
void free_rows(MYSQL_DATA *cur);
int ma_multi_command(MYSQL *mysql, enum enum_multi_status status);
MYSQL_FIELD * unpack_fields(MYSQL_DATA *data,
MA_MEM_ROOT *alloc,uint fields,
my_bool default_value);
and removes these prototypes from mariadb_stmt.c.
I think it should be safer this way.
Later I'll add there more prototypes into libmariadb/mariadb_priv.h,
e.g. functions that will be added under terms of MDEV-17832.
Note, I also removed the "my_bool long_flag_protocol" parameter
from unpack_fields(), it's not used anyway.
Under terms of MDEV-17832 I'll have to add a "const MYSQL *mysql"
parameter. So if we ever need to check CLIENT_LONG_FLAG inside
unpack_fields() again, it can be done through the "mysql" parameter:
(mysql->server_capabilities & CLIENT_LONG_FLAG)
Thanks!
diff --git a/libmariadb/mariadb_lib.c b/libmariadb/mariadb_lib.c
index 4c1108b..4176698 100644
--- a/libmariadb/mariadb_lib.c
+++ b/libmariadb/mariadb_lib.c
@@ -27,6 +27,7 @@
#include <ma_string.h>
#include <mariadb_ctype.h>
#include <ma_common.h>
+#include "mariadb_priv.h"
#include "ma_context.h"
#include "mysql.h"
#include "mariadb_version.h"
@@ -771,7 +772,7 @@ static size_t rset_field_offsets[]= {
MYSQL_FIELD *
unpack_fields(MYSQL_DATA *data,MA_MEM_ROOT *alloc,uint fields,
- my_bool default_value, my_bool long_flag_protocol __attribute__((unused)))
+ my_bool default_value)
{
MYSQL_ROWS *row;
MYSQL_FIELD *field,*result;
@@ -2192,9 +2193,7 @@ get_info:
if (!(fields=mysql->methods->db_read_rows(mysql,(MYSQL_FIELD*) 0,8)))
return(-1);
if (!(mysql->fields=unpack_fields(fields,&mysql->field_alloc,
- (uint) field_count,1,
- (my_bool) test(mysql->server_capabilities &
- CLIENT_LONG_FLAG))))
+ (uint) field_count, 1)))
return(-1);
mysql->status=MYSQL_STATUS_GET_RESULT;
mysql->field_count=field_count;
@@ -2525,9 +2524,7 @@ mysql_list_fields(MYSQL *mysql, const char *table, const char *wild)
result->eof=1;
result->field_count = (uint) query->rows;
result->fields= unpack_fields(query,&result->field_alloc,
- result->field_count,1,
- (my_bool) test(mysql->server_capabilities &
- CLIENT_LONG_FLAG));
+ result->field_count, 1);
if (result->fields)
return(result);
@@ -2552,9 +2549,8 @@ mysql_list_processes(MYSQL *mysql)
field_count=(uint) net_field_length(&pos);
if (!(fields = mysql->methods->db_read_rows(mysql,(MYSQL_FIELD*) 0,5)))
return(NULL);
- if (!(mysql->fields=unpack_fields(fields,&mysql->field_alloc,field_count,0,
- (my_bool) test(mysql->server_capabilities &
- CLIENT_LONG_FLAG))))
+ if (!(mysql->fields=unpack_fields(fields, &mysql->field_alloc,
+ field_count, 0)))
return(NULL);
mysql->status=MYSQL_STATUS_GET_RESULT;
mysql->field_count=field_count;
diff --git a/libmariadb/mariadb_priv.h b/libmariadb/mariadb_priv.h
new file mode 100644
index 0000000..811fc46
--- /dev/null
+++ b/libmariadb/mariadb_priv.h
@@ -0,0 +1,31 @@
+#ifndef MARIADB_PRIV_H
+#define MARIADB_PRIV_H
+/****************************************************************************
+ Copyright (C) 2020 MariaDB Corporation
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with this library; if not see <http://www.gnu.org/licenses>
+ or write to the Free Software Foundation, Inc.,
+ 51 Franklin St., Fifth Floor, Boston, MA 02110, USA
+
+ Part of this code includes code from the PHP project which
+ is freely available from http://www.php.net
+ *****************************************************************************/
+
+void free_rows(MYSQL_DATA *cur);
+int ma_multi_command(MYSQL *mysql, enum enum_multi_status status);
+MYSQL_FIELD * unpack_fields(MYSQL_DATA *data,
+ MA_MEM_ROOT *alloc,uint fields,
+ my_bool default_value);
+
+#endif
diff --git a/libmariadb/mariadb_stmt.c b/libmariadb/mariadb_stmt.c
index cf35e37..078f14e 100644
--- a/libmariadb/mariadb_stmt.c
+++ b/libmariadb/mariadb_stmt.c
@@ -55,6 +55,8 @@
#include <time.h>
#include <mysql/client_plugin.h>
#include <ma_common.h>
+#include "mariadb_priv.h"
+
#define UPDATE_STMT_ERROR(stmt)\
SET_CLIENT_STMT_ERROR((stmt), (stmt)->mysql->net.last_errno, (stmt)->mysql->net.sqlstate, (stmt)->mysql->net.last_error)
@@ -75,10 +77,6 @@ typedef struct
MA_MEM_ROOT fields_ma_alloc_root;
} MADB_STMT_EXTENSION;
-MYSQL_DATA *read_rows(MYSQL *mysql,MYSQL_FIELD *mysql_fields, uint fields);
-void free_rows(MYSQL_DATA *cur);
-int ma_multi_command(MYSQL *mysql, enum enum_multi_status status);
-MYSQL_FIELD * unpack_fields(MYSQL_DATA *data,MA_MEM_ROOT *alloc,uint fields, my_bool default_value, my_bool long_flag_protocol);
static my_bool net_stmt_close(MYSQL_STMT *stmt, my_bool remove);
static my_bool is_not_null= 0;
@@ -1598,8 +1596,7 @@ my_bool mthd_stmt_get_result_metadata(MYSQL_STMT *stmt)
if (!(result= stmt->mysql->methods->db_read_rows(stmt->mysql, (MYSQL_FIELD *)0, 7)))
return(1);
if (!(stmt->fields= unpack_fields(result,fields_ma_alloc_root,
- stmt->field_count, 0,
- stmt->mysql->server_capabilities & CLIENT_LONG_FLAG)))
+ stmt->field_count, 0)))
return(1);
return(0);
}