132 lines
6.5 KiB
Transact-SQL
132 lines
6.5 KiB
Transact-SQL
SET ANSI_NULLS ON;
|
|
GO
|
|
SET QUOTED_IDENTIFIER ON;
|
|
GO
|
|
|
|
IF COL_LENGTH(N'dbo.Scenes', N'StructuralSetting') IS NULL
|
|
ALTER TABLE dbo.Scenes ADD StructuralSetting nvarchar(300) NULL;
|
|
GO
|
|
|
|
CREATE OR ALTER PROCEDURE dbo.SceneStructuralSummary_Save
|
|
@SceneID int,
|
|
@StructuralSummary nvarchar(max),
|
|
@StructuralSetting nvarchar(300) = NULL
|
|
AS
|
|
BEGIN
|
|
SET NOCOUNT ON;
|
|
|
|
UPDATE dbo.Scenes
|
|
SET StructuralSummary = NULLIF(LTRIM(RTRIM(@StructuralSummary)), N''),
|
|
StructuralSetting = COALESCE(NULLIF(LTRIM(RTRIM(@StructuralSetting)), N''), StructuralSetting),
|
|
Summary = CASE
|
|
WHEN NULLIF(LTRIM(RTRIM(Summary)), N'') IS NULL THEN NULLIF(LTRIM(RTRIM(@StructuralSummary)), N'')
|
|
ELSE Summary
|
|
END,
|
|
UpdatedDate = SYSUTCDATETIME()
|
|
WHERE SceneID = @SceneID;
|
|
END;
|
|
GO
|
|
|
|
CREATE OR ALTER PROCEDURE dbo.Scene_ListByChapter
|
|
@ChapterID int
|
|
AS
|
|
BEGIN
|
|
SET NOCOUNT ON;
|
|
SELECT s.SceneID, s.ChapterID, c.BookID, b.BookNumber, b.SortOrder AS BookSortOrder, b.BookTitle, b.Subtitle AS BookSubtitle,
|
|
c.ChapterNumber, c.SortOrder AS ChapterSortOrder, c.ChapterTitle,
|
|
s.SceneNumber, s.SceneTitle, s.Summary, s.StructuralSummary, s.StructuralSetting,
|
|
s.POVCharacterID, pov.CharacterName AS POVCharacterName, s.POVSource, s.POVConfidence, s.POVEvidence, s.POVSuggestedName,
|
|
s.PrimaryLocationID, location.LocationName AS PrimaryLocationName, location.LocationPath AS PrimaryLocationPath,
|
|
s.FloorPlanID, s.InitialFloorPlanFloorID, s.SortOrder,
|
|
s.TimeModeID, tm.TimeModeName, s.StartDateTime, s.EndDateTime, s.DurationAmount,
|
|
s.DurationUnitID, du.DurationUnitName, s.RelativeTimeText, s.TimeConfidenceID,
|
|
tc.TimeConfidenceName, s.ScenePurposeNotes, s.SceneOutcomeNotes, s.RevisionStatusID,
|
|
rs.StatusName AS RevisionStatusName, s.CreatedDate, s.UpdatedDate, s.IsArchived,
|
|
s.ArchivedDate, s.ArchivedReason, s.IsLinkedToManuscript, s.ManuscriptDocumentID,
|
|
s.ExternalReference, s.LinkedUtc, s.ImportSource, s.ImportRunID,
|
|
s.SourceStartParagraph, s.SourceEndParagraph
|
|
FROM dbo.Scenes s
|
|
INNER JOIN dbo.Chapters c ON c.ChapterID = s.ChapterID
|
|
INNER JOIN dbo.Books b ON b.BookID = c.BookID
|
|
INNER JOIN dbo.TimeModes tm ON tm.TimeModeID = s.TimeModeID
|
|
LEFT JOIN dbo.DurationUnits du ON du.DurationUnitID = s.DurationUnitID
|
|
INNER JOIN dbo.TimeConfidences tc ON tc.TimeConfidenceID = s.TimeConfidenceID
|
|
INNER JOIN dbo.RevisionStatuses rs ON rs.RevisionStatusID = s.RevisionStatusID
|
|
LEFT JOIN dbo.LocationPaths location ON location.LocationID = s.PrimaryLocationID
|
|
LEFT JOIN dbo.Characters pov ON pov.CharacterID = s.POVCharacterID
|
|
WHERE s.ChapterID = @ChapterID AND s.IsArchived = 0
|
|
ORDER BY s.SortOrder, s.SceneNumber, s.SceneTitle;
|
|
END;
|
|
GO
|
|
|
|
CREATE OR ALTER PROCEDURE dbo.Scene_Get
|
|
@SceneID int
|
|
AS
|
|
BEGIN
|
|
SET NOCOUNT ON;
|
|
EXEC dbo.SceneMetric_EnsureDefaults @SceneID;
|
|
SELECT s.SceneID, s.ChapterID, c.BookID, b.BookNumber, b.SortOrder AS BookSortOrder, b.BookTitle, b.Subtitle AS BookSubtitle,
|
|
c.ChapterNumber, c.SortOrder AS ChapterSortOrder, c.ChapterTitle,
|
|
s.SceneNumber, s.SceneTitle, s.SceneTitleSource, s.Summary, s.StructuralSummary, s.StructuralSetting,
|
|
s.POVCharacterID, pov.CharacterName AS POVCharacterName, s.POVSource, s.POVConfidence, s.POVEvidence, s.POVSuggestedName,
|
|
s.PrimaryLocationID, s.FloorPlanID, s.InitialFloorPlanFloorID,
|
|
location.LocationName AS PrimaryLocationName, location.LocationPath AS PrimaryLocationPath,
|
|
s.SortOrder, s.TimeModeID, tm.TimeModeName, s.StartDateTime, s.EndDateTime, s.DurationAmount, s.DurationUnitID,
|
|
du.DurationUnitName, s.RelativeTimeText, s.TimeConfidenceID, tc.TimeConfidenceName, s.ScenePurposeNotes,
|
|
s.SceneOutcomeNotes, s.RevisionStatusID, rs.StatusName AS RevisionStatusName, s.CreatedDate, s.UpdatedDate, s.IsArchived,
|
|
s.ArchivedDate, s.ArchivedReason, s.IsLinkedToManuscript, s.ManuscriptDocumentID, s.ExternalReference, s.LinkedUtc,
|
|
s.ImportSource, s.ImportRunID, s.SourceStartParagraph, s.SourceEndParagraph
|
|
FROM dbo.Scenes s
|
|
INNER JOIN dbo.Chapters c ON c.ChapterID = s.ChapterID
|
|
INNER JOIN dbo.Books b ON b.BookID = c.BookID
|
|
INNER JOIN dbo.TimeModes tm ON tm.TimeModeID = s.TimeModeID
|
|
INNER JOIN dbo.TimeConfidences tc ON tc.TimeConfidenceID = s.TimeConfidenceID
|
|
INNER JOIN dbo.RevisionStatuses rs ON rs.RevisionStatusID = s.RevisionStatusID
|
|
LEFT JOIN dbo.DurationUnits du ON du.DurationUnitID = s.DurationUnitID
|
|
LEFT JOIN dbo.LocationPaths location ON location.LocationID = s.PrimaryLocationID
|
|
LEFT JOIN dbo.Characters pov ON pov.CharacterID = s.POVCharacterID
|
|
WHERE s.SceneID = @SceneID AND s.IsArchived = 0;
|
|
SELECT ScenePurposeTypeID FROM dbo.ScenePurposes WHERE SceneID = @SceneID;
|
|
EXEC dbo.SceneMetric_ListByScene @SceneID;
|
|
END;
|
|
GO
|
|
|
|
CREATE OR ALTER PROCEDURE dbo.SceneManuscriptSource_ListByChapter
|
|
@ChapterID int
|
|
AS
|
|
BEGIN
|
|
SET NOCOUNT ON;
|
|
|
|
SELECT source.SceneID, scene.SceneNumber, scene.SceneTitle, scene.SceneTitleSource,
|
|
source.ProjectID, source.BookID, source.ChapterID, source.SourceText,
|
|
source.SourceWordCount, source.SourceCharacterCount, source.SourceStartParagraph, source.SourceEndParagraph,
|
|
source.WordStartParagraphIndex, source.WordEndParagraphIndex, source.SourceKind,
|
|
scene.StructuralSummary, scene.StructuralSetting, source.CreatedUtc, source.UpdatedUtc
|
|
FROM dbo.SceneManuscriptSources source
|
|
INNER JOIN dbo.Scenes scene ON scene.SceneID = source.SceneID
|
|
WHERE source.ChapterID = @ChapterID
|
|
AND scene.IsArchived = 0
|
|
ORDER BY scene.SortOrder, scene.SceneNumber, scene.SceneID;
|
|
END;
|
|
GO
|
|
|
|
CREATE OR ALTER PROCEDURE dbo.SceneManuscriptSource_ListByBook
|
|
@BookID int
|
|
AS
|
|
BEGIN
|
|
SET NOCOUNT ON;
|
|
|
|
SELECT source.SceneID, scene.SceneNumber, scene.SceneTitle, scene.SceneTitleSource,
|
|
source.ProjectID, source.BookID, source.ChapterID, source.SourceText,
|
|
source.SourceWordCount, source.SourceCharacterCount, source.SourceStartParagraph, source.SourceEndParagraph,
|
|
source.WordStartParagraphIndex, source.WordEndParagraphIndex, source.SourceKind,
|
|
scene.StructuralSummary, scene.StructuralSetting, source.CreatedUtc, source.UpdatedUtc
|
|
FROM dbo.SceneManuscriptSources source
|
|
INNER JOIN dbo.Scenes scene ON scene.SceneID = source.SceneID
|
|
INNER JOIN dbo.Chapters chapter ON chapter.ChapterID = scene.ChapterID
|
|
WHERE source.BookID = @BookID
|
|
AND scene.IsArchived = 0
|
|
ORDER BY chapter.SortOrder, chapter.ChapterNumber, scene.SortOrder, scene.SceneNumber, scene.SceneID;
|
|
END;
|
|
GO
|