Exemplo n.º 1
0
        public ISqlResultSet ExecuteQuerry(string querry)
        {
            using (SqlConnection connection = new SqlConnection(_connectionString))
                using (SqlCommand cmd = CreateCommand(querry, connection))
                {
                    connection.Open();

                    cmd.Prepare();
                    SqlDataReader reader = cmd.ExecuteReader();

                    SqlResultBuilder builder = SqlResultBuilder.NewInstance(reader.FieldCount);

                    //HashSet<string> set = new HashSet<string>();

                    for (int i = 0; i < reader.FieldCount; i++)
                    {
                        string typename = reader.GetDataTypeName(i);
                        //set.Add(typename);
                        builder.SetColumnType(i, reader.GetDataTypeName(i));
                    }

                    /*foreach(string s in set)
                     * {
                     *  Console.WriteLine(s);
                     * }*/

                    for (int i = 0; i < reader.FieldCount; i++)
                    {
                        string name = reader.GetName(i);
                        builder.SetColumnName(i, name);
                    }

                    while (reader.Read())
                    {
                        builder.PushRow();
                        for (int i = 0; i < reader.FieldCount; i++)
                        {
                            object val = reader.GetValue(i);
                            builder.AddValue(val);
                        }
                        builder.PopRow();
                    }

                    return(builder.Build());
                }
        }
        public static SqlResultBuilder NewInstance(int columnCount)
        {
            SqlResultBuilder builder = new SqlResultBuilder(columnCount);

            return(builder);
        }