1242
/********************************************************************
1243
Implementation of new client API for 4.1 version.
1245
mysql_stmt_* are real prototypes used by applications.
1247
To make API work in embedded library all functions performing
1248
real I/O are prefixed with 'cli_' (abbreviated from 'Call Level
1249
Interface'). This functions are invoked via pointers set in
1250
MYSQL::methods structure. Embedded counterparts, prefixed with
1251
'emb_' reside in libmysqld/lib_sql.cc.
1252
*********************************************************************/
1255
static my_bool int_is_null_true= 1; /* Used for MYSQL_TYPE_NULL */
1256
static my_bool int_is_null_false= 0;
1258
/********************************************************************
1259
Fetch and conversion of result set rows (binary protocol).
1260
*********************************************************************/
1263
Read date, (time, datetime) value from network buffer and store it
1264
in MYSQL_TIME structure.
1267
read_binary_{date,time,datetime}()
1268
tm MYSQL_TIME structure to fill
1269
pos pointer to current position in network buffer.
1270
These functions increase pos to point to the beginning of the
1273
Auxiliary functions to read time (date, datetime) values from network
1274
buffer and store in MYSQL_TIME structure. Jointly used by conversion
1275
and no-conversion fetching.
1278
static void read_binary_time(MYSQL_TIME *tm, uchar **pos)
1280
/* net_field_length will set pos to the first byte of data */
1281
uint length= net_field_length(pos);
1288
tm->day= (ulong) sint4korr(to+1);
1289
tm->hour= (uint) to[5];
1290
tm->minute= (uint) to[6];
1291
tm->second= (uint) to[7];
1292
tm->second_part= (length > 8) ? (ulong) sint4korr(to+8) : 0;
1293
tm->year= tm->month= 0;
1296
/* Convert days to hours at once */
1297
tm->hour+= tm->day*24;
1300
tm->time_type= MYSQL_TIMESTAMP_TIME;
1305
set_zero_time(tm, MYSQL_TIMESTAMP_TIME);
1308
static void read_binary_datetime(MYSQL_TIME *tm, uchar **pos)
1310
uint length= net_field_length(pos);
1317
tm->year= (uint) sint2korr(to);
1318
tm->month= (uint) to[2];
1319
tm->day= (uint) to[3];
1323
tm->hour= (uint) to[4];
1324
tm->minute= (uint) to[5];
1325
tm->second= (uint) to[6];
1328
tm->hour= tm->minute= tm->second= 0;
1329
tm->second_part= (length > 7) ? (ulong) sint4korr(to+7) : 0;
1330
tm->time_type= MYSQL_TIMESTAMP_DATETIME;
1335
set_zero_time(tm, MYSQL_TIMESTAMP_DATETIME);
1338
static void read_binary_date(MYSQL_TIME *tm, uchar **pos)
1340
uint length= net_field_length(pos);
1345
tm->year = (uint) sint2korr(to);
1346
tm->month= (uint) to[2];
1347
tm->day= (uint) to[3];
1349
tm->hour= tm->minute= tm->second= 0;
1352
tm->time_type= MYSQL_TIMESTAMP_DATE;
1357
set_zero_time(tm, MYSQL_TIMESTAMP_DATE);
1362
Check that two field types are binary compatible i. e.
1363
have equal representation in the binary protocol and
1364
require client-side buffers of the same type.
1367
is_binary_compatible()
1368
type1 parameter type supplied by user
1369
type2 field type, obtained from result set metadata
1375
static my_bool is_binary_compatible(enum enum_field_types type1,
1376
enum enum_field_types type2)
1378
static const enum enum_field_types
1379
range1[]= { MYSQL_TYPE_SHORT, MYSQL_TYPE_YEAR, MYSQL_TYPE_NULL },
1380
range2[]= { MYSQL_TYPE_INT24, MYSQL_TYPE_LONG, MYSQL_TYPE_NULL },
1381
range3[]= { MYSQL_TYPE_DATETIME, MYSQL_TYPE_TIMESTAMP, MYSQL_TYPE_NULL },
1382
range4[]= { MYSQL_TYPE_ENUM, MYSQL_TYPE_SET, MYSQL_TYPE_TINY_BLOB,
1383
MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_LONG_BLOB, MYSQL_TYPE_BLOB,
1384
MYSQL_TYPE_VAR_STRING, MYSQL_TYPE_STRING, MYSQL_TYPE_GEOMETRY,
1385
MYSQL_TYPE_DECIMAL, MYSQL_TYPE_NULL };
1386
static const enum enum_field_types
1387
*range_list[]= { range1, range2, range3, range4 },
1388
**range_list_end= range_list + sizeof(range_list)/sizeof(*range_list);
1389
const enum enum_field_types **range, *type;
1393
for (range= range_list; range != range_list_end; ++range)
1395
/* check that both type1 and type2 are in the same range */
1396
my_bool type1_found= FALSE, type2_found= FALSE;
1397
for (type= *range; *type != MYSQL_TYPE_NULL; type++)
1399
type1_found|= type1 == *type;
1400
type2_found|= type2 == *type;
1402
if (type1_found || type2_found)
1403
return type1_found && type2_found;
1409
1242
int cli_unbuffered_fetch(MYSQL *mysql, char **row)
1411
1244
if (packet_error == cli_safe_read(mysql))