我需要你的帮助。
我想编写一个函数来检测和确定要在 SQL 字符串中使用的运算符 (LIKE/=)
例子:
var input_string = "SELECT * from table WHERE [FIRSTNAME]"
var input_text = document.GetElementbyId('firstname').value
如果给定的 input_text 满足 4 种可能组合中的 1 种,则运算符值为“LIKE”,否则为等号 (=)
1.) At the start of the string: %firstname
2.) somewhere in the string itself: first%name
3.) At the end of the string: firstname%
4.) at both ends of the string: %firstname%
例子:
var output_string = input_string + analyze(input_text) '+input_text+'
var output_string 示例:
SELECT * FROM TABLE WHERE [FIRSTNAME] LIKE '%firstname%'
SELECT * FROM TABLE WHERE [FIRSTNAME] LIKE '%first%name'
SELECT * FROM TABLE WHERE [FIRSTNAME] LIKE 'firstname%'
SELECT * FROM TABLE WHERE [FIRSTNAME] LIKE '%firstname%'
别的
SELECT * FROM TABLE WHERE [FIRSTNAME] = 'firstname'