Skip to content

Instantly share code, notes, and snippets.

@ryanhinton
Last active September 15, 2015 16:33
Show Gist options
  • Save ryanhinton/73f1f1c9378661d6697f to your computer and use it in GitHub Desktop.
Save ryanhinton/73f1f1c9378661d6697f to your computer and use it in GitHub Desktop.
using queryExecute() I'm coming across a perplexing issue. The following is what I get in the error and there is an extraneous "ID" placed after "(param 4)". It's not in the actual query. Anyone experienced a similar issue like this?
<cfscript>
local.addUpdateNotification = queryExecute(
"EXEC userNotificationAddUpdate
@title = :title,
@message = :message,
@userNotificationID = :userNotificationID,
@messageID = :messageID,
@caseID = :caseID,
@isMessagedDeleted = :isMessageDeleted,
@isNotificationDeleted = :isNotificationDeleted,
@runBy = :runBy
",
{
title = {value=arguments.title, cfsqltype="cf_sql_varchar"},
message = {value=arguments.message, cfsqltype="cf_sql_varchar"},
userNotificationID = {value=arguments.userNotificationID, cfsqltype="cf_sql_bigint", null="#yesNoFormat(arguments.userNotificationID eq 0)#"},
messageID = {value=arguments.messageID, cfsqltype="cf_sql_bigint", null="#yesNoFormat(arguments.messageID eq 0)#"},
caseID = {value=arguments.caseID, cfsqltype="cf_sql_bigint", null="#yesNoFormat(arguments.caseID eq 0)#"},
isMessageDeleted = {value=arguments.isMessageDeleted, cfsqltype="cf_sql_bit", null="#yesNoFormat(arguments.isMessageDeleted eq -1)#"},
isNotificationDeleted = {value=arguments.isNotificationDeleted, cfsqltype="cf_sql_bit", null="#yesNoFormat(arguments.isNotificationDeleted eq -1)#"},
runBy = {value=arguments.runBy, cfsqltype="cf_sql_bigint"}
},
{datasource = application.datasource}
);
</cfscript>
ALTER PROCEDURE [dbo].[userNotificationAddUpdate]
@caseID BIGINT = NULL,
@userNotificationID BIGINT = NULL,
@messageID BIGINT = NULL,
@title VARCHAR(200) = '@title is not passed in',
@message VARCHAR(MAX) = '@message is not passed in',
@isNotificationDeleted BIT = NULL, -- This param is ignored if message is being created whereby @messageID IS NULL
@isMessageDeleted BIT = NULL, -- This param is ignored if message is being created whereby @messageID IS NULL
@runBy BIGINT = 0,
@now DATETIME = NULL
AS
BEGIN
SET NOCOUNT ON;
SET @isNotificationDeleted = IIF(@isMessageDeleted = 1, 1, @isNotificationDeleted);
SET @now = IIF(@now IS NULL, GETDATE(), @now);
-- Create/Update Message
EXEC @messageID = messageAddUpdate
@messageID = @messageID,
@title = @title,
@message = @message,
@isDeleted = @isMessageDeleted,
@runBy = @runBy,
@now = @now
-- Create Notification for every qualified user.
IF @userNotificationID IS NULL AND @messageID IS NOT NULL BEGIN
INSERT
INTO userNotification (
userID,
caseID,
messageID,
created,
createdBy,
modified,
modifiedBy
)
SELECT userID,
caseID,
messageID,
created,
createdBy,
modified,
modifiedBy
FROM (-- Include all Admin users.
SELECT u.userID,
@caseID AS caseID,
@messageID AS messageID,
@now AS created,
@runBy AS createdBy,
@now AS modified,
@runBy AS modifiedBy
FROM users u WITH (NOLOCK)
INNER JOIN usersRole ur WITH (NOLOCK)
ON ur.userID = u.userID
AND ur.roleID = 1 -- Admin Role
WHERE u.active = 1
AND (u.userName IS NOT NULL
OR u.email IS NOT NULL)
AND u.password IS NOT NULL
UNION
-- Include the user that created the case.
SELECT c.createdBy AS userID,
c.caseID,
@messageID AS messageID,
@now AS created,
@runBy AS createdBy,
@now AS modified,
@runBy AS modifiedBy
FROM cases c WITH (NOLOCK)
WHERE c.caseID = @caseID) un1
WHERE NOT EXISTS (SELECT un.userID
FROM userNotification un WITH (NOLOCK)
WHERE un.userID = un1.userID
AND un.messageID = @messageID)
END
-- Update Notification for every qualified user.
IF @userNotificationID IS NULL AND @caseID IS NOT NULL AND (@messageID IS NOT NULL OR @isNotificationDeleted IS NOT NULL) BEGIN
UPDATE userNotification WITH (ROWLOCK)
SET caseID = CASE
WHEN @caseID IS NOT NULL THEN
@caseID
ELSE
caseID
END,
messageID = CASE
WHEN @messageID IS NOT NULL THEN
@messageID
ELSE
messageID
END,
isDeleted = CASE
WHEN @isNotificationDeleted IS NOT NULL THEN
@isNotificationDeleted
ELSE
isDeleted
END,
modified = @now,
modifiedBy = @runBy
WHERE messageID = @messageID
AND caseID = @caseID
END
-- Update Notification for a user.
IF @userNotificationID IS NOT NULL AND @caseID IS NOT NULL AND (@messageID IS NOT NULL OR @isNotificationDeleted IS NOT NULL) BEGIN
UPDATE userNotification WITH (ROWLOCK)
SET caseID = CASE
WHEN @caseID IS NOT NULL THEN
@caseID
ELSE
caseID
END,
messageID = CASE
WHEN @messageID IS NOT NULL THEN
@messageID
ELSE
messageID
END,
isDeleted = CASE
WHEN @isNotificationDeleted IS NOT NULL THEN
@isNotificationDeleted
ELSE
isDeleted
END,
modified = @now,
modifiedBy = @runBy
WHERE id = @userNotificationID
END
RETURN(@messageID)
END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment