|
| Previous Thread: ValidationMethodName function |
|
|
2/22/2006 10:58:26 PM CLR Table Valued Function |
Hi,
I have problem in the method name that I have written to be used as
"FillRowMethodName":
Imagine I want to use FileSystem.Drives to prepare three columns in
resultset: DriveLetter, TotalSpace and FreeSpace. I'm trying to access each
drive via its index in Drives collection, but I don't know how to determine
which drive letter to process, because I have no idea of the current index
in the method. Do I need an internal counter such as variable?
Any help would be greatly appreciated,
Leila
|
|
|
|
|
2/23/2006 1:20:39 AM Re: CLR Table Valued Function |
"Leila" <Leilas@hotpop.com> wrote in
news:uLvGsY#NGHA.140@TK2MSFTNGP12.phx.gbl:
For this particular task, why don't you use the drive info class?
The TVF would look something like this (without any attributes):
public static IEnumerable GetDriveInfo() {
return DriveInfo.GetDrives();
}
the FillRowMethod would look like this:
static void GetDriveRow(object drive, out string driveName, out long
totSpace, out long freeSpace) {
DriveInfo di = (DriveInfo)drive;
driveName = di.Name;
totSpace = di.TotalSize;
freeSpace = di.TotalFreeSpace;
}
Remember that the UDF returns an IEnumerable (or IEnumerator) and the
SQLCLR will loop through the return by moving next and sending each
individual element (in this case driveinfo object) to the FillRowMethod.
Niels
--
**************************************************
* Niels Berglund
* http://staff.develop.com/nielsb
* nielsb@no-spam.develop.com
* "A First Look at SQL Server 2005 for Developers"
* http://www.awprofessional.com/title/0321180593
**************************************************
|
|
|
2/23/2006 2:20:57 AM Re: CLR Table Valued Function |
"Leila" <Leilas@hotpop.com> wrote in news:OyAqaxFOGHA.3360
@TK2MSFTNGP15.phx.gbl:
I do not understand the question?
Niels
--
**************************************************
* Niels Berglund
* http://staff.develop.com/nielsb
* nielsb@no-spam.develop.com
* "A First Look at SQL Server 2005 for Developers"
* http://www.awprofessional.com/title/0321180593
**************************************************
|
|
|
2/23/2006 5:22:49 AM Re: CLR Table Valued Function |
"Leila" <Leilas@hotpop.com> wrote in
news:ejKC$THOGHA.1288@TK2MSFTNGP09.phx.gbl:
Ah, OK - in the case that you can not derive from the element which
element it is you have to create a class, which implements IEnumerator
and populate your class with the array elements, and in the class have
an extra property which indicates what element you're working on.
Niels
--
**************************************************
* Niels Berglund
* http://staff.develop.com/nielsb
* nielsb@no-spam.develop.com
* "A First Look at SQL Server 2005 for Developers"
* http://www.awprofessional.com/title/0321180593
**************************************************
|
|
|
2/23/2006 7:36:38 AM Re: CLR Table Valued Function |
"Leila" <Leilas@hotpop.com> wrote in
news:Op3j2aIOGHA.3944@tk2msftngp13.phx.gbl:
That is very dangerous!!! As the method is static, if more than one user
calls the function the users would share the variable, and you would get
totally wrong values.
Also, this can cause unwanted side effects, such as if an error occurs,
your app-domain may be torn down which adversly will effect both
performance as well as reliability.
Niels
--
**************************************************
* Niels Berglund
* http://staff.develop.com/nielsb
* nielsb@no-spam.develop.com
* "A First Look at SQL Server 2005 for Developers"
* http://www.awprofessional.com/title/0321180593
**************************************************
|
|
|
2/23/2006 1:03:26 PM Re: CLR Table Valued Function |
Thanks indeed! That's a much better solution!
I'm still curious to know about the times of my FillRowMethod being
executed, what about this one?
"Niels Berglund" <nielsb@develop.com> wrote in message
news:Xns97735F0966CE1nielsbdevelopcom@207.46.248.16...
|
|
|
2/23/2006 3:21:14 PM Re: CLR Table Valued Function |
Well, Imagine that the initial method of your TVF resturns a one-dimensional
array. Therefore FillRowMethod will iterate through its elements. The
elements do not carry any information when they are processed in
FillRowMethod, but you need to know which element (first, second or
third...) your are working on while processing them.
Thanks in advance
"Niels Berglund" <nielsb@develop.com> wrote in message
news:Xns97736942BF49Fnielsbdevelopcom@207.46.248.16...
|
|
|
2/23/2006 6:07:33 PM Re: CLR Table Valued Function |
I used a trick but I need help to complete it!
I declared an static variable named Counter, and used Counter += 1 in
FillRowMethod. Although your assembly must be cataloged using UNSAFE
permission, but it worked. The problem is that I don't know how to reset
this counter to 0 for next uses of TVF!
"Niels Berglund" <nielsb@develop.com> wrote in message
news:Xns97738817E30B1nielsbdevelopcom@207.46.248.16...
|
|
|
2/23/2006 7:17:30 PM Re: CLR Table Valued Function |
Oops! Thanks again :-)
"Niels Berglund" <nielsb@develop.com> wrote in message
news:Xns97739EC76C3A3nielsbdevelopcom@207.46.248.16...
|
|