# INSERT INTO 文を CSV 形式に変換する。 # # 制限 # ・INSERT INTO 文は 1 行で構成していること。 # ・カラムの値に '(' や ')'、',' が含まれないこと。 $ctx = [System.Collections.Generic.Dictionary[[String], [PSObject]]]::new() Function MainProcess { Process { $r = $_ -match 'INSERT[\t ]+INTO[\t ]+([^\t \)]+)[\t ]*\(([^\)]+)\)[\t ]*VALUES[\t ]*\(([^\)]+)\)' if( $r ) { $table = $ctx[$Matches[1]] if( $table -eq $Null ) { $table = @{ name = $Matches[1]; columns = $Matches[2]; records = [System.Collections.Generic.List[String]]::new(); } $ctx[$table.name] = $table } $table.records.Add($Matches[3]) #"::" + $Matches[1] + "::" #"------" #$Matches[2] #-split ',' | %{ '_{0}_' -f $_ } #"------" #$Matches[3] #-split ',' | %{ '_{0}_' -f $_ } } else { '失敗: ' + $_ } } } # # 以下はサンプル # 'insert into BOOKS (A,B,C) VALUES (''a'',0,XYZ)','insert into BOOKS (A,B,C) VALUES (''b'',1,ZZZ)' | MainProcess '--------' $ctx '--------' $ctx.Values | %{ $_.columns ; $_.records }