~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to libmysql/libmysql.c

  • Committer: Brian Aker
  • Date: 2008-07-03 00:14:39 UTC
  • Revision ID: brian@tangent.org-20080703001439-pit0mcl0wk8elxlq
Cleanup of sql-common and mysqldump

Show diffs side-by-side

added added

removed removed

Lines of Context:
1239
1239
  *to=0;
1240
1240
}
1241
1241
 
1242
 
/********************************************************************
1243
 
 Implementation of new client API for 4.1 version.
1244
 
 
1245
 
 mysql_stmt_* are real prototypes used by applications.
1246
 
 
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
 
*********************************************************************/
1253
 
 
1254
 
 
1255
 
static my_bool int_is_null_true= 1;             /* Used for MYSQL_TYPE_NULL */
1256
 
static my_bool int_is_null_false= 0;
1257
 
 
1258
 
/********************************************************************
1259
 
 Fetch and conversion of result set rows (binary protocol).
1260
 
*********************************************************************/
1261
 
 
1262
 
/*
1263
 
  Read date, (time, datetime) value from network buffer and store it
1264
 
  in MYSQL_TIME structure.
1265
 
 
1266
 
  SYNOPSIS
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
1271
 
          next column.
1272
 
 
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.
1276
 
*/
1277
 
 
1278
 
static void read_binary_time(MYSQL_TIME *tm, uchar **pos)
1279
 
{
1280
 
  /* net_field_length will set pos to the first byte of data */
1281
 
  uint length= net_field_length(pos);
1282
 
 
1283
 
  if (length)
1284
 
  {
1285
 
    uchar *to= *pos;
1286
 
    tm->neg=    to[0];
1287
 
 
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;
1294
 
    if (tm->day)
1295
 
    {
1296
 
      /* Convert days to hours at once */
1297
 
      tm->hour+= tm->day*24;
1298
 
      tm->day= 0;
1299
 
    }
1300
 
    tm->time_type= MYSQL_TIMESTAMP_TIME;
1301
 
 
1302
 
    *pos+= length;
1303
 
  }
1304
 
  else
1305
 
    set_zero_time(tm, MYSQL_TIMESTAMP_TIME);
1306
 
}
1307
 
 
1308
 
static void read_binary_datetime(MYSQL_TIME *tm, uchar **pos)
1309
 
{
1310
 
  uint length= net_field_length(pos);
1311
 
 
1312
 
  if (length)
1313
 
  {
1314
 
    uchar *to= *pos;
1315
 
 
1316
 
    tm->neg=    0;
1317
 
    tm->year=   (uint) sint2korr(to);
1318
 
    tm->month=  (uint) to[2];
1319
 
    tm->day=    (uint) to[3];
1320
 
 
1321
 
    if (length > 4)
1322
 
    {
1323
 
      tm->hour=   (uint) to[4];
1324
 
      tm->minute= (uint) to[5];
1325
 
      tm->second= (uint) to[6];
1326
 
    }
1327
 
    else
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;
1331
 
 
1332
 
    *pos+= length;
1333
 
  }
1334
 
  else
1335
 
    set_zero_time(tm, MYSQL_TIMESTAMP_DATETIME);
1336
 
}
1337
 
 
1338
 
static void read_binary_date(MYSQL_TIME *tm, uchar **pos)
1339
 
{
1340
 
  uint length= net_field_length(pos);
1341
 
 
1342
 
  if (length)
1343
 
  {
1344
 
    uchar *to= *pos;
1345
 
    tm->year =  (uint) sint2korr(to);
1346
 
    tm->month=  (uint) to[2];
1347
 
    tm->day= (uint) to[3];
1348
 
 
1349
 
    tm->hour= tm->minute= tm->second= 0;
1350
 
    tm->second_part= 0;
1351
 
    tm->neg= 0;
1352
 
    tm->time_type= MYSQL_TIMESTAMP_DATE;
1353
 
 
1354
 
    *pos+= length;
1355
 
  }
1356
 
  else
1357
 
    set_zero_time(tm, MYSQL_TIMESTAMP_DATE);
1358
 
}
1359
 
 
1360
 
 
1361
 
/*
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.
1365
 
 
1366
 
  SYNOPSIS
1367
 
    is_binary_compatible()
1368
 
    type1   parameter type supplied by user
1369
 
    type2   field type, obtained from result set metadata
1370
 
 
1371
 
  RETURN
1372
 
    TRUE or FALSE
1373
 
*/
1374
 
 
1375
 
static my_bool is_binary_compatible(enum enum_field_types type1,
1376
 
                                    enum enum_field_types type2)
1377
 
{
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;
1390
 
 
1391
 
  if (type1 == type2)
1392
 
    return TRUE;
1393
 
  for (range= range_list; range != range_list_end; ++range)
1394
 
  {
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++)
1398
 
    {
1399
 
      type1_found|= type1 == *type;
1400
 
      type2_found|= type2 == *type;
1401
 
    }
1402
 
    if (type1_found || type2_found)
1403
 
      return type1_found && type2_found;
1404
 
  }
1405
 
  return FALSE;
1406
 
}
1407
 
 
1408
 
 
1409
1242
int cli_unbuffered_fetch(MYSQL *mysql, char **row)
1410
1243
{
1411
1244
  if (packet_error == cli_safe_read(mysql))