From d3eb19b90f3649cb36b35b38508f57117c2638ca Mon Sep 17 00:00:00 2001 From: Sergey Bahchissaraitsev Date: Thu, 8 Jan 2015 19:18:56 +0200 Subject: [PATCH 1/6] gemspec version updated --- ruby-binlog.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ruby-binlog.gemspec b/ruby-binlog.gemspec index a5f48f8..a261e17 100644 --- a/ruby-binlog.gemspec +++ b/ruby-binlog.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |spec| spec.name = 'ruby-binlog' - spec.version = '0.1.8' + spec.version = '0.2.0' spec.summary = 'Ruby binding for MySQL Binary log API.' spec.description = 'Ruby binding for MySQL Binary log API.' spec.files = Dir.glob('ext/{*.cpp,*.h,extconf.rb}') + %w(README.md) From 42c12c0264bf5c6ea764e0bab036a40863befdeb Mon Sep 17 00:00:00 2001 From: Sergey Bahchissaraitsev Date: Thu, 8 Jan 2015 19:19:35 +0200 Subject: [PATCH 2/6] Mysql DateTime parsed as string instead of ruby DateTime --- ext/ruby_binlog_row_event.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/ext/ruby_binlog_row_event.cpp b/ext/ruby_binlog_row_event.cpp index d32fc3d..1ab9c40 100644 --- a/ext/ruby_binlog_row_event.cpp +++ b/ext/ruby_binlog_row_event.cpp @@ -1,4 +1,5 @@ #include "ruby_binlog.h" +#include VALUE rb_cBinlogRowEvent; @@ -316,13 +317,10 @@ void RowEvent::proc0(mysql::Row_of_fields &fields, VALUE rb_fields) { case mysql::system::MYSQL_TYPE_DATETIME: { boost::uint64_t timestamp = itor->as_int64(); - unsigned long d = timestamp / 1000000; - unsigned long t = timestamp % 1000000; + + std::string d = boost::lexical_cast(timestamp); - VALUE DateTime = rb_const_get(rb_cObject, rb_intern("DateTime")); - rval = rb_funcall(DateTime, rb_intern("new"), 6, - INT2FIX(d / 10000), INT2FIX((d % 10000) / 100), INT2FIX(d % 100), - INT2FIX(t / 10000), INT2FIX((t % 10000) / 100), INT2FIX(t % 100)); + rval = rb_str_new(d.c_str(), d.length()); } break; case mysql::system::MYSQL_TYPE_DATETIME2: { boost::uint64_t timestamp; From a47602636d6aa5b17439517e808446a2e1d77d16 Mon Sep 17 00:00:00 2001 From: Sergey Bahchissaraitsev Date: Sun, 11 Jan 2015 12:48:33 +0200 Subject: [PATCH 3/6] structured datetime string --- ext/ruby_binlog_row_event.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/ext/ruby_binlog_row_event.cpp b/ext/ruby_binlog_row_event.cpp index 1ab9c40..d852800 100644 --- a/ext/ruby_binlog_row_event.cpp +++ b/ext/ruby_binlog_row_event.cpp @@ -317,10 +317,19 @@ void RowEvent::proc0(mysql::Row_of_fields &fields, VALUE rb_fields) { case mysql::system::MYSQL_TYPE_DATETIME: { boost::uint64_t timestamp = itor->as_int64(); - - std::string d = boost::lexical_cast(timestamp); - rval = rb_str_new(d.c_str(), d.length()); + std::string date = "0000-00-00 00:00:00"; + + if(timestamp > 0) { + date = boost::lexical_cast(timestamp); + date.insert(4, "-"); + date.insert(7, "-"); + date.insert(10, " "); + date.insert(13, ":"); + date.insert(16, ":"); + } + + rval = rb_str_new(date.c_str(), date.length()); } break; case mysql::system::MYSQL_TYPE_DATETIME2: { boost::uint64_t timestamp; From 797f19a53a0745d1772dd8604efcb98e056e0f58 Mon Sep 17 00:00:00 2001 From: Sergey Bahchissaraitsev Date: Sun, 11 Jan 2015 17:11:48 +0200 Subject: [PATCH 4/6] using streams to lpad datetime string from int --- ext/ruby_binlog_row_event.cpp | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/ext/ruby_binlog_row_event.cpp b/ext/ruby_binlog_row_event.cpp index d852800..fe11028 100644 --- a/ext/ruby_binlog_row_event.cpp +++ b/ext/ruby_binlog_row_event.cpp @@ -1,5 +1,7 @@ #include "ruby_binlog.h" #include +#include +#include VALUE rb_cBinlogRowEvent; @@ -318,16 +320,22 @@ void RowEvent::proc0(mysql::Row_of_fields &fields, VALUE rb_fields) { case mysql::system::MYSQL_TYPE_DATETIME: { boost::uint64_t timestamp = itor->as_int64(); - std::string date = "0000-00-00 00:00:00"; - - if(timestamp > 0) { - date = boost::lexical_cast(timestamp); - date.insert(4, "-"); - date.insert(7, "-"); - date.insert(10, " "); - date.insert(13, ":"); - date.insert(16, ":"); - } + std::stringstream datestream; + datestream << std::setfill('0') << std::setw(14) << boost::lexical_cast(timestamp); + std::string date; + datestream >> date; + std::cerr << "before: " + date; + std::cerr << "\n"; + + // Format date + date.insert(4, "-"); + date.insert(7, "-"); + date.insert(10, " "); + date.insert(13, ":"); + date.insert(16, ":"); + + std::cerr << "after: " + date; + std::cerr << "\n"; rval = rb_str_new(date.c_str(), date.length()); } break; From ff227f5ca520e2afbac8ac3f96affa903b620546 Mon Sep 17 00:00:00 2001 From: Sergey Bahchissaraitsev Date: Mon, 12 Jan 2015 08:29:09 +0200 Subject: [PATCH 5/6] removed debug output --- ext/ruby_binlog_row_event.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/ext/ruby_binlog_row_event.cpp b/ext/ruby_binlog_row_event.cpp index fe11028..a2f0373 100644 --- a/ext/ruby_binlog_row_event.cpp +++ b/ext/ruby_binlog_row_event.cpp @@ -324,8 +324,6 @@ void RowEvent::proc0(mysql::Row_of_fields &fields, VALUE rb_fields) { datestream << std::setfill('0') << std::setw(14) << boost::lexical_cast(timestamp); std::string date; datestream >> date; - std::cerr << "before: " + date; - std::cerr << "\n"; // Format date date.insert(4, "-"); @@ -334,9 +332,6 @@ void RowEvent::proc0(mysql::Row_of_fields &fields, VALUE rb_fields) { date.insert(13, ":"); date.insert(16, ":"); - std::cerr << "after: " + date; - std::cerr << "\n"; - rval = rb_str_new(date.c_str(), date.length()); } break; case mysql::system::MYSQL_TYPE_DATETIME2: { From fc2e02db68fb2a12fa3b5e13759380060a939351 Mon Sep 17 00:00:00 2001 From: Sergey Bahchissaraitsev Date: Mon, 12 Jan 2015 17:04:42 +0200 Subject: [PATCH 6/6] date and time return string as well --- ext/ruby_binlog_row_event.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ext/ruby_binlog_row_event.cpp b/ext/ruby_binlog_row_event.cpp index a2f0373..8c24d74 100644 --- a/ext/ruby_binlog_row_event.cpp +++ b/ext/ruby_binlog_row_event.cpp @@ -295,8 +295,8 @@ void RowEvent::proc0(mysql::Row_of_fields &fields, VALUE rb_fields) { unsigned int month = date >> 5; unsigned int day = date - (month << 5); - VALUE Date = rb_const_get(rb_cObject, rb_intern("Date")); - rval = rb_funcall(Date, rb_intern("new"), 3, UINT2NUM(year), UINT2NUM(month), UINT2NUM(day)); + std::string full_date = boost::to_string(year) + "-" + boost::to_string(month) + "-" + boost::to_string(day); + rval = rb_str_new(full_date.c_str(), full_date.length()); } break; case mysql::system::MYSQL_TYPE_TIME: { @@ -307,8 +307,8 @@ void RowEvent::proc0(mysql::Row_of_fields &fields, VALUE rb_fields) { unsigned int min = (time % 10000) / 100; unsigned int hour = (time - min) / 10000; - VALUE Time = rb_const_get(rb_cObject, rb_intern("Time")); - rval = rb_funcall(Time, rb_intern("utc"), 6, 2000, 1, 1, UINT2NUM(hour), UINT2NUM(min), UINT2NUM(sec)); + std::string full_time = boost::to_string(hour) + ":" + boost::to_string(min) + ":" + boost::to_string(sec); + rval = rb_str_new(full_time.c_str(), full_time.length()); } break; case mysql::system::MYSQL_TYPE_YEAR: {