C # register and use sqlite udfs

Source: Internet
Author: User

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.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.