// returns true if the value contains a number (else it's some string) bool wxRegKey::IsNumericValue(const wxString& szValue) const { ValueType type = GetValueType(szValue); switch ( type ) { case Type_Dword: /* case Type_Dword_little_endian: == Type_Dword */ case Type_Dword_big_endian: return true; default: return false; } }
//******************************************************************************** BOOL CRegValue::ReadValue(CString& sValue, const REGSAM samDesired) { DWORD nSize; DWORD nType; SetOSResult(::RegQueryValueEx(GetKey(), GetValueName(), 0, &nType, NULL, &nSize)); if(GetOSResult() != ERROR_SUCCESS) return FALSE; if(GetValueType() > -1 && nType != GetValueType()) { SetResultCode(errValueTypeMismatch); return FALSE; } SetOSResult(::RegQueryValueEx(GetKey(), GetValueName(), 0, &m_nType, (UCHAR*) sValue.GetBuffer(nSize), &nSize)); sValue.ReleaseBuffer(); return GetOSResult() == ERROR_SUCCESS; }
/* Objects may have storage allocated for them. * Release memory associated to object type Values */ Value::~Value() { if (m_sourceInlined == true || m_cleanUp == false) { return; } switch (GetValueType()) { case VALUE_TYPE_VARCHAR: case VALUE_TYPE_VARBINARY: case VALUE_TYPE_ARRAY: { Varlen *sref = *reinterpret_cast<Varlen *const *>(m_data); if (sref != NULL) { delete sref; } } break; default: return; } }
bool SdfPropertySpec::SetDefaultValue(const VtValue &defaultValue) { if (defaultValue.IsEmpty()) { ClearDefaultValue(); return true; } if (defaultValue.IsHolding<SdfValueBlock>()) { return SetField(SdfFieldKeys->Default, defaultValue); } TfType valueType = GetValueType(); if (valueType.IsUnknown()) { TF_CODING_ERROR("Can't set value on attribute <%s> with " "unknown type \"%s\"", GetPath().GetText(), GetTypeName().GetAsToken().GetText()); return false; } if (ARCH_UNLIKELY(valueType.GetTypeid() == typeid(void))) { // valueType may be provided by a plugin that has not been loaded. // In that case, we cannot get the type info, which is required to cast. // So we load the plugin in that case. if (PlugPluginPtr p = PlugRegistry::GetInstance().GetPluginForType(valueType)) { p->Load(); } } VtValue value = VtValue::CastToTypeid(defaultValue, valueType.GetTypeid()); if (value.IsEmpty()) { TF_CODING_ERROR("Can't set value on <%s> to %s: " "expected a value of type \"%s\"", GetPath().GetText(), TfStringify(defaultValue).c_str(), valueType.GetTypeName().c_str()); return false; } return SetField(SdfFieldKeys->Default, value); }
//******************************************************************************** BOOL CRegValue::ReadValue(LPDWORD pValue, REGSAM samDesired) { DWORD nSize; DWORD nType; SetOSResult(::RegQueryValueEx(GetKey(), GetValueName(), 0, &nType, NULL, &nSize)); if(GetOSResult() != ERROR_SUCCESS) return FALSE; if(GetValueType() > -1 && nSize != sizeof(DWORD)) { SetResultCode(errValueTypeMismatch); return FALSE; } SetOSResult(::RegQueryValueEx(GetKey(), GetValueName(), 0, &nType, (UCHAR*) pValue, &nSize)); return GetOSResult() == ERROR_SUCCESS; }
wxString wxRegKey::FormatValue(const wxString& name) const { wxString rhs; const ValueType type = GetValueType(name); switch ( type ) { case Type_String: { wxString value; if ( !QueryValue(name, value) ) break; // quotes and backslashes must be quoted, linefeeds are not // allowed in string values rhs.reserve(value.length() + 2); rhs = wxT('"'); // there can be no NULs here bool useHex = false; for ( wxString::const_iterator p = value.begin(); p != value.end() && !useHex; ++p ) { switch ( (*p).GetValue() ) { case wxT('\n'): // we can only represent this string in hex useHex = true; break; case wxT('"'): case wxT('\\'): // escape special symbol rhs += wxT('\\'); // fall through default: rhs += *p; } } if ( useHex ) rhs = FormatAsHex(value, Type_String); else rhs += wxT('"'); } break; case Type_Dword: /* case Type_Dword_little_endian: == Type_Dword */ { long value; if ( !QueryValue(name, &value) ) break; rhs.Printf(wxT("dword:%08x"), (unsigned int)value); } break; case Type_Expand_String: case Type_Multi_String: { wxString value; if ( !QueryRawValue(name, value) ) break; rhs = FormatAsHex(value, type); } break; case Type_Binary: { wxMemoryBuffer buf; if ( !QueryValue(name, buf) ) break; rhs = FormatAsHex(buf.GetData(), buf.GetDataLen()); } break; // no idea how those appear in REGEDIT4 files case Type_None: case Type_Dword_big_endian: case Type_Link: case Type_Resource_list: case Type_Full_resource_descriptor: case Type_Resource_requirements_list: default: wxLogWarning(_("Can't export value of unsupported type %d."), type); } return rhs; }
//------------------------------------------------------------------------ char* CFileReadSLK::FetchKnownKeyValue( char* pData, bool& pIsEnd ) //------------------------------------------------------------------------ { char* ptrData = pData; ++ptrData; if( ';' != *ptrData) { pIsEnd = true; return ptrData; } for(;;) { if('\n' == *ptrData++ ) { return ptrData; } if('\0' == *ptrData) { pIsEnd = true; return ptrData; } emSlkValueType valueType = GetValueType( *ptrData ); switch( valueType ) { case ESVT_X: { char strValue[MAX_SLK_NUM_STRING_LEN]; memset( strValue, 0, sizeof(char)*MAX_SLK_NUM_STRING_LEN ); ptrData = GetSLKNumValue( ptrData, strValue, pIsEnd ); if( 0 < strlen(strValue) && strlen(strValue) < 11) { m_curCol = atoi( strValue ) -1; if(m_curCol > 300) { m_curCol = 0; } if( m_curCol < 0 ) { m_curCol = 0; //ZM::Log::global().log( "<<<ERROR>>> Error SLK File." ); } } else { ErrorLog(3,"---------slkerrr-----------"); } } break; case ESVT_Y: { char strValue[MAX_SLK_NUM_STRING_LEN]; memset( strValue, 0, sizeof(char)*MAX_SLK_NUM_STRING_LEN ); ptrData = GetSLKNumValue( ptrData, strValue, pIsEnd ); if( 0 < strlen(strValue) && strlen(strValue) < 11) { m_curRow = atoi( strValue ) - 1; if(m_curRow > 5000) { m_curRow = 0; } if( m_curRow < 0 ) { m_curRow = 0; //ZM::Log::global().log( "<<<ERROR>>> Error SLK File." ); } //OutputDebugString("\n"); } else { ErrorLog(3,"1111111111---------slkerrr-----------"); } } break; case ESVT_K: { if( '"' != *(ptrData+1) ) { if( IsNumberChar( *(ptrData+1) ) ) { char strValue[MAX_SLK_NUM_STRING_LEN]; memset( strValue, 0, sizeof(char)*MAX_SLK_NUM_STRING_LEN ); ptrData = GetSLKNumValue( ptrData, strValue, pIsEnd ); m_row = max( m_curRow+1, m_row ); m_col = max( m_curCol+1, m_col ); _TSLKValue* value = new _TSLKValue; value->col = m_curCol; value->row = m_curRow; value->value.intValue = atoi( strValue ); value->value.floatValue = atof( strValue ); size_t len = strlen( strValue ); if( MAX_SLK_NUM_STRING_LEN <= len ) { ErrorLog(3,"222222222---------slkerrr-----------"); } value->value.stringValue= new char[len+2]; memset( value->value.stringValue, 0, (len+2)*sizeof(char) ); strcpy( value->value.stringValue, strValue ); _TSLKValueArray.push_back( value ); //OutputDebugString(strValue); //OutputDebugString("\t"); //ZM::Log::global().log( "[%d,%d](%f)\n", m_curRow, m_curCol, atof( strValue ) ); } } else { char strValue[MAX_SLK_VALUE_STRING]; memset( strValue, 0, sizeof(char)*MAX_SLK_VALUE_STRING ); ptrData = GetSLKStringValue( ptrData, strValue, pIsEnd ); m_row = max( m_curRow+1, m_row ); m_col = max( m_curCol+1, m_col ); _TSLKValue* value = new _TSLKValue; value->col = m_curCol; value->row = m_curRow; value->value.intValue = atoi( strValue ); value->value.floatValue = atof( strValue ); size_t len = strlen( strValue ); if( MAX_SLK_VALUE_STRING <= len ) { ErrorLog(3,"3333---------slkerrr-----------"); } value->value.stringValue= new char[len+2]; memset( value->value.stringValue, 0, (len+2)*sizeof(char) ); strcpy( value->value.stringValue, strValue ); _TSLKValueArray.push_back( value ); //OutputDebugString(strValue); //OutputDebugString("\t"); //ZM::Log::global().log( "[%d,%d](%s)\n", m_curRow, m_curCol, strValue ); } } break; case ESVT_A: while('\n'!= *ptrData && '\0'!= *ptrData)ptrData++; break; case ESVT_Unkown: break; } } }
codegen::type::Type AbstractExpression::ResultType() const { return codegen::type::Type{GetValueType(), IsNullable()}; }
VariableUnion* GetArray(int parentId, int id) { int ValueType = GetValueType(parentId, GetArrayVariable(parentId, id)); return GetVariableValueAddress(parentId, GetArrayVariable(parentId, id)); }
VariableUnion* GetArrayStringIndexed(int parentId, int name) { int ValueType = GetValueType(parentId, GetVariable(parentId, name)); return GetVariableValueAddress(parentId, GetVariable(parentId, name)); }
TEST_F(BinderCorrectnessTest, SelectStatementTest) { SetupTables(); auto& parser = parser::PostgresParser::GetInstance(); catalog::Catalog* catalog_ptr = catalog::Catalog::GetInstance(); // Test regular table name LOG_INFO("Parsing sql query"); unique_ptr<binder::BindNodeVisitor> binder(new binder::BindNodeVisitor()); string selectSQL = "SELECT A.a1, B.b2 FROM A INNER JOIN b ON a.a1 = b.b1 " "WHERE a1 < 100 GROUP BY A.a1, B.b2 HAVING a1 > 50 " "ORDER BY a1"; auto parse_tree = parser.BuildParseTree(selectSQL); auto selectStmt = dynamic_cast<parser::SelectStatement*>(parse_tree->GetStatements().at(0)); binder->BindNameToNode(selectStmt); oid_t db_oid = catalog_ptr->GetDatabaseWithName(DEFAULT_DB_NAME)->GetOid(); oid_t tableA_oid = catalog_ptr->GetTableWithName(DEFAULT_DB_NAME, "a")->GetOid(); oid_t tableB_oid = catalog_ptr->GetTableWithName(DEFAULT_DB_NAME, "b")->GetOid(); // Check select_list LOG_INFO("Checking select list"); auto tupleExpr = (expression::TupleValueExpression*)(*selectStmt->select_list)[0]; EXPECT_EQ(tupleExpr->GetBoundOid(), make_tuple(db_oid, tableA_oid, 0)); // A.a1 EXPECT_EQ(type::TypeId::INTEGER, tupleExpr->GetValueType()); tupleExpr = (expression::TupleValueExpression*)(*selectStmt->select_list)[1]; EXPECT_EQ(tupleExpr->GetBoundOid(), make_tuple(db_oid, tableB_oid, 1)); // B.b2 EXPECT_EQ(type::TypeId::VARCHAR, tupleExpr->GetValueType()); // Check join condition LOG_INFO("Checking join condition"); tupleExpr = (expression::TupleValueExpression*) selectStmt->from_table->join->condition->GetChild(0); EXPECT_EQ(tupleExpr->GetBoundOid(), make_tuple(db_oid, tableA_oid, 0)); // a.a1 tupleExpr = (expression::TupleValueExpression*) selectStmt->from_table->join->condition->GetChild(1); EXPECT_EQ(tupleExpr->GetBoundOid(), make_tuple(db_oid, tableB_oid, 0)); // b.b1 // Check Where clause LOG_INFO("Checking where clause"); tupleExpr = (expression::TupleValueExpression*)selectStmt->where_clause->GetChild(0); EXPECT_EQ(tupleExpr->GetBoundOid(), make_tuple(db_oid, tableA_oid, 0)); // a1 // Check Group By and Having LOG_INFO("Checking group by"); tupleExpr = (expression::TupleValueExpression*)selectStmt->group_by->columns->at(0); EXPECT_EQ(tupleExpr->GetBoundOid(), make_tuple(db_oid, tableA_oid, 0)); // A.a1 tupleExpr = (expression::TupleValueExpression*)selectStmt->group_by->columns->at(1); EXPECT_EQ(tupleExpr->GetBoundOid(), make_tuple(db_oid, tableB_oid, 1)); // B.b2 tupleExpr = (expression::TupleValueExpression*)selectStmt->group_by->having->GetChild( 0); EXPECT_EQ(tupleExpr->GetBoundOid(), make_tuple(db_oid, tableA_oid, 0)); // a1 // Check Order By LOG_INFO("Checking order by"); tupleExpr = (expression::TupleValueExpression*)selectStmt->order->exprs->at(0); EXPECT_EQ(tupleExpr->GetBoundOid(), make_tuple(db_oid, tableA_oid, 0)); // a1 // Check alias ambiguous LOG_INFO("Checking duplicate alias and table name."); binder.reset(new binder::BindNodeVisitor()); selectSQL = "SELECT * FROM A, B as A"; parse_tree = parser.BuildParseTree(selectSQL); selectStmt = (parser::SelectStatement*)(parse_tree->GetStatements().at(0)); try { binder->BindNameToNode(selectStmt); EXPECT_TRUE(false); } catch (Exception& e) { LOG_INFO("Correct! Exception(%s) catched", e.what()); } // Test select from different table instances from the same physical schema binder.reset(new binder::BindNodeVisitor()); selectSQL = "SELECT * FROM A, A as AA where A.a1 = AA.a2"; parse_tree = parser.BuildParseTree(selectSQL); selectStmt = (parser::SelectStatement*)(parse_tree->GetStatements().at(0)); binder->BindNameToNode(selectStmt); LOG_INFO("Checking where clause"); tupleExpr = (expression::TupleValueExpression*)selectStmt->where_clause->GetChild(0); EXPECT_EQ(tupleExpr->GetBoundOid(), make_tuple(db_oid, tableA_oid, 0)); // a1 tupleExpr = (expression::TupleValueExpression*)selectStmt->where_clause->GetChild(1); EXPECT_EQ(tupleExpr->GetBoundOid(), make_tuple(db_oid, tableA_oid, 1)); // a1 // Test alias and select_list LOG_INFO("Checking select_list and table alias binding"); binder.reset(new binder::BindNodeVisitor()); selectSQL = "SELECT AA.a1, b2 FROM A as AA, B WHERE AA.a1 = B.b1"; parse_tree = parser.BuildParseTree(selectSQL); selectStmt = (parser::SelectStatement*)(parse_tree->GetStatements().at(0)); binder->BindNameToNode(selectStmt); tupleExpr = (expression::TupleValueExpression*)(selectStmt->select_list->at(0)); EXPECT_EQ(tupleExpr->GetBoundOid(), make_tuple(db_oid, tableA_oid, 0)); tupleExpr = (expression::TupleValueExpression*)(selectStmt->select_list->at(1)); EXPECT_EQ(tupleExpr->GetBoundOid(), make_tuple(db_oid, tableB_oid, 1)); // Delete the test database auto& txn_manager = concurrency::TransactionManagerFactory::GetInstance(); auto txn = txn_manager.BeginTransaction(); catalog_ptr->DropDatabaseWithName(DEFAULT_DB_NAME, txn); txn_manager.CommitTransaction(txn); }