如何通过Vbscript获取数据库结构类?
<script language='vbscript'> '********************************* '* classname: DataBaseOperertion '* 制作人: 刘晓逸 '* 作用: 用adox进行数据库的操作 '* 版本: 2.0 '********************************** Class DatabaseOperertion Dim m_DatabaseObject Private Sub Class_Initialize Set m_DatabaseObject=CreateObject("ADOX.Catalog") End Sub Public Property let Connection(conn) m_DatabaseObject.ActiveConnection=conn End Property Public Function GetTablesName Dim tablesArray() Dim i : i = 1 For Each tableObj in m_DatabaseObject.Tables If tableObj.type="TABLE" Then Redim Preserve tablesArray(i) tablesArray(i-1) = tableObj.name i = i + 1 End If Next GetTablesName = tablesArray End Function Public Function GetTableAttributes(tableName) Dim tableAttributesArray() Set tableObject = m_DatabaseObject.Tables.Item(tableName) For i=0 To tableObject.Columns.count - 1 Set tableInfo = CreateObject("Scripting.Dictionary") Redim Preserve tableAttributesArray(i + 1) tableInfo.add "name",tableObject.Columns.Item(i).Name tableInfo.add "type",type_int2str(tableObject.columns.Item(i).type) Set tableAttributesArray(i) = tableInfo Set tableInfo = Nothing Next GetTableAttributes = tableAttributesArray End Function Public Sub DeleteTable(tableName) m_DatabaseObject.Tables.Delete tableName End Sub Public Sub AddTable(tableName) Set tableObject = CreateObject("ADOX.Table") tableObject.Name = tableName Set tableObject.ParentCatalog = m_DatabaseObject m_DatabaseObject.Tables.Append tableObject Set tableObject = Nothing End Sub Public Sub DeleteColumns(columns, tableName) Set tableObject = m_DatabaseObject.Tables.Item(tableName) If IsArray(columns) Then For i=0 To Ubound(columns) tableObject.Columns.Delete columns(i) Next Else tableObject.Columns.Delete columns End If End Sub Public Sub AddColumns(columns, tableName) Set tableObject = m_DatabaseObject.Tables.Item(tableName) For i=0 To Ubound(columns) tableObject.Columns.Append columns(i,0),columns(i,1),columns(i,2) Next End Sub Function ConvertToString(number) Select Case number Case 3: ConvertToString = "数字" Case 202: ConvertToString = "文本" Case Else: ConvertToString = number End Select End Function Private Sub Class_Terminate Set m_DatabaseObject = Nothing End Sub End Class </script>
操作类未完待续......就是觉得十年前写得过分挫了,改改.好多年没写vbscript了,好怀念啊,仅此纪念
本文地址:http://www.45fan.com/a/question/70834.html