本文整理匯總了C#中RDBMS_DBCORE.DbFunctionTools類的典型用法代碼示例。如果您正苦於以下問題:C# DbFunctionTools類的具體用法?C# DbFunctionTools怎麽用?C# DbFunctionTools使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
DbFunctionTools類屬於RDBMS_DBCORE命名空間,在下文中一共展示了DbFunctionTools類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: INSTR
public static DbValue INSTR(DbFunctionTools tools, DbFunctionArguments args)
{
string FunctionName = "INSTR";
args.EnsureMinCount(FunctionName, 2);
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());
}
DbType arg1type;
ByteSlice arg1 = args[1].Eval(out arg1type);
if (Types.IsNullValue(arg1))
{
return tools.AllocNullValue(); // Give a null, take a null.
}
if (arg1type.ID != DbTypeID.CHARS)
{
args.Expected(FunctionName, 0, "input CHAR(n), got " + arg1type.Name.ToUpper());
}
int startIndex = 0;
if (args.Length > 2)
{
DbType arg2type;
ByteSlice arg2 = args[2].Eval(out arg2type);
if (arg2type.ID != DbTypeID.INT)
{
args.Expected(FunctionName, 0, "input INT, got " + arg2type.Name.ToUpper());
}
if (!Types.IsNullValue(arg2))
{
startIndex = tools.GetInt(arg2);
}
}
mstring sentence = tools.GetString(arg0);
mstring word = tools.GetString(arg1);
int index = -1;
if (startIndex < sentence.Length)
{
if (startIndex > 0)
{
sentence = sentence.SubstringM(startIndex);
}
index = sentence.IndexOf(word);
if (index > -1)
{
index += startIndex;
}
}
return tools.AllocValue(index);
}
示例2: 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.");
}
}
}
示例3: 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];
}
}
示例4: REVERSE
public static DbValue REVERSE(DbFunctionTools tools, DbFunctionArguments args)
{
string FunctionName = "REVERSE";
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.CHARS)
{
args.Expected(FunctionName, 0, "input CHAR(n), got " + arg0type.Name.ToUpper());
}
mstring x = tools.GetString(arg0);
mstring r = mstring.Prepare();
for (int i = x.Length-1; i >= 0; i--)
{
r = r.AppendM(x.SubstringM(i, 1));
}
return tools.AllocValue(r);
}
示例5: 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.");
}
}
}
示例6: ADD_MONTHS
public static DbValue ADD_MONTHS(DbFunctionTools tools, DbFunctionArguments args)
{
string FunctionName = "ADD_MONTHS";
args.EnsureCount(FunctionName, 2);
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.DATETIME)
{
args.Expected(FunctionName, 0, "input DATETIME, got " + arg0type.Name.ToUpper());
}
DbType arg1type;
ByteSlice arg1 = args[1].Eval(out arg1type);
if (Types.IsNullValue(arg1))
{
return tools.AllocNullValue(); // Give a null, take a null.
}
if (arg1type.ID != DbTypeID.INT)
{
args.Expected(FunctionName, 0, "input INT, got " + arg1type.Name.ToUpper());
}
DateTime dt = tools.GetDateTime(arg0);
int months = tools.GetInt(arg1);
dt = dt.AddMonths(months);
return tools.AllocValue(dt);
}
示例7: 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.");
}
}
}
示例8: ROUND
public static DbValue ROUND(DbFunctionTools tools, DbFunctionArguments args)
{
string FunctionName = "ROUND";
args.EnsureCount(FunctionName, 2);
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.DOUBLE)
{
args.Expected(FunctionName, 0, "input DOUBLE, got " + arg0type.Name.ToUpper());
}
DbType arg1type;
ByteSlice arg1 = args[1].Eval(out arg1type);
if (arg1type.ID != DbTypeID.INT)
{
args.Expected(FunctionName, 1, "digits INT, got " + arg1type.Name.ToUpper());
}
int digits = tools.GetInt(arg1);
double x = tools.GetDouble(arg0);
x = Math.Round(x, digits);
return tools.AllocValue(x);
}
示例9: 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);
}
}
示例10: 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.");
}
}
}
示例11: 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();
}
示例12: NVL2
public static DbValue NVL2(DbFunctionTools tools, DbFunctionArguments args)
{
string FunctionName = "NVL2";
args.EnsureCount(FunctionName, 3);
DbType arg0type;
ByteSlice arg0 = args[0].Eval(out arg0type);
DbType arg1type;
ByteSlice arg1 = args[1].Eval(out arg1type);
DbType arg2type;
ByteSlice arg2 = args[2].Eval(out arg2type);
if (arg0type.ID != arg1type.ID)
{
args.Expected(FunctionName, 0, "input " + arg0type.Name.ToString() + ", got " + arg1type.Name.ToUpper());
}
if (arg0type.ID != arg2type.ID)
{
args.Expected(FunctionName, 0, "input " + arg0type.Name.ToString() + ", got " + arg2type.Name.ToUpper());
}
if (Types.IsNullValue(arg0))
{
return args[2];
}
else
{
return args[1];
}
}
示例13: DbFunctions_NVL2
public static void DbFunctions_NVL2()
{
DbFunctionTools tools = new DbFunctionTools();
{
Console.WriteLine("Testing DbFunctions.NVL2(DateTime)...");
List<DbValue> args = new List<DbValue>();
DateTime dt = DateTime.Parse("12/1/2000 10:00:00 AM");
DateTime ifnull = DateTime.Parse("12/11/2000 10:00:00 AM");
DateTime notnull = DateTime.Parse("12/14/2000 10:00:00 AM");
args.Add(tools.AllocValue(dt));
args.Add(tools.AllocValue(notnull));
args.Add(tools.AllocValue(ifnull));
DbFunctionArguments fargs = new DbFunctionArguments(args);
DbValue valOutput = DbFunctions.NVL2(tools, fargs);
ByteSlice bs = valOutput.Eval();
DateTime output = tools.GetDateTime(bs);
DateTime expected = notnull;
if (expected != output)
{
throw new Exception("DbFunctions.NVL2(DateTime) has failed. Expected result: " + expected.ToString() + ", but received: " + output.ToString());
}
else
{
Console.WriteLine("Expected results received.");
}
}
{
Console.WriteLine("Testing DbFunctions.NVL2(DateTime)...");
List<DbValue> args = new List<DbValue>();
byte[] buf = new byte[9];
buf[0] = 1; //is null
DateTime ifnull = DateTime.Parse("12/11/2000 10:00:00 AM");
DateTime notnull = DateTime.Parse("12/14/2000 10:00:00 AM");
args.Add(tools.AllocValue(ByteSlice.Prepare(buf), DbType.Prepare("DateTime", 9)));
args.Add(tools.AllocValue(notnull));
args.Add(tools.AllocValue(ifnull));
DbFunctionArguments fargs = new DbFunctionArguments(args);
DbValue valOutput = DbFunctions.NVL2(tools, fargs);
ByteSlice bs = valOutput.Eval();
DateTime output = tools.GetDateTime(bs);
DateTime expected = ifnull;
if (expected != output)
{
throw new Exception("DbFunctions.NVL2(DateTime) has failed. Expected result: " + expected.ToString() + ", but received: " + output.ToString());
}
else
{
Console.WriteLine("Expected results received.");
}
}
}
示例14: DbFunctions_SYSDATE
public static void DbFunctions_SYSDATE()
{
DbFunctionTools tools = new DbFunctionTools();
//String,Int32.
{
Console.WriteLine("Testing DbFunctions.SYSDATE...");
DbValue valOutput = DbFunctions.SYSDATE(tools, new DbFunctionArguments());
ByteSlice bs = valOutput.Eval();
DateTime output = tools.GetDateTime(bs);
DateTime expected = DateTime.Now;
TimeSpan sp = output - expected;
if (sp.TotalMinutes > 5)
{
throw new Exception("DbFunctions.SYSDATE has failed. Expected result: " + expected.ToString() + ", but received: " + output.ToString());
}
else
{
Console.WriteLine("Expected results received.");
}
}
}
示例15: DbFunctions_UPPER
public static void DbFunctions_UPPER()
{
DbFunctionTools tools = new DbFunctionTools();
//String,Int32.
{
Console.WriteLine("Testing DbFunctions.UPPER(String)...");
List<DbValue> args = new List<DbValue>();
args.Add(tools.AllocValue(mstring.Prepare("hello world")));
DbFunctionArguments fargs = new DbFunctionArguments(args);
DbValue valOutput = DbFunctions.UPPER(tools, fargs);
ByteSlice bs = valOutput.Eval();
mstring output = tools.GetString(bs);
mstring expected = mstring.Prepare("HELLO WORLD");
if (expected != output)
{
throw new Exception("DbFunctions.UPPER(String) has failed. Expected result: " + expected.ToString() + ", but received: " + output.ToString());
}
else
{
Console.WriteLine("Expected results received.");
}
}
}