public ColumnCollection GetColumns() { ColumnCollection columns = new ColumnCollection(); ISqlScript sqlScript = SqlParserService.Parse(_select); if (sqlScript.Statements != null && sqlScript.Statements.Count > 0) { ISqlStatement statement = sqlScript.Statements[0]; if (statement is ISelectStatement) { ISelectStatement selectStatement = statement as ISelectStatement; if (selectStatement.QueryExpression != null && selectStatement.QueryExpression is ISelectExpression) { ISelectExpression selectExpression = selectStatement.QueryExpression as ISelectExpression; for (int i = 0; i < selectExpression.SelectList.Count; i++) { SelectColumn selectColumn = selectExpression.SelectList[i]; Column column = _table[selectColumn.Name]; if (column != null) { columns.Add(column); } } } } } return(columns); }
/// <summary> /// 添加要执行的sql语句对象 /// </summary> /// <param name="key">数据库连接字符串</param> /// <param name="sqlscript">要添加的sql语句对象</param> public void AddSqlScript(string key, ISqlScript sqlscript) { if (!this.sqlScripts.ContainsKey(key)) { throw new Exception("不存在要添加sqlscript的connect的key"); } this.sqlScripts[key].Enqueue(sqlscript); }
/// <summary> /// 执行某个指定连接的所有存储语句只能是非select的DML /// </summary> /// <param name="key">要执行sql语句的链接</param> /// <returns></returns> public bool ExecuteSql(string key) { if (!this.connectionList.ContainsKey(key)) { return(false); } IDBHelper helper = this.connectionList[key]; Queue <ISqlScript> list = this.sqlScripts[key]; while (list.Count > 0) { ISqlScript sqlscript = list.Dequeue(); if (sqlscript.IsSqlStringOnly) { try { helper.ExecSqlReInt(sqlscript.SqlString); } catch (Exception ex) { string errDescribe = ex.Message + " 异常: " + ex.InnerException + "位置:" + ex.StackTrace + "对象名称:" + ex.Source + "引发异常的方法:" + ex.TargetSite; this.errorMessage += errDescribe; return(false); } } else { try { helper.ExecSqlReInt(sqlscript.SqlString, sqlscript.SqlParams); } catch (Exception ex) { string errDescribe = ex.Message + " 异常: " + ex.InnerException + "位置:" + ex.StackTrace + "对象名称:" + ex.Source + "引发异常的方法:" + ex.TargetSite; this.errorMessage += errDescribe; return(false); } } } return(true); }
public static DataAssembler FromQuery(DataDomain dataDomain, string query) { ISqlScript sqlScript = SqlParserService.Parse(query); if (sqlScript.Statements != null && sqlScript.Statements.Count > 0) { ISqlStatement statement = sqlScript.Statements[0]; if (statement is ISelectStatement) { ISelectStatement selectStatement = statement as ISelectStatement; if (selectStatement.Tables != null && selectStatement.Tables.Count > 0) { SqlTable sqlTable = selectStatement.Tables[0]; Table table = dataDomain[sqlTable.Name]; DataAssembler dataAssembler = new DataAssembler(dataDomain.DomainUrl.Url, table, query); return(dataAssembler); } } } return(null); }
public void sql_data_stmt( ISqlScript sqlScript ) //throws RecognitionException, TokenStreamException { returnAST = null; ASTPair currentAST = new ASTPair(); AST sql_data_stmt_AST = null; ISqlStatement sqlStatement; switch ( LA(1) ) { case SQL2NRW_ada: case SQL2RW_module: case SQL2RW_select: case SQL2RW_table: case SQL2RW_values: case REGULAR_ID: case DELIMITED_ID: case LEFT_PAREN: case INTRODUCER: { sqlStatement=select_stmt(); if (0 == inputState.guessing) { astFactory.addASTChild(ref currentAST, returnAST); } if (0==inputState.guessing) { sqlScript.AddStatement(sqlStatement); } sql_data_stmt_AST = currentAST.root; break; } case SQL2RW_insert: { insert_stmt(); if (0 == inputState.guessing) { astFactory.addASTChild(ref currentAST, returnAST); } sql_data_stmt_AST = currentAST.root; break; } case SQL2RW_update: { update_stmt(); if (0 == inputState.guessing) { astFactory.addASTChild(ref currentAST, returnAST); } sql_data_stmt_AST = currentAST.root; break; } case SQL2RW_delete: { delete_stmt(); if (0 == inputState.guessing) { astFactory.addASTChild(ref currentAST, returnAST); } sql_data_stmt_AST = currentAST.root; break; } default: { throw new NoViableAltException(LT(1), getFilename()); } } returnAST = sql_data_stmt_AST; }
public void sql_single_stmt( ISqlScript sqlScript ) //throws RecognitionException, TokenStreamException { returnAST = null; ASTPair currentAST = new ASTPair(); AST sql_single_stmt_AST = null; { if ((tokenSet_0_.member(LA(1)))) { sql_stmt(sqlScript); if (0 == inputState.guessing) { astFactory.addASTChild(ref currentAST, returnAST); } } else if ((LA(1)==EOF||LA(1)==SEMICOLON)) { } else { throw new NoViableAltException(LT(1), getFilename()); } } { if ((LA(1)==SEMICOLON)) { AST tmp3_AST = null; tmp3_AST = astFactory.create(LT(1)); astFactory.addASTChild(ref currentAST, tmp3_AST); match(SEMICOLON); } else if ((LA(1)==EOF)) { } else { throw new NoViableAltException(LT(1), getFilename()); } } sql_single_stmt_AST = currentAST.root; returnAST = sql_single_stmt_AST; }
public void sql_stmt( ISqlScript sqlScript ) //throws RecognitionException, TokenStreamException { returnAST = null; ASTPair currentAST = new ASTPair(); AST sql_stmt_AST = null; sql_data_stmt(sqlScript); if (0 == inputState.guessing) { astFactory.addASTChild(ref currentAST, returnAST); } sql_stmt_AST = currentAST.root; returnAST = sql_stmt_AST; }