mirror of
https://github.com/sogou/workflow.git
synced 2026-10-29 03:27:04 +08:00
Merge pull request #865 from holmes1412/master
fix MySQLResult Cell get data
This commit is contained in:
@@ -175,10 +175,8 @@ inline int MySQLCell::as_int() const
|
||||
if (!this->is_int())
|
||||
return 0;
|
||||
|
||||
char num[MYSQL_INT_STR_LENGTH + 1];
|
||||
memcpy(num, this->data, this->len);
|
||||
num[this->len] = '\0';
|
||||
return atoi(num);
|
||||
std::string num((char *)this->data, this->len);
|
||||
return atoi(num.c_str());
|
||||
}
|
||||
|
||||
inline bool MySQLCell::is_float() const
|
||||
@@ -191,10 +189,8 @@ inline float MySQLCell::as_float() const
|
||||
if (!this->is_float())
|
||||
return 0;
|
||||
|
||||
char num[MYSQL_FLOAT_STR_LENGTH + 1];
|
||||
memcpy(num, this->data, this->len);
|
||||
num[this->len] = '\0';
|
||||
return strtof(num, NULL);
|
||||
std::string num((char *)this->data, this->len);
|
||||
return strtof(num.c_str(), NULL);
|
||||
}
|
||||
|
||||
inline bool MySQLCell::is_double() const
|
||||
@@ -207,10 +203,8 @@ inline double MySQLCell::as_double() const
|
||||
if (!this->is_double())
|
||||
return 0;
|
||||
|
||||
char num[MYSQL_DOUBLE_STR_LENGTH + 1];
|
||||
memcpy(num, this->data, this->len);
|
||||
num[this->len] = '\0';
|
||||
return strtod(num, NULL);
|
||||
std::string num((char *)this->data, this->len);
|
||||
return strtod(num.c_str(), NULL);
|
||||
}
|
||||
|
||||
inline bool MySQLCell::is_ulonglong() const
|
||||
@@ -223,10 +217,8 @@ inline unsigned long long MySQLCell::as_ulonglong() const
|
||||
if (!this->is_ulonglong())
|
||||
return 0;
|
||||
|
||||
char num[MYSQL_LONG_STR_LENGTH + 1];
|
||||
memcpy(num, this->data, this->len);
|
||||
num[this->len] = '\0';
|
||||
return strtoull(num, NULL, 10);
|
||||
std::string num((char *)this->data, this->len);
|
||||
return strtoull(num.c_str(), NULL, 10);
|
||||
}
|
||||
|
||||
inline bool MySQLCell::is_date() const
|
||||
|
||||
@@ -22,10 +22,6 @@
|
||||
|
||||
#define MYSQL_STATE_LENGTH 5
|
||||
#define MYSQL_STATE_DEFAULT "HY000"
|
||||
#define MYSQL_INT_STR_LENGTH 11 // 10 for unsigned int
|
||||
#define MYSQL_LONG_STR_LENGTH 21 // 20 for unsigned long long
|
||||
#define MYSQL_FLOAT_STR_LENGTH 7 // 7 for float
|
||||
#define MYSQL_DOUBLE_STR_LENGTH 19 // 19 for long double
|
||||
|
||||
// may be set by server in EOF/OK packet
|
||||
#define MYSQL_SERVER_MORE_RESULTS_EXIST 0x0008
|
||||
|
||||
Reference in New Issue
Block a user