📄 inc_engine.asp
字号:
for i=1 to IndexItem(0)
str = str & "[" & IndexItem(i).TargetField & "]"
if IndexItem(i).SortOrder = 2 then
str = str & " DESC"
end if
str = str & ","
next
If Len(str) > 0 then
sSQL = "DROP INDEX [" & IndexName & "] ON [" & Name_ & "]"
call Parent_.Execute(sSQL)
end if
sSQL = "CREATE "
if IsUnique then sSQL = sSQL & "UNIQUE "
sSQL = sSQL & "INDEX [" & IndexName & "] ON [" & Name_ & "](" & str & "[" & TargetField & "]"
if SortOrder = 2 then
sSQL = sSQL & " DESC"
end if
sSQL = sSQL & ")"
call Parent_.Execute(sSQL)
end if
CreateIndex = not Parent_.IsError
if not Parent_.HasError then
Indexes_.Item(".uninitialized") = null
end if
End Function
'#############################################################
'# Deletes an existing index ' 赵畅添加修改于2004.12.18
Public Function DeleteIndex(IndexName, FieldName)
dim key, sSQL, str, IsPrimary
dim i,IndexItem()
DeleteIndex = False
IsPrimary = False
'find out if this index is primary
str = ""
If Indexes.Exists(IndexName & "." & FieldName) then
if Indexes_.Item(IndexName & "." & FieldName).IsPrimary then
'save other primary indexes if any
for each key in Indexes_.Keys
if key <> IndexName & "." & FieldName and Indexes_.Item(key).IsPrimary then
str = str & "[" & Indexes_.Item(key).TargetField & "],"
end if
next
IsPrimary = True
else
redim IndexItem(Indexes_.Count)
IndexItem(0) = 0
for each key in Indexes_.Keys
if Indexes_.Item(key).Name=IndexName and key <> IndexName & "." & FieldName then
set IndexItem(Indexes_.Item(key).Ordinal) = Indexes_.Item(key)
IndexItem(0) = IndexItem(0) + 1
end if
next
for i=1 to Indexes_.Count
if not IsEmpty(IndexItem(i)) then
str = str & "[" & IndexItem(i).TargetField & "]"
if IndexItem(i).SortOrder = 2 then
str = str & " DESC"
end if
str = str & ","
end if
next
end if
sSQL = "DROP INDEX [" & IndexName & "] ON [" & Name_ & "]"
call Parent_.Execute(sSQL)
if not Parent_.IsError then
if Len(str) > 0 then
're-create all primary keys or index
str = Left(str, Len(str) - 1)
if IsPrimary then
sSQL = "CREATE INDEX [" & IndexName & "] ON [" & Name_ & "](" & str & ") WITH PRIMARY"
else
sSQL = "CREATE INDEX [" & IndexName & "] ON [" & Name_ & "](" & str & ")"
end if
call Parent_.Execute(sSQL)
DeleteIndex = not Parent_.IsError
end if
If not Parent_.HasError then Indexes_.Remove IndexName & "." & FieldName
end if
end if
End Function
'########################################################
'# Returns an ADO Recordset object with data of the table
Public Function GetRawData(PageSize, Filter, ReadOnly)
dim rec, lockType
if Len(Filter) = 0 then Filter = "SELECT * FROM [" & Name_ & "]"
set rec = Server.CreateObject("ADODB.Recordset")
if IsNumeric(PageSize) then
rec.CacheSize = CInt(PageSize)
rec.PageSize = CInt(PageSize)
end if
if ReadOnly then lockType = adLockReadOnly else lockType = adLockOptimistic
rec.Open Filter, Parent_.JetConnection, adOpenKeyset, lockType
Set GetRawData = rec
End Function
'########################################################
'# Returns True is the object has been initialized
Public Function IsInitialized
if Len(Name_) > 0 and IsObject(Parent_) then IsInitialized = True else IsInitialized = False
End Function
'---------------------------
'protected and private
Private Parent_
Private Indexes_
Private Fields_
Private Name_
Private TableType_
Private Description_
Private DateCreated_
Private DateModified_
End Class
' END CLASS DEFINITION DBATable
'///////////////////////////////////////////////////
'// ' Class that describes View in database
'//
Class DBAView
'constructor
Private Sub Class_Initialize
Set Parent_ = Nothing
Name_ = ""
Body_ = ""
DateCreated_ = null
DateModified_ = null
Description_ = ""
End Sub
'destructor
Private Sub Class_Terminate
Set Parent_ = Nothing
End Sub
'########################################################
'#
Public Property Set Parent(v)
Set Parent_ = v
End Property
Public Property Get Parent
Set Parent = Parent_
End Property
'########################################################
'# Name of the View
Public Property Let Name(v)
if IsInitialized and Name_ <> v then
'we are updating the view. Actually just deleting it and creating again
dim con, sSQL
sSQL = "DROP VIEW [" & Name_ & "]"
set con = Parent_.JetConnection
Parent_.BeginTransaction
if not DBAE_DEBUG then On Error Resume Next
Parent_.Execute sSQL
call Parent_.IsError
Name_ = CStr(v)
Parent_.Execute SQL
if Parent_.IsError then
Parent_.RollbackTransaction
else
Parent_.CommitTransaction
end if
end if
Name_ = CStr(v)
End Property
Public Property Get Name
Name = Name_
End Property
'########################################################
'# Code of the view
Public Property Let Body(v)
if IsInitialized and Body_ <> v then
dim xCatalog, Command
if not DBAE_DEBUG then On Error Resume Next
set xCatalog = Server.CreateObject("ADOX.Catalog")
If IsEmpty(xCatalog) or xCatalog Is Nothing or not Parent_.UseADOX Then
'when ADOX is not available. Just re-create the view
dim con, sSQL
sSQL = "DROP VIEW [" & Name_ & "]"
set con = Parent_.JetConnection
con.BeginTrans
call con.Execute(sSQL, adExecuteNoRecords)
call Parent_.IsError
Body_ = CStr(v)
con.Execute SQL, adExecuteNoRecords
if Parent_.IsError then
con.RollbackTrans
else
con.CommitTrans
end if
Else
set Command = Server.CreateObject("ADODB.Command")
set xCatalog.ActiveConnection = Parent_.JetConnection
with Command
.ActiveConnection = Parent_.JetConnection
.CommandText = CStr(v)
.CommandType = adCmdText
end with
set xCatalog.Views(Name_).Command = Command
if not Parent_.IsError then Body_ = CStr(v)
set Command = Nothing
set xCatalog = Nothing
End If
end if
Body_ = CStr(v)
End Property
Public Property Get Body
Body = Body_
End Property
'########################################################
'# SQL statement that can be used to create this view
Public Property Get SQL
'PROCEDURE instead of VIEW just to avoid "Only simple queries.." error
SQL = "CREATE PROCEDURE [" & Name_ & "] AS " & vbCrLf & Body_
End Property
'########################################################
'#
Public Property Let Description(v)
if Len(Description_) = 0 and not IsNull(v) then Description_ = CStr(v)
End Property
Public Property Get Description
Description = Description_
End Property
'########################################################
'#
Public Property Let DateCreated(v)
if IsDate(v) and IsNull(DateCreated_) then DateCreated_ = CDate(v)
End Property
Public Property Get DateCreated
DateCreated = DateCreated_
End Property
'########################################################
'#
Public Property Let DateModified(v)
if IsDate(v) and IsNull(DateModified_) then DateModified_ = CDate(v)
End Property
Public Property Get DateModified
DateModified = DateModified_
End Property
'########################################################
'# Returns True if the object has been initizliazed
Public Function IsInitialized
if Len(Name_) > 0 and Len(Body_) > 0 then IsInitialized = True else IsInitialized = False
End Function
'---------------------------
'protected and private
Private Parent_
Private Name_
Private Body_
Private Description_
Private DateCreated_
Private DateModified_
End Class
' END CLASS DEFINITION DBAView
'///////////////////////////////////////////////////
'// ' Class that describes a single Procedure in database
'//
Class DBAProcedure
'########################################################
'#
Public Property Set Parent(v)
Set Parent_ = v
End Property
Public Property Get Parent
Set Parent = Parent_
End Property
'########################################################
'# Name of procedure
Public Property Let Name(v)
if IsInitialized and Name_ <> v then
'we are updating the procedure. Actually just deleting it and creating again
dim con, sSQL
sSQL = "DROP PROCEDURE [" & Name_ & "]"
set con = Parent_.JetConnection
con.BeginTrans
if not DBAE_DEBUG then On Error Resume Next
con.Execute sSQL, adExecuteNoRecords
call Parent_.IsError
Name_ = CStr(v)
con.Execute SQL, adExecuteNoRecords
if Parent_.IsError then
con.RollbackTrans
else
con.CommitTrans
end if
end if
Name_ = CStr(v)
End Property
Public Property Get Name
Name = Name_
End Property
'########################################################
'# Procedure's code
Public Property Let Body(v)
if IsInitialized and Body_ <> v then
dim xCatalog, Command
if not DBAE_DEBUG then On Error Resume Next
set xCatalog = Server.CreateObject("ADOX.Catalog")
If IsEmpty(xCatalog) or xCatalog Is Nothing or not Parent_.UseADOX Then
'when ADOX is not available. Just re-create the view
dim con, sSQL
sSQL = "DROP PROCEDURE [" & Name_ & "]"
set con = Parent_.JetConnection
con.BeginTrans
call con.Execute(sSQL, adExecuteNoRecords)
call Parent_.IsError
Body_ = CStr(v)
con.Execute SQL, adExecuteNoRecords
if Parent_.IsError then
con.RollbackTrans
else
con.CommitTrans
end if
Else
set Command = Server.CreateObject("ADODB.Command")
set xCatalog.ActiveConnection = Parent_.JetConnection
with Command
.ActiveConnection = Parent_.JetConnection
.CommandText = CStr(v)
.CommandType = adCmdText
end with
set xCatalog.Procedures(Name_).Command = Command
if not Parent_.IsError then Body_ = Command.CommandText
set Command = Nothing
set xCatalog = Nothing
End If
end if
Body_ = CStr(v)
End Property
Public Property Get Body
Body = Body_
End Property
'########################################################
'# SQL statement needed to create such procedure
Public Property Get SQL
SQL = "CREATE PROCEDURE [" & Name_ & "] AS " & vbCrLf & Body_
End Property
'########################################################
'# Description of procedure (read-only)
Public Property Let Description(v)
if Len(Description_) = 0 and not IsNull(v) then Description_ = CStr(v)
End Property
Public Property Get Description
Description = Description_
End Property
'########################################################
'# Date when the procedure was created. Read-only
Public Property Let DateCreated(v)
if IsDate(v) and IsNull(DateCreated_) then DateCreated_ = CDate(v)
End Property
Public Property Get DateCreated
DateCreated = DateCreated_
End Property
'########################################################
'# Date when the procedure was last modified. Usually same as DateCreated. Read-only
Public Property Let DateModified(v)
if IsDate(v) and IsNull(DateModified_) then DateModified_ = CDate(v)
End Property
Public Property Get DateModified
DateModified = DateModified_
End Property
'########################################################
'# Returns True is the object has been properly initialized
Public Function IsInitialized()
if Len(Name_) > 0 and Len(Body_) > 0 then IsInitialized = True else IsInitialized = False
End Function
'---------------------------
'protected and private
Private Parent_
Private Name_
Private Body_
Private Description_
Private DateCreated_
Private DateModified_
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -