ext/flydata/source_mysql/parser/sql_parser.cpp in flydata-0.7.0 vs ext/flydata/source_mysql/parser/sql_parser.cpp in flydata-0.7.1
- old
+ new
@@ -1,9 +1,9 @@
#include <iostream>
#include "sql_parser.h"
-static int $DEBUG = 0;
+#define DEBUG 0
enum status_t {
start,
value,
first_zero,
@@ -52,11 +52,11 @@
status = start;
}
break;
case value:
- if ($DEBUG) std::cout << "value[" << *current << "(0x" << std::hex << (*current & 0xff) << ")]: " << std::endl << std::flush;
+ if (DEBUG) std::cout << "value[" << *current << "(0x" << std::hex << (*current & 0xff) << ")]: " << std::endl << std::flush;
if (*current == '\'') {
status = first_char;
} else if (*current == 'N') {
status = null_n;
} else if (*current == '0') {
@@ -74,11 +74,11 @@
status = error;
}
break;
case first_zero:
- if ($DEBUG) std::cout << "first_zero[" << *current << "(0x" << std::hex << (*current & 0xff) << ")]: " << std::endl << std::flush;
+ if (DEBUG) std::cout << "first_zero[" << *current << "(0x" << std::hex << (*current & 0xff) << ")]: " << std::endl << std::flush;
if (*current == ',') {
ch.value_callback(mark, value_len - 1, true);//value_callback :end_value
mark = 0; value_len = 0; //mark_reset
status = value;
} else if (*current == ')') {
@@ -100,11 +100,11 @@
status = error;
}
break;
case leading_zero:
- if ($DEBUG) std::cout << "leading_zero[" << *current << "(0x" << std::hex << (*current & 0xff) << ")]: " << std::endl << std::flush;
+ if (DEBUG) std::cout << "leading_zero[" << *current << "(0x" << std::hex << (*current & 0xff) << ")]: " << std::endl << std::flush;
if (*current == ',') {
ch.value_callback(mark, value_len - 1, true);//value_callback :end_value
mark = 0; value_len = 0; //mark_reset
status = value;
} else if (*current == ')') {
@@ -124,11 +124,11 @@
status = error;
}
break;
case number:
- if ($DEBUG) std::cout << "number[" << *current << "(0x" << std::hex << (*current & 0xff) << ")]: " << std::endl << std::flush;
+ if (DEBUG) std::cout << "number[" << *current << "(0x" << std::hex << (*current & 0xff) << ")]: " << std::endl << std::flush;
if ((*current >= '0' && *current <= '9') || *current == '.' || *current == 'e' || *current == 'E' || *current == '-') {
status = number;
} else if (*current == ',') {
ch.value_callback(mark, value_len - 1, true);//value_callback :end_value
mark = 0; value_len = 0; //mark_reset
@@ -142,38 +142,38 @@
status = error;
}
break;
case null_n:
- if ($DEBUG) std::cout << "null_n[" << *current << "(0x" << std::hex << (*current & 0xff) << ")]: " << std::endl << std::flush;
+ if (DEBUG) std::cout << "null_n[" << *current << "(0x" << std::hex << (*current & 0xff) << ")]: " << std::endl << std::flush;
if (*current == 'U') {
status = null_u;
} else {
status = error;
}
break;
case null_u:
- if ($DEBUG) std::cout << "null_u[" << *current << "(0x" << std::hex << (*current & 0xff) << ")]: " << std::endl << std::flush;
+ if (DEBUG) std::cout << "null_u[" << *current << "(0x" << std::hex << (*current & 0xff) << ")]: " << std::endl << std::flush;
if (*current == 'L') {
status = null_l1;
} else {
status = error;
}
break;
case null_l1:
- if ($DEBUG) std::cout << "null_l1[" << *current << "(0x" << std::hex << (*current & 0xff) << ")]: " << std::endl << std::flush;
+ if (DEBUG) std::cout << "null_l1[" << *current << "(0x" << std::hex << (*current & 0xff) << ")]: " << std::endl << std::flush;
if (*current == 'L') {
status = null_l2;
} else {
status = error;
}
break;
case null_l2:
- if ($DEBUG) std::cout << "null_l2[" << *current << "(0x" << std::hex << (*current & 0xff) << ")]: " << std::endl << std::flush;
+ if (DEBUG) std::cout << "null_l2[" << *current << "(0x" << std::hex << (*current & 0xff) << ")]: " << std::endl << std::flush;
if (*current == ',') {
//# 0 is NULL pointer
ch.value_callback(0, 0, true);//value_callback 0 :end_value
mark = 0; value_len = 0;
status = value;
@@ -187,22 +187,22 @@
status = error;
}
break;
case hex_blob:
- if ($DEBUG) std::cout << "hex_blob[" << *current << "(0x" << std::hex << (*current & 0xff) << ")]: " << std::endl << std::flush;
+ if (DEBUG) std::cout << "hex_blob[" << *current << "(0x" << std::hex << (*current & 0xff) << ")]: " << std::endl << std::flush;
if ((*current >= '0' && *current <= '9') ||
(*current >= 'A' && *current <= 'F') ||
(*current >= 'a' && *current <= 'f')) {
status = hex_blob_number;
} else {
status = error;
}
break;
case hex_blob_number:
- if ($DEBUG) std::cout << "hex_blob_number[" << *current << "(0x" << std::hex << (*current & 0xff) << ")]: " << std::endl << std::flush;
+ if (DEBUG) std::cout << "hex_blob_number[" << *current << "(0x" << std::hex << (*current & 0xff) << ")]: " << std::endl << std::flush;
if ((*current >= '0' && *current <= '9') ||
(*current >= 'A' && *current <= 'F') ||
(*current >= 'a' && *current <= 'f')) {
status = hex_blob_number;
} else if (*current == ',') {
@@ -218,11 +218,11 @@
status = error;
}
break;
case first_char:
- if ($DEBUG) std::cout << "first_char[" << *current << "(0x" << std::hex << (*current & 0xff) << ")]: " << std::endl << std::flush;
+ if (DEBUG) std::cout << "first_char[" << *current << "(0x" << std::hex << (*current & 0xff) << ")]: " << std::endl << std::flush;
if (*current == '\'') {
mark = current; value_len = 1; //mark
ch.value_callback(mark, value_len - 1, true);//value_callback, :end_value
mark = 0; value_len = 0; //mark_reset
status = value;
@@ -246,11 +246,11 @@
status = following_char;
}
break;
case utf8_2_firstbyte:
- if ($DEBUG) std::cout << "utf8_2_firstbyte[" << *current << "(0x" << std::hex << (*current & 0xff) << ")]: " << std::endl << std::flush;
+ if (DEBUG) std::cout << "utf8_2_firstbyte[" << *current << "(0x" << std::hex << (*current & 0xff) << ")]: " << std::endl << std::flush;
if ((*current & 0xc0) == 0x80) {
temp_mark = 0; //temp_mark reset)
status = following_char;
} else {
ch.value_callback(mark, temp_mark - mark, false);//value_callback mark...temp_mark
@@ -260,20 +260,20 @@
status = first_char;
}
break;
case utf8_3_firstbyte:
- if ($DEBUG) std::cout << "utf8_3_firstbyte[" << *current << "(0x" << std::hex << (*current & 0xff) << ")]: " << std::endl << std::flush;
+ if (DEBUG) std::cout << "utf8_3_firstbyte[" << *current << "(0x" << std::hex << (*current & 0xff) << ")]: " << std::endl << std::flush;
if ((*current & 0xc0) == 0x80) {
status = utf8_3_secondbyte;
} else {
status = utf8_3_err_secondbyte;
}
break;
case utf8_3_secondbyte:
- if ($DEBUG) std::cout << "utf8_3_secondbyte[" << *current << "(0x" << std::hex << (*current & 0xff) << ")]: " << std::endl << std::flush;
+ if (DEBUG) std::cout << "utf8_3_secondbyte[" << *current << "(0x" << std::hex << (*current & 0xff) << ")]: " << std::endl << std::flush;
if ((*current & 0xc0) == 0x80) {
temp_mark = 0; //temp_mark reset)
status = following_char;
} else {
ch.value_callback(mark, temp_mark - mark, false);//value_callback mark...temp_mark
@@ -283,43 +283,43 @@
status = first_char;
}
break;
case utf8_3_err_secondbyte:
- if ($DEBUG) std::cout << "utf8_3_err_secondbyte[" << *current << "(0x" << std::hex << (*current & 0xff) << ")]: " << std::endl << std::flush;
+ if (DEBUG) std::cout << "utf8_3_err_secondbyte[" << *current << "(0x" << std::hex << (*current & 0xff) << ")]: " << std::endl << std::flush;
ch.value_callback(mark, temp_mark - mark, false);//value_callback mark...temp_mark
mark = 0; value_len = 0; //mark_reset
ch.value_callback("\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd", 9, false); //value_callback "\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd"
temp_mark = 0; //temp_mark reset
status = first_char;
break;
case utf8_4_firstbyte:
- if ($DEBUG) std::cout << "utf8_4_firstbyte[" << *current << "(0x" << std::hex << (*current & 0xff) << ")]: " << std::endl << std::flush;
+ if (DEBUG) std::cout << "utf8_4_firstbyte[" << *current << "(0x" << std::hex << (*current & 0xff) << ")]: " << std::endl << std::flush;
if ((*current & 0xc0) == 0x80) {
status = utf8_4_secondbyte;
} else {
status = utf8_4_err_secondbyte;
}
break;
case utf8_4_secondbyte:
- if ($DEBUG) std::cout << "utf8_4_secondbyte[" << *current << "(0x" << std::hex << (*current & 0xff) << ")]: " << std::endl << std::flush;
+ if (DEBUG) std::cout << "utf8_4_secondbyte[" << *current << "(0x" << std::hex << (*current & 0xff) << ")]: " << std::endl << std::flush;
if ((*current & 0xc0) == 0x80) {
status = utf8_4_thirdbyte;
} else {
status = utf8_4_err_thirdbyte;
}
break;
case utf8_4_err_secondbyte:
- if ($DEBUG) std::cout << "utf8_4_err_secondbyte[" << *current << "(0x" << std::hex << (*current & 0xff) << ")]: " << std::endl << std::flush;
+ if (DEBUG) std::cout << "utf8_4_err_secondbyte[" << *current << "(0x" << std::hex << (*current & 0xff) << ")]: " << std::endl << std::flush;
status = utf8_4_err_thirdbyte;
break;
case utf8_4_thirdbyte:
- if ($DEBUG) std::cout << "utf8_4_thirdbyte[" << *current << "(0x" << std::hex << (*current & 0xff) << ")]: " << std::endl << std::flush;
+ if (DEBUG) std::cout << "utf8_4_thirdbyte[" << *current << "(0x" << std::hex << (*current & 0xff) << ")]: " << std::endl << std::flush;
if ((*current & 0xc0) == 0x80) {
temp_mark = 0; //temp_mark reset)
status = following_char;
} else {
ch.value_callback(mark, temp_mark - mark, false);//value_callback mark...temp_mark
@@ -329,20 +329,20 @@
status = first_char;
}
break;
case utf8_4_err_thirdbyte:
- if ($DEBUG) std::cout << "utf8_4_err_thirdbyte[" << *current << "(0x" << std::hex << (*current & 0xff) << ")]: " << std::endl << std::flush;
+ if (DEBUG) std::cout << "utf8_4_err_thirdbyte[" << *current << "(0x" << std::hex << (*current & 0xff) << ")]: " << std::endl << std::flush;
ch.value_callback(mark, temp_mark - mark, false);//value_callback mark...temp_mark
mark = 0; value_len = 0; //mark_reset
ch.value_callback("\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd", 12, false); //value_callback "\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd"
temp_mark = 0; //temp_mark reset
status = first_char;
break;
case following_char:
- if ($DEBUG) std::cout << "following_char[" << *current << "(0x" << std::hex << (*current & 0xff) << ")]: " << std::endl << std::flush;
+ if (DEBUG) std::cout << "following_char[" << *current << "(0x" << std::hex << (*current & 0xff) << ")]: " << std::endl << std::flush;
if (*current == '\'') {
ch.value_callback(mark, value_len - 1, true);//value_callback, :end_value
mark = 0; value_len = 0; //mark_reset
status = value;
} else if (*current == '\\') {
@@ -362,11 +362,11 @@
status = following_char;
}
break;
case escape:
- if ($DEBUG) std::cout << "escape[" << *current << "(0x" << std::hex << (*current & 0xff) << ")]: " << std::endl << std::flush;
+ if (DEBUG) std::cout << "escape[" << *current << "(0x" << std::hex << (*current & 0xff) << ")]: " << std::endl << std::flush;
if (*current == '\"') {
ch.value_callback("\"", 1, false);//value_callback '\"'
mark = 0; value_len = 0;
status = first_char;
} else if (*current == '\'') {
@@ -399,15 +399,15 @@
status = following_char;
}
break;
case error:
- if ($DEBUG) std::cout << "error[" << *current << std::endl << std::flush;
+ if (DEBUG) std::cout << "error[" << *current << std::endl << std::flush;
ret = pos - 1;
break;
default:
- if ($DEBUG) std::cout << "default[" << *current << "(0x" << std::hex << (*current & 0xff) << ")]: " << std::endl << std::flush;
+ if (DEBUG) std::cout << "default[" << *current << "(0x" << std::hex << (*current & 0xff) << ")]: " << std::endl << std::flush;
break;
}//switch
if (ret != -1)
break;
}//for