1. sqlite does not have the built-in function of ToUpper. It doesn't matter. We can create it;
2. sqlite cannot directly create user-defined functions. It cannot be easily created and used as in SQL server. It doesn't matter. We can still create it. After the creation is successful, we can still do what we like (such as batch update ).
Effect:
Var ss = JonseTest. SqlLiteHelper. GetSingle (out sError, "select ToUpper ('abccdsf ')"); // ABCcdsf
Var ss2 = JonseTest. SqlLiteHelper. GetSingle (out sError, "select GetChinesePYChar ('My a * % love your China')"); // Wa * % ANZG
Solution:
Step 1: Create a class ToUpper and 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 );
}
}
}
Step 2:
Var ss = JonseTest. SqlLiteHelper. GetSingle (out sError, "select ToUpper ('abccdsf ')"); // ABCcdsf
Var ss2 = JonseTest. SqlLiteHelper. GetSingle (out sError, "select GetChinesePYChar ('My a * % love your China')"); // Wa * % ANZG
Step 3:
Public static string ResetAllPointNameChinesePYChar ()
{
Return "update tblLinePoint set ChinesePYChar = GetChinesePYChar (Name )";
}
End.