我試圖分割字符串這是一個SQL語句的WHERE子句與5個輸出陣列,其中下面的數據是每個索引下保持:分裂一個WHERE SQL子句成陣列
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方法類似的方式分割它,但由於其中的差異條款我在這方面遇到了困難。從環顧四周,我想我會更好地使用正則表達式,但無法找出需要的東西。任何幫助或方向將不勝感激。
爲什麼地球上,你會想要做這樣的事情? – LoztInSpace
雖然我無法回答您的問題,但是您需要解析SQL嗎?這不是一項微不足道的任務。你試圖解決什麼潛在的問題,你將如何處理標記化的SQL? – CodeCaster
它有什麼是BETWEEN,IN或一些子查詢? –