Turning the ship in the gutter wastes an hour

Source: Internet
Author: User

After such a long period of time, the company can solve or provide solutions for a small number of problems in the short term, especially to colleagues, but today I bought it in an hour.

Maybe Boyou is serious. This kind of low IQ error should not happen, but it happened to me, who is not too talented.

Stored Procedure debugging:

Code
1 Alter   Procedure [ DBO ] . [ P_chkuserinfo ]  
2 (
3 @ DeviceID Varchar ( 64 ),
4 @ Rlt   Tinyint Output
5 )
6 As
7 Begin
8 Declare   @ CNT   As   Int
9 Declare   @ Flag   As   Int
10 Select   @ CNT   =   Count ( * ) From Userinfo Where DeviceID = @ DeviceID ;
11 If ( @ CNT > 0 )
12 Begin
13 Select   @ Flag   = Valid From Userinfo Where DeviceID = @ DeviceID ;
14 If ( @ Flag = 0 )
15 Begin
16 Set   @ Rlt   = 0 -- Registered
17 End
18 Else
19 Begin
20 Set   @ Rlt = 1   -- Not registered
21 End
22 End
23 Else
24 Begin
25 Insert   Into Userinfo (DeviceID, valid) Values ( @ DeviceID , 1 );
26 Set   @ Rlt =   3 -- The original user table does not have
27 End
28 End

 
 
  

It's so easy. If a device is not registered, it cannot be registered. The returned value is 3;

Apparently there was no data inserted, but there was no exception. I don't understand. Half an hour has passed and the problem persists. Let's go out and walk around. We can't be so depressed, right, if an exception occurs in the stored procedure, it will not be thrown unless you handle the exception.

So I made an exception in the storage process, and the problem suddenly showed up. I cut it off and fainted. Oh, check that the device ID exceeds the length of 32 characters, 64 should be enough.

Good beforeProgramThe local database is not synchronized with the development.

Good project management and good programming style need to be kept in mind. If the stored procedure performs Exception Handling, if the database is synchronized with the development library, if it is smart, realize that the stored procedure will eat exceptions ...... will I still make this low-level mistake? I will not regret it when I get off work.

Exception Handling is an important part of the design. whenever and wherever it is like a transaction, do not leave multithreading alone.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.