std::string CDatabaseQueryRule::FormatWhereClause(const std::string &negate, const std::string &oper, const std::string ¶m, const CDatabase &db, const std::string &strType) const { std::string parameter = FormatParameter(oper, param, db, strType); std::string query; if (m_field != 0) { std::string fmt = "%s"; if (GetFieldType(m_field) == NUMERIC_FIELD) fmt = "CAST(%s as DECIMAL(5,1))"; else if (GetFieldType(m_field) == SECONDS_FIELD) fmt = "CAST(%s as INTEGER)"; query = StringUtils::Format(fmt.c_str(), GetField(m_field,strType).c_str()); query += negate + parameter; // special case for matching parameters in fields that might be either empty or NULL. if (( param.empty() && negate.empty() ) || ( !param.empty() && !negate.empty() )) query += " OR " + GetField(m_field,strType) + " IS NULL"; } if (query == negate + parameter) query = "1"; return query; }
std::string CDatabaseQueryRule::FormatParameter(const std::string &operatorString, const std::string ¶m, const CDatabase &db, const std::string &strType) const { std::string parameter; if (GetFieldType(m_field) == TEXTIN_FIELD) { std::vector<std::string> split = StringUtils::Split(param, ','); for (std::vector<std::string>::iterator itIn = split.begin(); itIn != split.end(); ++itIn) { if (!parameter.empty()) parameter += ","; parameter += db.PrepareSQL("'%s'", StringUtils::Trim(*itIn).c_str()); } parameter = " IN (" + parameter + ")"; } else parameter = db.PrepareSQL(operatorString.c_str(), ValidateParameter(param).c_str()); if (GetFieldType(m_field) == DATE_FIELD) { if (m_operator == OPERATOR_IN_THE_LAST || m_operator == OPERATOR_NOT_IN_THE_LAST) { // translate time period CDateTime date=CDateTime::GetCurrentDateTime(); CDateTimeSpan span; span.SetFromPeriod(param); date-=span; parameter = db.PrepareSQL(operatorString.c_str(), date.GetAsDBDate().c_str()); } } return parameter; }
std::string CDatabaseQueryRule::ValidateParameter(const std::string ¶meter) const { if ((GetFieldType(m_field) == REAL_FIELD || GetFieldType(m_field) == NUMERIC_FIELD || GetFieldType(m_field) == SECONDS_FIELD) && parameter.empty()) return "0"; // interpret empty fields as 0 return parameter; }
std::string CDatabaseQueryRule::GetWhereClause(const CDatabase &db, const std::string& strType) const { SEARCH_OPERATOR op = GetOperator(strType); std::string operatorString = GetOperatorString(op); std::string negate; if (op == OPERATOR_DOES_NOT_CONTAIN || op == OPERATOR_FALSE || (op == OPERATOR_DOES_NOT_EQUAL && GetFieldType(m_field) != REAL_FIELD && GetFieldType(m_field) != NUMERIC_FIELD && GetFieldType(m_field) != SECONDS_FIELD)) negate = " NOT "; // boolean operators don't have any values in m_parameter, they work on the operator if (m_operator == OPERATOR_FALSE || m_operator == OPERATOR_TRUE) return GetBooleanQuery(negate, strType); // The BETWEEN operator is handled special if (op == OPERATOR_BETWEEN) { if (m_parameter.size() != 2) return ""; FIELD_TYPE fieldType = GetFieldType(m_field); if (fieldType == REAL_FIELD) return db.PrepareSQL("%s BETWEEN %s AND %s", GetField(m_field, strType).c_str(), m_parameter[0].c_str(), m_parameter[1].c_str()); else if (fieldType == NUMERIC_FIELD) return db.PrepareSQL("CAST(%s as DECIMAL(5,1)) BETWEEN %s AND %s", GetField(m_field, strType).c_str(), m_parameter[0].c_str(), m_parameter[1].c_str()); else if (fieldType == SECONDS_FIELD) return db.PrepareSQL("CAST(%s as INTEGER) BETWEEN %s AND %s", GetField(m_field, strType).c_str(), m_parameter[0].c_str(), m_parameter[1].c_str()); else return db.PrepareSQL("%s BETWEEN '%s' AND '%s'", GetField(m_field, strType).c_str(), m_parameter[0].c_str(), m_parameter[1].c_str()); } // now the query parameter std::string wholeQuery; for (std::vector<std::string>::const_iterator it = m_parameter.begin(); it != m_parameter.end(); ++it) { std::string query = '(' + FormatWhereClause(negate, operatorString, *it, db, strType) + ')'; if (it + 1 != m_parameter.end()) { if (negate.empty()) query += " OR "; else query += " AND "; } wholeQuery += query; } return wholeQuery; }
std::string CDatabaseQueryRule::GetOperatorString(SEARCH_OPERATOR op) const { std::string operatorString; if (GetFieldType(m_field) != TEXTIN_FIELD) { // the comparison piece switch (op) { case OPERATOR_CONTAINS: operatorString = " LIKE '%%%s%%'"; break; case OPERATOR_DOES_NOT_CONTAIN: operatorString = " LIKE '%%%s%%'"; break; case OPERATOR_EQUALS: if (GetFieldType(m_field) == REAL_FIELD || GetFieldType(m_field) == NUMERIC_FIELD || GetFieldType(m_field) == SECONDS_FIELD) operatorString = " = %s"; else operatorString = " LIKE '%s'"; break; case OPERATOR_DOES_NOT_EQUAL: if (GetFieldType(m_field) == REAL_FIELD || GetFieldType(m_field) == NUMERIC_FIELD || GetFieldType(m_field) == SECONDS_FIELD) operatorString = " != %s"; else operatorString = " LIKE '%s'"; break; case OPERATOR_STARTS_WITH: operatorString = " LIKE '%s%%'"; break; case OPERATOR_ENDS_WITH: operatorString = " LIKE '%%%s'"; break; case OPERATOR_AFTER: case OPERATOR_GREATER_THAN: case OPERATOR_IN_THE_LAST: operatorString = " > "; if (GetFieldType(m_field) == REAL_FIELD || GetFieldType(m_field) == NUMERIC_FIELD || GetFieldType(m_field) == SECONDS_FIELD) operatorString += "%s"; else operatorString += "'%s'"; break; case OPERATOR_BEFORE: case OPERATOR_LESS_THAN: case OPERATOR_NOT_IN_THE_LAST: operatorString = " < "; if (GetFieldType(m_field) == REAL_FIELD || GetFieldType(m_field) == NUMERIC_FIELD || GetFieldType(m_field) == SECONDS_FIELD) operatorString += "%s"; else operatorString += "'%s'"; break; case OPERATOR_TRUE: operatorString = " = 1"; break; case OPERATOR_FALSE: operatorString = " = 0"; break; default: break; } } return operatorString; }
void CField::pg_Delete(void *pDestArrar) { if (GetFieldType() == fString) delete ((PF_STRING)pDestArrar); else delete ((PF_NUM)pDestArrar); }
/************************************************************************************ 函数名称: int CFields::LoadFromBuffer(LPBYTE& lpData,int FieldCount) 功能说明:从Buffer读取指定个数的字段信息. 详细解释:1.返回读取的字节数. 2.如果传入的参数无效,则返回-1. 出入参数: [in]: 1.lpData:要读的起始地址. 2.FieldCount:要读取的字段个数. [out]:1.lpData:传入参数lpData向后移动FieldCount个记录后的地址. 返回类型:int 制作:YTLI 2002/07/15 修改: ***********************************************************************************/ int CFields::LoadFromBuffer(LPBYTE& lpData,int FieldCount) { if( (!lpData) || (FieldCount <=0) ) return -1; m_nCurVersion = 0; m_nLastPosVersion = -1; int iRetValue = (int)lpData; int iFieldCnt = 0; while( iFieldCnt < FieldCount ) { CFieldType chType = GetFieldType(lpData); CField* pField = NewFieldType(this,chType); if(!pField) return -1; pField->m_pFields = this; lpData += pField->LoadFromBuffer(lpData); Add(pField); iFieldCnt++; } iRetValue = (int)lpData - iRetValue; return iRetValue; }
static void DrawTile_Clear(TileInfo *ti) { switch (GetClearGround(ti->tile)) { case CLEAR_GRASS: DrawClearLandTile(ti, GetClearDensity(ti->tile)); break; case CLEAR_ROUGH: DrawHillyLandTile(ti); break; case CLEAR_ROCKS: DrawGroundSprite((HasGrfMiscBit(GMB_SECOND_ROCKY_TILE_SET) && (TileHash(ti->x, ti->y) & 1) ? SPR_FLAT_ROCKY_LAND_2 : SPR_FLAT_ROCKY_LAND_1) + SlopeToSpriteOffset(ti->tileh), PAL_NONE); break; case CLEAR_FIELDS: DrawGroundSprite(_clear_land_sprites_farmland[GetFieldType(ti->tile)] + SlopeToSpriteOffset(ti->tileh), PAL_NONE); DrawClearLandFence(ti); break; case CLEAR_SNOW: case CLEAR_DESERT: DrawGroundSprite(_clear_land_sprites_snow_desert[GetClearDensity(ti->tile)] + SlopeToSpriteOffset(ti->tileh), PAL_NONE); break; } DrawBridgeMiddle(ti); }
LPBYTE CField::pg_GetAt(void*pDestArrar,int nIndex) { if (GetFieldType() == fString) return(LPBYTE) &((*(PF_STRING)pDestArrar)[nIndex]); else return(LPBYTE) &((*(PF_NUM)pDestArrar)[nIndex]); }
void CField::pg_RemoveAll(void *pDestArrar) { if (GetFieldType() == fString) ((PF_STRING)pDestArrar)->RemoveAll(); else ((PF_NUM)pDestArrar)->RemoveAll(); }
bool Create(const TCHAR* file) { USES_CONVERSION; int array_count = GetFieldCount(); DBaseFieldVector vector; vector.resize(array_count); for (int i = 0; i < array_count; i++) { CDaoFieldInfo info; DBF_FIELD_INFO* item = &vector[i]; GetFieldInfo(i, info); strncpy(item->name, T2CA(info.m_strName), _countof(item->name)); item->name[_countof(item->name) - 1] = 0; item->decimals = 0; item->length = info.m_lSize; item->type = GetFieldType(i, info, &item->length); } zlib_filefunc_def api; fill_fopen_filefunc(&api); void* stream = api.zopen_file(api.opaque, T2CA(file), ZLIB_FILEFUNC_MODE_CREATE | ZLIB_FILEFUNC_MODE_WRITE); bool ok = (NULL != stream); if (ok) ok = m_dbf.Create(file, stream, &api, vector); return ok; }
void CField::pg_InsertAt(void*pDestArrar,int nIndex) { if (GetFieldType() == fString) ((PF_STRING)pDestArrar)->InsertAt(nIndex,*(FieldString*)m_pTempData); else ((PF_NUM)pDestArrar)->InsertAt(nIndex,*(FieldNUM*)m_pTempData); }
void CField::pg_RemoveAt(void *pDestArrar,int nIndex) { if (GetFieldType() == fString) ((PF_STRING)pDestArrar)->RemoveAt(nIndex); else ((PF_NUM)pDestArrar)->RemoveAt(nIndex); }
void CField::pg_Add(void*pDestArrar) { if (GetFieldType() == fString) ((PF_STRING)pDestArrar)->Add(*(FieldString*)m_pTempData); else ((PF_NUM)pDestArrar)->Add(*(FieldNUM*)m_pTempData); }
/************************************************************************************ 函数名称: void CField::SetNull() 功能说明:将m_pValve所指向的数据设置为空值NULL. 详细解释: 出入参数: [in]: 无. [out]:无. 返回类型:void 制作:YTLI 2002/07/15 修改: ************************************************************************************/ void CField::SetNull() { if (GetFieldType() == fString) *(FieldString*)m_pValue = ""; else *(FieldNUM*)m_pValue = NULLValue; }
// get value into a wxVariant bool wxDBase::GetValueByRow(wxVariant* var, unsigned int row, unsigned int col) { bool ok = SetPosition(row); // unconst if (ok) switch (GetFieldType(GetFieldPtr(col))) { case DBF_DATA_TYPE_INTEGER: { long n; ok = Read(col, &n); if (ok) var->operator=(n); break; } case DBF_DATA_TYPE_FLOAT : { double n; ok = Read(col, &n); if (ok) var->operator=(n); break; } case DBF_DATA_TYPE_DATE : { wxDateTime n; ok = Read(col, &n); if (ok) var->operator=(n); break; } case DBF_DATA_TYPE_BOOLEAN: { bool n; ok = Read(col, &n); if (ok) var->operator=(n); break; } case DBF_DATA_TYPE_MEMO : case DBF_DATA_TYPE_CHAR : { wxString str; /*ok = */Read(col, &str); if (ok) { var->operator=(str); } break; } case DBF_DATA_TYPE_UNKNOWN: default: ok = false; break; } return ok; }
/*! */ xbShort xbDbf::MemoFieldsPresent() const { xbShort i; for( i = 0; i < NoOfFields; i++ ) if( GetFieldType( i ) == 'M' ) return 1; return 0; }
DBType MyBasicResults::GetFieldDataType(unsigned int field) { DBType type = GetFieldType(field); if (type == DBType_Blob) { return DBType_Blob; } else { return DBType_String; } }
/*! */ xbShort xbDbf::GetLogicalField( xbShort FieldNo ) { char buf[3]; if( GetFieldType( FieldNo ) != 'L' ) return -1; memset( buf, 0x00, 3 ); GetField( FieldNo, buf ); if( buf[0] == 'Y' || buf[0] == 'y' || buf[0] == 'T' || buf[0] == 't' ) return 1; else return 0; }
void FieldIcon::Refresh() { ClientUI* ui = ClientUI::GetClientUI(); if (!ui) return; const Field* field = GetField(m_field_id); if (!field) return; const FieldType* type = GetFieldType(field->FieldTypeName()); if (!type) return; m_texture = ui->GetTexture(ClientUI::ArtDir() / type->Graphic(), true); }
int CField::QuerySaveLength() { if (GetFieldType() == fString) { return Align4(m_nWidth); } else { return sizeof(FieldNUM); } }
void CPlayer::Deserialize(rapidjson::Value& json) { for (rapidjson::Value::MemberIterator it = json.MemberBegin(); it != json.MemberEnd(); ++it) { if (it->value.IsInt()) { SetFieldInt(GetFieldType(it->name.GetString()), it->value.GetInt()); } else if (it->value.IsInt64()) { SetFieldI64(GetFieldType(it->name.GetString()), it->value.GetInt64()); } else if (it->value.IsString()) { SetFieldStr(GetFieldType(it->name.GetString()), it->value.GetString()); } else if (it->value.IsArray()) { } else if (it->value.IsObject()) { } } }
/************************************************************************************ 函数名称: bool CField::LoadDataFromBuffer(LPBYTE& lpIndicate, LPBYTE& lpData) 功能说明:虚函數,读取一条记录某一字段的数据,可以用来读取值标签. 详细解释:1.子类实现. 出入参数: [in]: 1.lpIndicate:指示字节地址. 2.lpData :数据地址. [out]:1.lpIndicate:下一数据块的指示字节地址. 2.lpData :下一数据块的数据地址. 返回类型:bool 制作:YTLI 2002/07/12 修改: ************************************************************************************/ void CField::LoadDataFromBuffer( LPBYTE& lpData) { if(m_pValue==NULL) {//旧版本 if(m_nNextModifyField == -1) { NewData(); LoadDataFromBuffer(lpData); DeleteData(); } else { if(m_pFields->IsConvertToLastVersion(this)) { NewData(); LoadDataFromBuffer(lpData); CField* pNewField = m_pFields->m_FieldVersion.GetFieldByAbsolutePos(m_nNextModifyField); pNewField->ConvertToCurField(this); DeleteData(); } } } else {//当前最新 if (GetFieldType() == fString) { FieldString* pStr = (FieldString*)m_pValue; char *pBuf = new char[m_nWidth+2]; memset(pBuf,0,m_nWidth+2); memcpy(pBuf,lpData,m_nWidth); *pStr= pBuf; /* char* lpstr = pStr->GetBuffer(m_nWidth+2); memcpy(lpstr,lpData,m_nWidth); *(lpstr+m_nWidth)= 0; *(lpstr+m_nWidth+1)= 0; pStr->ReleaseBuffer(); */ //pStr->TrimLeft();//,左边空格保留 pStr->TrimRight(); lpData = lpData + Align4(m_nWidth); } else { memcpy( &*((FieldNUM *)m_pValue), lpData, sizeof(FieldNUM) ); //ytli Modify 2002/09/04 lpData = lpData + sizeof(FieldNUM); } } }
void CField::pg_Add(void*pDestArrar,int nCount) { if (GetFieldType() == fString) { for (int i=0;i<nCount ;i++) ((PF_STRING)pDestArrar)->Add(*(FieldString*)m_pTempData); } else { for (int i=0;i<nCount ;i++) ((PF_NUM)pDestArrar)->Add(*(FieldNUM*)m_pTempData); } }
//取得数据类型(离散型/连续型) int CField::GetDCDataType(int nIndex) { int nMeasure=GetMeasure(), nDataType=GetFieldType(); if(nMeasure== msNominal) return CONTINU_DATA; if(nDataType==fBoolean || nDataType==fString || nMeasure==msScale || nMeasure==msOrdinal) return DISPERSE_DATA; return 0; }
int main(int argc, char *argv[]) { char ErrBuf[2048]; if (ParseCommandLine(argc, argv) == 0) return 0; printf("\n\nLoading NetPDL protocol database...\n"); // Get the class that contains the NetPDL protocol database struct _nbNetPDLDatabase *NetPDLProtoDB= nbProtoDBXMLLoad(NetPDLFileName, nbPROTODB_FULL, ErrBuf, sizeof(ErrBuf)); if (NetPDLProtoDB == NULL) { printf("Error loading the NetPDL protocol Database: %s\n", ErrBuf); return 0; } printf("NetPDL Protocol database loaded.\n"); printf(" Creator: %s\n", NetPDLProtoDB->Creator); printf(" Creation date: %s\n", NetPDLProtoDB->CreationDate); printf(" NetPDL version: %u.%u\n\n", (unsigned int) NetPDLProtoDB->VersionMajor, (unsigned int) NetPDLProtoDB->VersionMinor); // Scan the content of the protocol database, from the first to the last protocol for (unsigned int i= 0; i < NetPDLProtoDB->ProtoListNItems; i++) { struct _nbNetPDLElementBase *NetPDLElement; char FieldString[1024]; NetPDLElement= NetPDLProtoDB->ProtoList[i]->FirstField; // If the protocol has fields, let's retrieve the structure associated to the first field printf("\nProtocol n. %d: %s (%s)\n", i, NetPDLProtoDB->ProtoList[i]->Name, NetPDLProtoDB->ProtoList[i]->LongName); if (NetPDLElement) { while (NetPDLElement != nbNETPDL_INVALID_ELEMENT) { GetFieldType(NetPDLElement, FieldString); printf("%s", FieldString); NetPDLElement= nbNETPDL_GET_ELEMENT(NetPDLProtoDB, NetPDLElement->NextSibling); } } else printf("\t(no fields associated to this protocol)\n"); } nbProtoDBXMLCleanup(); return 1; }
// called from code:MethodTableBuilder::InitializeFieldDescs#InitCall VOID FieldDesc::Init(mdFieldDef mb, CorElementType FieldType, DWORD dwMemberAttrs, BOOL fIsStatic, BOOL fIsRVA, BOOL fIsThreadLocal, BOOL fIsContextLocal, LPCSTR pszFieldName) { LIMITED_METHOD_CONTRACT; // We allow only a subset of field types here - all objects must be set to TYPE_CLASS // By-value classes are ELEMENT_TYPE_VALUETYPE _ASSERTE( FieldType == ELEMENT_TYPE_I1 || FieldType == ELEMENT_TYPE_BOOLEAN || FieldType == ELEMENT_TYPE_U1 || FieldType == ELEMENT_TYPE_I2 || FieldType == ELEMENT_TYPE_U2 || FieldType == ELEMENT_TYPE_CHAR || FieldType == ELEMENT_TYPE_I4 || FieldType == ELEMENT_TYPE_U4 || FieldType == ELEMENT_TYPE_I8 || FieldType == ELEMENT_TYPE_I || FieldType == ELEMENT_TYPE_U || FieldType == ELEMENT_TYPE_U8 || FieldType == ELEMENT_TYPE_R4 || FieldType == ELEMENT_TYPE_R8 || FieldType == ELEMENT_TYPE_CLASS || FieldType == ELEMENT_TYPE_VALUETYPE || FieldType == ELEMENT_TYPE_PTR || FieldType == ELEMENT_TYPE_FNPTR ); _ASSERTE(fIsStatic || (!fIsRVA && !fIsThreadLocal && !fIsContextLocal)); _ASSERTE(fIsRVA + fIsThreadLocal + fIsContextLocal <= 1); m_requiresFullMbValue = 0; SetMemberDef(mb); m_type = FieldType; m_prot = fdFieldAccessMask & dwMemberAttrs; m_isStatic = fIsStatic != 0; m_isRVA = fIsRVA != 0; m_isThreadLocal = fIsThreadLocal != 0; #ifdef _DEBUG m_debugName = (LPUTF8)pszFieldName; #endif #if CHECK_APP_DOMAIN_LEAKS m_isDangerousAppDomainAgileField = 0; #endif _ASSERTE(GetMemberDef() == mb); // no truncation _ASSERTE(GetFieldType() == FieldType); _ASSERTE(GetFieldProtection() == (fdFieldAccessMask & dwMemberAttrs)); _ASSERTE((BOOL) IsStatic() == (fIsStatic != 0)); }
void CField::RealNewData() { if (GetFieldType() == fString) { FieldString* pStr = new FieldString(); m_pValue = (LPBYTE)(pStr); } else { m_pValue =(LPBYTE) new FieldNUM; *(FieldNUM*)m_pValue = NULLValue; } }
/* print fields */ void print_fields(Struct *s) { printf("\nFIELDS\n______\n\n"); if (s->FieldCount == 1) { /* index into field array */ ; /* FIXME */ } else if (s->FieldCount > 1) { /* offset into field indices array */ int offset = header.FieldIndicesOffset + s->DataOrDataOffset; unsigned i; /* seek into field indices array */ if (fseek(fp, offset, SEEK_SET) != 0) { error("unable to seek into field indices array.\n"); } for (i = 0; i < s->FieldCount; i++) { unsigned index, offset; Field field; /* read next field index */ if (!fread(&index, sizeof(unsigned int), 1, fp)) { error("unable to read field index.\n"); } fppush(); /* seek into field array */ offset = header.FieldOffset + sizeof(Field) * index; if (fseek(fp, offset, SEEK_SET) != 0) { error("unable to seek into field array.\n"); } /* read next field */ if (!fread(&field, sizeof(Field), 1, fp)) { error("unable to read field.\n"); } if (i > 0) printf("\n"); printf("Field #%d\nType: %s\nLabel Index: %d\nDataOrDataOffset: %d\n", i+1, GetFieldType(field.FieldType), field.LabelIndex, field.DataOrDataOffset); print_field(&field); fppop(); } } }
void* CField::pg_New() { if (GetFieldType() == fString) { PF_STRING pResult = new F_STRING; pResult->SetSize(0,IncreaseSize); return pResult; } else { PF_NUM pResult = new F_NUM; pResult->SetSize(0,IncreaseSize); return pResult; } }