Example #1
0
        private string toStringRecursive(SqlQueryBatch batch)
        {
            StringBuilder temp = new StringBuilder();

            foreach (object o in batch)
            {
                if (o is SqlQuery)
                {
                    temp.Append("\n\r");
                    temp.Append((o as SqlQuery).Sql);
                }
                else
                {
                    temp.Append(toStringRecursive(o as SqlQueryBatch));
                }
            }
            return(temp.ToString());
        }
Example #2
0
 private void OnExecuteCompleteRecursion(SqlQueryBatch queryBatch, Dictionary <SqlQueryBatch, object> resultDictionary, bool isSuccess)
 {
     foreach (object obj in queryBatch)
     {
         if (!(obj is SqlQueryBatch))
         {
             continue;
         }
         (obj as SqlQueryBatch).OnExecuteCompleteRecursion(obj as SqlQueryBatch, resultDictionary, isSuccess);
     }
     if (isSuccess == false)
     {
         isSuccess = false;
     }
     if (resultDictionary.ContainsKey(queryBatch))
     {
         queryBatch.OnExecuteComplete(new SqlQueryBatchEventArgs(isSuccess, resultDictionary[queryBatch]));
     }
     else
     {
         queryBatch.OnExecuteComplete(new SqlQueryBatchEventArgs(isSuccess, null));
     }
 }
Example #3
0
        private object ExecuteInternalTransaction(SqlQueryBatch queryBatch, DbTransaction transaction, DbCommand command, DbConnection connection, Dictionary <SqlQueryBatch, object> resultDictionary)
        {
            object returnValue = 0;

            foreach (object obj in queryBatch)
            {
                if (obj == null)
                {
                    continue;
                }
                if (obj is SqlQueryBatch)
                {
                    returnValue = ExecuteInternalTransaction((SqlQueryBatch)obj, transaction, command, connection, resultDictionary);
                    continue;
                }
                SqlQuery sqlQuery = (SqlQuery)obj;
                command             = (DbCommand)Activator.CreateInstance(CommandType);
                _sqlTemp            = sqlQuery.Sql;
                command.CommandText = sqlQuery.Sql;
                command.Connection  = connection;
                command.Transaction = transaction;
                if (sqlQuery.Parameters != null)
                {
                    foreach (KeyValuePair <string, object> paramArg in sqlQuery.Parameters)
                    {
                        DbParameter parameter = (DbParameter)Activator.CreateInstance(ParameterType);
                        parameter.ParameterName = paramArg.Key;
                        if (paramArg.Value is DateTime)
                        {
                            parameter.Value  = ((DateTime)paramArg.Value).ToString(SqlQuery.DateTimeStringFormat);
                            parameter.DbType = DbType.DateTime;
                        }
                        else if (paramArg.Value is Enum)
                        {
                            parameter.Value  = paramArg.Value;
                            parameter.DbType = DbType.Int32;
                        }
                        else
                        {
                            parameter.Value  = paramArg.Value;
                            parameter.DbType = DbType.String;
                            parameter.Size   = paramArg.ToString().Length;
                        }
                        command.Parameters.Add(parameter);
                    }
                }
                _parametersTemp = command.Parameters;
                command.Prepare();
                if (sqlQuery.Sql.Trim().ToLower().StartsWith("select"))
                {
                    DataTable temp = new DataTable();
                    temp.Load(command.ExecuteReader());
                    returnValue = temp;
                }
                else
                {
                    returnValue = command.ExecuteNonQuery();
                }
                command.Dispose();
            }
            resultDictionary.Add(queryBatch, returnValue);
            return(returnValue);
        }