2012-04-10 2 views
0

나는 일반적으로 이와 같이 Access를 특별히 "올바른"방법으로 찾고 있음을 강조하고 싶다. 내가 가지고있는 솔루션은 SQL Server에서 사용하기 위해 생각해 낸 솔루션이지만, 올바르지 않거나 Access에서 작동하지 않는다면 그 사실을 알고 싶습니다.JET/ACE SQL을 구문 분석하는 방법

ProgressBar를 제공하기 위해 SQL 문 에 의해 반환 될 레코드의 수를 반환하는 (더 효율적인) SQL 문을 생성하는 데 사용하는 다음 함수가 있습니다. SQL Server 2008 데이터베이스에 대해 작동합니다. Access 데이터베이스에 대해 비슷한 치료 방법을 사용하고 싶지만 JET/ACE 용 TSql100Parser 및 Sql100ScriptGenerator와 비슷한 것은 없습니다. 그런 것이 있습니까? 더 나은 해결책이 있습니까?

Imports Microsoft.Data.Schema.ScriptDom 
Imports Microsoft.Data.Schema.ScriptDom.Sql 

Private Function GetCountSQL(ByVal sql As String) As String 
    Dim _tsBatch As TSqlBatch 
    Dim _peErrors As IList(Of ParseError) = Nothing 
    Dim _tssFragment As TSqlScript 
    Dim _tspParser As New TSql100Parser(False) 
    Dim _retval As String = vbNullString 
    Dim _sgScriptGenerator As New Microsoft.Data.Schema.ScriptDom.Sql.Sql100ScriptGenerator 
    Dim _tsStatement As TSqlStatement 

    _tssFragment = _tspParser.Parse(New StringReader(sql), _peErrors) 
    If _peErrors Is Nothing OrElse _peErrors.Count = 0 Then 
     For Each _tsBatch In _tssFragment.Batches 
      For Each _tsStatement In _tsBatch.Statements 
       If TypeOf _tsStatement Is Microsoft.Data.Schema.ScriptDom.Sql.SelectStatement AndAlso CType(_tsStatement, Microsoft.Data.Schema.ScriptDom.Sql.SelectStatement).OrderByClause IsNot Nothing Then 
        CType(_tsStatement, Microsoft.Data.Schema.ScriptDom.Sql.SelectStatement).OrderByClause = Nothing 
       End If 
      Next 
     Next 
     _sgScriptGenerator.GenerateScript(_tssFragment, _retval) 
     _retval = String.Format("Select Count(*) FROM ({0}) SQ", _retval) 
    End If 
    Return _retval 
End Function 

답변

0

나는 Access와 같은 것을 찾을 수 없을 것이라고 생각합니다. 이 파서는 그 자체가 상당히 새로운 것입니다. 정규식 기반 구문 분석을 사용하는 것이 유일한 방법 일 것이라고 제안합니다. 원하는 모든 것이 열 개수라면 정규 표현식을 사용하여 목록을 찾고 열을 계산하는 분할 함수를 사용할 수 있습니다.

관련 문제