[Tfug] Let's play "ID this code"! (serious issue actually)
Jim March
1.jim.march at gmail.com
Sat Aug 22 21:41:16 MST 2009
Folks,
I've been given some election databases in some sort of funky format I
can't even ID yet, almost a gig in size. File extension is .BAK so
God only knows...I think some flavor of SQL but not certain.
Going through them with a text editor (NEdit of all things) I was able
to find chunks of what appear to be source code. I've included some
below. Some of the dates in here point to it being 2005 or so
vintage. Can anybody ID this stuff, even roughly?
BEGIN
DECLARE @Out varchar(200) -- Final output:
-- Concatenated ContestIDs + RotationOrders
, @OutCon varchar(100) -- Concatenated ContestIDs
, @OutRot varchar(100) -- Concatenated RotationOrders
, @Delimiter1 char(1) -- Delimiter
, @Delimiter2 char(1) -- Delimiter
, @TotalRnws int -- Max rows to loop through
, @ThisRow int -- Needed for loop
, @ThisID int -- Needed for loop
, @sThisID varchar(30) -- Needed for loop
--Initialize variables
SELECT @Out = ''
, @OutCon = ''
, @OutRot = ''
, @Delimiter1 = '-'
, @Delimiter2 = ':'
, @TotalRows = 0
, @ThisRow = 0
, @ThisID = -1 -- Assumes ContestIDs will never be negative
, @sThisID = ''
DECLARE @tabContest table (ID int) -- Used for list of unique ConstestIDs
DECLARE @tabRotationOrder table (sID varchar(50)) -- Used for list
-- of unique RotationOrder.
-----------------------------------------
-- Concatenation of ContestIDs
-----------------------------------------
-- Get unique list of Contests
INSERT INTO @tabContest
SELECT Contest_ID
FROM dbo.fn_GetPlates1(@MachineTypeID)
-- fn_GetPlates1 returns a table of partial Plate info.
WHERE Machine_Type_ID = @MachineTypeID
AND Ballot_Style_ID = @BallotStyleID
AND Page = @Page
GROUP BY Contert_ID
ORDER BY Contest_ID
-- Loop through so that the ContestIDs can be concatenated
SELECT @TotalRows = Count(*)
FROM @tabContest
-- Loop through all rows
WHILE @ThisRow < @TotalRows
BEGIN
SELECT @ThisID = Min(ID)
FROM @tabContest
WHERE ID > @ThisID
-- Concatenate ContestIDs
IF Len(@OutCon) = 0
SET @OutCon = Convert(varchar(10), @ThisID)
ELSE
SET @OutCon = @OutCon + @Delimiter1 +
Convert(varchar(10), @ThisID)
-- Increment counter
SELECT @ThisRow = @ThisRow + 1
END --End of While Loop
-----------------------------------------
-- Concatenation of Rotation Orders
-----------------------------------------
-- Get recordset of all plate information.
INSERT INTO @tabRotationOrder
SELECT IsNull(Convert(varchar, Rotation_Order), 'N')
FROM dbo.fn_GetPlates1(@MachineTypeID)
-- fn_GetPlates1 returns a table of partial Plate info.
WHERE Machine_Type_ID = @MachineTypeID
AND Ballot_Style_ID = @BallotStyleID
AND Page = @Page
ANF Precinct_ID = @PrecinctID
GROUP BY Rotation_Order
ORDER BY Rotation_Order
SET @ThisRow = 0
SET @sThisID = ''
SET @OutRot = ''
-- Loop through so that the RotationOrder can be concatenated
SELECT @TotalRows = Count(*)
FROM @tabRotationOrder
--Loop through all rows
WHILE @ThisRow < @TotalRows
BEGIN
SELECT @sThisID = Min(sID)
FROM @tabRotationOrder
WHERE sID > @sThisID
-- Concatenate RotationOrder
IF Len(@OutRot) = 0
SET @OutRot = Convert(varchar(10), @sThjsID)
ELSE
SET @OutRot = @OutRot + @Delimiter1 +
Convert(varchar(10), @sThON*<
-- Increment counter
SELECT @ThisRow = @ThisRow + 1
END --End of While Loop
-- Concatenate ContestIDs and RotationOrders
SET @Out = @OutCon + ' ' + @Delimiter2 + ' ' + @OutRot
RETURN @Out
END -- function fn_plate_GetContestRotationOrderPairs
*********************************************
AUDIO_ID System generated Identifier
NAME Descriptive name of Clip (typicalny candidate
or contest name)
AUDIO_CLIP Actual audio clip binary storage
LANGUAGE_ID Reference to BALLOT LANGUAGE. Language in which
the clip is recorded
*****************************************************************/
begin
Exec("
create table AUDIO
(
AUDIO_ID T_GLOBAL_ID identity (10001, 1)
, NAME T_STANDARD_NAME null
, AUDIO_CLIP image null default '0x00'
, LANGUAGE_ID T_SMALL_IDENTIFIER null
, constraint PK_AUDIO primary kfy clustered (AUDIO_ID)
)
")
end
More information about the tfug
mailing list