我正在尝试将SQL语句的WHERE子句拆分为一个包含5个输出的数组,其中每个索引下保存以下数据:
0 - The initial clauses (WHERE/AND/OR) plus any open brackets. e.g "AND((("
1 - Either the table the first clause comes from or "VALUE" if its a value. e.g. "transactions".
2 - The field name or value. e.g. "id"
3 - The joining value. e.g. >
4 - Either the table the second clause comes from or "VALUE" if its a value. e.g. "transactions".
5 - The field name or value. e.g. "id"
6 - Any closing brackets. e.g. ")))"
例如循环以下字符串将输出以下数组:
WHERE transactions.status_code= 'AFA 2'
AND (transactions.supp_ref = supplier.supp_ref
AND supplier.supp_addr_ref = address.addr_ref)
OR transactions.user_code = user.user_code
output[0] = "WHERE"
output[1] = "transactions"
output[2] = "status_code"
output[3] = "="
output[4] = "VALUE'
output[5] = "AFA 2"
output[6] = ""
output[0] = "AND("
output[1] = "transactions"
output[2] = "supp_ref"
output[3] = "="
output[4] = "supplier"
output[5] = "supp_ref"
output[6] = ""
output[0] = "AND"
output[1] = "supplier"
output[2] = "supp_addr_ref"
output[3] = "="
output[4] = "address"
output[5] = "addr_ref"
output[6] = ")"
output[0] = "OR"
output[1] = "transactions"
output[2] = "user_code"
output[3] = "="
output[4] = "user"
output[5] = "user_code"
output[6] = ""
对于SQL语句的其余部分,我已经成功地使用String.Split方法进行了类似的拆分,但是由于where从句的变化,我在处理这部分时遇到了困难。从周围的环境来看,我认为最好使用正则表达式,但无法确定所需内容。任何帮助或指导将不胜感激。