using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.IO;
using Dimensions;

namespace UseLDimOnClient
{
    class Program
    {
        static void Main(string[] args)
        {
            using (SqlConnection conn = new SqlConnection("server=.;integrated security=true;database=pubs"))
            using (SqlCommand cmd = new SqlCommand("select id, length from dbo.tiles", conn))
            {
                conn.Open();

                SqlDataReader rdr1 = cmd.ExecuteReader();

                while (rdr1.Read())
                    Console.WriteLine("{0} {1}", rdr1["id"], rdr1["length"]);

                DataTable t = rdr1.GetSchemaTable();
                for (int i = 0; i < t.Columns.Count; i++)
                  Console.WriteLine("{0} {1}", t.Columns[i].ColumnName, t.Rows[1][i]);
              
                rdr1.Close();

                SqlDataReader rdr2 = cmd.ExecuteReader();
                while (rdr2.Read())
                {
                    LDim ld = (LDim)rdr2["length"];
                    Console.WriteLine("{0} {1}", rdr2["id"], ld);
                }
                rdr2.Close();

                SqlDataReader rdr3 = cmd.ExecuteReader();
                LDim ld3 = new LDim();

                SqlBytes b = new SqlBytes();
                
                while (rdr3.Read())
                {
                    b = rdr3.GetSqlBytes(1);
                    ld3.Read(new BinaryReader(b.Stream));
                    Console.WriteLine(ld3);
                }
            }
        }
    }
}
