zoukankan
html css js c++ java
拼音查询生成SQL条件的类
拼音查询生成SQL条件的类
public
class
SQLPingYing
{
private
static
string
[] startChars
=
{
"
啊
"
,
"
芭
"
,
"
擦
"
,
"
搭
"
,
"
蛾
"
,
"
发
"
,
"
噶
"
,
"
哈
"
,
"
击
"
,
"
击
"
,
"
喀
"
,
"
垃
"
,
"
妈
"
,
"
拿
"
,
"
哦
"
,
"
啪
"
,
"
期
"
,
"
然
"
,
"
撒
"
,
"
塌
"
,
"
挖
"
,
"
挖
"
,
"
挖
"
,
"
昔
"
,
"
压
"
,
"
匝
"
}
;
private
static
string
[] endChars
=
{
"
澳
"
,
"
怖
"
,
"
错
"
,
"
堕
"
,
"
贰
"
,
"
咐
"
,
"
过
"
,
"
祸
"
,
"
啊
"
,
"
骏
"
,
"
阔
"
,
"
络
"
,
"
穆
"
,
"
诺
"
,
"
沤
"
,
"
瀑
"
,
"
群
"
,
"
弱
"
,
"
所
"
,
"
唾
"
,
"
啊
"
,
"
啊
"
,
"
误
"
,
"
迅
"
,
"
孕
"
,
"
座
"
}
;
/**/
///
<summary>
///
根据字符和对应的中文字符,转成SQL查询条件
///
</summary>
///
<param name="cChar">
要转化的字符,[A-Z]
</param>
///
<param name="strFieldName">
条件左值
</param>
///
<returns>
SQL条件
</returns>
///
<remarks>
Sxf 2001-1-4 ***** JY 2002-1-4
</remarks>
public
static
string
GetCharCondition(
char
cChar,
string
strFieldName)
{
string
strWord;
int
Index
=
(
int
)(
char
.ToUpper(cChar))
-
(
int
)
'
A
'
;
if
(Index
>=
0
&&
Index
<
26
)
strWord
=
startChars[Index];
else
strWord
=
startChars[
0
];
//
return string.Format("(({0}>='{1}' AND {0}<'[') OR ({0} >= '{3}' AND {0} < '{{') OR {0}>='{2}')",
//
strFieldName, char.ToUpper(cChar), strWord, char.ToLower(cChar));
return
string
.Format(
"
(({0} >= '{3}' AND {0} <= 'zzzzzzzz') OR {0}>='{2}')
"
,
strFieldName,
char
.ToUpper(cChar), strWord,
char
.ToLower(cChar));
}
/**/
///
<summary>
///
将指定字段值的每个字符分割,这样可以生成同音查询的SQL
///
</summary>
///
<param name="fieldName">
字段名
</param>
///
<param name="fieldValue">
字段值
</param>
///
<returns>
生成的可以进行同音查询的SQL
</returns>
public
static
string
GetCharFullCondition(
string
fieldName,
string
fieldValue)
{
StringBuilder sql
=
new
StringBuilder(
1024
);
int
i
=
1
;
foreach
(
char
c
in
fieldValue)
{
if
(i
>
1
)
sql.Append(
"
AND
"
);
int
index
=
(
int
)(
char
.ToUpper(c))
-
(
int
)
'
A
'
;
string
startWord, endWord;
if
(index
>=
0
&&
index
<
26
)
{
startWord
=
startChars[index];
endWord
=
endChars[index];
}
else
{
startWord
=
startChars[
0
];
endWord
=
endChars[
0
];
}
string
subStr
=
String.Format(
"
SUBSTRING({0}, {1}, {2})
"
, fieldName, i,
1
);
sql.AppendFormat(
"
({0} BETWEEN '{1}' AND '{2}')
"
, subStr, startWord, endWord);
++
i;
}
return
sql.ToString();
}
}
查看全文
相关阅读:
遇见SQL(2)
遇见SQL(1)
JAVA自学笔记(10)—Stream流、方法引用
JAVA自学笔记(9)——网络通信、函数式接口
JAVA自学笔记(7)—文件
JAVA自学笔记(6)—异常、线程、函数式编程
Python--模块Module
Python--软件目录结构
Python--迭代器
Python--生成器
原文地址:https://www.cnblogs.com/skyblue/p/951691.html
最新文章
【机器学习笔记】ID3构建决策树
【深度学习】神经网络入门
【机器学习笔记】朴素贝叶斯_分类评论示例
WPF后台代码实现TextBlock滚动条
基本数据类型、类型转换
常量、变量
注释、关键字、标识符
二、Markdown篇
一、Typora篇
socketserver并发服务
热门文章
验证客户端的合法性
基于TCP协议传输文件
最简单的网络通讯
网络基本概念
导入的模板
一些内置的魔术方法
两个装饰函数
反射
JDBC快速入门
遇见SQL(3)
Copyright © 2011-2022 走看看