#define compileErrorsNot

using System;
using System.Data;
using System.Data.Sql;
using System.Data.SqlTypes;

/*

Deterministic false, Precise false
create table tA2
(
id int,
stuff as dbo.Add2(id) PERSISTED UNIQUE
)
.Net SqlClient Data Provider: Msg 4931, Level 16, State 1, Line 1
Computed column 'stuff' in table 'tA2' cannot be persisted because the column is non-deterministic.


Deterministic true, Precise false
create table tA3
(
id int,
stuff as dbo.Add3(id) PERSISTED UNIQUE
)
Command(s) completed successfully


Deterministic false, Precise true
create table tA5
(
id int,
stuff as dbo.Add5(id) PERSISTED UNIQUE
)
.Net SqlClient Data Provider: Msg 4931, Level 16, State 1, Line 1
Computed column 'stuff' in table 'tA5' cannot be persisted because the column is non-deterministic.


Deterministic true, Precise true
create table tA6
(
id int,
stuff as dbo.Add6(id) PERSISTED UNIQXSUE
)
Command(s) completed successfully


*/


namespace Chapter3
{
	public class Functions
	{
		static readonly Random r = new Random();
		static public SqlInt32 AddJob()
		{
			return r.Next();
		}
		static public SqlString Repeat(SqlInt32 i, SqlString c)
		{
			return new String(c.Value[0], i.Value);
		}
		static public SqlGuid NEWID()
		{
			return new SqlGuid(Guid.NewGuid());
			
			
		}
		[SqlFunction(IsDeterministic=false)]
		static public SqlGuid NEWID2()
		{
			return new SqlGuid(Guid.NewGuid());

		}
		[SqlFunction(IsDeterministic=false, IsPrecise=false)]
				static public int Add2(int i)
		{
			return i + 3;
		}
		[SqlFunction(IsDeterministic=true, IsPrecise=false)]
		static public int Add3(int i)
		{
			return i + 3;
		}
		[SqlFunction(IsPrecise=true, IsDeterministic=false)]
		static public int Add5(int i)
		{
			return i + 5;
		}
		[SqlFunction(IsPrecise=true, IsDeterministic=true)]
				static public int Add6(int i)
		{
			return i + 6;
		}
		
	}
}



