oCn := TOLEAuto():New('ADODB.Connection')
oCn:CursorLocation := 3 // adUseClient — REQUIRED for UpdateBatch
oCn:ConnectionString := xConnect
oCn:Open( xConnect )
// Open ONE recordset for batch inserts
cSql := "SELECT * FROM WEBEMR.EMR_TEMP_OPDDRUG WHERE 1=0"
oRs := FW_OpenRecordSet( oCn, cSql, 3, 4, , 1 )
// adOpenStatic^ ^adLockBatchOptimistic
SELE WCHAAAM1
DO WHILE !EOF()
IF FWAdoAppendBlank( oRs )
oRs:Fields("erop_drorderno"):Value := MSERNO
oRs:Fields("erop_patname"):Value := HB_TRANSLATE(MNAME,'BIG5','UTF8')
oRs:Fields("erop_sex"):Value := MSEX
ENDIF
SELE WCHAAAM1
SKIP
ENDDO
TRY
oRs:UpdateBatch()
CATCH
oErr := FW_GetAdoError( oRs:ActiveConnection )
IF oErr != nil
LogFile("WRISRUNERR", { oErr:Description })
ENDIF
oRs:CancelBatch() // CancelBatch, not CancelUpdate
END
oRs:Close()
oCn:Close()
Summary of fixes:
CursorLocation := 3 on the connection (client-side cursor)
LockType 4 (adLockBatchOptimistic) instead of 3
Open one recordset outside the loop, append all records, then call UpdateBatch() once
Use CancelBatch() instead of CancelUpdate() for batch operations
If you only need to insert (not check existence first), use WHERE 1=0 to get an empty recordset with the right
schema
If you need the existence check per record, you can either keep individual recordsets with adLockOptimistic (3) and
use oRs:Update() (not UpdateBatch) inside the loop, or do the check with a separate query and batch the inserts
separately.
oCn := TOLEAuto():New('ADODB.Connection')
oCn:CursorLocation := 3 // adUseClient — REQUIRED for UpdateBatch
oCn:ConnectionString := xConnect
oCn:Open( xConnect )
// Open ONE recordset for batch inserts
cSql := "SELECT * FROM WEBEMR.EMR_TEMP_OPDDRUG WHERE 1=0"
oRs := FW_OpenRecordSet( oCn, cSql, 3, 4, , 1 )
// adOpenStatic^ ^adLockBatchOptimistic
SELE WCHAAAM1
DO WHILE !EOF()
IF FWAdoAppendBlank( oRs )
oRs:Fields("erop_drorderno"):Value := MSERNO
oRs:Fields("erop_patname"):Value := HB_TRANSLATE(MNAME,'BIG5','UTF8')
oRs:Fields("erop_sex"):Value := MSEX
ENDIF
SELE WCHAAAM1
SKIP
ENDDO
TRY
oRs:UpdateBatch()
CATCH
oErr := FW_GetAdoError( oRs:ActiveConnection )
IF oErr != nil
LogFile("WRISRUNERR", { oErr:Description })
ENDIF
oRs:CancelBatch() // CancelBatch, not CancelUpdate
END
oRs:Close()
oCn:Close()
Summary of fixes:
CursorLocation := 3 on the connection (client-side cursor)
LockType 4 (adLockBatchOptimistic) instead of 3
Open one recordset outside the loop, append all records, then call UpdateBatch() once
Use CancelBatch() instead of CancelUpdate() for batch operations
If you only need to insert (not check existence first), use WHERE 1=0 to get an empty recordset with the right
schema
If you need the existence check per record, you can either keep individual recordsets with adLockOptimistic (3) and
use oRs:Update() (not UpdateBatch) inside the loop, or do the check with a separate query and batch the inserts
separately.
Dear Antonio,
I will try it. Thanks a lot.
Best Regards,
Richard
Harbour 3.2.0dev (r2503251254) => Borland C++ v7.7 32bit
MySQL v8.0
Harbour 3.2.0dev (r2503251254) => Borland C++ v7.7 64bit