001package gudusoft.gsqlparser.stmt.mssql; 002 003import gudusoft.gsqlparser.*; 004import gudusoft.gsqlparser.nodes.TParseTreeVisitor; 005import gudusoft.gsqlparser.nodes.TObjectName; 006import gudusoft.gsqlparser.nodes.TConstant; 007import gudusoft.gsqlparser.nodes.mssql.TMssqlBulkInsertOption; 008import gudusoft.gsqlparser.nodes.mssql.TMssqlBulkInsertSqlNode; 009 010import java.util.ArrayList; 011import java.util.List; 012 013public class TMssqlBulkInsert extends TCustomSqlStatement { 014 public TMssqlBulkInsert (EDbVendor dbvendor){ 015 super(dbvendor); 016 sqlstatementtype = ESqlStatementType.sstmssqlbulkinsert ; 017 } 018 019 void buildsql() { 020 } 021 022 void clear() { 023 } 024 025 String getasprettytext() { 026 return ""; 027 } 028 029 void iterate(TVisitorAbs pvisitor) { 030 } 031 032 public int doParseStatement(TCustomSqlStatement psql) { 033 if (rootNode == null) return -1; 034 TMssqlBulkInsertSqlNode bulkInsertSqlNode = (TMssqlBulkInsertSqlNode)rootNode; 035 super.doParseStatement(psql); 036 this.tableName = bulkInsertSqlNode.getTableName(); 037 this.datafile = bulkInsertSqlNode.getDatafile(); 038 this.options = bulkInsertSqlNode.getOptions(); 039 return 0; 040 } 041 042 private TObjectName tableName = null; 043 private TConstant datafile = null; 044 private List<TMssqlBulkInsertOption> options = new ArrayList<TMssqlBulkInsertOption>(); 045 046 public TConstant getDatafile() { 047 return datafile; 048 } 049 050 public TObjectName getTableName() { 051 return tableName; 052 } 053 054 /** The {@code WITH (...)} options in the order written; empty without a WITH clause. */ 055 public List<TMssqlBulkInsertOption> getOptions() { 056 return options; 057 } 058 059 /** The option named {@code name} (ignoring case), such as {@code DATA_SOURCE}, {@code FORMATFILE}, {@code FIRSTROW}; null when absent. */ 060 public TMssqlBulkInsertOption getOption(String name) { 061 for (TMssqlBulkInsertOption option : options) { 062 if (option.isNamed(name)) { 063 return option; 064 } 065 } 066 return null; 067 } 068 069 /** The value of the option named {@code name} (string literals unquoted), or null when absent or a flag. */ 070 public String getOptionValue(String name) { 071 TMssqlBulkInsertOption option = getOption(name); 072 return option == null ? null : option.getValue(); 073 } 074 075 public void accept(TParseTreeVisitor v){ 076 v.preVisit(this); 077 v.postVisit(this); 078 } 079 080 /** Visits the target table name, the data file constant and the options. */ 081 public void acceptChildren(TParseTreeVisitor v){ 082 v.preVisit(this); 083 if (tableName != null) { 084 tableName.acceptChildren(v); 085 } 086 if (datafile != null) { 087 datafile.acceptChildren(v); 088 } 089 for (TMssqlBulkInsertOption option : options) { 090 option.acceptChildren(v); 091 } 092 v.postVisit(this); 093 } 094 095 public void setTableName(TObjectName tableName) { 096 this.tableName = tableName; 097 } 098 099 public void setDatafile(TConstant datafile) { 100 this.datafile = datafile; 101 } 102}