1,sqlite 沒有 ToUpper 的自帶函數。 沒關系,我們可以創建它;
2,sqlite 不能直接創建自定義函數,不能像 sql server中那樣方便創建並使用。沒關系,我們照樣可以創建它,創建成功後,我們照樣可以隨心所欲(比如 批量更新等)。
效果:
var ss = JonseTest.SqlLiteHelper.GetSingle(out sError, "select ToUpper('ABCcdsf')"); // ABCCDSF
var ss2 = JonseTest.SqlLiteHelper.GetSingle(out sError, "select GetChinesePYChar('我a*%愛你中國')"); // Wa*%ANZG
方案:
step1: 創建類 ToUpper 和 GetChinesePYChar
[csharp]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SQLite;
namespace MetroGuide
{
[SQLiteFunction(Name = "ToUpper", Arguments = 1, FuncType = FunctionType.Scalar)]
public class ToUpper : SQLiteFunction
{
public override object Invoke(object[] args)
{
return args[0].ToString().ToUpper();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SQLite;
namespace MetroGuide
{
[SQLiteFunction(Name = "ToUpper", Arguments = 1, FuncType = FunctionType.Scalar)]
public class ToUpper : SQLiteFunction
{
public override object Invoke(object[] args)
{
return args[0].ToString().ToUpper();
}
}
}
[csharp]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SQLite;
namespace MetroGuide
{
[SQLiteFunction(Name = "GetChinesePYChar", Arguments = 1, FuncType = FunctionType.Scalar)]
public class GetChinesePYChar : SQLiteFunction
{
public override object Invoke(object[] args)
{
string sOrigion = args[0].ToString();
return Common.GetPYString(sOrigion);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SQLite;
namespace MetroGuide
{
[SQLiteFunction(Name = "GetChinesePYChar", Arguments = 1, FuncType = FunctionType.Scalar)]
public class GetChinesePYChar : SQLiteFunction
{
public override object Invoke(object[] args)
{
string sOrigion = args[0].ToString();
return Common.GetPYString(sOrigion);
}
}
}
step2:
var ss = JonseTest.SqlLiteHelper.GetSingle(out sError, "select ToUpper('ABCcdsf')"); // ABCCDSF
var ss2 = JonseTest.SqlLiteHelper.GetSingle(out sError, "select GetChinesePYChar('我a*%愛你中國')"); // Wa*%ANZG
step3:
public static string ResetAllPointNameChinesePYChar()
{
return "update tblLinePoint set ChinesePYChar=GetChinesePYChar(Name)";
}
結束。