日期:2014-05-18  浏览次数:20609 次

VB6 执行UPDATE操作是否会锁表
如题

当我对A表执行批量更新操作时
在后台SELECT A表,一直处于等待状态
直到退出下面这个函数 才能查询A表数据

SQL code


Public Function ExecuteSynEx(ByVal strConn As String, _
                            ByVal strTableName As String, _
                            ByVal bIsIdentity As Long, _
                            ByVal strAddSQL As Variant, _
                            ByVal strUpdSQL As Variant, _
                            ByVal strDelSQL As Variant, _
                            ByRef ReturnMsg As String) As Boolean
10    On Error GoTo HError
          Dim cn As ADODB.Connection
          Dim lInterID As Long, lTransType As Long
          Dim i As Long
          Dim strSQL As String
          Dim obj As Object
          Dim lSQLCount As Long
          
'20        GetObjectContext.SetAbort
30        ExecuteSynEx = False
          
40        Set cn = New ADODB.Connection
50        cn.Open strConn
60        cn.CursorLocation = adUseClient
70        cn.CommandTimeout = 3600

'80        cn.Execute "alter table " & strTableName & " nocheck constraint all"
          If bIsIdentity = 1 Then
            cn.Execute "SET IDENTITY_INSERT " & strTableName & " on"
          End If
90        Set obj = CreateObject("KFOX.StringBuilder")
100       lSQLCount = 0
110       For i = LBound(strDelSQL) To UBound(strDelSQL)
120           strSQL = Trim(strDelSQL(i))
130           If Len(strSQL) > 0 Then
140               lSQLCount = lSQLCount + 1
150               obj.Append strSQL
160           End If
170           If lSQLCount = 100 Then
180               cn.Execute obj.StringValue
190               obj.Remove 1, obj.length
200               lSQLCount = 0
210               If cn.Errors.Count > 0 Then
220                   Err.Raise -1, "ExecuteSynEx", cn.Errors.Item(0).Description
230               End If
240           End If
250       Next i
260       If lSQLCount > 0 Then
270           cn.Execute obj.StringValue
280           obj.Remove 1, obj.length
290           lSQLCount = 0
300           If cn.Errors.Count > 0 Then
310               Err.Raise -1, "ExecuteSynEx", cn.Errors.Item(0).Description
320           End If
330       End If
340       Set obj = Nothing
        
350       Set obj = CreateObject("KFOX.StringBuilder")
360       lSQLCount = 0
370       For i = LBound(strAddSQL) To UBound(strAddSQL)
380           strSQL = Trim(strAddSQL(i))
390           If Len(strSQL) > 0 Then
400               lSQLCount = lSQLCount + 1
410               obj.Append strSQL
420           End If
430           If lSQLCount = 100 Then
440               cn.Execute obj.StringValue
450               obj.Remove 1, obj.length
460               lSQLCount = 0
470               If cn.Errors.Count > 0 Then
480                   Err.Raise -1, "ExecuteSynEx", cn.Errors.Item(0).Description
490               End If
500           End If
510       Next i
520       If lSQLCount > 0 Then
530           cn.Execute obj.StringValue
540           obj.Remove 1, obj.length
550           lSQLCount = 0
560           If cn.Errors.Count > 0 Then
570               Err.Raise -1, "ExecuteSynEx", cn.Errors.Item(0).Description
580           End If
590       End If
600       Set obj = Nothing

610       Set obj = CreateObject("KFOX.StringBuilder")
620       lSQLCount = 0
630       For i = LBound(strUpdSQL) To UBound(strUpdSQL)
640           strSQL = Trim(strUpdSQL(i))
650           If Len(strSQL) > 0 Then
660               lSQLCount = lSQLCount + 1
670               obj.Append strSQL
680           End If
690           If lSQLCount = 100 Then
700               cn.Execute obj.StringValue
710               obj.Remove 1, obj.length
720               lSQLCount = 0
730               If cn.Errors.Count > 0 T