private static CodeStatementCollection BuildSelectReturnDataSet(IDataProviderDatabase database) { CodeStatementCollection statements = new CodeStatementCollection(); CodeVariableDeclarationStatement statement = new CodeVariableDeclarationStatement(typeof(IDbDataAdapter), "dataAdapter"); CodeExpression[] parameters = new CodeExpression[0]; statement.InitExpression = new CodeObjectCreateExpression(database.AdapterType, parameters); statements.Add(statement); CodeVariableReferenceExpression targetObject = new CodeVariableReferenceExpression("dataAdapter"); CodePropertyReferenceExpression left = new CodePropertyReferenceExpression(targetObject, "SelectCommand"); CodeVariableReferenceExpression right = new CodeVariableReferenceExpression("dbCommand"); statements.Add(new CodeAssignStatement(left, right)); CodeVariableDeclarationStatement statement2 = new CodeVariableDeclarationStatement(typeof(DataSet), "dataSet"); statement2.InitExpression = new CodeObjectCreateExpression(typeof(DataSet), new CodeExpression[0]); statements.Add(statement2); CodeVariableReferenceExpression expression = new CodeVariableReferenceExpression("dataSet"); CodeMethodInvokeExpression expression5 = new CodeMethodInvokeExpression(targetObject, "Fill", new CodeExpression[] { expression }); statements.Add(expression5); statements.Add(new CodeSnippetStatement(string.Empty)); CodeMethodReturnStatement statement3 = new CodeMethodReturnStatement(expression); statements.Add(statement3); return statements; }
private static CodeStatementCollection BuildConnection(IDataProviderDatabase database, string connectionString) { CodeStatementCollection statements = new CodeStatementCollection(); CodeVariableDeclarationStatement statement = new CodeVariableDeclarationStatement(typeof(string), "connectionString"); statement.InitExpression = new CodePrimitiveExpression(connectionString); statements.Add(statement); CodeVariableDeclarationStatement statement2 = new CodeVariableDeclarationStatement(typeof(IDbConnection), "dbConnection"); CodeVariableReferenceExpression expression = new CodeVariableReferenceExpression("connectionString"); statement2.InitExpression = new CodeObjectCreateExpression(database.ConnectionType, new CodeExpression[] { expression }); statements.Add(statement2); return statements; }
private static CodeStatementCollection BuildDbParameterAssignment(IDataProviderDatabase database, string paramName, DbType paramType, CodeDomProvider provider) { CodeStatementCollection statements = new CodeStatementCollection(); string name = "dbParam_" + GetVariableNameFromParameterName(paramName); CodeVariableDeclarationStatement statement = new CodeVariableDeclarationStatement(typeof(IDataParameter), name); CodeExpression[] parameters = new CodeExpression[0]; statement.InitExpression = new CodeObjectCreateExpression(database.ParameterType, parameters); statements.Add(statement); CodeVariableReferenceExpression targetObject = new CodeVariableReferenceExpression(name); CodePropertyReferenceExpression left = new CodePropertyReferenceExpression(targetObject, "ParameterName"); CodePrimitiveExpression right = new CodePrimitiveExpression(paramName); statements.Add(new CodeAssignStatement(left, right)); CodePropertyReferenceExpression expression4 = new CodePropertyReferenceExpression(targetObject, "Value"); CodeVariableReferenceExpression expression = new CodeVariableReferenceExpression(GetVariableNameFromParameterName(paramName)); CodeExpression expression6 = expression; if (provider.FileExtension.ToLower().EndsWith("jsl")) { System.Type typeFromDbType = QueryParameter.GetTypeFromDbType(paramType); if (typeFromDbType.IsPrimitive) { expression6 = new CodeCastExpression(typeFromDbType.FullName + " ", expression); } } statements.Add(new CodeAssignStatement(expression4, expression6)); CodePropertyReferenceExpression expression7 = new CodePropertyReferenceExpression(targetObject, "DbType"); CodeTypeReferenceExpression expression8 = new CodeTypeReferenceExpression(typeof(DbType)); CodeFieldReferenceExpression expression9 = new CodeFieldReferenceExpression(expression8, Enum.GetName(typeof(DbType), paramType)); statements.Add(new CodeAssignStatement(expression7, expression9)); CodeVariableReferenceExpression expression10 = new CodeVariableReferenceExpression("dbCommand"); CodePropertyReferenceExpression expression11 = new CodePropertyReferenceExpression(expression10, "Parameters"); CodeMethodInvokeExpression expression12 = new CodeMethodInvokeExpression(expression11, "Add", new CodeExpression[] { targetObject }); statements.Add(expression12); return statements; }
private static CodeStatementCollection BuildCommand(IDataProviderDatabase database) { CodeStatementCollection statements = new CodeStatementCollection(); CodeVariableDeclarationStatement statement = new CodeVariableDeclarationStatement(typeof(IDbCommand), "dbCommand"); CodeExpression[] parameters = new CodeExpression[0]; statement.InitExpression = new CodeObjectCreateExpression(database.CommandType, parameters); statements.Add(statement); CodeVariableReferenceExpression targetObject = new CodeVariableReferenceExpression("dbCommand"); CodeVariableReferenceExpression right = new CodeVariableReferenceExpression("queryString"); CodePropertyReferenceExpression left = new CodePropertyReferenceExpression(targetObject, "CommandText"); statements.Add(new CodeAssignStatement(left, right)); CodeVariableReferenceExpression expression4 = new CodeVariableReferenceExpression("dbConnection"); CodePropertyReferenceExpression expression5 = new CodePropertyReferenceExpression(targetObject, "Connection"); statements.Add(new CodeAssignStatement(expression5, expression4)); return statements; }