Cihat Altuntas sitesini begenerek takip ettigim yazilimcilardan biri.
Özellikle refactoring ve TDD ile ilgili örneklerle pekistirdigi güzel makaleleri var. Bunlardan bir tanesini sizin ile paylasmak istedim. TDD nin örnek bir uygulama ile güzel bir sekilde anlatildigi bir makale. Asagidaki linkden makaleye ulasabilirsiniz.
Test Driven Development
22 Ocak 2008 Salı
Oracle - PL-SQL ile Dosya Boyutunu bulma
CREATE OR REPLACE FUNCTION flength (
location_in IN VARCHAR2,
file_in IN VARCHAR2
)
RETURN PLS_INTEGER
IS
TYPE fgetattr_t IS RECORD (
fexists BOOLEAN,
file_length PLS_INTEGER,
block_size PLS_INTEGER
);
fgetattr_rec fgetattr_t;
BEGIN
UTL_FILE.fgetattr (
location => location_in,
filename => file_in,
fexists => fgetattr_rec.fexists,
file_length => fgetattr_rec.file_length,
block_size => fgetattr_rec.block_size
);
RETURN fgetattr_rec.file_length;
END flength;
/
location_in IN VARCHAR2,
file_in IN VARCHAR2
)
RETURN PLS_INTEGER
IS
TYPE fgetattr_t IS RECORD (
fexists BOOLEAN,
file_length PLS_INTEGER,
block_size PLS_INTEGER
);
fgetattr_rec fgetattr_t;
BEGIN
UTL_FILE.fgetattr (
location => location_in,
filename => file_in,
fexists => fgetattr_rec.fexists,
file_length => fgetattr_rec.file_length,
block_size => fgetattr_rec.block_size
);
RETURN fgetattr_rec.file_length;
END flength;
/
SQL Server - T-Sql ile Dosya boyutunu bulma
CREATE FUNCTION udf_GetFileSize (@filename varchar(1000))
returns bigint
as
BEGIN
DECLARE @FS int
DECLARE @OLEResult int
DECLARE @FileID int
DECLARE @Size bigint
DECLARE @Flag bigint
Set @size =0
Set @Flag =0
EXECUTE @OLEResult = sp_OACreate 'Scripting.FileSystemObject', @FS OUT
EXECUTE @OLEResult = sp_OAMethod @FS, 'GetFile', @FileID OUT,@filename
IF @OLEResult <> 0
begin
set @Flag =-1
end
else
begin
EXECUTE @OLEResult = sp_OAGetProperty @FileId,'Size', @Size OUT
IF @OLEResult <> 0
begin
set @Flag =-2
end
end
EXECUTE @OLEResult = sp_OADestroy @FileID
EXECUTE @OLEResult = sp_OADestroy @FS
if @flag <> -1 and @flag <> -2
begin
set @flag = @size
end
return @flag
END
'Kullanimi
select dbo.udf_GetFileSize ('c:\temp\test.txt')
returns bigint
as
BEGIN
DECLARE @FS int
DECLARE @OLEResult int
DECLARE @FileID int
DECLARE @Size bigint
DECLARE @Flag bigint
Set @size =0
Set @Flag =0
EXECUTE @OLEResult = sp_OACreate 'Scripting.FileSystemObject', @FS OUT
EXECUTE @OLEResult = sp_OAMethod @FS, 'GetFile', @FileID OUT,@filename
IF @OLEResult <> 0
begin
set @Flag =-1
end
else
begin
EXECUTE @OLEResult = sp_OAGetProperty @FileId,'Size', @Size OUT
IF @OLEResult <> 0
begin
set @Flag =-2
end
end
EXECUTE @OLEResult = sp_OADestroy @FileID
EXECUTE @OLEResult = sp_OADestroy @FS
if @flag <> -1 and @flag <> -2
begin
set @flag = @size
end
return @flag
END
'Kullanimi
select dbo.udf_GetFileSize ('c:\temp\test.txt')
Etiketler:
sql,
Sql Server,
t-sql,
Tips and Tricks
16 Ocak 2008 Çarşamba
12 Agile Principles
Nurettin Şimşek msegitim.net |
Kaydol:
Kayıtlar (Atom)