Click here to Skip to main content
12,635,802 members (25,237 online)
Click here to Skip to main content
Articles » Database » Database » Utilities » Downloads

Stats

24.2K views
41 bookmarked
Posted

FUSE(file system in userspace) for Microsoft-SQL using C#

, 19 Aug 2010 CPOL
Map your database table as network disk
MSSQLFS
Application
bin
MSSQLFS_App.suo
Properties
CodeProject
MSSQLFS.suo
SqlFS
bin
Metadata
Properties
SqlFS.csproj.user
SqlFS.suo
Zalohy
Program.zip
Zdroje
DokanNet+-+2009_01_30+-+With+working+MirrorFS+and+TraceFS.zip
Zdroje
Database-Off.bmp
Database-On.bmp
Icon.bmp
Icon.pdn
Icon1.ico
Server-off.bmp
Server-on.bmp
User.bmp
Z lohy
��USE [ekvelb2]

GO

/****** Object:  User [nedopilm]    Script Date: 08/13/2010 14:12:19 ******/

CREATE USER [nedopilm] FOR LOGIN [nedopilm] WITH DEFAULT_SCHEMA=[dbo]

GO

/****** Object:  Table [dbo].[DOKANFS]    Script Date: 08/13/2010 14:12:21 ******/

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

SET ANSI_PADDING ON

GO

CREATE TABLE [dbo].[DOKANFS](

	[IDFILE] [int] IDENTITY(1,1) NOT NULL,

	[FILENAME] [varchar](255) NULL,

	[ISDIRECTORY] [bit] NULL,

	[CONTENT] [varbinary](max) NULL,

	[LastAccessTime] [datetime] NOT NULL,

	[LastWriteTime] [datetime] NOT NULL,

	[CreationTime] [datetime] NOT NULL,

	[Attributes] [bigint] NULL,

	[IsZipped] [bit] NULL,

	[IsEncrypted] [bit] NULL,

	[OriginalSize] [bigint] NULL,

	[Version] [int] NULL,

 CONSTRAINT [PK_DOKANFS] PRIMARY KEY CLUSTERED 

(

	[IDFILE] ASC

)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]

) ON [PRIMARY]

GO

SET ANSI_PADDING OFF

GO

CREATE UNIQUE NONCLUSTERED INDEX [IX_DOKANFS] ON [dbo].[DOKANFS] 

(

	[FILENAME] ASC,

	[Version] ASC

)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]

GO

/****** Object:  StoredProcedure [dbo].[WriteFile]    Script Date: 08/13/2010 14:12:23 ******/

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

CREATE PROCEDURE [dbo].[WriteFile]

	(

	@filename varchar(255),

	@data varbinary(max),

	@IsZipped bit,

	@OriginalSize bigint

	)

	

AS

    declare @isVersioned int

    set @isVersioned = 0

    

	SET NOCOUNT ON

	if patindex('%.version',@filename) = len(@filename) - LEN('.version') + 1 begin

	   set @filename = substring(@filename,1,patindex('%.version',@filename)-1)

	   set @isVersioned = 1

	   end

	   

    if 1=(select top 1 1 from DOKANFS where FILENAME = @filename and Version is null) begin

	   

	  	   /* get last version number and increment */

	    if @isVersioned = 1 begin	   

		   declare @version int

		   select @version = isnull(version,0) + 1

		   From DOKANFS

		   where FILENAME = @filename 

			 and isnull(Version,0) = (select MAX(isnull(version,0)) 

							  from DOKANFS 

							 where FILENAME = @filename)

		   

		   /* save current to version file */

		   insert into DOKANFS

		   (FILENAME,ISDIRECTORY,CONTENT,IsZipped,OriginalSize,CreationTime,IsEncrypted,LastAccessTime,LastWriteTime, Version)

		   select FILENAME,ISDIRECTORY,CONTENT,IsZipped,OriginalSize,CreationTime,IsEncrypted,LastAccessTime,LastWriteTime, @version

		   From DOKANFS

		   where FILENAME = @filename and Version is null

	       end

	   

	   /* update current context file */

	   update DOKANFS

	      set CONTENT = @data,

	          LastAccessTime = GetDate(),

	          LastWriteTime = GETDATE(),

	          OriginalSize = @OriginalSize,

	          isZipped = @IsZipped

	      where FILENAME = @filename and Version is null

	   end else begin

	   

   	   insert into DOKANFS(FILENAME,ISDIRECTORY,CONTENT,IsZipped, OriginalSize,CreationTime, LastAccessTime, LastWriteTime) 

   	   values(@filename,0,@data,@IsZipped,@OriginalSize, GetDate(), GetDate(), GetDate()) 

   	   

   	   end

	 

	RETURN

GO

/****** Object:  StoredProcedure [dbo].[ReadFile]    Script Date: 08/13/2010 14:12:23 ******/

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

CREATE PROCEDURE [dbo].[ReadFile]

	

	(

	@filename varchar(255)

	)

	

AS



/*







declare @readbytes bigint



exec ReadFile2

 '\ahoj.txt',

 0

 



 

 

 print @readbytes



 */

 

	SET NOCOUNT ON



	

	SELECT DATALENGTH(CONTENT) as size, IsZipped, DOKANFS.CONTENT

	from DOKANFS

	where FILENAME = @filename

	  and Version is null

	

	

	RETURN

GO

/****** Object:  StoredProcedure [dbo].[MoveFile]    Script Date: 08/13/2010 14:12:23 ******/

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

