Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mariadb
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
mariadb
Commits
c2221956
Commit
c2221956
authored
Jan 07, 2003
by
venu@myvenu.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Code cleaup to fix the conversion routines - binary protocol
parent
bcacfe28
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
50 deletions
+34
-50
include/mysql.h
include/mysql.h
+2
-2
libmysql/libmysql.c
libmysql/libmysql.c
+32
-48
No files found.
include/mysql.h
View file @
c2221956
...
@@ -439,13 +439,12 @@ typedef struct st_mysql_bind
...
@@ -439,13 +439,12 @@ typedef struct st_mysql_bind
{
{
long
*
length
;
/* output length pointer */
long
*
length
;
/* output length pointer */
gptr
buffer
;
/* buffer */
gptr
buffer
;
/* buffer */
unsigned
long
buffer_length
;
/* buffer length */
enum
enum_field_types
buffer_type
;
/* buffer type */
enum
enum_field_types
buffer_type
;
/* buffer type */
enum
enum_field_types
field_type
;
/* field type */
my_bool
is_null
;
/* NULL indicator */
my_bool
is_null
;
/* NULL indicator */
my_bool
is_long_data
;
/* long data indicator */
my_bool
is_long_data
;
/* long data indicator */
/* The following are for internal use. Set by mysql_bind_param */
/* The following are for internal use. Set by mysql_bind_param */
unsigned
long
buffer_length
;
/* buffer length */
long
bind_length
;
/* Default length of data */
long
bind_length
;
/* Default length of data */
my_bool
long_ended
;
/* All data supplied for long */
my_bool
long_ended
;
/* All data supplied for long */
unsigned
int
param_number
;
/* For null count and error messages */
unsigned
int
param_number
;
/* For null count and error messages */
...
@@ -511,6 +510,7 @@ MYSQL_RES *STDCALL mysql_prepare_result(MYSQL_STMT *stmt);
...
@@ -511,6 +510,7 @@ MYSQL_RES *STDCALL mysql_prepare_result(MYSQL_STMT *stmt);
#define MYSQL_NO_DATA 100
#define MYSQL_NO_DATA 100
#define MYSQL_NEED_DATA 99
#define MYSQL_NEED_DATA 99
#define MYSQL_NULL_DATA (-1)
#define MYSQL_NULL_DATA (-1)
#define MYSQL_LONG_DATA (-2)
#define mysql_reload(mysql) mysql_refresh((mysql),REFRESH_GRANT)
#define mysql_reload(mysql) mysql_refresh((mysql),REFRESH_GRANT)
...
...
libmysql/libmysql.c
View file @
c2221956
...
@@ -4097,8 +4097,7 @@ static my_bool store_param(MYSQL_STMT *stmt, MYSQL_BIND *param)
...
@@ -4097,8 +4097,7 @@ static my_bool store_param(MYSQL_STMT *stmt, MYSQL_BIND *param)
DBUG_PRINT
(
"enter"
,(
"type: %d, buffer:%lx, length: %d"
,
param
->
buffer_type
,
DBUG_PRINT
(
"enter"
,(
"type: %d, buffer:%lx, length: %d"
,
param
->
buffer_type
,
param
->
buffer
?
param
->
buffer
:
"0"
,
*
param
->
length
));
param
->
buffer
?
param
->
buffer
:
"0"
,
*
param
->
length
));
if
(
param
->
is_null
||
param
->
buffer_type
==
MYSQL_TYPE_NULL
||
if
(
param
->
is_null
||
*
param
->
length
==
MYSQL_NULL_DATA
)
*
param
->
length
==
MYSQL_NULL_DATA
)
store_param_null
(
net
,
param
);
store_param_null
(
net
,
param
);
else
else
{
{
...
@@ -4190,7 +4189,7 @@ int STDCALL mysql_execute(MYSQL_STMT *stmt)
...
@@ -4190,7 +4189,7 @@ int STDCALL mysql_execute(MYSQL_STMT *stmt)
for
(
param
=
stmt
->
params
;
param
<
param_end
;
param
++
)
for
(
param
=
stmt
->
params
;
param
<
param_end
;
param
++
)
{
{
/* Check for long data which has not been propery given/terminated */
/* Check for long data which has not been propery given/terminated */
if
(
param
->
is_long_data
)
if
(
param
->
is_long_data
||
*
param
->
length
==
MYSQL_LONG_DATA
)
{
{
if
(
!
param
->
long_ended
)
if
(
!
param
->
long_ended
)
DBUG_RETURN
(
MYSQL_NEED_DATA
);
DBUG_RETURN
(
MYSQL_NEED_DATA
);
...
@@ -4281,7 +4280,7 @@ my_bool STDCALL mysql_bind_param(MYSQL_STMT *stmt, MYSQL_BIND * bind)
...
@@ -4281,7 +4280,7 @@ my_bool STDCALL mysql_bind_param(MYSQL_STMT *stmt, MYSQL_BIND * bind)
/* Setup data copy functions for the different supported types */
/* Setup data copy functions for the different supported types */
switch
(
param
->
buffer_type
)
{
switch
(
param
->
buffer_type
)
{
case
MYSQL_TYPE_NULL
:
case
MYSQL_TYPE_NULL
:
param
->
is_null
=
1
;
param
->
is_null
=
1
;
break
;
break
;
case
MYSQL_TYPE_TINY
:
case
MYSQL_TYPE_TINY
:
param
->
bind_length
=
1
;
param
->
bind_length
=
1
;
...
@@ -4412,41 +4411,32 @@ mysql_send_long_data(MYSQL_STMT *stmt, uint param_number,
...
@@ -4412,41 +4411,32 @@ mysql_send_long_data(MYSQL_STMT *stmt, uint param_number,
1 Error (Can't alloc net->buffer)
1 Error (Can't alloc net->buffer)
****************************************************************************/
****************************************************************************/
/* Return the default binary data length for the common types */
static
u
long
get_field
_length
(
uint
type
)
static
u
nsigned
int
get_binary
_length
(
uint
type
)
{
{
ulong
length
;
switch
(
type
)
{
switch
(
type
)
{
case
MYSQL_TYPE_TINY
:
case
MYSQL_TYPE_TINY
:
length
=
1
;
return
1
;
break
;
case
MYSQL_TYPE_SHORT
:
case
MYSQL_TYPE_SHORT
:
case
MYSQL_TYPE_YEAR
:
case
MYSQL_TYPE_YEAR
:
length
=
2
;
return
2
;
break
;
case
MYSQL_TYPE_LONG
:
case
MYSQL_TYPE_LONG
:
case
MYSQL_TYPE_FLOAT
:
case
MYSQL_TYPE_FLOAT
:
length
=
4
;
return
4
;
break
;
case
MYSQL_TYPE_LONGLONG
:
case
MYSQL_TYPE_LONGLONG
:
case
MYSQL_TYPE_DOUBLE
:
case
MYSQL_TYPE_DOUBLE
:
length
=
8
;
return
8
;
break
;
default:
default:
length
=
0
;
return
0
;
}
}
return
length
;
}
}
/* Convert Numeric to buffer types */
static
void
send_data_long
(
MYSQL_BIND
*
param
,
longlong
value
)
static
void
send_data_long
(
MYSQL_BIND
*
param
,
longlong
value
)
{
{
char
*
buffer
=
param
->
buffer
;
char
*
buffer
=
param
->
buffer
;
*
param
->
length
=
get_field_length
(
param
->
buffer_type
);
switch
(
param
->
buffer_type
)
{
switch
(
param
->
buffer_type
)
{
case
MYSQL_TYPE_TINY
:
case
MYSQL_TYPE_TINY
:
*
param
->
buffer
=
(
uchar
)
value
;
*
param
->
buffer
=
(
uchar
)
value
;
break
;
break
;
...
@@ -4480,13 +4470,12 @@ static void send_data_long(MYSQL_BIND *param, longlong value)
...
@@ -4480,13 +4470,12 @@ static void send_data_long(MYSQL_BIND *param, longlong value)
}
}
}
}
/* Convert Double to buffer types */
static
void
send_data_double
(
MYSQL_BIND
*
param
,
double
value
)
static
void
send_data_double
(
MYSQL_BIND
*
param
,
double
value
)
{
{
char
*
buffer
=
param
->
buffer
;
char
*
buffer
=
param
->
buffer
;
*
param
->
length
=
get_field_length
(
param
->
buffer_type
);
switch
(
param
->
buffer_type
)
{
switch
(
param
->
buffer_type
)
{
case
MYSQL_TYPE_TINY
:
case
MYSQL_TYPE_TINY
:
*
buffer
=
(
uchar
)
value
;
*
buffer
=
(
uchar
)
value
;
break
;
break
;
...
@@ -4520,63 +4509,64 @@ static void send_data_double(MYSQL_BIND *param, double value)
...
@@ -4520,63 +4509,64 @@ static void send_data_double(MYSQL_BIND *param, double value)
}
}
}
}
static
void
send_data_str
(
MYSQL_BIND
*
param
,
char
*
value
,
uint
src_length
)
/* Convert string to buffer types */
static
void
send_data_str
(
MYSQL_BIND
*
param
,
char
*
value
,
uint
length
)
{
{
char
*
buffer
=
param
->
buffer
;
char
*
buffer
=
param
->
buffer
;
*
param
->
length
=
get_field_length
(
param
->
buffer_type
);
switch
(
param
->
buffer_type
)
{
switch
(
param
->
buffer_type
)
{
case
MYSQL_TYPE_TINY
:
case
MYSQL_TYPE_TINY
:
*
buffer
=
(
char
)
*
value
;
{
uchar
data
=
(
uchar
)
my_strntol
(
system_charset_info
,
value
,
length
,
NULL
,
10
);
*
buffer
=
data
;
break
;
break
;
}
case
MYSQL_TYPE_SHORT
:
case
MYSQL_TYPE_SHORT
:
{
{
short
data
=
(
short
)
sint2korr
(
value
);
short
data
=
(
short
)
my_strntol
(
system_charset_info
,
value
,
length
,
NULL
,
10
);
int2store
(
buffer
,
data
);
int2store
(
buffer
,
data
);
break
;
break
;
}
}
case
MYSQL_TYPE_LONG
:
case
MYSQL_TYPE_LONG
:
{
{
int32
data
=
(
int32
)
sint4korr
(
value
);
int32
data
=
(
int32
)
my_strntol
(
system_charset_info
,
value
,
length
,
NULL
,
10
);
int4store
(
buffer
,
data
);
int4store
(
buffer
,
data
);
break
;
break
;
}
}
case
MYSQL_TYPE_LONGLONG
:
case
MYSQL_TYPE_LONGLONG
:
{
{
longlong
data
=
sint8korr
(
value
);
longlong
data
=
my_strntoll
(
system_charset_info
,
value
,
length
,
NULL
,
10
);
int8store
(
buffer
,
data
);
int8store
(
buffer
,
data
);
break
;
break
;
}
}
case
MYSQL_TYPE_FLOAT
:
case
MYSQL_TYPE_FLOAT
:
{
{
float
data
;
float
data
=
(
float
)
my_strntod
(
system_charset_info
,
value
,
length
,
NULL
);
float4get
(
data
,
value
);
float4store
(
buffer
,
data
);
float4store
(
buffer
,
data
);
break
;
break
;
}
}
case
MYSQL_TYPE_DOUBLE
:
case
MYSQL_TYPE_DOUBLE
:
{
{
double
data
;
double
data
=
my_strntod
(
system_charset_info
,
value
,
length
,
NULL
);
float8get
(
data
,
value
);
float8store
(
buffer
,
data
);
float8store
(
buffer
,
data
);
break
;
break
;
}
}
default:
default:
*
param
->
length
=
src_
length
;
*
param
->
length
=
length
;
memcpy
(
buffer
,
value
,
src_
length
);
memcpy
(
buffer
,
value
,
length
);
buffer
[
src_
length
]
=
'\0'
;
buffer
[
length
]
=
'\0'
;
}
}
}
}
/* Fetch data to buffers */
static
my_bool
fetch_results
(
MYSQL_STMT
*
stmt
,
MYSQL_BIND
*
param
,
static
my_bool
fetch_results
(
MYSQL_STMT
*
stmt
,
MYSQL_BIND
*
param
,
uint
field_type
,
uchar
**
row
)
uint
field_type
,
uchar
**
row
)
{
{
ulong
length
;
ulong
length
;
length
=
get_field_length
(
field_type
);
length
=
(
ulong
)
get_binary_length
(
field_type
);
switch
(
field_type
)
{
switch
(
field_type
)
{
case
MYSQL_TYPE_TINY
:
case
MYSQL_TYPE_TINY
:
{
{
uchar
value
=
(
uchar
)
**
row
;
uchar
value
=
(
uchar
)
**
row
;
...
@@ -4813,27 +4803,21 @@ my_bool STDCALL mysql_bind_result(MYSQL_STMT *stmt, MYSQL_BIND *bind)
...
@@ -4813,27 +4803,21 @@ my_bool STDCALL mysql_bind_result(MYSQL_STMT *stmt, MYSQL_BIND *bind)
/* Setup data copy functions for the different supported types */
/* Setup data copy functions for the different supported types */
switch
(
param
->
buffer_type
)
{
switch
(
param
->
buffer_type
)
{
case
MYSQL_TYPE_TINY
:
case
MYSQL_TYPE_TINY
:
param
->
bind_length
=
1
;
param
->
fetch_result
=
fetch_result_tinyint
;
param
->
fetch_result
=
fetch_result_tinyint
;
break
;
break
;
case
MYSQL_TYPE_SHORT
:
case
MYSQL_TYPE_SHORT
:
param
->
bind_length
=
2
;
param
->
fetch_result
=
fetch_result_short
;
param
->
fetch_result
=
fetch_result_short
;
break
;
break
;
case
MYSQL_TYPE_LONG
:
case
MYSQL_TYPE_LONG
:
param
->
bind_length
=
4
;
param
->
fetch_result
=
fetch_result_int32
;
param
->
fetch_result
=
fetch_result_int32
;
break
;
break
;
case
MYSQL_TYPE_LONGLONG
:
case
MYSQL_TYPE_LONGLONG
:
param
->
bind_length
=
8
;
param
->
fetch_result
=
fetch_result_int64
;
param
->
fetch_result
=
fetch_result_int64
;
break
;
break
;
case
MYSQL_TYPE_FLOAT
:
case
MYSQL_TYPE_FLOAT
:
param
->
bind_length
=
4
;
param
->
fetch_result
=
fetch_result_float
;
param
->
fetch_result
=
fetch_result_float
;
break
;
break
;
case
MYSQL_TYPE_DOUBLE
:
case
MYSQL_TYPE_DOUBLE
:
param
->
bind_length
=
8
;
param
->
fetch_result
=
fetch_result_double
;
param
->
fetch_result
=
fetch_result_double
;
break
;
break
;
case
MYSQL_TYPE_TINY_BLOB
:
case
MYSQL_TYPE_TINY_BLOB
:
...
@@ -4842,7 +4826,6 @@ my_bool STDCALL mysql_bind_result(MYSQL_STMT *stmt, MYSQL_BIND *bind)
...
@@ -4842,7 +4826,6 @@ my_bool STDCALL mysql_bind_result(MYSQL_STMT *stmt, MYSQL_BIND *bind)
case
MYSQL_TYPE_BLOB
:
case
MYSQL_TYPE_BLOB
:
case
MYSQL_TYPE_VAR_STRING
:
case
MYSQL_TYPE_VAR_STRING
:
case
MYSQL_TYPE_STRING
:
case
MYSQL_TYPE_STRING
:
param
->
bind_length
=
0
;
param
->
fetch_result
=
fetch_result_str
;
param
->
fetch_result
=
fetch_result_str
;
break
;
break
;
default:
default:
...
@@ -4852,6 +4835,7 @@ my_bool STDCALL mysql_bind_result(MYSQL_STMT *stmt, MYSQL_BIND *bind)
...
@@ -4852,6 +4835,7 @@ my_bool STDCALL mysql_bind_result(MYSQL_STMT *stmt, MYSQL_BIND *bind)
}
}
if
(
!
param
->
length
)
if
(
!
param
->
length
)
param
->
length
=
&
param
->
bind_length
;
param
->
length
=
&
param
->
bind_length
;
*
param
->
length
=
(
long
)
get_binary_length
(
param
->
buffer_type
);
}
}
stmt
->
res_buffers
=
1
;
stmt
->
res_buffers
=
1
;
DBUG_RETURN
(
0
);
DBUG_RETURN
(
0
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment