DatabaseProcApplicationCreatedLinks
sybsystemprocssp_hadrvrfyargs  14 déc. 14Defects Propagation Dependencies

1     
2     /*
3     ** SP_HADRVRFYARGS 	**** INTERNAL ONLY ****
4     ** This procedure verifies the arguments passed to the main
5     ** sp_hadr_admin procedure and makes sure that for the given
6     ** action all the required parameters are correctly set. If
7     ** anything is missing, it will print the usage error. 
8     **
9     */
10    create or replace procedure sp_hadrvrfyargs
11        @cmd varchar(255),
12        @arg1 varchar(255),
13        @arg2 varchar(255),
14        @arg3 varchar(255),
15        @arg4 varchar(255),
16        @arg5 varchar(255),
17        @arg6 varchar(255),
18        @srvstate varchar(32)
19    as
20        declare @retstat int, /* return value of executing a SQL */
21            @timeout int, /* timeout for deactivate command */
22            @hadrstate int, /* Current HADR state */
23            @hadrmode int, /* Current HADR mode */
24            @name varchar(30),
25            @dbcount int
26    
27        /* Initialize the defaults */
28        select @retstat = 0
29        select @timeout = 0
30        select @hadrstate = @@hadr_state
31        select @hadrmode = @@hadr_mode
32    
33        /* First process the param list */
34        if @cmd not in ("activate", "deactivate", "cancel", "drain", "status", "map",
35                "primary", "standby", "addserver", "dropserver", "listserver",
36                "init", "propagate", "event", "failover_timeestimate",
37                "setlogin", "dropgroup", "config_bs", NULL)
38        begin
39            /* 19702, "'%1!' is not a valid option to the '%2!' command." */
40            raiserror 19702, @cmd, sp_hadr_admin
41            return (1)
42        end
43    
44        /* Process the parameters */
45    
46        /* "activate" command does not take any argument" */
47        if (@cmd = "activate")
48        begin
49            if @arg1 != NULL or @arg2 != NULL or @arg3 != NULL or @arg4 != NULL
50            begin
51                /* 
52                ** 19210,
53                ** "Syntax error. Extra arguments passed to '%1!' command.
54                ** Run: %2! 'help', '%3!' for usage information."
55                */
56                raiserror 19210, "sp_hadr_admin", "sp_hadr_admin", "activate"
57                return (1)
58            end
59            /*
60            ** Activate is valid only if the server is PRIMARY and in 
61            ** INACTIVE state
62            */
63            if @hadrmode != 1 or @hadrstate != 2
64            begin
65                /* 17157, "'%1!' command is not allowed in current server state (%2!)." */
66                raiserror 17157, "ACTIVATE", @srvstate
67                return (1)
68            end
69        end
70        else
71        if (@cmd = 'failover_timeestimate')
72        begin
73            /* valid only if the server is currently active */
74            if @hadrmode != 1 or @hadrstate != 1
75            begin
76                /* 17157, "'%1!' command is not allowed in current server state
77                */
78                raiserror 17157, "failover_timeestimate", @srvstate
79                return (1)
80            end
81            if @arg2 != NULL or @arg3 != NULL or @arg4 != NULL
82            begin
83                /*
84                ** 19210,
85                ** "Syntax error. Extra arguments passed to '%1!' command.
86                ** Run: %2! 'help', '%3!' for usage information."
87                */
88                raiserror 19210, "sp_hadr_admin", "sp_hadr_admin", "failover_timeestimate"
89                return (1)
90            end
91        end
92        else
93        if (@cmd = 'setlogin')
94        begin
95            if @arg1 IS NULL
96            begin
97                /* 19381, "Invalid argument to %1!. It requires a non-null value ." */
98                raiserror 19381, "setlogin"
99                return (1)
100           end
101   
102           if @arg2 != NULL or @arg3 != NULL or @arg4 != NULL
103           begin
104               /*
105               ** 19210,
106               ** "Syntax error. Extra arguments passed to '%1!' command.
107               ** Run: %2! 'help', '%3!' for usage information."
108               */
109               raiserror 19210, "sp_hadr_admin", "sp_hadr_admin", "setlogin"
110               return (1)
111           end
112       end
113       else
114       if (@cmd = 'standby')
115       begin
116           if @arg1 != NULL or @arg2 != NULL or @arg3 != NULL or @arg4 != NULL
117           begin
118               /*
119               ** 19210,
120               ** "Syntax error. Extra arguments passed to '%1!' command.
121               ** Run: %2! 'help', '%3!' for usage information."
122               */
123               raiserror 19210, "sp_hadr_admin", "sp_hadr_admin", "standby"
124               return (1)
125           end
126           /*
127           ** Standby is valid only if the server is PRIMARY and in
128           ** INACTIVE state
129           */
130           if @hadrmode != 1 or @hadrstate != 2
131           begin
132               /* 17157, "'%1!' command is not allowed in current server state (%2!)." */
133               raiserror 17157, "standby", @srvstate
134               return (1)
135           end
136       end
137       else
138       /* "Usage: sp_hadr_admin "primary", [, "force"] */
139       if (@cmd = "primary")
140       begin
141           if @arg1 IS NOT NULL
142           begin
143               if @arg1 not in ("force")
144               begin
145                   /* 17993, "'%1!' is not a valid argument." */
146                   raiserror 17993, @arg1
147                   return (1)
148               end
149               if @arg2 != NULL or @arg3 != NULL or @arg4 != NULL
150               begin
151                   /*
152                   ** 19210,
153                   ** "Syntax error. Extra arguments passed to '%1!' command.
154                   ** Run: %2! 'help', '%3!' for usage information."
155                   */
156                   raiserror 19210, "sp_hadr_admin", "sp_hadr_admin", "primary"
157                   return (1)
158               end
159           end
160           /*
161           ** primary is valid only if the server is currently standby
162           */
163           if @hadrmode != 0
164           begin
165               /* 17157, "'%1!' command is not allowed in current server state (%2!)." */
166               raiserror 17157, "standby", @srvstate
167               return (1)
168           end
169       end
170       else
171       /* "Usage: sp_hadr_admin "deactivate",  "", "
172       if (@cmd = "deactivate")
173       begin
174           if @arg1 IS NULL or @arg2 IS NULL
175           begin
176               /* 19381, "Invalid argument to %1!. It requires a non-null value." */
177               raiserror 19381, "deactivate"
178               return (1)
179           end
180           select @timeout = convert(int, @arg1)
181           if @timeout <= 0
182           begin
183               /* 18899, "Invalid value supplied to parameter '%1!'." */
184               raiserror 18899, "timeout"
185               return (1)
186           end
187   
188           if @arg3 IS NOT NULL
189               if @arg3 not in ("force")
190               begin
191                   /* 17993, "'%1!' is not a valid argument." */
192                   raiserror 17993, @arg3
193                   return (1)
194               end
195   
196           /* label is ignored for 'nodrain' option, but if 'nodrain' is not
197           ** specified, check for label to be non-null.
198           */
199           if @arg4 IS NOT NULL
200           begin
201               if @arg4 not in ("nodrain")
202               begin
203                   /* 17993, "'%1!' is not a valid argument." */
204                   raiserror 17993, @arg4
205                   return (1)
206               end
207           end
208   
209           /*
210           ** Deactivate is valid only if the server is PRIMARY and in 
211           ** ACTIVE state
212           */
213           if @hadrmode != 1 or @hadrstate != 1
214           begin
215               /* 17157, "'%1!' command is not allowed in current server state (%2!)." */
216               raiserror 17157, "DEACTIVATE", @srvstate
217               return (1)
218           end
219       end
220       else
221       if (@cmd = "cancel")
222       begin
223           if @arg1 != NULL or @arg2 != NULL or @arg3 != NULL or @arg4 != NULL
224           begin
225               /* 
226               ** 19210,
227               ** "Syntax error. Extra arguments passed to '%1!' command.
228               ** Run: %2! 'help', '%3!' for usage information."
229               */
230               raiserror 19210, "sp_hadr_admin", "sp_hadr_admin", "cancel"
231               return (1)
232           end
233           /*
234           ** Cancel is valid only if the server is PRIMARY and in 
235           ** DEACTIVATING state
236           */
237           if @hadrmode != 1 or @hadrstate != 3
238           begin
239               /* 17157, "'%1!' command is not allowed in current server state (%2!)." */
240               raiserror 17157, "CANCEL", @srvstate
241               return (1)
242           end
243       end
244       else
245       if (@cmd = "drain")
246       begin
247   
248           if @arg2 != NULL or @arg3 != NULL or @arg4 != NULL
249           begin
250               /* 
251               ** 19210,
252               ** "Syntax error. Extra arguments passed to '%1!' command.
253               ** Run: %2! 'help', '%3!' for usage information."
254               */
255               raiserror 19210, "sp_hadr_admin", "sp_hadr_admin", "drain"
256               return (1)
257           end
258           if @arg1 IS NULL
259           begin
260               /* 19381, "Invalid argument to %1!. It requires a non-null value." */
261               raiserror 19381, "drain"
262               return (1)
263           end
264   
265           /*
266           ** drain is valid only if the server is PRIMARY and in 
267           ** INACTIVE state
268           */
269           if @hadrmode != 1 or @hadrstate != 2
270           begin
271               /* 17157, "'%1!' command is not allowed in current server state (%2!)." */
272               raiserror 17157, "DRAIN", @srvstate
273               return (1)
274           end
275       end
276       else
277       if (@cmd = "status")
278       begin
279           if @arg3 != NULL or @arg4 != NULL
280           begin
281               /* 
282               ** 19210,
283               ** "Syntax error. Extra arguments passed to '%1!' command.
284               ** Run: %2! 'help', '%3!' for usage information."
285               */
286               raiserror 19210, "sp_hadr_admin", "sp_hadr_admin", "status"
287               return (1)
288           end
289   
290           /* The label is required to query the status on a STANDBY server. */
291           if @hadrmode = 0 and @arg1 IS NULL
292           begin
293               /* 19381, "Invalid argument to %1!. It requires a non-null value." */
294               raiserror 19381, "status"
295               return (1)
296           end
297   
298           if @arg2 IS NOT NULL
299               if @arg2 not in ("all")
300               begin
301                   select @dbcount = count(*)
302                   from master.dbo.sysdatabases
303                   where name like @arg2
304                   if @dbcount = 0
305                   begin
306                       /* 17590, "The specified database does not exist." */
307                       raiserror 17590
308                       return (1)
309                   end
310               end
311       end
312       else
313       if (@cmd = "addserver")
314       begin
315           if @arg1 IS NULL
316           begin
317               /* 19381, "Invalid argument to %1!. It requires a non-null value." */
318               raiserror 19381, "addserver"
319               return (1)
320           end
321   
322           if @arg3 IS NOT NULL
323               if @arg3 not in ('nopropagate', 'propagate')
324               begin
325                   /* 18899, "Invalid value supplied to parameter '%1!'." */
326                   raiserror 18899, "addserver"
327                   return (1)
328               end
329       end
330       else
331       if (@cmd = "dropserver")
332       begin
333           if @arg3 != NULL or @arg4 != NULL
334           begin
335               /* 
336               ** 19210,
337               ** "Syntax error. Extra arguments passed to '%1!' command.
338               ** Run: %2! 'help', '%3!' for usage information."
339               */
340               raiserror 19210, "sp_hadr_admin", "sp_hadr_admin", "dropserver"
341               return (1)
342           end
343           if @arg1 IS NULL
344           begin
345               /* 19381, "Invalid argument to %1!. It requires a non-null value." */
346               raiserror 19381, "dropserver"
347               return (1)
348           end
349   
350           if @arg2 IS NOT NULL
351               if @arg2 not in ('nopropagate', 'propagate')
352               begin
353                   /* 18899, "Invalid value supplied to parameter '%1!'." */
354                   raiserror 18899, "dropserver"
355                   return (1)
356               end
357       end
358       else
359       if (@cmd = "listserver")
360       begin
361           /* 'listserver' does not take any arg */
362           if @arg1 != NULL or @arg2 != NULL or @arg3 != NULL or @arg4 != NULL
363           begin
364               /* 
365               ** 19210,
366               ** "Syntax error. Extra arguments passed to '%1!' command.
367               ** Run: %2! 'help', '%3!' for usage information."
368               */
369               raiserror 19210, "sp_hadr_admin", "sp_hadr_admin", "listserver"
370               return (1)
371           end
372       end
373       else
374       if (@cmd = "propagate")
375       begin
376           if @arg2 != NULL or @arg3 != NULL or @arg4 != NULL
377           begin
378               /* 
379               ** 19210,
380               ** "Syntax error. Extra arguments passed to '%1!' command.
381               ** Run: %2! 'help', '%3!' for usage information."
382               */
383               raiserror 19210, "sp_hadr_admin", "sp_hadr_admin", "propagate"
384               return (1)
385           end
386           /*
387           ** propagate is valid only if the server is PRIMARY 
388           */
389           if @hadrmode != 1
390           begin
391               /* 17157, "'%1!' command is not allowed in current server state (%2!)." */
392               raiserror 17157, "PROPAGATE", @srvstate
393               return (1)
394           end
395       end
396       else
397       if (@cmd = "init")
398       begin
399           if @arg3 != NULL or @arg4 != NULL or @arg5 != NULL or @arg6 != NULL
400           begin
401               /* 
402               ** 19210,
403               ** "Syntax error. Extra arguments passed to '%1!' command.
404               ** Run: %2! 'help', '%3!' for usage information."
405               */
406               raiserror 19210, "sp_hadr_admin", "sp_hadr_admin", "init"
407               return (1)
408           end
409           if @arg1 IS NULL
410           begin
411               /* 19381, "Invalid argument to %1!. It requires a non-null value." */
412               raiserror 19381, "init"
413               return (1)
414           end
415   
416           /* check if any group already exists */
417           if exists (select *
418                   from master.dbo.sysservers
419                   where srvclass = 17)
420           begin
421               select @name = srvname from master.dbo.sysservers
422               where srvclass = 17
423               /*
424               ** 17172,
425               ** HADR group '%1!' is already configured on this server. Drop an existing group before configuring new group.
426               */
427               raiserror 17172, @name
428               return 1
429           end
430       end
431       else
432       if (@cmd = "dropgroup")
433       begin
434           if @arg2 != NULL or @arg3 != NULL or @arg4 != NULL or @arg5 != NULL or @arg6 != NULL
435           begin
436               /* 
437               ** 19210,
438               ** "Syntax error. Extra arguments passed to '%1!' command.
439               ** Run: %2! 'help', '%3!' for usage information."
440               */
441               raiserror 19210, "sp_hadr_admin", "sp_hadr_admin", "dropgroup"
442               return (1)
443           end
444           if @arg1 IS NULL
445           begin
446               /* 19381, "Invalid argument to %1!. It requires a non-null value." */
447               raiserror 19381, "dropgroup"
448               return (1)
449           end
450       end
451       else
452       if (@cmd = "event")
453       begin
454           if @arg1 IS NULL or @arg2 IS NULL or @arg3 != NULL or @arg4 != NULL or @arg5 != NULL or @arg6 != NULL
455           begin
456               /* return silently since this is an internal RPC */
457               return (1)
458           end
459   
460           /*
461           ** event is valid only if the server is standby 
462           */
463           if @hadrmode != 0
464           begin
465               /* 17157, "'%1!' command is not allowed in current server state (%2!)." */
466               raiserror 17157, "EVENT", @srvstate
467               return (1)
468           end
469       end
470       else
471       if (@cmd = "map")
472       begin
473           if @arg1 != NULL or @arg2 != NULL or @arg3 != NULL or @arg4 != NULL
474           begin
475               /* 
476               ** 19210,
477               ** "Syntax error. Extra arguments passed to '%1!' command.
478               ** Run: %2! 'help', '%3!' for usage information."
479               */
480               raiserror 19210, "sp_hadr_admin", "sp_hadr_admin", "map"
481               return (1)
482           end
483           /*
484           ** map is valid only if the server is PRIMARY 
485           */
486           if @hadrmode != 1
487           begin
488               /* 17157, "'%1!' command is not allowed in current server state (%2!)." */
489               raiserror 17157, "MAP", @srvstate
490               return (1)
491           end
492       end
493       else
494       if (@cmd = 'config_bs')
495       begin
496           if @arg2 is null
497           begin
498               /* 19381, "Invalid argument to %1!. It requires a non-null value ." */
499               raiserror 19381, "config_bs"
500               return (1)
501           end
502   
503           if @arg3 is not null or @arg4 is not null or @arg5 is not null or @arg6 is not null
504           begin
505               /*
506               ** 19210,
507               ** "Syntax error. Extra arguments passed to '%1!' command.
508               ** Run: %2! 'help', '%3!' for usage information."
509               */
510               raiserror 19210, "sp_hadr_admin", "sp_hadr_admin", "config_bs"
511               return (1)
512           end
513       end
514       return (0)
515   
516   


