示例#1
0
        public async Task <SQLQueryHolder <R> > DelayQueryHolder <R>(SQLQueryHolder <R> holder)
        {
            return(await Task.Run(() =>
            {
                string query = "";

                try
                {
                    using (var Connection = _connectionInfo.GetConnection())
                    {
                        Connection.OpenAsync();

                        foreach (var pair in holder.m_queries)
                        {
                            List <object[]> rows = new List <object[]>();
                            using (MySqlCommand cmd = Connection.CreateCommand())
                            {
                                cmd.CommandText = pair.Value.stmt.CommandText;
                                foreach (var parameter in pair.Value.stmt.Parameters)
                                {
                                    cmd.Parameters.AddWithValue("@" + parameter.Key, parameter.Value);
                                }

                                query = cmd.CommandText;
                                using (var reader = cmd.ExecuteReader())
                                {
                                    if (reader.HasRows)
                                    {
                                        while (reader.Read())
                                        {
                                            var row = new object[reader.FieldCount];

                                            reader.GetValues(row);
                                            rows.Add(row);
                                        }
                                    }
                                }
                            }

                            holder.SetResult(pair.Key, new SQLResult(rows));
                        }
                    }

                    return holder;
                }
                catch (MySqlException ex)
                {
                    HandleMySQLException(ex, query);
                    return holder;
                }
            }));
        }
示例#2
0
        public bool Execute <T>(MySqlBase <T> mySqlBase)
        {
            if (m_holder == null)
            {
                return(false);
            }

            // execute all queries in the holder and pass the results
            foreach (var pair in m_holder.m_queries)
            {
                m_holder.SetResult(pair.Key, mySqlBase.Query(pair.Value));
            }

            return(m_result.TrySetResult(m_holder));
        }