本文整理匯總了C#中RDBMS_DBCORE.DbFunctionTools.AllocValue方法的典型用法代碼示例。如果您正苦於以下問題:C# DbFunctionTools.AllocValue方法的具體用法?C# DbFunctionTools.AllocValue怎麽用?C# DbFunctionTools.AllocValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類RDBMS_DBCORE.DbFunctionTools
的用法示例。
在下文中一共展示了DbFunctionTools.AllocValue方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: DbFunctions_ADD_MONTHS
public static void DbFunctions_ADD_MONTHS()
{
DbFunctionTools tools = new DbFunctionTools();
//String,Int32.
{
Console.WriteLine("Testing DbFunctions.ADD_MONTHS...");
List<DbValue> args = new List<DbValue>();
DateTime dt = DateTime.Now;
int months = 9;
args.Add(tools.AllocValue(dt));
args.Add(tools.AllocValue(months));
DbFunctionArguments fargs = new DbFunctionArguments(args);
DbValue valOutput = DbFunctions.ADD_MONTHS(tools, fargs);
ByteSlice bs = valOutput.Eval();
DateTime output = tools.GetDateTime(bs);
DateTime expected = dt.AddMonths(months);
if (expected != output)
{
throw new Exception("DbFunctions.ADD_MONTHS has failed. Expected result: " + expected.ToString() + ", but received: " + output.ToString());
}
else
{
Console.WriteLine("Expected results received.");
}
}
}
示例2: DbFunctions_CONCAT
public static void DbFunctions_CONCAT()
{
DbFunctionTools tools = new DbFunctionTools();
//String,Int32.
{
Console.WriteLine("Testing DbFunctions.CONCAT(String,String)...");
List<DbValue> args = new List<DbValue>();
args.Add(tools.AllocValue(mstring.Prepare("hello ")));
args.Add(tools.AllocValue(mstring.Prepare("world")));
DbFunctionArguments fargs = new DbFunctionArguments(args);
DbValue valOutput = DbFunctions.CONCAT(tools, fargs);
ByteSlice bs = valOutput.Eval();
mstring output = tools.GetString(bs);
mstring expected = mstring.Prepare("hello world");
if (expected != output)
{
throw new Exception("DbFunctions.CONCAT(String,String) has failed. Expected result: " + expected.ToString() + ", but received: " + output.ToString());
}
else
{
Console.WriteLine("Expected results received.");
}
}
}
示例3: DbFunctions_RIGHT
public static void DbFunctions_RIGHT()
{
DbFunctionTools tools = new DbFunctionTools();
//String,Int32.
{
Console.WriteLine("Testing DbFunctions.RIGHT(String,Int32)...");
mstring input = Utils.GenString(100);
List<DbValue> args = new List<DbValue>();
args.Add(tools.AllocValue(input));
args.Add(tools.AllocValue(5));
DbFunctionArguments fargs = new DbFunctionArguments(args);
DbValue valOutput = DbFunctions.RIGHT(tools, fargs);
ByteSlice bs = valOutput.Eval();
mstring output = tools.GetString(bs);
string str = input.ToString();
string expected = str.Substring(str.Length - 5, 5);
if (expected != output.ToString())
{
throw new Exception("DbFunctions.RIGHT(String,Int32) has failed. Expected result: " + expected.ToString() + ", but received: " + output.ToString());
}
else
{
Console.WriteLine("Expected results received.");
}
}
}
示例4: DbFunctions_PATINDEX
public static void DbFunctions_PATINDEX()
{
DbFunctionTools tools = new DbFunctionTools();
//String,Int32.
{
Console.WriteLine("Testing DbFunctions.PATINDEX(String, string)...");
List<DbValue> args = new List<DbValue>();
args.Add(tools.AllocValue(mstring.Prepare("%ap_pl[e]%")));
args.Add(tools.AllocValue(mstring.Prepare("red is ap5ple, my favourite.")));
DbFunctionArguments fargs = new DbFunctionArguments(args);
DbValue valOutput = DbFunctions.PATINDEX(tools, fargs);
ByteSlice bs = valOutput.Eval();
int output = tools.GetInt(bs);
int expected = 7;
if (expected != output)
{
throw new Exception("DbFunctions.PATINDEX(String) has failed. Expected result: " + expected.ToString() + ", but received: " + output.ToString());
}
else
{
Console.WriteLine("Expected results received.");
}
}
}
示例5: DbFunctions_CHARINDEX
public static void DbFunctions_CHARINDEX()
{
DbFunctionTools tools = new DbFunctionTools();
//String,Int32.
{
Console.WriteLine("Testing DbFunctions.CHARINDEX(char(n), char(n)...");
mstring word = mstring.Prepare("apple");
mstring sentence = mstring.Prepare("Red is apple");
List<DbValue> args = new List<DbValue>();
args.Add(tools.AllocValue(word));
args.Add(tools.AllocValue(sentence));
DbFunctionArguments fargs = new DbFunctionArguments(args);
DbValue valOutput = DbFunctions.CHARINDEX(tools, fargs);
ByteSlice bs = valOutput.Eval();
int output = tools.GetInt(bs);
int expected = 7;
if (expected != output)
{
throw new Exception("DbFunctions.CHARINDEX(char(n), char(n) has failed. Expected result: " + expected.ToString() + ", but received: " + output.ToString());
}
else
{
Console.WriteLine("Expected results received.");
}
}
{
Console.WriteLine("Testing DbFunctions.CHARINDEX(char(n), char(n), Int32...");
mstring word = mstring.Prepare("apple");
mstring sentence = mstring.Prepare("Red is apple, or more apples.");
int startIndex = 8;
List<DbValue> args = new List<DbValue>();
args.Add(tools.AllocValue(word));
args.Add(tools.AllocValue(sentence));
args.Add(tools.AllocValue(startIndex));
DbFunctionArguments fargs = new DbFunctionArguments(args);
DbValue valOutput = DbFunctions.CHARINDEX(tools, fargs);
ByteSlice bs = valOutput.Eval();
int output = tools.GetInt(bs);
int expected = 22;
if (expected != output)
{
throw new Exception("DbFunctions.CHARINDEX(char(n), char(n), Int32 has failed. Expected result: " + expected.ToString() + ", but received: " + output.ToString());
}
else
{
Console.WriteLine("Expected results received.");
}
}
}
示例6: DbFunctions_SUBSTRING
public static void DbFunctions_SUBSTRING()
{
DbFunctionTools tools = new DbFunctionTools();
//String,Int32.
{
Console.WriteLine("Testing DbFunctions.SUBSTRING(String, int, int)...");
List<DbValue> args = new List<DbValue>();
args.Add(tools.AllocValue(mstring.Prepare("HELLO WORLD")));
int si = 6;
int len = 5;
args.Add(tools.AllocValue(si));
args.Add(tools.AllocValue(len));
DbFunctionArguments fargs = new DbFunctionArguments(args);
DbValue valOutput = DbFunctions.SUBSTRING(tools, fargs);
ByteSlice bs = valOutput.Eval();
mstring output = tools.GetString(bs);
mstring expected = mstring.Prepare("WORLD");
if (expected != output)
{
throw new Exception("DbFunctions.SUBSTRING(String, int, int) has failed. Expected result: " + expected.ToString() + ", but received: " + output.ToString());
}
else
{
Console.WriteLine("Expected results received.");
}
}
}
示例7: SPACE
public static DbValue SPACE(DbFunctionTools tools, DbFunctionArguments args)
{
string FunctionName = "SPACE";
args.EnsureCount(FunctionName, 1);
DbType arg0type;
ByteSlice arg0 = args[0].Eval(out arg0type);
if (Types.IsNullValue(arg0))
{
return tools.AllocNullValue(); // Give a null, take a null.
}
if (arg0type.ID != DbTypeID.INT)
{
args.Expected(FunctionName, 0, "input INT, got " + arg0type.Name.ToUpper());
return null;
}
int len = tools.GetInt(arg0);
if (len < 1)
{
return tools.AllocValue(mstring.Prepare(""));
}
else
{
mstring s = mstring.Prepare();
for (int i = 0; i < len; i++)
{
s = s.AppendM(" ");
}
return tools.AllocValue(s);
}
}
示例8: NULLIF
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];
}
}
示例9: SUBSTRING
public static DbValue SUBSTRING(DbFunctionTools tools, DbFunctionArguments args)
{
string FunctionName = "SUBSTRING";
args.EnsureCount(FunctionName, 3);
DbType arg0type;
ByteSlice arg0 = args[0].Eval(out arg0type);
if (Types.IsNullValue(arg0))
{
return tools.AllocNullValue(); // Give a null, take a null.
}
if (arg0type.ID != DbTypeID.CHARS)
{
args.Expected(FunctionName, 0, "input CHAR(n), got " + arg0type.Name.ToUpper());
return null;
}
DbType arg1type;
ByteSlice arg1 = args[1].Eval(out arg1type);
if (arg1type.ID != DbTypeID.INT)
{
args.Expected(FunctionName, 1, "count INT, got " + arg1type.Name.ToUpper());
return null;
}
DbType arg2type;
ByteSlice arg2 = args[2].Eval(out arg2type);
if (arg2type.ID != DbTypeID.INT)
{
args.Expected(FunctionName, 1, "count INT, got " + arg2type.Name.ToUpper());
return null;
}
mstring x = tools.GetString(arg0);
int startIndex = tools.GetInt(arg1);
if (startIndex < 0)
{
startIndex = 0;
}
int len = tools.GetInt(arg2);
if (len < 0)
{
throw new ArgumentException(FunctionName + " length cannot be negative");
}
if (startIndex + len > x.Length)
{
return tools.AllocValue(mstring.Prepare());
}
else
{
mstring sub = x.SubstringM(startIndex, len);
return tools.AllocValue(sub);
}
}
示例10: SUM
public static DbValue SUM(DbFunctionTools tools, DbAggregatorArguments args)
{
string AggregatorName = "SUM";
double sumd = 0;
int sumi = 0;
long suml = 0;
DbType arg0type = DbType.PrepareNull();
for (int iarg = 0; iarg < args.Length; iarg++)
{
args[iarg].EnsureCount(AggregatorName, 1);
ByteSlice arg0 = args[iarg][0].Eval(out arg0type);
if (!Types.IsNullValue(arg0)) //ignore null
{
switch (arg0type.ID)
{
case DbTypeID.INT:
sumi += tools.GetInt(arg0);
break;
case DbTypeID.LONG:
suml += tools.GetLong(arg0);
break;
case DbTypeID.DOUBLE:
sumd += tools.GetDouble(arg0);
break;
default:
args[iarg].Expected(AggregatorName, 0, "input INT, LONG or DOUBLE, got " + arg0type.Name.ToUpper());
return null; // Doesn't reach here.
}
}
}
if (args.Length > 0)
{
switch (arg0type.ID)
{
case DbTypeID.INT:
return tools.AllocValue(sumi);
break;
case DbTypeID.LONG:
return tools.AllocValue(suml);
break;
case DbTypeID.DOUBLE:
return tools.AllocValue(sumd);
break;
}
}
return tools.AllocValue(sumi);
}
示例11: DbFunctions_NVL
public static void DbFunctions_NVL()
{
DbFunctionTools tools = new DbFunctionTools();
{
Console.WriteLine("Testing DbFunctions.NVL(DateTime)...");
List<DbValue> args = new List<DbValue>();
DateTime dt = DateTime.Parse("12/1/2000 10:00:00 AM");
args.Add(tools.AllocValue(dt));
args.Add(tools.AllocValue(DateTime.Parse("12/12/2000 10:00:00 AM")));
DbFunctionArguments fargs = new DbFunctionArguments(args);
DbValue valOutput = DbFunctions.NVL(tools, fargs);
ByteSlice bs = valOutput.Eval();
DateTime output = tools.GetDateTime(bs);
DateTime expected = DateTime.Parse("12/1/2000 10:00:00 AM");
if (expected != output)
{
throw new Exception("DbFunctions.NVL(DateTime) has failed. Expected result: " + expected.ToString() + ", but received: " + output.ToString());
}
else
{
Console.WriteLine("Expected results received.");
}
}
{
Console.WriteLine("Testing DbFunctions.NVL(DateTime)...");
List<DbValue> args = new List<DbValue>();
byte[] buf = new byte[9];
buf[0] = 1; //is null
args.Add(tools.AllocValue(ByteSlice.Prepare(buf), DbType.Prepare("DateTime", 9)));
args.Add(tools.AllocValue(DateTime.Parse("1/1/2009 10:00:00 AM")));
DbFunctionArguments fargs = new DbFunctionArguments(args);
DbValue valOutput = DbFunctions.NVL(tools, fargs);
ByteSlice bs = valOutput.Eval();
DateTime output = tools.GetDateTime(bs);
DateTime expected = DateTime.Parse("1/1/2009 10:00:00 AM");
if (expected != output)
{
throw new Exception("DbFunctions.NVL(DateTime) has failed. Expected result: " + expected.ToString() + ", but received: " + output.ToString());
}
else
{
Console.WriteLine("Expected results received.");
}
}
}
示例12: DbFunctions_INSTR
public static void DbFunctions_INSTR()
{
DbFunctionTools tools = new DbFunctionTools();
{
Console.WriteLine("Testing DbFunctions.SUBSTR(String,String)...");
List<DbValue> args = new List<DbValue>();
args.Add(tools.AllocValue(mstring.Prepare("apple is red")));
args.Add(tools.AllocValue(mstring.Prepare("red")));
DbFunctionArguments fargs = new DbFunctionArguments(args);
DbValue valOutput = DbFunctions.INSTR(tools, fargs);
ByteSlice bs = valOutput.Eval();
int output = tools.GetInt(bs);
int expected = 9;
if (expected != output)
{
throw new Exception("DbFunctions.SUBSTR(String,String) has failed. Expected result: " + expected.ToString() + ", but received: " + output.ToString());
}
else
{
Console.WriteLine("Expected results received.");
}
}
{
Console.WriteLine("Testing DbFunctions.SUBSTR(String,String, Int32)...");
List<DbValue> args = new List<DbValue>();
args.Add(tools.AllocValue(mstring.Prepare("apple is red")));
args.Add(tools.AllocValue(mstring.Prepare("red")));
int startindex = 2;
args.Add(tools.AllocValue(startindex));
DbFunctionArguments fargs = new DbFunctionArguments(args);
DbValue valOutput = DbFunctions.INSTR(tools, fargs);
ByteSlice bs = valOutput.Eval();
int output = tools.GetInt(bs);
int expected = 9;
if (expected != output)
{
throw new Exception("DbFunctions.SUBSTR(String,String, Int32) has failed. Expected result: " + expected.ToString() + ", but received: " + output.ToString());
}
else
{
Console.WriteLine("Expected results received.");
}
}
}
示例13: LESSEREQUAL
public static DbValue LESSEREQUAL(DbFunctionTools tools, DbFunctionArguments args)
{
DbValue dbvcompare = COMPARE(tools, args);
DbType typecompare;
ByteSlice bsresult = dbvcompare.Eval(out typecompare);
if (DbTypeID.INT != typecompare.ID)
{
return tools.AllocValue(bsresult, typecompare);
}
int compare = tools.GetInt(bsresult);
return tools.AllocValue(compare <= 0 ? 1 : 0);
}
示例14: Conv_String
ByteSlice Conv_String(ByteSlice value, int ResultSize, DbFunctionTools tools)
{
mstring x = tools.GetString(value);
x = x.ToUpperM();
DbValue v = tools.AllocValue(x, ResultSize);
return v.Eval();
}
示例15: DbFunctions_RAND
public static void DbFunctions_RAND()
{
DbFunctionTools tools = new DbFunctionTools();
Random rnd = new Random();
{
Console.WriteLine("Testing DbFunctions.RAND(Int32)...");
int input = rnd.Next(Int32.MinValue, Int32.MaxValue);
List<DbValue> args = new List<DbValue>();
args.Add(tools.AllocValue(input));
DbFunctionArguments fargs = new DbFunctionArguments(args);
DbValue valOutput = DbFunctions.RAND(tools, fargs);
ByteSlice bs = valOutput.Eval();
double output = tools.GetDouble(bs);
Console.WriteLine("Expected results received: {0}", output);
}
{
Console.WriteLine("Testing DbFunctions.RAND()...");
List<DbValue> args = new List<DbValue>();
DbFunctionArguments fargs = new DbFunctionArguments(args);
DbValue valOutput = DbFunctions.RAND(tools, fargs);
ByteSlice bs = valOutput.Eval();
double output = tools.GetDouble(bs);
Console.WriteLine("Expected results received: {0}", output);
}
}