CREATE PROCEDURE [dbo].[MoveFile]

	

	(

	@filename varchar(255),

	@newname varchar(255),

	@replace bit

	)

	

AS

	/* SET NOCOUNT ON */

	

	if @replace = 0 begin

	   if 1=(select top 1 1 from DOKANFS where FILENAME = @newname) 

	      raiserror('File already exists',16,1)

	   end

	delete from dokanfs

	where filename = @newname and Version is null

	

	update dokanfs

	set filename = @newname

	where filename = @filename

	  and Version is null

	

	RETURN

GO

/****** Object:  StoredProcedure [dbo].[GetFileInformation]    Script Date: 08/13/2010 14:12:23 ******/

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

CREATE PROCEDURE [dbo].[GetFileInformation]

	(

	@filename varchar(255),

	@IsDirectory  bit OUTPUT,

	@Length bigint OUTPUT,

	@LastAccessTime DateTime OUTPUT,

	@LastWriteTime DateTime OUTPUT,

	@CreationTime DateTime OUTPUT

	)

	

AS

	SET NOCOUNT ON 

	

	select @IsDirectory = isdirectory, @Length = IsNull(OriginalSize,DATALENGTH([CONTENT])),

	       @LastAccessTime = LastAccessTime, @LastWriteTime = LastWriteTime,

	       @CreationTime = CreationTime

	  from DOKANFS 

	 where (filename = @filename)

	   and Version is null

	

	RETURN

GO

/****** Object:  StoredProcedure [dbo].[FindFiles]    Script Date: 08/13/2010 14:12:23 ******/

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

CREATE PROCEDURE [dbo].[FindFiles]

	(

	@filename varchar(255)

	)

	

AS

    /*

    exec FindFiles @filename = '\Treti' 

    */

	SET NOCOUNT ON 

	

	if @filename = '\' set @filename = '\' else set @filename = @filename+'\'

	

	select filename, isdirectory, IsNull(OriginalSize,DATALENGTH([CONTENT])) as size, filename as fullfilename,

	       LastAccessTime,LastWriteTime,CreationTime

	  into #TEMP

	  from DOKANFS 

	 where (filename like @filename+'%' and FILENAME not like @filename+'%\%' and Version is null)

	

	update #TEMP

	set filename = SUBSTRING(filename, CHARINDEX(@filename,filename)+LEN(@filename),255)

	

	insert into #TEMP (filename, isdirectory,size,fullfilename,LastAccessTime,LastWriteTime,CreationTime) 

	       values ('.',1,0,'.',GETDATE(),GETDATE(),GETDATE())

	if @filename <> '\' 

	   insert into #TEMP (filename,isdirectory,size,fullfilename,LastAccessTime,LastWriteTime,CreationTime) 

	          values ('..',1,0,'..',GETDATE(),GETDATE(),GETDATE())

	

	select * from #TEMP order by filename

	

	RETURN

GO

/****** Object:  StoredProcedure [dbo].[DeleteFile]    Script Date: 08/13/2010 14:12:23 ******/

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

CREATE PROCEDURE [dbo].[DeleteFile]

	

	(

	@filename varchar(255)

	)

	

AS

    SET NOCOUNT ON 

    

    delete from DOKANFS where FILENAME like @filename+'%' and Version is null

    

    RETURN

GO

/****** Object:  StoredProcedure [dbo].[CreateDirectory]    Script Date: 08/13/2010 14:12:23 ******/

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

CREATE PROCEDURE [dbo].[CreateDirectory]

	

	(

	@filename varchar(255)

	)

	

AS

    SET NOCOUNT ON 

    insert into DOKANFS(FILENAME, ISDIRECTORY) VALUES (@Filename,1) 

	RETURN

GO

/****** Object:  Default [DF_DOKANFS_LastAccessTime]    Script Date: 08/13/2010 14:12:21 ******/

ALTER TABLE [dbo].[DOKANFS] ADD  CONSTRAINT [DF_DOKANFS_LastAccessTime]  DEFAULT (getdate()) FOR [LastAccessTime]

GO

/****** Object:  Default [DF_DOKANFS_LastWriteTime]    Script Date: 08/13/2010 14:12:21 ******/

ALTER TABLE [dbo].[DOKANFS] ADD  CONSTRAINT [DF_DOKANFS_LastWriteTime]  DEFAULT (getdate()) FOR [LastWriteTime]

GO

/****** Object:  Default [DF_DOKANFS_CreationTime]    Script Date: 08/13/2010 14:12:21 ******/

ALTER TABLE [dbo].[DOKANFS] ADD  CONSTRAINT [DF_DOKANFS_CreationTime]  DEFAULT (getdate()) FOR [CreationTime]

GO

/****** Object:  Default [DF_DOKANFS_IsZipped]    Script Date: 08/13/2010 14:12:21 ******/

ALTER TABLE [dbo].[DOKANFS] ADD  CONSTRAINT [DF_DOKANFS_IsZipped]  DEFAULT ((0)) FOR [IsZipped]

GO

/****** Object:  Default [DF_DOKANFS_IsEncrypted]    Script Date: 08/13/2010 14:12:21 ******/

ALTER TABLE [dbo].[DOKANFS] ADD  CONSTRAINT [DF_DOKANFS_IsEncrypted]  DEFAULT ((0)) FOR [IsEncrypted]

GO

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

martin.nedopil
Czech Republic Czech Republic
No Biography provided

You may also be interested in...

Pro
Pro
| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.161208.2 | Last Updated 19 Aug 2010
Article Copyright 2010 by martin.nedopil
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid