Special Character escape for sqlite

Source: Internet
Author: User
For special escape characters of sqlite, select * fromtablewherenumberlike % escape... some special characters need to be escaped when the sqlite3 database is searching. The specific escape is as follows:

Special Character escape for sqlite select * fromtablewhere number like %/% escape /... when the sqlite3 database is searching, some special characters need to be escaped. The specific escape is as follows: /-//-[-/[]-/] %-/_ (-/()-/) www.2cto.com note that special words

Special Character escape for sqlite

Select * fromtablewhere number like '%/%' escape '/'...

When the sqlite3 database is searching, some special characters need to be escaped. The specific escape is as follows:

/-> //

'->''

[-> /[

]->/]

%->/%

&-> /&

_-> /_

(-> /(

)-> /)

Www.2cto.com

Note that special characters do not use the Backslash "\" to indicate escape characters.

01

Public static String sqliteEscape (String keyWord ){

02

KeyWord = keyWord. replace ("/","//");

03

KeyWord = keyWord. replace ("'","''");

04

KeyWord = keyWord. replace ("[","/[");

05

KeyWord = keyWord. replace ("]", "/]");

06

KeyWord = keyWord. replace ("%", "/% ");

07

KeyWord = keyWord. replace ("&","/&");

08

KeyWord = keyWord. replace ("_","/_");

09

KeyWord = keyWord. replace ("(","/(");

10

KeyWord = keyWord. replace (")","/)");

11

Return keyWord;

12

}

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.