|
03.11.2006, 11:01
#34103230
Ссылка:
Ссылка на сообщение:
Ссылка с названием темы:
|
|
|
|
Может кто нибудь скомпилировать этот скрипт и приложить полученную DLL. Скомпилировать самому нет возможности, т.к. с MS SQL 2005 Express поставился какой-то урезаный MS 2005.
Это для создания в MS SQL пользовательской аггрегатной ф-и LIST.
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. 49. 50. 51. 52. 53. 54. 55. 56. 57. 58. 59. 60. 61. 62. 63. 64. 65. 66. 67. 68. 69. 70. 71. 72. 73. 74. 75. 76. 77. 78. 79. 80.
using System;
using System.Data;
using Microsoft.SqlServer.Server;
using System.Data.SqlTypes;
using System.IO;
using System.Text;
[Serializable]
[SqlUserDefinedAggregate(
Format.UserDefined, //use clr serialization to serialize the intermediate result
IsInvariantToNulls = true, //optimizer property
IsInvariantToDuplicates = false, //optimizer property
IsInvariantToOrder = false, //optimizer property
MaxByteSize = 8000 ) //maximum size in bytes of persisted value
]
public class Concatenate : IBinarySerialize
{
/// <summary>
/// The variable that holds the intermediate result of the concatenation
/// </summary>
private StringBuilder intermediateResult;
/// <summary>
/// Initialize the internal data structures
/// </summary>
public void Init()
{
this.intermediateResult = new StringBuilder();
}
/// <summary>
/// Accumulate the next value, not if the value is null
/// </summary>
/// <param name="value"></param>
public void Accumulate(SqlString value)
{
if (value.IsNull)
{
return;
}
this.intermediateResult.Append(value.Value).Append(',');
}
/// <summary>
/// Merge the partially computed aggregate with this aggregate.
/// </summary>
/// <param name="other"></param>
public void Merge(Concatenate other)
{
this.intermediateResult.Append(other.intermediateResult);
}
/// <summary>
/// Called at the end of aggregation, to return the results of the aggregation.
/// </summary>
/// <returns></returns>
public SqlString Terminate()
{
string output = string.Empty;
//delete the trailing comma, if any
if (this.intermediateResult != null
&& this.intermediateResult.Length > 0 )
{
output = this.intermediateResult.ToString( 0 , this.intermediateResult.Length - 1 );
}
return new SqlString(output);
}
public void Read(BinaryReader r)
{
intermediateResult = new StringBuilder(r.ReadString());
}
public void Write(BinaryWriter w)
{
w.Write(this.intermediateResult.ToString());
}
}
Вот для чего это надо.
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12.
В SQL Server 2005 возможно создание объектов базы данных в экземпляре
SQL Server, которые программируются в сборке, созданной в среде CLR Microsoft
.NET Framework. К объектам базы данных, способным обогатить возможности
применения многофункциональной модели программирования среды CLR, относятся
статистические функции, функции, хранимые процедуры, триггеры и типы.
Чтобы создать функцию CLR в SQL Server, необходимо выполнить следующие шаги:
Определить функцию как статический метод класса на языке, поддерживаемом
.NET Framework. Дополнительные сведения о программировании функций в среде
CLR см. в разделе CLR User-Defined Functions. После этого следует скомпилировать
класс, чтобы создать сборку в .NET Framework, используя компилятор
соответствующего языка...
|
|
|