Skip to content

Comments

Morse code tsql#14

Open
dbanerjee716 wants to merge 3 commits intoSoftWriters:masterfrom
dbanerjee716:MorseCode-TSQL
Open

Morse code tsql#14
dbanerjee716 wants to merge 3 commits intoSoftWriters:masterfrom
dbanerjee716:MorseCode-TSQL

Conversation

@dbanerjee716
Copy link

No description provided.

SOLUTION OVERVIEW:

This is a solution to the Morse Code problem using a T-SQL stored procedure on MS SQL Server 2008.

This stored procedure accepts a file path and an input file name as parameters. The file
contains multiple lines of Morse Codes. The output of the stored procedure is a result set
containing the English translation of the Morse Code lines, which can be used by any 
application code executing this stored procedure. Create this stored procedure in any 
database of choice. The DDL for the stored procedure usp_MorseDecipher can be found in the 
file named MorseDecipher.
	
Prerequisites:

1. On the SQL Server instance grant permission for 'Administer Bulk Operations'
	2. The SQL Server Service Agent must have read privilege on the folder where the input file resides
3. This stored procedure uses 4 files for processing. These files should be present in the
   same file path passed as the first parameter to this stored procedure. These files are:
	(a) The Morse Code input file (a sample provided in the packet
	(b) The Morse Code input format file called MorseInputFormat.fmt, which contains the metadata 
	    of the input file (included in the packet)
	(c) The Morse Code mapping file which contains the Morse Code to English alphabet mappings
	    (included in the packet)
	(d) The Morse Code mapping format file called MorseInputFormat.fmt, which contains the metadata 
	    of the mapping file (included in the packet)
Imran-imtiaz48

This comment was marked as off-topic.

Copy link

@Imran-imtiaz48 Imran-imtiaz48 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This stored procedure is ambitious and covers a full end to end Morse code decoding process, but there are several areas where the implementation can be made cleaner, safer, and more maintainable. The overall logic works, but the procedure relies heavily on dynamic SQL for loading files, which introduces avoidable security and performance risks. Using OPENROWSET is fine, but constructing raw strings with file paths directly from parameters makes the procedure sensitive to formatting errors and SQL injection if the inputs are ever exposed externally. The procedure also creates multiple temporary tables on every execution, some of which could be handled with table variables or a single reusable structure to reduce overhead. The cursor based loops work, but they make the procedure hard to follow and could be replaced by set based processing, especially in the break detection logic. The nested pattern scanning for letter and word boundaries is correct but complex, and the cleanup cursor introduces additional work that could be simplified with conditional filtering. There are also several variables that can be scoped more tightly, and some repeated logic that can be extracted into smaller helper blocks for readability. Overall, the procedure succeeds in performing its intended decoding, but it would benefit from security hardening, reduced cursor usage, and structural simplification to make long term maintenance easier and performance more predictable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants