Permalink
Browse files

[+] skipping decimal fields

  • Loading branch information...
1 parent 233a612 commit a0be19e7b23ad6c9c5c0e812bea6f18dd20d2ac5 @vozbu committed Jan 3, 2012
Showing with 38 additions and 0 deletions.
  1. +3 −0 Slave.cpp
  2. +29 −0 field.cpp
  3. +6 −0 field.h
View
@@ -257,6 +257,9 @@ void Slave::createTable(RelayLogInfo& rli,
else if (extract_field == "longblob")
field = PtrField(new Field_longblob(name, type));
+ else if (extract_field == "decimal")
+ field = PtrField(new Field_decimal(name, type));
+
else {
LOG_ERROR(log, "createTable: class name don't exist: " << extract_field );
throw std::runtime_error("class name does not exist: " + extract_field);
View
@@ -395,5 +395,34 @@ unsigned int Field_blob::get_length(const char *pos) {
throw std::runtime_error("Oops, wrong packlength in Field_blob::get_length(): wanted 1, 2, 3 or 4.");
}
+Field_decimal::Field_decimal(const std::string& field_name_arg, const std::string& type):
+ Field_longstr(field_name_arg, type)
+{
+ // Получаем размеры поля: decimal(M,D)
+ // M - общее количество цифр, M-D - после запятой
+
+ const std::string::size_type b = type.find('(', 0);
+
+ if (b == std::string::npos) {
+ throw std::runtime_error("Field_string: Incorrect field DECIMAL");
+ }
+
+ int m, d;
+ if (2 != sscanf(type.c_str() + b, "(%d,%d)", &m, &d) || m <= 0 || m < d) {
+ throw std::runtime_error("Field_string: Incorrect field DECIMAL");
+ }
+
+ const int intg = m - d;
+ const int frac = d;
+
+ static const int dig2bytes[] = {0, 1, 1, 2, 2, 3, 3, 4, 4, 4};
+ field_length = (intg / 9) * 4 + dig2bytes[intg % 9] + (frac / 9) * 4 + dig2bytes[frac % 9];
+}
+
+const char* Field_decimal::unpack(const char *from)
+{
+ return from + pack_length();
+}
+
}
View
@@ -251,6 +251,12 @@ class Field_set: public Field_enum {
const char* unpack(const char* from);
};
+class Field_decimal : public Field_longstr {
+public:
+ Field_decimal(const std::string& field_name_arg, const std::string& type);
+ const char* unpack(const char *from);
+};
+
}
#endif

0 comments on commit a0be19e

Please sign in to comment.