Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Data;
- using System.Data.SqlClient;
- using System.Data.SqlTypes;
- using Microsoft.SqlServer.Server;
- using System.Collections.Generic;
- using System.IO;
- [Serializable]
- [SqlUserDefinedAggregate(Format.Native)]
- public struct GEOAVE
- {
- private int licznik; // field to count the not null rows
- private double iloczyn;
- private double temp;
- public void Init()
- {
- licznik = 0;
- iloczyn = 1;// initialization
- }
- public void Accumulate(double? Value)
- {
- if (Value != null) // count just the rows that are not equal to NULL
- {
- licznik++;
- iloczyn = iloczyn * (double)Value;
- }
- }
- public void Merge(GEOAVE Group)
- {
- this.licznik += Group.licznik;
- this.iloczyn *= Group.iloczyn; // when merge is needed the counter of other groups should be added
- }
- public double? Terminate() //SqlString
- {
- //return new SqlString(Counter.ToString());
- temp = 1.0 / licznik;
- iloczyn = Math.Pow(iloczyn, temp);
- return (double?)this.iloczyn;//returning the results
- }
- }
- [Serializable]
- [SqlUserDefinedAggregate(Format.UserDefined, MaxByteSize = 8000)]
- public struct LiczZnaki : IBinarySerialize
- {
- private int? licznik; // field to count the not null rows
- private int licz;
- public void Init()
- {
- licz = 0;
- licznik = 0;
- }
- public void Accumulate(SqlString Value)
- {
- if (!Value.IsNull) // count just the rows that are not equal to NULL
- {
- licz++;
- licznik = licznik + Value.ToString().Length;
- }
- }
- public void Merge(LiczZnaki Group)
- {
- this.licznik += Group.licznik;
- this.licz += Group.licz;
- }
- public int? Terminate() //SqlString
- {
- if (licz != 0) return this.licznik;//returning the results
- else return null;
- }
- public void Read(BinaryReader r)
- {
- licz = r.ReadInt32();
- licznik = r.ReadInt32();
- }
- public void Write(BinaryWriter w)
- {
- w.Write(licz);
- w.Write((int)licznik);
- }
- }
- [Serializable]
- [SqlUserDefinedAggregate(Format.UserDefined, MaxByteSize = -1)]
- public struct LaczZnaki : IBinarySerialize
- {
- private string slowo; // field to count the not null rows
- private int licz;
- public void Init()
- {
- licz = 0;
- slowo = "";
- }
- public void Accumulate(SqlString Value)
- {
- if (!Value.IsNull) // count just the rows that are not equal to NULL
- {
- licz++;
- slowo = slowo + Value.ToString() + ", ";
- }
- }
- public void Merge(LaczZnaki Group)
- {
- this.slowo += Group.slowo;
- this.licz += Group.licz;
- }
- public string Terminate() //SqlString
- {
- if (licz != 0) return this.slowo.Substring(0, slowo.Length-2) ;//returning the results
- else return null;
- }
- public void Read(BinaryReader r)
- {
- licz = r.ReadInt32();
- slowo = r.ReadString();
- }
- public void Write(BinaryWriter w)
- {
- w.Write(licz);
- w.Write(slowo);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement