示例#1
0
        private void BuildIndexes()
        {
            const string sql = @"SELECT DISTINCT
	   index_name		= [index].name,
	   column_name		= [columns].name,
	   index_column_id  = [index_columns].index_column_id
from sys.indexes [index]
          LEFT JOIN sys.objects [objects] ON ( [objects].object_id = [index].object_id )
          LEFT JOIN sys.index_columns [index_columns] ON ( [index_columns].index_id = [index].index_id )
		                                                 AND ( [index_columns].object_id  = [index].object_id )
          LEFT JOIN sys.columns [columns] ON ( [index_columns].OBJECT_id = [columns].object_id )
                                             AND ( [index_columns].Column_id = [columns].column_id )
WHERE ( [objects].schema_id = SCHEMA_ID(@schema_name) )
	  AND ( [objects].name = @object_name )
	  AND ( [index].type = 2 )
ORDER BY [index].name, [index_columns].index_column_id";

            using (var comm = new DbCommandUtil(sql))
            {
                comm.AddParameter("@schema_name", DbType.AnsiString, Schema);
                comm.AddParameter("@object_name", DbType.AnsiString, Name);
                var reader            = comm.ExecuteReader(CommandBehavior.CloseConnection);
                var previousIndexName = "";
                var indexColumns      = new List <Column>();
                while (reader.Read())
                {
                    var indexName = reader.GetString(0);
                    if (previousIndexName == "")
                    {
                        previousIndexName = indexName;
                    }

                    if (previousIndexName != indexName)
                    {
                        _Indexes.Add(new Index(previousIndexName, indexColumns));
                        indexColumns = new List <Column>();
                    }
                    indexColumns.Add(Columns[reader.GetString(1)]);
                    previousIndexName = indexName;
                }
                _Indexes.Add(new Index(previousIndexName, indexColumns));

                reader.Close();
            }
        }
示例#2
0
        public void NullParameterTest()
        {
            Insert();
            var comm = new DbCommandUtil("SELECT * FROM TEST WHERE ID = @ID");

            Assert.Equal(ConnectionState.Closed, comm.DaScopeContext.Connection.State);
            comm.AddParameter("@ID", DbType.Int32, null);
            Assert.Equal(0, comm.GetDataTable().Rows.Count);
            comm.SetParameterValue("@ID", 0);
            Assert.Equal(0, comm.GetDataTable().Rows.Count);
        }
示例#3
0
        public void ParameterPrecisionTest()
        {
            Insert();
            var comm = new DbCommandUtil("SELECT ID FROM TEST WHERE Value = @Value");

            Assert.Equal(ConnectionState.Closed, comm.DaScopeContext.Connection.State);
            comm.AddParameter("@Value", DbType.Double, 4, 2, 35.4);
            var idValue = comm.ExecuteScalar <int?>();

            Assert.Equal(3, idValue);
        }