exec sp_procxmode 'sp_hadrvrfyargs', 'AnyMode'
go

Grant Execute on sp_hadrvrfyargs to public
go
DEFECTS
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 419
 QTYP 4 Comparison type mismatch Comparison type mismatch: smallint vs int 422
 MGTP 3 Grant to public master..sysdatabases  
 MGTP 3 Grant to public master..sysservers  
 MGTP 3 Grant to public sybsystemprocs..sp_hadrvrfyargs  
 MNAC 3 Not using ANSI 'is null' 49
 MNAC 3 Not using ANSI 'is null' 81
 MNAC 3 Not using ANSI 'is null' 102
 MNAC 3 Not using ANSI 'is null' 116
 MNAC 3 Not using ANSI 'is null' 149
 MNAC 3 Not using ANSI 'is null' 223
 MNAC 3 Not using ANSI 'is null' 248
 MNAC 3 Not using ANSI 'is null' 279
 MNAC 3 Not using ANSI 'is null' 333
 MNAC 3 Not using ANSI 'is null' 362
 MNAC 3 Not using ANSI 'is null' 376
 MNAC 3 Not using ANSI 'is null' 399
 MNAC 3 Not using ANSI 'is null' 434
 MNAC 3 Not using ANSI 'is null' 454
 MNAC 3 Not using ANSI 'is null' 473
 MUCO 3 Useless Code Useless Brackets 41
 MUCO 3 Useless Code Useless Brackets 47
 MUCO 3 Useless Code Useless Brackets 57
 MUCO 3 Useless Code Useless Brackets 67
 MUCO 3 Useless Code Useless Brackets 71
 MUCO 3 Useless Code Useless Brackets 79
 MUCO 3 Useless Code Useless Brackets 89
 MUCO 3 Useless Code Useless Brackets 93
 MUCO 3 Useless Code Useless Brackets 99
 MUCO 3 Useless Code Useless Brackets 110
 MUCO 3 Useless Code Useless Brackets 114
 MUCO 3 Useless Code Useless Brackets 124
 MUCO 3 Useless Code Useless Brackets 134
 MUCO 3 Useless Code Useless Brackets 139
 MUCO 3 Useless Code Useless Brackets 147
 MUCO 3 Useless Code Useless Brackets 157
 MUCO 3 Useless Code Useless Brackets 167
 MUCO 3 Useless Code Useless Brackets 172
 MUCO 3 Useless Code Useless Brackets 178
 MUCO 3 Useless Code Useless Brackets 185
 MUCO 3 Useless Code Useless Brackets 193
 MUCO 3 Useless Code Useless Brackets 205
 MUCO 3 Useless Code Useless Brackets 217
 MUCO 3 Useless Code Useless Brackets 221
 MUCO 3 Useless Code Useless Brackets 231
 MUCO 3 Useless Code Useless Brackets 241
 MUCO 3 Useless Code Useless Brackets 245
 MUCO 3 Useless Code Useless Brackets 256
 MUCO 3 Useless Code Useless Brackets 262
 MUCO 3 Useless Code Useless Brackets 273
 MUCO 3 Useless Code Useless Brackets 277
 MUCO 3 Useless Code Useless Brackets 287
 MUCO 3 Useless Code Useless Brackets 295
 MUCO 3 Useless Code Useless Brackets 308
 MUCO 3 Useless Code Useless Brackets 313
 MUCO 3 Useless Code Useless Brackets 319
 MUCO 3 Useless Code Useless Brackets 327
 MUCO 3 Useless Code Useless Brackets 331
 MUCO 3 Useless Code Useless Brackets 341
 MUCO 3 Useless Code Useless Brackets 347
 MUCO 3 Useless Code Useless Brackets 355
 MUCO 3 Useless Code Useless Brackets 359
 MUCO 3 Useless Code Useless Brackets 370
 MUCO 3 Useless Code Useless Brackets 374
 MUCO 3 Useless Code Useless Brackets 384
 MUCO 3 Useless Code Useless Brackets 393
 MUCO 3 Useless Code Useless Brackets 397
 MUCO 3 Useless Code Useless Brackets 407
 MUCO 3 Useless Code Useless Brackets 413
 MUCO 3 Useless Code Useless Brackets 432
 MUCO 3 Useless Code Useless Brackets 442
 MUCO 3 Useless Code Useless Brackets 448
 MUCO 3 Useless Code Useless Brackets 452
 MUCO 3 Useless Code Useless Brackets 457
 MUCO 3 Useless Code Useless Brackets 467
 MUCO 3 Useless Code Useless Brackets 471
 MUCO 3 Useless Code Useless Brackets 481
 MUCO 3 Useless Code Useless Brackets 490
 MUCO 3 Useless Code Useless Brackets 494
 MUCO 3 Useless Code Useless Brackets 500
 MUCO 3 Useless Code Useless Brackets 511
 MUCO 3 Useless Code Useless Brackets 514
 QAFM 3 Var Assignment from potentially many rows 421
 VNRD 3 Variable is not read @retstat 28
 MSUB 2 Subquery Marker 417
 MTR1 2 Metrics: Comments Ratio Comments: 43% 10
 MTR2 2 Metrics: Cyclomatic Complexity Cyclo: 77 = 120dec - 45exi + 2 10
 MTR3 2 Metrics: Query Complexity Complexity: 291 10

DEPENDENCIES
PROCS AND TABLES USED
reads table master..sysservers (1)  
reads table master..sysdatabases (1)  

CALLERS
called by proc sybsystemprocs..sp_hadr_admin  
   called by proc sybsystemprocs..sp_hadr_update