~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/protocol.cc

  • Committer: Andrey Hristov
  • Date: 2008-08-05 20:32:06 UTC
  • mto: (264.1.5 codestyle)
  • mto: This revision was merged to the branch mainline in revision 266.
  • Revision ID: ahristov@mysql.com-20080805203206-ufhdgu1oz8frq03p
Remove support for the old, pre-4.1, protocol

Show diffs side-by-side

added added

removed removed

Lines of Context:
177
177
  buff[0]=0;                                    // No fields
178
178
  pos=net_store_length(buff+1,affected_rows);
179
179
  pos=net_store_length(pos, id);
180
 
  if (thd->client_capabilities & CLIENT_PROTOCOL_41)
181
 
  {
182
 
    int2store(pos, server_status);
183
 
    pos+=2;
184
 
 
185
 
    /* We can only return up to 65535 warnings in two bytes */
186
 
    uint tmp= min(total_warn_count, 65535);
187
 
    int2store(pos, tmp);
188
 
    pos+= 2;
189
 
  }
190
 
  else if (net->return_status)                  // For 4.0 protocol
191
 
  {
192
 
    int2store(pos, server_status);
193
 
    pos+=2;
194
 
  }
 
180
 
 
181
  int2store(pos, server_status);
 
182
  pos+=2;
 
183
 
 
184
  /* We can only return up to 65535 warnings in two bytes */
 
185
  uint tmp= min(total_warn_count, 65535);
 
186
  int2store(pos, tmp);
 
187
  pos+= 2;
 
188
 
195
189
  thd->main_da.can_overwrite_status= true;
196
190
 
197
191
  if (message && message[0])
204
198
  return;
205
199
}
206
200
 
207
 
static uchar eof_buff[1]= { (uchar) 254 };      /* Marker for end of fields */
208
 
 
209
201
/**
210
202
  Send eof (= end of result set) to the client.
211
203
 
212
204
  The eof packet has the following structure:
213
205
 
214
 
  - 254         : Marker (1 byte)
 
206
  - 254 (DRIZZLE_PROTOCOL_NO_MORE_DATA) : Marker (1 byte)
215
207
  - warning_count       : Stored in 2 bytes; New in 4.1 protocol
216
208
  - status_flag : Stored in 2 bytes;
217
209
  For flags like SERVER_MORE_RESULTS_EXISTS.
250
242
                             uint server_status,
251
243
                             uint total_warn_count)
252
244
{
253
 
  if (thd->client_capabilities & CLIENT_PROTOCOL_41)
254
 
  {
255
 
    uchar buff[5];
256
 
    /*
257
 
      Don't send warn count during SP execution, as the warn_list
258
 
      is cleared between substatements, and mysqltest gets confused
259
 
    */
260
 
    uint tmp= min(total_warn_count, 65535);
261
 
    buff[0]= 254;
262
 
    int2store(buff+1, tmp);
263
 
    /*
264
 
      The following test should never be true, but it's better to do it
265
 
      because if 'is_fatal_error' is set the server is not going to execute
266
 
      other queries (see the if test in dispatch_command / COM_QUERY)
267
 
    */
268
 
    if (thd->is_fatal_error)
269
 
      server_status&= ~SERVER_MORE_RESULTS_EXISTS;
270
 
    int2store(buff + 3, server_status);
271
 
    VOID(my_net_write(net, buff, 5));
272
 
  }
273
 
  else
274
 
    VOID(my_net_write(net, eof_buff, 1));
 
245
  uchar buff[5];
 
246
  /*
 
247
    Don't send warn count during SP execution, as the warn_list
 
248
    is cleared between substatements, and mysqltest gets confused
 
249
  */
 
250
  uint tmp= min(total_warn_count, 65535);
 
251
  buff[0]= DRIZZLE_PROTOCOL_NO_MORE_DATA;
 
252
  int2store(buff+1, tmp);
 
253
  /*
 
254
    The following test should never be true, but it's better to do it
 
255
    because if 'is_fatal_error' is set the server is not going to execute
 
256
    other queries (see the if test in dispatch_command / COM_QUERY)
 
257
  */
 
258
  if (thd->is_fatal_error)
 
259
    server_status&= ~SERVER_MORE_RESULTS_EXISTS;
 
260
  int2store(buff + 3, server_status);
 
261
  VOID(my_net_write(net, buff, 5));
275
262
}
276
263
 
277
264
void net_send_error_packet(THD *thd, uint sql_errno, const char *err)
290
277
 
291
278
  int2store(buff,sql_errno);
292
279
  pos= buff+2;
293
 
  if (thd->client_capabilities & CLIENT_PROTOCOL_41)
294
 
  {
295
 
    /* The first # is to make the protocol backward compatible */
296
 
    buff[2]= '#';
297
 
    pos= (uchar*) strmov((char*) buff+3, drizzle_errno_to_sqlstate(sql_errno));
298
 
  }
 
280
 
 
281
  /* The first # is to make the protocol backward compatible */
 
282
  buff[2]= '#';
 
283
  pos= (uchar*) strmov((char*) buff+3, drizzle_errno_to_sqlstate(sql_errno));
 
284
 
299
285
  length= (uint) (strmake((char*) pos, err, DRIZZLE_ERRMSG_SIZE-1) -
300
286
                  (char*) buff);
301
287
  err= (char*) buff;
525
511
 
526
512
    prot.prepare_for_resend();
527
513
 
528
 
    if (thd->client_capabilities & CLIENT_PROTOCOL_41)
 
514
 
 
515
    if (prot.store(STRING_WITH_LEN("def"), cs, thd_charset) ||
 
516
        prot.store(field.db_name, (uint) strlen(field.db_name),
 
517
                   cs, thd_charset) ||
 
518
        prot.store(field.table_name, (uint) strlen(field.table_name),
 
519
                   cs, thd_charset) ||
 
520
        prot.store(field.org_table_name, (uint) strlen(field.org_table_name),
 
521
                   cs, thd_charset) ||
 
522
        prot.store(field.col_name, (uint) strlen(field.col_name),
 
523
                   cs, thd_charset) ||
 
524
        prot.store(field.org_col_name, (uint) strlen(field.org_col_name),
 
525
                   cs, thd_charset) ||
 
526
        local_packet->realloc(local_packet->length()+12))
 
527
      goto err;
 
528
 
 
529
    /* Store fixed length fields */
 
530
    pos= (char*) local_packet->ptr()+local_packet->length();
 
531
    *pos++= 12;                         // Length of packed fields
 
532
    if (item->collation.collation == &my_charset_bin || thd_charset == NULL)
529
533
    {
530
 
      if (prot.store(STRING_WITH_LEN("def"), cs, thd_charset) ||
531
 
          prot.store(field.db_name, (uint) strlen(field.db_name),
532
 
                     cs, thd_charset) ||
533
 
          prot.store(field.table_name, (uint) strlen(field.table_name),
534
 
                     cs, thd_charset) ||
535
 
          prot.store(field.org_table_name, (uint) strlen(field.org_table_name),
536
 
                     cs, thd_charset) ||
537
 
          prot.store(field.col_name, (uint) strlen(field.col_name),
538
 
                     cs, thd_charset) ||
539
 
          prot.store(field.org_col_name, (uint) strlen(field.org_col_name),
540
 
                     cs, thd_charset) ||
541
 
          local_packet->realloc(local_packet->length()+12))
542
 
        goto err;
543
 
      /* Store fixed length fields */
544
 
      pos= (char*) local_packet->ptr()+local_packet->length();
545
 
      *pos++= 12;                               // Length of packed fields
546
 
      if (item->collation.collation == &my_charset_bin || thd_charset == NULL)
547
 
      {
548
 
        /* No conversion */
549
 
        int2store(pos, field.charsetnr);
550
 
        int4store(pos+2, field.length);
551
 
      }
552
 
      else
553
 
      {
554
 
        /* With conversion */
555
 
        uint max_char_len;
556
 
        int2store(pos, thd_charset->number);
557
 
        /*
558
 
          For TEXT/BLOB columns, field_length describes the maximum data
559
 
          length in bytes. There is no limit to the number of characters
560
 
          that a TEXT column can store, as long as the data fits into
561
 
          the designated space.
562
 
          For the rest of textual columns, field_length is evaluated as
563
 
          char_count * mbmaxlen, where character count is taken from the
564
 
          definition of the column. In other words, the maximum number
565
 
          of characters here is limited by the column definition.
566
 
        */
567
 
        max_char_len= field.length / item->collation.collation->mbmaxlen;
568
 
        int4store(pos+2, max_char_len * thd_charset->mbmaxlen);
569
 
      }
570
 
      pos[6]= field.type;
571
 
      int2store(pos+7,field.flags);
572
 
      pos[9]= (char) field.decimals;
573
 
      pos[10]= 0;                               // For the future
574
 
      pos[11]= 0;                               // For the future
575
 
      pos+= 12;
 
534
      /* No conversion */
 
535
      int2store(pos, field.charsetnr);
 
536
      int4store(pos+2, field.length);
576
537
    }
577
538
    else
578
539
    {
579
 
      if (prot.store(field.table_name, (uint) strlen(field.table_name),
580
 
                     cs, thd_charset) ||
581
 
          prot.store(field.col_name, (uint) strlen(field.col_name),
582
 
                     cs, thd_charset) ||
583
 
          local_packet->realloc(local_packet->length()+10))
584
 
        goto err;
585
 
      pos= (char*) local_packet->ptr()+local_packet->length();
 
540
      /* With conversion */
 
541
      uint max_char_len;
 
542
      int2store(pos, thd_charset->number);
 
543
      /*
 
544
        For TEXT/BLOB columns, field_length describes the maximum data
 
545
        length in bytes. There is no limit to the number of characters
 
546
        that a TEXT column can store, as long as the data fits into
 
547
        the designated space.
 
548
        For the rest of textual columns, field_length is evaluated as
 
549
        char_count * mbmaxlen, where character count is taken from the
 
550
        definition of the column. In other words, the maximum number
 
551
        of characters here is limited by the column definition.
 
552
      */
 
553
      max_char_len= field.length / item->collation.collation->mbmaxlen;
 
554
      int4store(pos+2, max_char_len * thd_charset->mbmaxlen);
 
555
    }
 
556
    pos[6]= field.type;
 
557
    int2store(pos+7,field.flags);
 
558
    pos[9]= (char) field.decimals;
 
559
    pos[10]= 0;                         // For the future
 
560
    pos[11]= 0;                         // For the future
 
561
    pos+= 12;
586
562
 
587
 
        pos[0]=3;
588
 
        int3store(pos+1,field.length);
589
 
        pos[4]=1;
590
 
        pos[5]=field.type;
591
 
        pos[6]=3;
592
 
        int2store(pos+7,field.flags);
593
 
        pos[9]= (char) field.decimals;
594
 
        pos+= 10;
595
 
    }
596
563
    local_packet->length((uint) (pos - local_packet->ptr()));
597
564
    if (flags & SEND_DEFAULTS)
598
565
      item->send(&prot, &tmp);                  // Send default value