67 return GetUInt8() == 1 ?
true :
false;
76 if (!IsType(MYSQL_TYPE_TINY))
78 TC_LOG_WARN(
"sql.sql",
"Warning: GetUInt8() on non-tinyint field %s.%s (%s.%s) at index %u. Using type: %s.",
79 meta.TableAlias, meta.Alias, meta.TableName, meta.Name, meta.Index, meta.Type);
85 return *
reinterpret_cast<uint8*
>(data.value);
86 return static_cast<uint8>(strtoul((
char*)data.value,
nullptr, 10));
95 if (!IsType(MYSQL_TYPE_TINY))
97 TC_LOG_WARN(
"sql.sql",
"Warning: GetInt8() on non-tinyint field %s.%s (%s.%s) at index %u. Using type: %s.",
98 meta.TableAlias, meta.Alias, meta.TableName, meta.Name, meta.Index, meta.Type);
104 return *
reinterpret_cast<int8*
>(data.value);
105 return static_cast<int8>(strtol((
char*)data.value,
NULL, 10));
114 if (!IsType(MYSQL_TYPE_SHORT) && !IsType(MYSQL_TYPE_YEAR))
116 TC_LOG_WARN(
"sql.sql",
"Warning: GetUInt16() on non-smallint field %s.%s (%s.%s) at index %u. Using type: %s.",
117 meta.TableAlias, meta.Alias, meta.TableName, meta.Name, meta.Index, meta.Type);
123 return *
reinterpret_cast<uint16*
>(data.value);
124 return static_cast<uint16>(strtoul((
char*)data.value,
nullptr, 10));
133 if (!IsType(MYSQL_TYPE_SHORT) && !IsType(MYSQL_TYPE_YEAR))
135 TC_LOG_WARN(
"sql.sql",
"Warning: GetInt16() on non-smallint field %s.%s (%s.%s) at index %u. Using type: %s.",
136 meta.TableAlias, meta.Alias, meta.TableName, meta.Name, meta.Index, meta.Type);
142 return *
reinterpret_cast<int16*
>(data.value);
143 return static_cast<int16>(strtol((
char*)data.value,
NULL, 10));
152 if (!IsType(MYSQL_TYPE_INT24) && !IsType(MYSQL_TYPE_LONG))
154 TC_LOG_WARN(
"sql.sql",
"Warning: GetUInt32() on non-(medium)int field %s.%s (%s.%s) at index %u. Using type: %s.",
155 meta.TableAlias, meta.Alias, meta.TableName, meta.Name, meta.Index, meta.Type);
161 return *
reinterpret_cast<uint32*
>(data.value);
162 return static_cast<uint32>(strtoul((
char*)data.value,
nullptr, 10));
171 if (!IsType(MYSQL_TYPE_INT24) && !IsType(MYSQL_TYPE_LONG))
173 TC_LOG_WARN(
"sql.sql",
"Warning: GetInt32() on non-(medium)int field %s.%s (%s.%s) at index %u. Using type: %s.",
174 meta.TableAlias, meta.Alias, meta.TableName, meta.Name, meta.Index, meta.Type);
180 return *
reinterpret_cast<int32*
>(data.value);
181 return static_cast<int32>(strtol((
char*)data.value,
NULL, 10));
190 if (!IsType(MYSQL_TYPE_LONGLONG) && !IsType(MYSQL_TYPE_BIT))
192 TC_LOG_WARN(
"sql.sql",
"Warning: GetUInt64() on non-bigint field %s.%s (%s.%s) at index %u. Using type: %s.",
193 meta.TableAlias, meta.Alias, meta.TableName, meta.Name, meta.Index, meta.Type);
199 return *
reinterpret_cast<uint64*
>(data.value);
200 return static_cast<uint64>(strtoull((
char*)data.value,
nullptr, 10));
209 if (!IsType(MYSQL_TYPE_LONGLONG) && !IsType(MYSQL_TYPE_BIT))
211 TC_LOG_WARN(
"sql.sql",
"Warning: GetInt64() on non-bigint field %s.%s (%s.%s) at index %u. Using type: %s.",
212 meta.TableAlias, meta.Alias, meta.TableName, meta.Name, meta.Index, meta.Type);
218 return *
reinterpret_cast<int64*
>(data.value);
219 return static_cast<int64>(strtoll((
char*)data.value,
NULL, 10));
228 if (!IsType(MYSQL_TYPE_FLOAT))
230 TC_LOG_WARN(
"sql.sql",
"Warning: GetFloat() on non-float field %s.%s (%s.%s) at index %u. Using type: %s.",
231 meta.TableAlias, meta.Alias, meta.TableName, meta.Name, meta.Index, meta.Type);
237 return *
reinterpret_cast<float*
>(data.value);
238 return static_cast<float>(atof((
char*)data.value));
247 if (!IsType(MYSQL_TYPE_DOUBLE) && !IsType(MYSQL_TYPE_NEWDECIMAL))
249 TC_LOG_WARN(
"sql.sql",
"Warning: GetDouble() on non-double/non-decimal field %s.%s (%s.%s) at index %u. Using type: %s.",
250 meta.TableAlias, meta.Alias, meta.TableName, meta.Name, meta.Index, meta.Type);
255 if (data.raw && !IsType(MYSQL_TYPE_NEWDECIMAL))
256 return *
reinterpret_cast<double*
>(data.value);
257 return static_cast<double>(atof((
char*)data.value));
268 TC_LOG_WARN(
"sql.sql",
"Error: GetCString() on numeric field %s.%s (%s.%s) at index %u. Using type: %s.",
269 meta.TableAlias, meta.Alias, meta.TableName, meta.Name, meta.Index, meta.Type);
273 return static_cast<char const*
>(data.value);
281 char const*
string = GetCString();
285 return std::string(
string, data.length);
290 std::vector<uint8> result;
291 if (!data.value || !data.length)
294 result.resize(data.length);
295 memcpy(result.data(), data.value, data.length);
301 return data.value ==
NULL;
315 #pragma pack(push, 1)
325 void SetByteValue(
void* newValue, enum_field_types newType,
uint32 length);
326 void SetStructuredValue(
char* newValue, enum_field_types newType,
uint32 length);
332 delete[] ((
char*)data.value);
340 case MYSQL_TYPE_NULL:
342 case MYSQL_TYPE_TINY:
344 case MYSQL_TYPE_YEAR:
345 case MYSQL_TYPE_SHORT:
347 case MYSQL_TYPE_INT24:
348 case MYSQL_TYPE_LONG:
349 case MYSQL_TYPE_FLOAT:
351 case MYSQL_TYPE_DOUBLE:
352 case MYSQL_TYPE_LONGLONG:
356 case MYSQL_TYPE_TIMESTAMP:
357 case MYSQL_TYPE_DATE:
358 case MYSQL_TYPE_TIME:
359 case MYSQL_TYPE_DATETIME:
360 return sizeof(MYSQL_TIME);
362 case MYSQL_TYPE_TINY_BLOB:
363 case MYSQL_TYPE_MEDIUM_BLOB:
364 case MYSQL_TYPE_LONG_BLOB:
365 case MYSQL_TYPE_BLOB:
366 case MYSQL_TYPE_STRING:
367 case MYSQL_TYPE_VAR_STRING:
368 return field->max_length + 1;
370 case MYSQL_TYPE_DECIMAL:
371 case MYSQL_TYPE_NEWDECIMAL:
374 case MYSQL_TYPE_GEOMETRY:
381 TC_LOG_WARN(
"sql.sql",
"SQL::SizeForType(): invalid field type %u",
uint32(field->type));
388 return data.type == type;
393 return (data.type == MYSQL_TYPE_TINY ||
394 data.type == MYSQL_TYPE_SHORT ||
395 data.type == MYSQL_TYPE_INT24 ||
396 data.type == MYSQL_TYPE_LONG ||
397 data.type == MYSQL_TYPE_FLOAT ||
398 data.type == MYSQL_TYPE_DOUBLE ||
399 data.type == MYSQL_TYPE_LONGLONG );
404 static char const* FieldTypeToString(enum_field_types type)
408 case MYSQL_TYPE_BIT:
return "BIT";
409 case MYSQL_TYPE_BLOB:
return "BLOB";
410 case MYSQL_TYPE_DATE:
return "DATE";
411 case MYSQL_TYPE_DATETIME:
return "DATETIME";
412 case MYSQL_TYPE_NEWDECIMAL:
return "NEWDECIMAL";
413 case MYSQL_TYPE_DECIMAL:
return "DECIMAL";
414 case MYSQL_TYPE_DOUBLE:
return "DOUBLE";
415 case MYSQL_TYPE_ENUM:
return "ENUM";
416 case MYSQL_TYPE_FLOAT:
return "FLOAT";
417 case MYSQL_TYPE_GEOMETRY:
return "GEOMETRY";
418 case MYSQL_TYPE_INT24:
return "INT24";
419 case MYSQL_TYPE_LONG:
return "LONG";
420 case MYSQL_TYPE_LONGLONG:
return "LONGLONG";
421 case MYSQL_TYPE_LONG_BLOB:
return "LONG_BLOB";
422 case MYSQL_TYPE_MEDIUM_BLOB:
return "MEDIUM_BLOB";
423 case MYSQL_TYPE_NEWDATE:
return "NEWDATE";
424 case MYSQL_TYPE_NULL:
return "NULL";
425 case MYSQL_TYPE_SET:
return "SET";
426 case MYSQL_TYPE_SHORT:
return "SHORT";
427 case MYSQL_TYPE_STRING:
return "STRING";
428 case MYSQL_TYPE_TIME:
return "TIME";
429 case MYSQL_TYPE_TIMESTAMP:
return "TIMESTAMP";
430 case MYSQL_TYPE_TINY:
return "TINY";
431 case MYSQL_TYPE_TINY_BLOB:
return "TINY_BLOB";
432 case MYSQL_TYPE_VAR_STRING:
return "VAR_STRING";
433 case MYSQL_TYPE_YEAR:
return "YEAR";
434 default:
return "-Unknown-";
438 void SetMetadata(MYSQL_FIELD* field,
uint32 fieldIndex)
440 meta.TableName = field->org_table;
441 meta.TableAlias = field->table;
442 meta.Name = field->org_name;
443 meta.Alias = field->name;
444 meta.Type = FieldTypeToString(field->type);
445 meta.Index = fieldIndex;
#define TC_DATABASE_API
Definition: Define.h:122
int8_t int8
Definition: Define.h:148
uint64 GetUInt64() const
Definition: Field.h:184
float GetFloat() const
Definition: Field.h:222
int64_t int64
Definition: Define.h:145
Class used to access individual fields of database query result.
Definition: Field.h:56
int64 GetInt64() const
Definition: Field.h:203
arena_t NULL
Definition: jemalloc_internal.h:624
bool IsType(enum_field_types type) const
Definition: Field.h:386
Definition: QueryResult.h:30
char const * GetCString() const
Definition: Field.h:260
std::vector< uint8 > GetBinary() const
Definition: Field.h:288
uint8 GetUInt8() const
Definition: Field.h:70
void * value
Definition: Field.h:319
int32_t int32
Definition: Define.h:146
uint32_t uint32
Definition: Define.h:150
uint64_t uint64
Definition: Define.h:149
bool raw
Definition: Field.h:321
uint16_t uint16
Definition: Define.h:151
void CleanUp()
Definition: Field.h:328
uint16 GetUInt16() const
Definition: Field.h:108
double GetDouble() const
Definition: Field.h:241
float length(float v)
Definition: vectorMath.h:208
int32 GetInt32() const
Definition: Field.h:165
int16 GetInt16() const
Definition: Field.h:127
bool IsNumeric() const
Definition: Field.h:391
enum_field_types type
Definition: Field.h:320
bool IsNull() const
Definition: Field.h:299
uint32 GetUInt32() const
Definition: Field.h:146
uint32 length
Definition: Field.h:318
#define TC_LOG_WARN(filterType__,...)
Definition: Log.h:204
uint8_t uint8
Definition: Define.h:152
int16_t int16
Definition: Define.h:147
uint32_t uint32
Definition: g3dmath.h:168
int8 GetInt8() const
Definition: Field.h:89
#define const
Definition: zconf.h:217
bool GetBool() const
Definition: Field.h:65
Definition: QueryResult.h:63
static uint32 SizeForType(MYSQL_FIELD *field)
Definition: Field.h:336
std::string GetString() const
Definition: Field.h:276