Modified copy and delete record to sql routines to lock the queue record before attempting to prevent long running copy or delete calls form being processed more than once and wasting resources.
This commit is contained in:
@ -18,81 +18,91 @@ Compile function Delete_Record_From_SQL(Table, Key, LogError, pKey)
|
||||
-------
|
||||
09/15/2010 KRF Original Programmer
|
||||
\*****************************************************************************/
|
||||
|
||||
$insert Microsoft_Ado_Equates
|
||||
|
||||
If Assigned(LogError) else LogError = 0
|
||||
$Insert APP_INSERTS
|
||||
$insert MICROSOFT_ADO_EQUATES
|
||||
|
||||
Declare subroutine Sql_Services, SRP_COM
|
||||
Declare function Sql_Services, Error_Services, SRP_COM, Environment_Services
|
||||
Ans = ""
|
||||
Declare function Sql_Services, Error_Services, SRP_COM, Environment_Services, Unassigned
|
||||
|
||||
// Make sure table is uppercase
|
||||
Convert @LOWER_CASE to @UPPER_CASE in Table
|
||||
Main:
|
||||
|
||||
If Unassigned(LogError) else LogError = False$
|
||||
Ans = ""
|
||||
Done = False$
|
||||
// Make sure table is uppercase
|
||||
Convert @LOWER_CASE to @UPPER_CASE in Table
|
||||
|
||||
Open 'SQL_PENDING' to pTable then
|
||||
|
||||
// The expected name of the handler
|
||||
Handler = "DELETE_":Table:"_RECORD_FROM_SQL"
|
||||
If pKey NE '' then Lock pTable, pKey else Done = True$
|
||||
|
||||
If Not(Done) then
|
||||
// The expected name of the handler
|
||||
Handler = "DELETE_":Table:"_RECORD_FROM_SQL"
|
||||
|
||||
// Find the stored procedure that handles this table
|
||||
Open "SYSOBJ" to hSysObj then
|
||||
Read ObjCode from hSysObj, "$":Handler:"*LSL2" then
|
||||
// Connect to the ODBC/ADO
|
||||
If SRP_Com(Connection, "CREATE", "ADODB.Connection") then
|
||||
// Connect to the database via ODBC
|
||||
ConnectionString = Environment_Services('GetSQLScrapeConnectionString')
|
||||
If SRP_Com(Connection, "CALL", "Open", ConnectionString) EQ "" then
|
||||
// Read the record and call the handler
|
||||
If Key NE "" then
|
||||
Ans = Function(@Handler(Connection, Key))
|
||||
If Ans EQ '' then
|
||||
If Assigned(pKey) then
|
||||
Open 'SQL_PENDING' to pTable then
|
||||
Delete pTable, pKey else null
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end else
|
||||
Ans = 'Unable to open connection to SQL server. SQL connection error: ':SRP_Com(Connection, "ERROR")
|
||||
end
|
||||
SRP_Com(Connection, "CALL", "Close")
|
||||
SRP_Com(Connection, "RELEASE")
|
||||
end else
|
||||
Ans = "Unable to create ADO connection."
|
||||
end
|
||||
end
|
||||
end
|
||||
// Find the stored procedure that handles this table
|
||||
Open "SYSOBJ" to hSysObj then
|
||||
Read ObjCode from hSysObj, "$":Handler:"*LSL2" then
|
||||
// Connect to the ODBC/ADO
|
||||
If SRP_Com(Connection, "CREATE", "ADODB.Connection") then
|
||||
// Connect to the database via ODBC
|
||||
ConnectionString = Environment_Services('GetSQLScrapeConnectionString')
|
||||
If SRP_Com(Connection, "CALL", "Open", ConnectionString) EQ "" then
|
||||
// Read the record and call the handler
|
||||
If Key NE "" then
|
||||
Ans = Function(@Handler(Connection, Key))
|
||||
If Ans EQ '' then
|
||||
If Assigned(pKey) then
|
||||
Delete pTable, pKey else Null
|
||||
Unlock pTable, pKey else Null
|
||||
end
|
||||
end
|
||||
end
|
||||
end else
|
||||
Ans = 'Unable to open connection to SQL server. SQL connection error: ':SRP_Com(Connection, "ERROR")
|
||||
end
|
||||
SRP_Com(Connection, "CALL", "Close")
|
||||
SRP_Com(Connection, "RELEASE")
|
||||
end else
|
||||
Ans = "Unable to create ADO connection."
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
If LogError AND Len(Ans) then
|
||||
Open "SQL_ERROR" to hSqlError then
|
||||
Read Errors from hSqlError, Date() then
|
||||
Errors := @FM:Table:@VM:Key:@VM:Ans
|
||||
Write Errors to hSqlError, Date()
|
||||
end else
|
||||
Errors = Table:@VM:Key:@VM:Ans
|
||||
Write Errors to hSqlError, Date()
|
||||
end
|
||||
end
|
||||
end
|
||||
If LogError AND Len(Ans) then
|
||||
Open "SQL_ERROR" to hSqlError then
|
||||
Read Errors from hSqlError, Date() then
|
||||
Errors := @FM:Table:@VM:Key:@VM:Ans
|
||||
Write Errors to hSqlError, Date()
|
||||
end else
|
||||
Errors = Table:@VM:Key:@VM:Ans
|
||||
Write Errors to hSqlError, Date()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
// Always log the result
|
||||
|
||||
If Assigned(pKey) then
|
||||
Open 'SQL_LOG' to hLog then
|
||||
If Ans EQ '' then
|
||||
Result = 'PROCESSED'
|
||||
end else
|
||||
Result = Ans
|
||||
end
|
||||
CurrDate = Date()
|
||||
Read Log from hLog, CurrDate then
|
||||
Log := @FM:pKey:@VM:Result
|
||||
end else
|
||||
Log = pKey:@VM:Result
|
||||
end
|
||||
Write Log to hLog, CurrDate
|
||||
end
|
||||
end
|
||||
// Always log the result
|
||||
|
||||
If Assigned(pKey) then
|
||||
If (pKey NE '') then
|
||||
Open 'SQL_LOG' to hLog then
|
||||
If Ans EQ '' then
|
||||
Result = 'PROCESSED'
|
||||
end else
|
||||
Result = Ans
|
||||
end
|
||||
CurrDate = Date()
|
||||
Read Log from hLog, CurrDate then
|
||||
Log := @FM:pKey:@VM:Result
|
||||
end else
|
||||
Log = pKey:@VM:Result
|
||||
end
|
||||
Write Log to hLog, CurrDate
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Return Ans
|
||||
|
||||
|
Reference in New Issue
Block a user