|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
限制,如果WHERE子句的查询条件里有不等号(WHEREcoloum!=),MySQL将无法使用索引。类似地,如果WHERE子句的查询条件里使用了函数(WHEREDAY(column)=),MySQL也将无法使用索引。server|工具|数据|数据库头几天看到有人问是不是能够便利的取得SQLSERVER2000指定工具的权限和指定USER的权
限。我写了一个存储历程,能够取得用户和脚色的权限。请人人协助测试一下。看看是
否另有BUG:-)
IFOBJECTPROPERTY(OBJECT_ID(usp_getObjectAuthor),IsProcedure)=1
DROPPROCusp_getObjectAuthor
GO
/***************************************************************************
*****/
/*CreatedBy:leimin*/
/*CreatedOn:29May2004*/
/*Description:Thisstoredprocedurereturnstheobjectpermissionwhich
you*/
/*GRANT,DENYandREVOKE.
*/
/***************************************************************************
*****/
Createprocusp_getObjectAuthor
@objectnamesysname=null,
@usernamesysname=null
as
setnocounton
begin
/***************************************************************************
*****/
/*definedtheinitilizationvariable*/
/***************************************************************************
*****/
Declare@rcint
Declare@rowcountint
Declare@groupidint
Set@rc=0
Set@rowcount=0
/***************************************************************************
*****/
/*Judgetheinputparameters,if@objectnameisnulland@usernameis
null*/
/*thenreturnallobjectsauthorization.*/
/***************************************************************************
*****/
if@objectnameisnulland@usernameisnull
begin
selectobject_name(a.id)asobjectname,
user_name(a.uid)asusename,
caseb.issqlrolewhen1thenGroup
elseUser
endasRole,
casea.protecttypewhen205thenGrant
when204thenGrant
when206thenDeny
elseRevoke
endasProtectType,
casea.[action]when26thenREFERENCES
when178thenCREATEFUNCTION
when193thenSELECT
when195thenINSERT
when196thenDELETE
when197thenUPDATE
when198thenCREATETABLE
when203thenCREATEDATABASE
when207thenCREATEVIEW
when222thenCREATEPROCEDURE
when224thenEXECUTE
when228thenBACKUPDATABASE
when233thenCREATEDEFAULT
when235thenBACKUPLOG
when236thenCREATERULE
else0
endas[Action],
user_name(a.grantor)asGrantor
fromsysprotectsainnerjoinsysusersbona.uid=b.uid
whereexists(select1fromsysobjects
where[name]=object_name(a.id)andxtypeS)
orderbyobject_name(a.id)
select@rowcount=@@rowcount
if@rowcount=0
begin
select@rc=-1
printThereanouserobjectsindatabase!
return@rc
end
end
/***************************************************************************
*****/
/*Judgetheinputparameters,if@objectnameisnulland@usernameisnot
null*/
/*thenreturnallobjectsauthorizationwhererelation@username*/
/*iftheuserbelongtoagroup,sowemustaddthegroupauthorization*/
/***************************************************************************
*****/
if@rc=0and@usernameisnotnulland@objectnameisnull
begin
ifnotexists(select*fromsysuserswhere[uid]=user_id(@username)and
status0)
begin
select@rc=-2
printTheusernameisnotincludeinsysuserstable.
return@rc
end
ifexists(select1fromsysmemberswhere[memberuid]=user_id(@username))
begin
selectobject_name(a.id)asobjectname,
user_name(a.uid)asusename,
caseb.issqlrolewhen1thenGroup
elseUser
endasRole,
casea.protecttypewhen205thenGrant
when204thenGrant
when206thenDeny
elseRevoke
endasProtectType,
casea.[action]when26thenREFERENCES
when178thenCREATEFUNCTION
when193thenSELECT
when195thenINSERT
when196thenDELETE
when197thenUPDATE
when198thenCREATETABLE
when203thenCREATEDATABASE
when207thenCREATEVIEW
when222thenCREATEPROCEDURE
when224thenEXECUTE
when228thenBACKUPDATABASE
when233thenCREATEDEFAULT
when235thenBACKUPLOG
when236thenCREATERULE
else0
endas[Action],
user_name(a.grantor)asGrantor
fromsysprotectsainnerjoinsysusersbona.uid=b.uid
whereexists(select1fromsysobjects
where[name]=object_name(a.id)andxtypeS)
and(exists(select1fromsysmembers
wheregroupuid=a.uidandmemberuid=user_id(@username))
ora.uid=user_id(@username))
orderbyobject_name(a.id)
select@rowcount=@@rowcount
if@rowcount=0
begin
select@rc=-3
print@username+havenotanyobjectsauthorization.
return@rc
end
end
else
begin
selectobject_name(a.id)asobjectname,
user_name(a.uid)asusename,
caseb.issqlrolewhen1thenGroup
elseUser
endasRole,
casea.protecttypewhen205thenGrant
when204thenGrant
when206thenDeny
elseRevoke
endasProtectType,
casea.[action]when26thenREFERENCES
when178thenCREATEFUNCTION
when193thenSELECT
when195thenINSERT
when196thenDELETE
when197thenUPDATE
when198thenCREATETABLE
when203thenCREATEDATABASE
when207thenCREATEVIEW
when222thenCREATEPROCEDURE
when224thenEXECUTE
when228thenBACKUPDATABASE
when233thenCREATEDEFAULT
when235thenBACKUPLOG
when236thenCREATERULE
else0
endas[Action],
user_name(a.grantor)asGrantor
fromsysprotectsainnerjoinsysusersbona.uid=b.uid
whereexists(select1fromsysobjects
where[name]=object_name(a.id)andxtypeS)
anda.uid=user_id(@username)
orderbyobject_name(a.id)
select@rowcount=@@rowcount
if@rowcount=0
begin
select@rc=-4
print@username+havenotanyobjectsauthorization.
return@rc
end
end
end
/***************************************************************************
*****/
/*Judgetheinputparameters,if@objectnameisnotnulland@usernameis
null*/
/*thenreturnoneobjectsauthorization*/
/***************************************************************************
*****/
if@rc=0and@objectnameisnotnulland@usernameisnull
begin
ifnotexists(select*fromsysobjectswhere[id]=object_id(@objectname)
andxtypeS)
begin
select@rc=-5
return@rc
end
if@rc=0
begin
selectobject_name(a.id)asobjectname,
user_name(a.uid)asusename,
caseb.issqlrolewhen1thenGroup
elseUser
endasRole,
casea.protecttypewhen205thenGrant
when204thenGrant
when206thenDeny
elseRevoke
endasProtectType,
casea.[action]when26thenREFERENCES
when178thenCREATEFUNCTION
when193thenSELECT
when195thenINSERT
when196thenDELETE
when197thenUPDATE
when198thenCREATETABLE
when203thenCREATEDATABASE
when207thenCREATEVIEW
when222thenCREATEPROCEDURE
when224thenEXECUTE
when228thenBACKUPDATABASE
when233thenCREATEDEFAULT
when235thenBACKUPLOG
when236thenCREATERULE
else0
endas[Action],
user_name(a.grantor)asGrantor
fromsysprotectsainnerjoinsysusersbona.uid=b.uid
whereexists(select1fromsysobjects
where[name]=object_name(a.id)andxtypeS)
and[id]=object_id(@objectname)
orderbyobject_name(a.id)
select@rowcount=@@rowcount
if@rowcount=0
begin
select@rc=-6
print@objectname+havenotgrantauthorizationtoanyuser
return@rc
end
end
end
/***************************************************************************
*****/
/*Judgetheinputparameters,if@objectnameisnotnulland@usernameis
notnull*/
/*thenreturnoneobjectsauthorizationbyoneuser*/
/***************************************************************************
*****/
if@rc=0and@objectnameisnotnulland@usernameisnotnull
begin
ifnotexists(select*fromsysobjectswhere[id]=object_id(@objectname)
andxtypeS)
begin
select@rc=-7
printTheobjectnameisnotincludeinsysobjectstable.
return@rc
end
ifnotexists(select*fromsysuserswhere[uid]=user_id(@username)and
status0)
begin
select@rc=-8
printTheusernameisnotincludeinsysuserstable.
return@rc
end
ifexists(select1fromsysmemberswhere[memberuid]=user_id(@username))
begin
selectobject_name(a.id)asobjectname,
user_name(a.uid)asusename,
caseb.issqlrolewhen1thenGroup
elseUser
endasRole,
casea.protecttypewhen205thenGrant
when204thenGrant
when206thenDeny
elseRevoke
endasProtectType,
casea.[action]when26thenREFERENCES
when178thenCREATEFUNCTION
when193thenSELECT
when195thenINSERT
when196thenDELETE
when197thenUPDATE
when198thenCREATETABLE
when203thenCREATEDATABASE
when207thenCREATEVIEW
when222thenCREATEPROCEDURE
when224thenEXECUTE
when228thenBACKUPDATABASE
when233thenCREATEDEFAULT
when235thenBACKUPLOG
when236thenCREATERULE
else0
endas[Action],
user_name(a.grantor)asGrantor
fromsysprotectsainnerjoinsysusersbona.uid=b.uid
whereexists(select1fromsysobjects
where[name]=object_name(a.[id])andxtypeS)
and(exists(select1fromsysmembers
wheregroupuid=a.uidandmemberuid=user_id(@username))
ora.uid=user_id(@username))
and[id]=object_id(@objectname)
orderbyobject_name(a.id)
select@rowcount=@@rowcount
if@rowcount=0
begin
select@rc=-9
print@username+havenotanyobjectsauthorization.
return@rc
end
end
else
begin
selectobject_name(a.id)asobjectname,
user_name(a.uid)asusename,
caseb.issqlrolewhen1thenGroup
elseUser
endasRole,
casea.protecttypewhen205thenGrant
when204thenGrant
when206thenDeny
elseRevoke
endasProtectType,
casea.[action]when26thenREFERENCES
when178thenCREATEFUNCTION
when193thenSELECT
when195thenINSERT
when196thenDELETE
when197thenUPDATE
when198thenCREATETABLE
when203thenCREATEDATABASE
when207thenCREATEVIEW
when222thenCREATEPROCEDURE
when224thenEXECUTE
when228thenBACKUPDATABASE
when233thenCREATEDEFAULT
when235thenBACKUPLOG
when236thenCREATERULE
else0
endas[Action],
user_name(a.grantor)asGrantor
fromsysprotectsainnerjoinsysusersbona.uid=b.uid
whereexists(select1fromsysobjects
where[name]=object_name(a.[id])andxtypeS)
anda.uid=user_id(@username)
and[id]=object_id(@objectname)
orderbyobject_name(a.id)
select@rowcount=@@rowcount
if@rowcount=0
begin
select@rc=-10
print@username+havenotanyobjectsauthorization.
return@rc
end
end
end
end
go
execusp_getObjectAuthor
导致了一个使用几乎和mSQL一样的API接口的用于他们的数据库的新的SQL接口的产生,这样,这个API被设计成允许为用于mSQL而写的第三方代码更容易移植到MySQL。 |
|