Quantcast
Channel: SQL Server Compact Forum
Viewing all articles
Browse latest Browse all 193

RDA pull() error when using column aliases

$
0
0

I'm using SQL CE 3.5 to pull data to a PDA.  On the pull() side, we use stored procedures to get the data.  On the push() side, we push to a table with an INSTEAD OF INSERT trigger; the trigger looks up/computes various values and inserts into the server-side table where the "real" data resides.  Thus, we should be able to change the proc and the 'abstraction' table to hide underlying schema changes from the PDA code.  It's been working well for years.

I'm struggling currently.  We changed the column names of the server-side table that stores the 'real' data.  Simple enough - we first need to update the stored procedure that is used to get the data by adding aliases to the columns whose names have changed.  However, doing so yields the vaunted error 29007 - The query cannot be tracked. There might not be a primary key, or the query might involve multiple tables.  However, that doesn't seem likely as the PDA works just fine if all aliases are removed from the stored proc.  Using the new column names would of course would require code changes on the PDA which we are trying to avoid.

The aliases are needed on the NON-PK column; the name of the PK column is unchanged.  When no aliases are used, we can see in Profiler that the stored proc call completes and then a call to sp_primary_keys_rowset() is made.  It's because this call returns the base column name from the table that we have NOT changed the name of the PK column in the physical table NOR aliased it in the stored proc.

I've seen where older versions of SQL CE had issues with NULLable columns being aliased.  However, the pull() call fails even if we only alias a single NOT NULL column in the server-side table using the stored procedure.

Below are the server-side table definition and the proc definition.  Any thoughts/help anyone can provide would be most appreciated.  If I wind up having to change the compiled code to use unaliased column names, it will greatly expand our testing effort which we would very much like to avoid.

SERVER-SIDE TABLE DEFINITION:

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[BradenScale](
	[braden_scale_id] [uniqueidentifier] NOT NULL,
	[LocationID] [int] NOT NULL,
	[PatientID] [int] NOT NULL,
	[DateTaken] [datetime] NOT NULL,
	[SensoryPerception] [nvarchar](30) NOT NULL,
	[Moisture] [nvarchar](30) NOT NULL,
	[Activity] [nvarchar](30) NOT NULL,
	[Mobility] [nvarchar](30) NOT NULL,
	[Nutrition] [nvarchar](30) NOT NULL,
	[FrictionAndShear] [nvarchar](30) NOT NULL,
	[Score] [int] NOT NULL,
	[Risk] [nvarchar](50) NOT NULL,
	[active] [smallint] NOT NULL,
	[UserID] [int] NOT NULL,
	[UserInfo] [nvarchar](100) NOT NULL,
	[Outcome] [nvarchar](50) NULL,
	[ScarOverBonyProminence] [bit] NULL,
	[HasNonRemovableDressing] [bit] NULL,
 CONSTRAINT [PK_BradenScale] PRIMARY KEY NONCLUSTERED 
(
	[braden_scale_id] 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


/****** Object:  Index [BradenScale_UCDX]    Script Date: 07/30/2012 17:36:51 ******/
CREATE UNIQUE CLUSTERED INDEX [BradenScale_UCDX] ON [dbo].[BradenScale] 
(
	[LocationID] ASC,
	[PatientID] ASC,
	[braden_scale_id] 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

STORED PROCEDURE CALL VIA PULL():

If you uncomment ANY of the aliases, the call to PULL() fails.

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE procedure [dbo].[SelectBradenScalePDA]( @location_id int )
as
SET NOCOUNT ON

Select 
	b.braden_scale_id
	, b.PatientID as patient_id
	, b.DateTaken --as date_taken
	, b.SensoryPerception --as sensory_perception
	, b.Moisture --as moisture
	, b.Activity --as activity
	, b.Mobility --as mobility
	, b.Nutrition --as nutrition
	, b.FrictionAndShear --as friction_shear
	, b.Score --as score
	, b.Risk --as risk
	, b.Active --as active
	, b.Outcome --as outcome!
	, b.UserID --as nurse_id
	, b.ScarOverBonyProminence --as scar_over_bony_prominence!
	, b.HasNonRemovableDressing --as non_removable_dressing!
--	, b.locationID, UserInfo	-- these are new columns whose values get assigned by the INSTEAD OF INSERT trigger on the 'abstraction' table
From dbo.BradenScale b with (nolock)
where b.Active = 1
	and b.PatientID in (
		select patient_id
		from dbo.Patient with (nolock)
		where location_id = @location_id
			and Active = 1
	)

SET NOCOUNT OFF

GO


Viewing all articles
Browse latest Browse all 193

Trending Articles