SoftTree Technologies SoftTree Technologies
Technical Support Forums
RegisterSearchFAQMemberlistUsergroupsLog in
Refactor - Version 6

 
Reply to topic    SoftTree Technologies Forum Index » SQL Assistant View previous topic
View next topic
Refactor - Version 6
Author Message
brianshannon



Joined: 18 Feb 2010
Posts: 18
Country: United States

Post Refactor - Version 6 Reply with quote
For the first time I am using the Refactoring feature of the professional version.

During my initial attempts to refactor a test table I continue to get a message stating:

Database Error MSG 139, Level 15 State 1, Cannot assign a default value to a local variable

Any thoughts?

Also, If i change the name of a column in a table using Refactor, is it supposed to change the column name in all dependecies such as stored procedures and functions?
Thu Oct 06, 2011 2:03 pm View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7849

Post Reply with quote
Quote:
During my initial attempts to refactor a test table I continue to get a message stating:
Database Error MSG 139, Level 15 State 1, Cannot assign a default value to a local variable


Please provide DDL for your test table and describe exactly what you are changing and where exactly the error is reported.

Quote:
Also, If i change the name of a column in a table using Refactor, is it supposed to change the column name in all dependecies such as stored procedures and functions?


That's correct. You can see all that in the change preview dialog and choose what to change and what not. By default it will attempt to rename all found references to the column.
Thu Oct 06, 2011 11:01 pm View user's profile Send private message
brianshannon



Joined: 18 Feb 2010
Posts: 18
Country: United States

Post Reply with quote
My DDL:
CREATE TABLE dbo._bs_refactor
(
a INT,
b INT,
c int
)

-I will highlight the table name: dbo._bs_refactor
-I enter a new name _bs_refactor_1 and leave all other defaults unchanged --> click next
-Step 2 shows a tree diagram where i can select what i want refactored --> click Refactor
-Step 3 shows the error box. Database Error MSG 139, Level 15 State 1, Cannot assign a default value to a local variable
Wed Oct 12, 2011 5:23 pm View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7849

Post Reply with quote
Quote:
-Step 3 shows the error box. Database Error MSG 139, Level 15 State 1, Cannot assign a default value to a local variable


Do you know the dependent object this error is displayed for? Do you see any invalid code changes in the preview (step 2)?
Thu Oct 13, 2011 10:05 am View user's profile Send private message
brianshannon



Joined: 18 Feb 2010
Posts: 18
Country: United States

Post Reply with quote
I tried to process the code generated and get the same error:

declare @objname varchar(255) = '['+ 'dbo'+'].['+'_bs_refactor'+']'
EXEC sp_rename @objname, '_bs_refactor_1', 'OBJECT'

The error occurs at: declare @objname varchar(255) = '['+ 'dbo'+'].['+'_bs_refactor'+']'

If I change it and run the below it will work:

declare @objname varchar(255)
SET @objname = '['+ 'dbo'+'].['+'_bs_refactor'+']'

Is there a fix for this?
Fri Oct 14, 2011 6:10 pm View user's profile Send private message
gemisigo



Joined: 11 Mar 2010
Posts: 2109

Post Reply with quote
brianshannon wrote:
I tried to process the code generated and get the same error:

declare @objname varchar(255) = '['+ 'dbo'+'].['+'_bs_refactor'+']'
EXEC sp_rename @objname, '_bs_refactor_1', 'OBJECT'

The error occurs at: declare @objname varchar(255) = '['+ 'dbo'+'].['+'_bs_refactor'+']'

If I change it and run the below it will work:

declare @objname varchar(255)
SET @objname = '['+ 'dbo'+'].['+'_bs_refactor'+']'

Is there a fix for this?


If I recall correctly, declaring a variable and assigning value at the same time was introduced in SQL Server 2k8. If you are on Server 2k or 2k5 you get the error 'Cannot assign a default value to a local variable' when executing 'DECLARE @myvariable INT = 0' and similar. Perhaps the refactoring code does not take this into account.
Sat Oct 15, 2011 8:16 am View user's profile Send private message
brianshannon



Joined: 18 Feb 2010
Posts: 18
Country: United States

Post Reply with quote
I am running this on 2 k server or is that a bug.

So refactor only works on 2008 server?

I have another post about view dependencies not working. Is that the case there as well.
Sat Oct 15, 2011 8:39 am View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7849

Post Reply with quote
you will need to change "object rename query" in SQL Assistant options.

Here is what you have now

Code:
[code]declare @objname varchar(255) = '['+ :REFACTORING_SCHEMA+'].['+:REFACTORING_OLD_NAME+']'
EXEC sp_rename @objname, :REFACTORING_NEW_NAME, 'OBJECT'[/code]


Here is what you need to make it compatible with SQL 2000

Code:
DECLARE @objname varchar(255)
SET @objname = '['+ :REFACTORING_SCHEMA+'].['+:REFACTORING_OLD_NAME+']'
EXEC sp_rename @objname, :REFACTORING_NEW_NAME, 'OBJECT'


To modify the query, open SQL Assistant Options, click Refactoring tab, click SQL Server Refactoring type in the left top corner, expand DB Queries for SQL Server Refactoring group on the left bottom; select [object rename] query, update the code as described above.
Sat Oct 15, 2011 4:19 pm View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7849

Post Reply with quote
Please make similar changes in [column delete] and [column rename] queries, separating variable declarations from value assignments. That should do it.
Sat Oct 15, 2011 4:27 pm View user's profile Send private message
Display posts from previous:    
Reply to topic    SoftTree Technologies Forum Index » SQL Assistant All times are GMT - 4 Hours
Page 1 of 1

 
Jump to: 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


 

 

Powered by phpBB © 2001, 2005 phpBB Group
Design by Freestyle XL / Flowers Online.