/* ** This function is used to allocate and populate UnpackedRecord ** structures intended to be compared against sample index keys stored ** in the sqlite_stat4 table. ** ** A single call to this function attempts to populates field iVal (leftmost ** is 0 etc.) of the unpacked record with a value extracted from expression ** pExpr. Extraction of values is possible if: ** ** * (pExpr==0). In this case the value is assumed to be an SQL NULL, ** ** * The expression is a bound variable, and this is a reprepare, or ** ** * The sqlite3ValueFromExpr() function is able to extract a value ** from the expression (i.e. the expression is a literal value). ** ** If a value can be extracted, the affinity passed as the 5th argument ** is applied to it before it is copied into the UnpackedRecord. Output ** parameter *pbOk is set to true if a value is extracted, or false ** otherwise. ** ** When this function is called, *ppRec must either point to an object ** allocated by an earlier call to this function, or must be NULL. If it ** is NULL and a value can be successfully extracted, a new UnpackedRecord ** is allocated (and *ppRec set to point to it) before returning. ** ** Unless an error is encountered, SQLITE_OK is returned. It is not an ** error if a value cannot be extracted from pExpr. If an error does ** occur, an SQLite error code is returned. */ SQLITE_PRIVATE int sqlite3Stat4ProbeSetValue( Parse *pParse, /* Parse context */ Index *pIdx, /* Index being probed */ UnpackedRecord **ppRec, /* IN/OUT: Probe record */ Expr *pExpr, /* The expression to extract a value from */ u8 affinity, /* Affinity to use */ int iVal, /* Array element to populate */ int *pbOk /* OUT: True if value was extracted */ ){ int rc = SQLITE_OK; sqlite3_value *pVal = 0; sqlite3 *db = pParse->db; struct ValueNewStat4Ctx alloc; alloc.pParse = pParse; alloc.pIdx = pIdx; alloc.ppRec = ppRec; alloc.iVal = iVal; /* Skip over any TK_COLLATE nodes */ pExpr = sqlite3ExprSkipCollate(pExpr); if( !pExpr ){ pVal = valueNew(db, &alloc); if( pVal ){ sqlite3VdbeMemSetNull((Mem*)pVal); *pbOk = 1; } }else if( pExpr->op==TK_VARIABLE || (pExpr->op==TK_REGISTER && pExpr->op2==TK_VARIABLE) ){ Vdbe *v; int iBindVar = pExpr->iColumn; sqlite3VdbeSetVarmask(pParse->pVdbe, iBindVar); if( (v = pParse->pReprepare)!=0 ){ pVal = valueNew(db, &alloc); if( pVal ){ rc = sqlite3VdbeMemCopy((Mem*)pVal, &v->aVar[iBindVar-1]); if( rc==SQLITE_OK ){ sqlite3ValueApplyAffinity(pVal, affinity, ENC(db)); } pVal->db = pParse->db; *pbOk = 1; sqlite3VdbeMemStoreType((Mem*)pVal); } }else{ *pbOk = 0; } }else{ rc = valueFromExpr(db, pExpr, ENC(db), affinity, &pVal, &alloc); *pbOk = (pVal!=0); } assert( pVal==0 || pVal->db==db ); return rc; }
LONGBOW_TEST_CASE(Global, PARC_TreeRedBlack_Insert_Overwrite) { PARCTreeRedBlack *tree; tree = parcTreeRedBlack_Create(stringComp, keyFree, NULL, NULL, valueFree, NULL); parcTreeRedBlack_Insert(tree, keyNew("1"), valueNew("v1")); parcTreeRedBlack_Insert(tree, keyNew("2"), valueNew("v2")); parcTreeRedBlack_Insert(tree, keyNew("3"), valueNew("v3")); parcTreeRedBlack_Insert(tree, keyNew("3"), valueNew("v4")); parcTreeRedBlack_Insert(tree, keyNew("3"), valueNew("v5")); assertTrue(3 == parcTreeRedBlack_Size(tree), "Wrong size of tree should stay at 3"); parcTreeRedBlack_Destroy(&tree); }
void SoQtComposeTranslation::setValue_delta(double d_delta) { if (oldvalue != d_delta) { oldvalue = (float)d_delta; axis[index] = (float)d_delta; emit valueNew(d_delta); } }
LONGBOW_TEST_CASE(Global, PARC_TreeRedBlack_Insert_Destroy) { PARCTreeRedBlack *tree; tree = parcTreeRedBlack_Create(stringComp, keyFree, NULL, NULL, valueFree, NULL); void *value1 = valueNew("value 1"); void *key1 = keyNew("1"); void *value2 = valueNew("value 2"); void *key2 = keyNew("2"); void *value3 = valueNew("value 3"); void *key3 = keyNew("3"); parcTreeRedBlack_Insert(tree, key1, value1); parcTreeRedBlack_Insert(tree, key2, value2); parcTreeRedBlack_Insert(tree, key3, value3); parcTreeRedBlack_Destroy(&tree); }
bool wxRegKey::CopyValue(const wxString& szValue, wxRegKey& keyDst, const wxString& szValueNew) { wxString valueNew(szValueNew); if ( valueNew.empty() ) { // by default, use the same name valueNew = szValue; } switch ( GetValueType(szValue) ) { case Type_String: { wxString strVal; return QueryValue(szValue, strVal) && keyDst.SetValue(valueNew, strVal); } case Type_Dword: /* case Type_Dword_little_endian: == Type_Dword */ { long dwVal; return QueryValue(szValue, &dwVal) && keyDst.SetValue(valueNew, dwVal); } case Type_Binary: { wxMemoryBuffer buf; return QueryValue(szValue,buf) && keyDst.SetValue(valueNew,buf); } // these types are unsupported because I am not sure about how // exactly they should be copied and because they shouldn't // occur among the application keys (supposedly created with // this class) case Type_None: case Type_Expand_String: case Type_Dword_big_endian: case Type_Link: case Type_Multi_String: case Type_Resource_list: case Type_Full_resource_descriptor: case Type_Resource_requirements_list: default: wxLogError(_("Can't copy values of unsupported type %d."), GetValueType(szValue)); return false; } }
static DecimalExpr *decimalExprNew(double val) { DecimalExpr *e = (DecimalExpr *)malloc(sizeof(*e)); if (!e) return 0; #ifndef NDEBUG e->node.type = NT_DECIMAL_EXPR; #endif e->value = valueNew(VT_DOUBLE); if (!e->value) { free(e); return 0; } e->value->f = val; e->node.clean = decimalExprClean; e->node.interp = decimalExprInterp; return e; }
static IntExpr *intExprNew(int val) { IntExpr *e = (IntExpr *)malloc(sizeof(*e)); if (!e) return 0; #ifndef NDEBUG e->node.type = NT_INT_EXPR; #endif e->value = valueNew(VT_INT); if (!e->value) { free(e); return 0; } e->value->i = val; e->node.clean = intExprClean; e->node.interp = intExprInterp; return e; }
/* ** Extract a value from the supplied expression in the manner described ** above sqlite3ValueFromExpr(). Allocate the sqlite3_value object ** using valueNew(). ** ** If pCtx is NULL and an error occurs after the sqlite3_value object ** has been allocated, it is freed before returning. Or, if pCtx is not ** NULL, it is assumed that the caller will free any allocated object ** in all cases. */ static int valueFromExpr( sqlite3 *db, /* The database connection */ Expr *pExpr, /* The expression to evaluate */ u8 enc, /* Encoding to use */ u8 affinity, /* Affinity to use */ sqlite3_value **ppVal, /* Write the new value here */ struct ValueNewStat4Ctx *pCtx /* Second argument for valueNew() */ ){ int op; char *zVal = 0; sqlite3_value *pVal = 0; int negInt = 1; const char *zNeg = ""; int rc = SQLITE_OK; if( !pExpr ){ *ppVal = 0; return SQLITE_OK; } op = pExpr->op; /* op can only be TK_REGISTER if we have compiled with SQLITE_ENABLE_STAT4. ** The ifdef here is to enable us to achieve 100% branch test coverage even ** when SQLITE_ENABLE_STAT4 is omitted. */ #ifdef SQLITE_ENABLE_STAT3_OR_STAT4 if( op==TK_REGISTER ) op = pExpr->op2; #else if( NEVER(op==TK_REGISTER) ) op = pExpr->op2; #endif /* Handle negative integers in a single step. This is needed in the ** case when the value is -9223372036854775808. */ if( op==TK_UMINUS && (pExpr->pLeft->op==TK_INTEGER || pExpr->pLeft->op==TK_FLOAT) ){ pExpr = pExpr->pLeft; op = pExpr->op; negInt = -1; zNeg = "-"; } if( op==TK_STRING || op==TK_FLOAT || op==TK_INTEGER ){ pVal = valueNew(db, pCtx); if( pVal==0 ) goto no_mem; if( ExprHasProperty(pExpr, EP_IntValue) ){ sqlite3VdbeMemSetInt64(pVal, (i64)pExpr->u.iValue*negInt); }else{ zVal = sqlite3MPrintf(db, "%s%s", zNeg, pExpr->u.zToken); if( zVal==0 ) goto no_mem; sqlite3ValueSetStr(pVal, -1, zVal, SQLITE_UTF8, SQLITE_DYNAMIC); if( op==TK_FLOAT ) pVal->type = SQLITE_FLOAT; } if( (op==TK_INTEGER || op==TK_FLOAT ) && affinity==SQLITE_AFF_NONE ){ sqlite3ValueApplyAffinity(pVal, SQLITE_AFF_NUMERIC, SQLITE_UTF8); }else{ sqlite3ValueApplyAffinity(pVal, affinity, SQLITE_UTF8); } if( pVal->flags & (MEM_Int|MEM_Real) ) pVal->flags &= ~MEM_Str; if( enc!=SQLITE_UTF8 ){ rc = sqlite3VdbeChangeEncoding(pVal, enc); } }else if( op==TK_UMINUS ) { /* This branch happens for multiple negative signs. Ex: -(-5) */ if( SQLITE_OK==sqlite3ValueFromExpr(db,pExpr->pLeft,enc,affinity,&pVal) && pVal!=0 ){ sqlite3VdbeMemNumerify(pVal); if( pVal->u.i==SMALLEST_INT64 ){ pVal->flags &= MEM_Int; pVal->flags |= MEM_Real; pVal->r = (double)LARGEST_INT64; }else{ pVal->u.i = -pVal->u.i; } pVal->r = -pVal->r; sqlite3ValueApplyAffinity(pVal, affinity, enc); } }else if( op==TK_NULL ){ pVal = valueNew(db, pCtx); if( pVal==0 ) goto no_mem; } #ifndef SQLITE_OMIT_BLOB_LITERAL else if( op==TK_BLOB ){ int nVal; assert( pExpr->u.zToken[0]=='x' || pExpr->u.zToken[0]=='X' ); assert( pExpr->u.zToken[1]=='\'' ); pVal = valueNew(db, pCtx); if( !pVal ) goto no_mem; zVal = &pExpr->u.zToken[2]; nVal = sqlite3Strlen30(zVal)-1; assert( zVal[nVal]=='\'' ); sqlite3VdbeMemSetStr(pVal, sqlite3HexToBlob(db, zVal, nVal), nVal/2, 0, SQLITE_DYNAMIC); } #endif if( pVal ){ sqlite3VdbeMemStoreType(pVal); } *ppVal = pVal; return rc; no_mem: db->mallocFailed = 1; sqlite3DbFree(db, zVal); assert( *ppVal==0 ); #ifdef SQLITE_ENABLE_STAT3_OR_STAT4 if( pCtx==0 ) sqlite3ValueFree(pVal); #else assert( pCtx==0 ); sqlite3ValueFree(pVal); #endif return SQLITE_NOMEM; }