Esempio n. 1
0
/**
 * Metodo para montar a lista de labels=valores para uso no
 * no update, note bAllFields, permite levar os null's na query
 */
CString CTableBase::BuildFieldValueList(BOOL bAllFields, BOOL bNoKeyInSet)
{
	CString s;
	POSITION pos = m_mapFields.GetStartPosition();
	CString sKey;
	CField *pClass;
	int counter = 0;
	BOOL usefull = FALSE;

	///Ll## STLOG_WRITE("Inicio CTableBase::BuildFieldValueList()");

	while(pos != NULL)
	{
		m_mapFields.GetNextAssoc( pos, sKey, pClass );

		// Naoadicionar as chaves no set xxxx='xxxx'
		if(pClass->IsKey() && bNoKeyInSet)
			continue;

		if(!bAllFields) // Skipar os nulos !
		{
			if(!pClass->IsNull())
			{
				if(counter++ > 0)
					s += _T(",\r\n");

				usefull = TRUE;

				//if(sKey.Find(' ') > 0)
				s += _T("[") + sKey + _T("]=");
				//else
				//	s += sKey + _T("=");
				
				s += pClass->GetQueryFormatValue();
			}
		}
		else // fazer assign mesmo dos nulos / nao preenchidos !!!
		{
			usefull = TRUE;

			if(counter++ > 0)
				s += _T(",\r\n");

			//if(sKey.Find(' ') > 0)
			s += _T("[") + sKey + _T("]=");
			//else
			//	s += sKey + _T("=");

			if(!pClass->IsNull())
				s += pClass->GetQueryFormatValue();
			else
				s += _T("NULL");
		}
	}

	//STLOG_WRITE(L"CTableBase::BuildFieldValueList: CAMPOS/VALORES: %s", s);

	return s;
}
Esempio n. 2
0
/**
 * Metodo para limpar todos os valores dos campos da tabela
 */
void CTableBase::Reset(BOOL bExcludeKeys)
{
	POSITION pos = m_mapFields.GetStartPosition();
	CString sKey;
	CField *pField;

	while(pos != NULL)
	{
		m_mapFields.GetNextAssoc( pos, sKey, pField );
		
		if(pField->IsKey() && bExcludeKeys)
			continue;

		pField->SetValue(_T(""));
	}
}
Esempio n. 3
0
/**
 * Metodo para montar a lista de label=valor para uso no
 * where clause da query
 */ 
CString CTableBase::BuildWhereList(BOOL bOnlyKeys, BOOL bIgnoreNULL)
{
	CString s(_T("WHERE "));
	POSITION pos = m_mapFields.GetStartPosition();
	CString sKey;
	CField *pClass;
	int counter = 0;
	BOOL usefull = FALSE;

	while(pos != NULL)
	{
		m_mapFields.GetNextAssoc( pos, sKey, pClass );

		// Se o campo estiver na lista de ignore... nao usar ...
		if(m_ignoreFields.Find(sKey) != NULL)
			continue;

		// Se nao for chave ...
		if(bOnlyKeys && !pClass->IsKey())
			continue;

		if(!pClass->IsNull())
		{
			usefull = TRUE;

			CString s1 = pClass->GetQueryFormatValue();

			if(s1.CompareNoCase(_T("NULL")) == 0 || 
			   s1.CompareNoCase(_T("\"NULL\"")) == 0 )
			{
				if(!bIgnoreNULL)
				{
					if(counter++ > 0)
						s += _T("\r\n AND ");

					s += _T("[") + sKey + _T("] IS NULL");
				}
			}
			else
			{
				if(counter++ > 0)
					s += _T("\r\n AND ");

				//if(sKey.Find(' ') > 0)
				s += _T("[") + sKey + _T("]=");
				//else
				//	s += sKey + _T("=");
				
				s += s1;
			}
		}
		else
		{
			if(!bIgnoreNULL)
			{
				if(counter++ > 0)
					s += _T("\r\n AND ");

				s += _T("[") + sKey + _T("] IS NULL");
			}
		}
	}

	if(!usefull)
		return _T("");

	return s;
}