Filestream Filetable 在插入时不计算 file_type 列的问题
Issue with Filestream Filetable not computing file_type column on insert
我的文件流文件表有问题,当我在其上 运行 插入语句时文件保存,但 file_type 列为空(并且显然不能手动更新,因为这是一个计算列)
DECLARE @counter INT, @maxPolicySectionId INT
DECLARE @name NVARCHAR(128)
DECLARE @file_stream VARBINARY(MAX)
DECLARE @path NVARCHAR(256)
DECLARE @command NVARCHAR(MAX)
DECLARE @fileTable TABLE(
name NVARCHAR(50),
filePath NVARCHAR(128),
polSecId INT
);
--...Populate @fileTable from database table...--
SELECT @counter = MIN(policySectionId), @maxPolicySectionId = MAX(policySectionId) FROM tblPolicySection
SET @name = (SELECT name FROM @fileTable WHERE polSecId = @counter)
SET @path = (SELECT filePath FROM @fileTable WHERE polSecId = @counter)
SET @path = REPLACE(@path, '192.168.0.6', 'meta-filesrv')
--SET @file_type in Filetable somehow.. unable to perform UPDATE because it's a computed column
SET @command = N'SELECT @file_stream1 = CAST(bulkcolumn AS varbinary(MAX))
from OPENROWSET(BULK ''' + @path + ''',
SINGLE_BLOB) AS x'
EXEC sp_executesql @command, N'@file_stream1 VARBINARY(MAX) OUTPUT',@file_stream1 = @file_stream OUTPUT
IF @path IS NOT NULL AND @name IS NOT NULL
BEGIN
INSERT INTO BlobDocStore(
name,
file_stream
)
SELECT
@name,
@file_stream
END
SET @counter = @counter + 1
如您所见,我正在将一个流传递到插入语句中,据我所知,它应该可以正常工作。我希望过去有人对此有过一些经验。谢谢
file_type是从指定的文件名派生的。如果 file_type 列是 NULL
,这表明 @name 值没有文件扩展名。
我的文件流文件表有问题,当我在其上 运行 插入语句时文件保存,但 file_type 列为空(并且显然不能手动更新,因为这是一个计算列)
DECLARE @counter INT, @maxPolicySectionId INT
DECLARE @name NVARCHAR(128)
DECLARE @file_stream VARBINARY(MAX)
DECLARE @path NVARCHAR(256)
DECLARE @command NVARCHAR(MAX)
DECLARE @fileTable TABLE(
name NVARCHAR(50),
filePath NVARCHAR(128),
polSecId INT
);
--...Populate @fileTable from database table...--
SELECT @counter = MIN(policySectionId), @maxPolicySectionId = MAX(policySectionId) FROM tblPolicySection
SET @name = (SELECT name FROM @fileTable WHERE polSecId = @counter)
SET @path = (SELECT filePath FROM @fileTable WHERE polSecId = @counter)
SET @path = REPLACE(@path, '192.168.0.6', 'meta-filesrv')
--SET @file_type in Filetable somehow.. unable to perform UPDATE because it's a computed column
SET @command = N'SELECT @file_stream1 = CAST(bulkcolumn AS varbinary(MAX))
from OPENROWSET(BULK ''' + @path + ''',
SINGLE_BLOB) AS x'
EXEC sp_executesql @command, N'@file_stream1 VARBINARY(MAX) OUTPUT',@file_stream1 = @file_stream OUTPUT
IF @path IS NOT NULL AND @name IS NOT NULL
BEGIN
INSERT INTO BlobDocStore(
name,
file_stream
)
SELECT
@name,
@file_stream
END
SET @counter = @counter + 1
如您所见,我正在将一个流传递到插入语句中,据我所知,它应该可以正常工作。我希望过去有人对此有过一些经验。谢谢
file_type是从指定的文件名派生的。如果 file_type 列是 NULL
,这表明 @name 值没有文件扩展名。