~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/replication_services.cc

  • Committer: Brian Aker
  • Date: 2009-12-18 18:51:03 UTC
  • mfrom: (1143.4.23 transaction_log)
  • Revision ID: brian@gaz-20091218185103-pc5fo3n9xmd0b503
Merge Jay

Show diffs side-by-side

added added

removed removed

Lines of Context:
58
58
#include "drizzled/message/table.pb.h"
59
59
#include "drizzled/gettext.h"
60
60
#include "drizzled/session.h"
 
61
#include "drizzled/error.h"
61
62
 
62
63
#include <vector>
63
64
 
328
329
}
329
330
 
330
331
message::Statement &ReplicationServices::getInsertStatement(Session *in_session,
331
 
                                                            Table *in_table) const
 
332
                                                                 Table *in_table) const
332
333
{
333
334
  message::Statement *statement= in_session->getStatementMessage();
 
335
  /*
 
336
   * We check to see if the current Statement message is of type INSERT.
 
337
   * If it is not, we finalize the current Statement and ensure a new
 
338
   * InsertStatement is created.
 
339
   */
 
340
  if (statement != NULL &&
 
341
      statement->type() != message::Statement::INSERT)
 
342
  {
 
343
    finalizeStatement(*statement, in_session);
 
344
    statement= in_session->getStatementMessage();
 
345
  }
334
346
 
335
347
  if (statement == NULL)
336
348
  {
384
396
  }
385
397
}
386
398
 
387
 
void ReplicationServices::insertRecord(Session *in_session, Table *in_table)
 
399
bool ReplicationServices::insertRecord(Session *in_session, Table *in_table)
388
400
{
389
401
  if (! is_active)
390
 
    return;
 
402
    return false;
 
403
  /**
 
404
   * We do this check here because we don't want to even create a 
 
405
   * statement if there isn't a primary key on the table...
 
406
   *
 
407
   * @todo
 
408
   *
 
409
   * Multi-column primary keys are handled how exactly?
 
410
   */
 
411
  if (in_table->s->primary_key == MAX_KEY)
 
412
  {
 
413
    my_error(ER_NO_PRIMARY_KEY_ON_REPLICATED_TABLE, MYF(0));
 
414
    return true;
 
415
  }
391
416
 
392
417
  message::Statement &statement= getInsertStatement(in_session, in_table);
393
418
 
411
436
    record->add_insert_value(string_value->c_ptr(), string_value->length());
412
437
    string_value->free();
413
438
  }
 
439
  return false;
414
440
}
415
441
 
416
442
message::Statement &ReplicationServices::getUpdateStatement(Session *in_session,
419
445
                                                            const unsigned char *new_record) const
420
446
{
421
447
  message::Statement *statement= in_session->getStatementMessage();
 
448
  /*
 
449
   * We check to see if the current Statement message is of type UPDATE.
 
450
   * If it is not, we finalize the current Statement and ensure a new
 
451
   * UpdateStatement is created.
 
452
   */
 
453
  if (statement != NULL &&
 
454
      statement->type() != message::Statement::UPDATE)
 
455
  {
 
456
    finalizeStatement(*statement, in_session);
 
457
    statement= in_session->getStatementMessage();
 
458
  }
422
459
 
423
460
  if (statement == NULL)
424
461
  {
460
497
 
461
498
  Field *current_field;
462
499
  Field **table_fields= in_table->field;
463
 
  String *string_value= new (in_session->mem_root) String(ReplicationServices::DEFAULT_RECORD_SIZE);
464
 
  string_value->set_charset(system_charset_info);
465
500
 
466
501
  message::FieldMetadata *field_metadata;
467
502
 
589
624
                                                            Table *in_table) const
590
625
{
591
626
  message::Statement *statement= in_session->getStatementMessage();
 
627
  /*
 
628
   * We check to see if the current Statement message is of type DELETE.
 
629
   * If it is not, we finalize the current Statement and ensure a new
 
630
   * DeleteStatement is created.
 
631
   */
 
632
  if (statement != NULL &&
 
633
      statement->type() != message::Statement::DELETE)
 
634
  {
 
635
    finalizeStatement(*statement, in_session);
 
636
    statement= in_session->getStatementMessage();
 
637
  }
592
638
 
593
639
  if (statement == NULL)
594
640
  {