~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/message/transaction_reader.cc

  • Committer: Jay Pipes
  • Date: 2009-11-06 15:22:29 UTC
  • mto: (1234.1.1 push) (1237.2.10 push)
  • mto: This revision was merged to the branch mainline in revision 1215.
  • Revision ID: jpipes@serialcoder-20091106152229-7wa6lzrip1n5xbxs
Adds support for BLOB fields in the replication stream. Note that
this does not yet support extremely large BLOB data.  Extremely large
BLOB data will be written to the transaction log in specialized transaction
log entries for that.  In this patch, we simply allow the main Transaction
message and the reader/writer programs to work with binary data properly.

Adds a simple test for BLOB fields and the transaction log.
The problem was figuring out how to correctly replace embedded NUL
characters in the output of the transaction reader with \\0 so that
mysqltest.cc wouldn't puke when cat'ing the result of the reading
of the transaction log when BLOB data was contained.

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
using namespace drizzled;
44
44
using namespace google;
45
45
 
 
46
static const char *replace_with_spaces= "\n\r";
 
47
 
46
48
static void printStatement(const message::Statement &statement)
47
49
{
48
50
  vector<string> sql_strings;
49
51
 
50
52
  message::transformStatementToSql(statement, sql_strings, message::DRIZZLE);
51
53
 
52
 
  vector<string>::iterator sql_string_iter= sql_strings.begin();
53
 
  const std::string newline= "\n";
54
 
  while (sql_string_iter != sql_strings.end())
 
54
  for (vector<string>::iterator sql_string_iter= sql_strings.begin();
 
55
       sql_string_iter != sql_strings.end();
 
56
       ++sql_string_iter)
55
57
  {
56
58
    string &sql= *sql_string_iter;
 
59
 
57
60
    /* 
58
 
     * Replace \n with spaces so that SQL statements 
 
61
     * Replace \n and \r with spaces so that SQL statements 
59
62
     * are always on a single line 
60
63
     */
61
 
    while (sql.find(newline) != std::string::npos)
62
 
      sql.replace(sql.find(newline), 1, " ");
 
64
    {
 
65
      string::size_type found= sql.find_first_of(replace_with_spaces);
 
66
      while (found != string::npos)
 
67
      {
 
68
        sql[found]= ' ';
 
69
        found= sql.find_first_of(replace_with_spaces, found);
 
70
      }
 
71
    }
 
72
 
 
73
    /*
 
74
     * Embedded NUL characters are a pain in the ass.
 
75
     */
 
76
    {
 
77
      string::size_type found= sql.find_first_of('\0');
 
78
      while (found != string::npos)
 
79
      {
 
80
        sql[found]= '\\';
 
81
        sql.insert(found + 1, 1, '0');
 
82
        found= sql.find_first_of('\0', found);
 
83
      }
 
84
    }
63
85
 
64
86
    cout << sql << ';' << endl;
65
 
    ++sql_string_iter;
66
87
  }
67
88
}
68
89