public static DbValue NULLIF(DbFunctionTools tools, DbFunctionArguments args) { string FunctionName = "NULLIF"; args.EnsureCount(FunctionName, 2); DbType arg0type; ByteSlice arg0 = args[0].Eval(out arg0type); ImmediateValue argval = null; argval = tools.AllocValue(arg0type.ID); argval.SetValue(arg0); DbFunctionArguments compareargs = new DbFunctionArguments(new DbValue[2]); compareargs[0] = argval; compareargs[1] = args[1]; DbValue result = COMPARE(tools, compareargs); int iresult = tools.GetInt(result); if (iresult == 0) { List <byte> buf = tools.AllocBuffer(arg0type.Size); buf.Add(1); for (int i = 0; i < arg0type.Size - 1; i++) { buf.Add(0); } return(tools.AllocValue(ByteSlice.Prepare(buf), arg0type)); } else { return(args[0]); } }
public static DbValue MAX(DbFunctionTools tools, DbAggregatorArguments args) { string AggregatorName = "MAX"; DbValue highest = null; DbValue nullest = null; DbFunctionArguments compareargs = new DbFunctionArguments(new DbValue[2]); ImmediateValue argval = null; for (int iarg = 0; iarg < args.Length; iarg++) { args[iarg].EnsureCount(AggregatorName, 1); DbType arg0type; ByteSlice arg0 = args[iarg][0].Eval(out arg0type); if (Types.IsNullValue(arg0)) { if (null == nullest) { nullest = tools.AllocValue(arg0, arg0type); } } else { if (null == argval) { argval = tools.AllocValue(arg0type.ID); } argval.SetValue(arg0); compareargs[0] = argval; compareargs[1] = highest; if (null == highest || tools.GetInt(DbFunctions.COMPARE(tools, compareargs)) > 0) { highest = argval; // Keep this one. argval = null; // New one next time. } } } if (null == highest) { if (null == nullest) { return(tools.AllocNullValue()); } return(nullest); } return(highest); }
public ImmediateValue AllocValue(DbTypeID typeID) { if (curval >= values.Count) { ImmediateValue val = new ImmediateValue(null, ByteSlice.Prepare(), DbType.Prepare(0, typeID)); values.Add(val); curval++; return(val); } else { ImmediateValue val = values[curval++]; val._value = ByteSlice.Prepare(); val._type = DbType.Prepare(0, typeID); return(val); } }
public DbValue AllocValue(ByteSlice value, DbType type) { if (curval >= values.Count) { ImmediateValue val = new ImmediateValue(null, value, type); values.Add(val); curval++; return(val); } else { ImmediateValue val = values[curval++]; val._value = value; val._type = type; return(val); } }
public ImmediateValue AllocValue(DbTypeID typeID) { if (curval >= values.Count) { ImmediateValue val = new ImmediateValue(null, ByteSlice.Prepare(), DbType.Prepare(0, typeID)); values.Add(val); curval++; return val; } else { ImmediateValue val = values[curval++]; val._value = ByteSlice.Prepare(); val._type = DbType.Prepare(0, typeID); return val; } }
public DbValue AllocValue(ByteSlice value, DbType type) { if (curval >= values.Count) { ImmediateValue val = new ImmediateValue(null, value, type); values.Add(val); curval++; return val; } else { ImmediateValue val = values[curval++]; val._value = value; val._type = type; return val; } }