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:
@ -1,6 +1,4 @@
|
|||||||
Compile subroutine Copy_Backlog_Records_To_SQL(VOID)
|
Compile subroutine Copy_Backlog_Records_To_SQL(VOID)
|
||||||
#pragma precomp SRP_PreCompiler
|
|
||||||
|
|
||||||
/*****************************************************************************\
|
/*****************************************************************************\
|
||||||
This is a utility function. For each record found in SQL_BACKLOG, it makes
|
This is a utility function. For each record found in SQL_BACKLOG, it makes
|
||||||
sure the identified record is copied to SQL. Then the backlog record is
|
sure the identified record is copied to SQL. Then the backlog record is
|
||||||
@ -10,95 +8,97 @@ Compile subroutine Copy_Backlog_Records_To_SQL(VOID)
|
|||||||
-------
|
-------
|
||||||
08/10/2010 KRF Original Programmer
|
08/10/2010 KRF Original Programmer
|
||||||
\*****************************************************************************/
|
\*****************************************************************************/
|
||||||
|
#pragma precomp SRP_PreCompiler
|
||||||
$Insert APP_INSERTS
|
$Insert APP_INSERTS
|
||||||
|
|
||||||
Declare subroutine Copy_Record_To_SQL, Delete_Record_From_SQL, SRP_TcpClient, Copy_Pending_Records_To_Sql
|
Declare subroutine Copy_Record_To_SQL, Delete_Record_From_SQL, SRP_TcpClient, Copy_Pending_Records_To_Sql
|
||||||
Declare function GetTickCount, Database_Services, SRP_TcpClient, Datetime, Environment_Services
|
Declare function GetTickCount, Database_Services, SRP_TcpClient, Datetime, Environment_Services
|
||||||
|
|
||||||
hSysLists = Database_Services('GetTableHandle', 'SYSLISTS')
|
Main:
|
||||||
Lock hSysLists, 'Copy_Backlog_Records_To_SQL' then
|
|
||||||
|
hSysLists = Database_Services('GetTableHandle', 'SYSLISTS')
|
||||||
|
Lock hSysLists, 'Copy_Backlog_Records_To_SQL' then
|
||||||
|
|
||||||
Copy_Pending_Records_To_Sql()
|
Copy_Pending_Records_To_Sql()
|
||||||
|
|
||||||
CurrDtm = Datetime()
|
CurrDtm = Datetime()
|
||||||
TablesToSkip = Database_Services('ReadDataRow', 'APP_INFO', 'SQL_TABLES_TO_SKIP')
|
TablesToSkip = Database_Services('ReadDataRow', 'APP_INFO', 'SQL_TABLES_TO_SKIP')
|
||||||
NonCriticalTables = Database_Services('ReadDataRow', 'APP_INFO', 'NONCRITICAL_SQL_TABLES')
|
NonCriticalTables = Database_Services('ReadDataRow', 'APP_INFO', 'NONCRITICAL_SQL_TABLES')
|
||||||
|
|
||||||
Open "SQL_PENDING" to pTable then
|
Open "SQL_PENDING" to pTable then
|
||||||
|
|
||||||
Open "SQL_BACKLOG" to hTable then
|
Open "SQL_BACKLOG" to hTable then
|
||||||
ClearSelect
|
ClearSelect
|
||||||
Select hTable
|
Select hTable
|
||||||
Done = 0
|
Done = 0
|
||||||
Loop
|
Loop
|
||||||
ReadNext Key else Done = 1
|
ReadNext Key else Done = 1
|
||||||
Command = ''
|
Command = ''
|
||||||
Skip = False$
|
Skip = False$
|
||||||
Until Done
|
Until Done
|
||||||
Table = Key[1, "*"]
|
Table = Key[1, "*"]
|
||||||
Locate Table in TablesToSkip by "AL" using "," setting ListPos then
|
Locate Table in TablesToSkip by "AL" using "," setting ListPos then
|
||||||
Delete hTable, Key else null
|
Delete hTable, Key else null
|
||||||
end else
|
end else
|
||||||
Locate Table in NonCriticalTables using @FM setting Dummy then
|
Locate Table in NonCriticalTables using @FM setting Dummy then
|
||||||
ID = Key[Col2() + 1, Len(Key)]
|
ID = Key[Col2() + 1, Len(Key)]
|
||||||
|
|
||||||
Read Dummy From pTable, Key then
|
Read Dummy From pTable, Key then
|
||||||
Skip = True$
|
Skip = True$
|
||||||
end
|
end
|
||||||
|
|
||||||
If Skip EQ False$ then
|
If Skip EQ False$ then
|
||||||
Begin Case
|
Begin Case
|
||||||
Case ID[-7, 7] EQ "*DELETE"
|
Case ID[-7, 7] EQ "*DELETE"
|
||||||
ID[-7, 7] = ""
|
ID[-7, 7] = ""
|
||||||
Command := 'RUN DELETE_RECORD_FROM_SQL ':Quote(Table):', ':Quote(ID):', 1, ':Quote(Key)
|
Command := 'RUN DELETE_RECORD_FROM_SQL ':Quote(Table):', ':Quote(ID):', 1, ':Quote(Key)
|
||||||
Write CurrDtm to pTable, Key then Delete hTable, Key
|
Write CurrDtm to pTable, Key then Delete hTable, Key
|
||||||
Case ID[-6, 6] EQ "*WRITE"
|
Case ID[-6, 6] EQ "*WRITE"
|
||||||
ID[-6, 6] = ""
|
ID[-6, 6] = ""
|
||||||
Command := 'RUN COPY_RECORD_TO_SQL ':Quote(Table):', ':Quote(ID):', 1, ':Quote(Key)
|
Command := 'RUN COPY_RECORD_TO_SQL ':Quote(Table):', ':Quote(ID):', 1, ':Quote(Key)
|
||||||
Write CurrDtm to pTable, Key then Delete hTable, Key
|
Write CurrDtm to pTable, Key then Delete hTable, Key
|
||||||
End Case
|
End Case
|
||||||
end else
|
end else
|
||||||
// This record is already being processed and we don't need to process it multiple times.
|
// This record is already being processed and we don't need to process it multiple times.
|
||||||
Delete hTable, Key else null
|
Delete hTable, Key else null
|
||||||
end
|
end
|
||||||
end else
|
end else
|
||||||
TempKey = Key
|
TempKey = Key
|
||||||
TempKey[1, Len(Table) + 1] = ''
|
TempKey[1, Len(Table) + 1] = ''
|
||||||
TransTime = TempKey[-1, 'B*']
|
TransTime = TempKey[-1, 'B*']
|
||||||
TempKey[-1, Neg(Len(TransTime) + 1)] = ''
|
TempKey[-1, Neg(Len(TransTime) + 1)] = ''
|
||||||
TransDate = TempKey[-1, 'B*']
|
TransDate = TempKey[-1, 'B*']
|
||||||
TempKey[-1, Neg(Len(TransDate) + 1)] = ''
|
TempKey[-1, Neg(Len(TransDate) + 1)] = ''
|
||||||
Process = TempKey[-1, 'B*']
|
Process = TempKey[-1, 'B*']
|
||||||
TempKey[-1, Neg(Len(Process) + 1)] = ''
|
TempKey[-1, Neg(Len(Process) + 1)] = ''
|
||||||
ID = TempKey
|
ID = TempKey
|
||||||
If Process EQ 'DELETE' then
|
If Process EQ 'DELETE' then
|
||||||
pKey = Key
|
pKey = Key
|
||||||
Command := 'RUN DELETE_RECORD_FROM_SQL ':Quote(Table):', ':Quote(ID):', 1, ':Quote(pKey)
|
Command := 'RUN DELETE_RECORD_FROM_SQL ':Quote(Table):', ':Quote(ID):', 1, ':Quote(pKey)
|
||||||
Write CurrDtm to pTable, pKey then Delete hTable, Key
|
Write CurrDtm to pTable, pKey then Delete hTable, Key
|
||||||
end else
|
end else
|
||||||
pKey = Key
|
pKey = Key
|
||||||
Command := 'RUN COPY_RECORD_TO_SQL ':Quote(Table):', ':Quote(ID):', 1, ':Quote(pKey)
|
Command := 'RUN COPY_RECORD_TO_SQL ':Quote(Table):', ':Quote(ID):', 1, ':Quote(pKey)
|
||||||
Write CurrDtm to pTable, pKey then Delete hTable, Key
|
Write CurrDtm to pTable, pKey then Delete hTable, Key
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
If Skip EQ False$ then
|
If Skip EQ False$ then
|
||||||
TcpClientHandle = 0
|
TcpClientHandle = 0
|
||||||
ServerIP = Environment_Services('GetApplicationRootIP')
|
ServerIP = Environment_Services('GetApplicationRootIP')
|
||||||
Convert '\' to '' in ServerIP
|
ServerPort = Environment_Services('GetScrapeServerPort')
|
||||||
If SRP_TcpClient(TcpClientHandle, 'CONNECT', ServerIP, '20779') then
|
Convert '\' to '' in ServerIP
|
||||||
SRP_TcpClient(TcpClientHandle, 'SEND_SES', Command)
|
If SRP_TcpClient(TcpClientHandle, 'CONNECT', ServerIP, ServerPort) then
|
||||||
SRP_TcpClient(TcpClientHandle, 'CLOSE_SES')
|
SRP_TcpClient(TcpClientHandle, 'SEND_SES', Command)
|
||||||
end
|
SRP_TcpClient(TcpClientHandle, 'CLOSE_SES')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
Repeat
|
end
|
||||||
end
|
Repeat
|
||||||
end
|
end
|
||||||
Unlock hSysLists, 'Copy_Backlog_Records_To_SQL' else Null
|
end
|
||||||
end
|
Unlock hSysLists, 'Copy_Backlog_Records_To_SQL' else Null
|
||||||
|
end
|
||||||
|
|
||||||
Return
|
Return
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
Compile subroutine Copy_Pending_Records_To_SQL(VOID)
|
Compile subroutine Copy_Pending_Records_To_SQL(VOID)
|
||||||
#pragma precomp SRP_PreCompiler
|
|
||||||
|
|
||||||
/*****************************************************************************\
|
/*****************************************************************************\
|
||||||
This is a utility function. For each record found in SQL_PENDING, it makes
|
This is a utility function. For each record found in SQL_PENDING, it makes
|
||||||
sure the identified record is copied to SQL.
|
sure the identified record is copied to SQL.
|
||||||
@ -9,98 +7,104 @@ Compile subroutine Copy_Pending_Records_To_SQL(VOID)
|
|||||||
-------
|
-------
|
||||||
02/06/2023 DJS Adapted from Copy_Backlog_Records_To_SQL
|
02/06/2023 DJS Adapted from Copy_Backlog_Records_To_SQL
|
||||||
\*****************************************************************************/
|
\*****************************************************************************/
|
||||||
|
#pragma precomp SRP_PreCompiler
|
||||||
$Insert APP_INSERTS
|
$Insert APP_INSERTS
|
||||||
|
|
||||||
|
EQU FIVE_MINUTES$ to 0.003472
|
||||||
|
EQU SECONDS_PER_DAY$ to 86400
|
||||||
|
EQU THIRTY_MINUTES$ to 1800
|
||||||
|
|
||||||
Declare subroutine Copy_Record_To_SQL, Delete_Record_From_SQL, SRP_TcpClient, Database_Services
|
Declare subroutine Copy_Record_To_SQL, Delete_Record_From_SQL, SRP_TcpClient, Database_Services
|
||||||
Declare function GetTickCount, Database_Services, SRP_TcpClient, Datetime, Database_Services, Environment_Services
|
Declare function GetTickCount, Database_Services, SRP_TcpClient, Datetime, Database_Services, Environment_Services
|
||||||
|
|
||||||
// This only needs to be called every once in a while (e.g. 5 minutes ~ 0.003472)
|
Main:
|
||||||
Run = False$
|
|
||||||
CurrDtm = Datetime()
|
|
||||||
LastRunDtm = Database_Services('ReadDataRow', 'APP_INFO', 'SQL_PENDING_LAST_RUNTIME')
|
|
||||||
If LastRunDtm NE '' then
|
|
||||||
TimeDiff = CurrDtm - LastRunDtm
|
|
||||||
If TimeDiff GT 0.003472 then
|
|
||||||
Run = True$
|
|
||||||
LastRunDtm = CurrDtm
|
|
||||||
end
|
|
||||||
end else
|
|
||||||
Run = True$
|
|
||||||
LastRunDtm = CurrDtm
|
|
||||||
end
|
|
||||||
|
|
||||||
If Run then
|
// This only needs to be called every once in a while (e.g. 5 minutes ~ 0.003472)
|
||||||
Database_Services('WriteDataRow', 'APP_INFO', 'SQL_PENDING_LAST_RUNTIME', LastRunDtm)
|
Run = False$
|
||||||
hSysLists = Database_Services('GetTableHandle', 'SYSLISTS')
|
CurrDtm = Datetime()
|
||||||
Lock hSysLists, 'Copy_Pending_Records_To_SQL' then
|
LastRunDtm = Database_Services('ReadDataRow', 'APP_INFO', 'SQL_PENDING_LAST_RUNTIME')
|
||||||
|
If LastRunDtm NE '' then
|
||||||
|
TimeDiff = CurrDtm - LastRunDtm
|
||||||
|
If TimeDiff GT FIVE_MINUTES$ then
|
||||||
|
Run = True$
|
||||||
|
LastRunDtm = CurrDtm
|
||||||
|
end
|
||||||
|
end else
|
||||||
|
Run = True$
|
||||||
|
LastRunDtm = CurrDtm
|
||||||
|
end
|
||||||
|
|
||||||
NonCriticalTables = Database_Services('ReadDataRow', 'APP_INFO', 'NONCRITICAL_SQL_TABLES')
|
If Run then
|
||||||
Open "SQL_PENDING" to pTable then
|
Database_Services('WriteDataRow', 'APP_INFO', 'SQL_PENDING_LAST_RUNTIME', LastRunDtm)
|
||||||
|
hSysLists = Database_Services('GetTableHandle', 'SYSLISTS')
|
||||||
ClearSelect
|
Lock hSysLists, 'Copy_Pending_Records_To_SQL' then
|
||||||
Select pTable
|
|
||||||
Done = False$
|
|
||||||
Loop
|
|
||||||
ReadNext Key else Done = True$
|
|
||||||
Command = ''
|
|
||||||
Until Done
|
|
||||||
|
|
||||||
Read Rec from pTable, Key then
|
|
||||||
TransDtm = Rec<1>
|
|
||||||
ElapSecs = (CurrDtm - TransDtm) * 86400
|
|
||||||
If ElapSecs LT 1800 then
|
|
||||||
// Retry recent pending transactions (1800 seconds = 30 minutes)
|
|
||||||
Table = Key[1, "*"]
|
|
||||||
Locate Table in NonCriticalTables using @FM setting Dummy then
|
|
||||||
ID = Key[Col2() + 1, Len(Key)]
|
|
||||||
Begin Case
|
|
||||||
Case ID[-7, 7] EQ "*DELETE"
|
|
||||||
ID[-7, 7] = ""
|
|
||||||
Command := 'RUN DELETE_RECORD_FROM_SQL ':Quote(Table):', ':Quote(ID):', 1, ':Quote(Key)
|
|
||||||
Case ID[-6, 6] EQ "*WRITE"
|
|
||||||
ID[-6, 6] = ""
|
|
||||||
Command := 'RUN COPY_RECORD_TO_SQL ':Quote(Table):', ':Quote(ID):', 1, ':Quote(Key)
|
|
||||||
End Case
|
|
||||||
end else
|
|
||||||
TempKey = Key
|
|
||||||
TempKey[1, Len(Table) + 1] = ''
|
|
||||||
TransTime = TempKey[-1, 'B*']
|
|
||||||
TempKey[-1, Neg(Len(TransTime) + 1)] = ''
|
|
||||||
TransDate = TempKey[-1, 'B*']
|
|
||||||
TempKey[-1, Neg(Len(TransDate) + 1)] = ''
|
|
||||||
Process = TempKey[-1, 'B*']
|
|
||||||
TempKey[-1, Neg(Len(Process) + 1)] = ''
|
|
||||||
ID = TempKey
|
|
||||||
If Process EQ 'DELETE' then
|
|
||||||
Command := 'RUN DELETE_RECORD_FROM_SQL ':Quote(Table):', ':Quote(ID):', 1, ':Quote(Key)
|
|
||||||
end else
|
|
||||||
Command := 'RUN COPY_RECORD_TO_SQL ':Quote(Table):', ':Quote(ID):', 1, ':Quote(Key)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
TcpClientHandle = 0
|
|
||||||
ServerIP = Environment_Services('GetApplicationRootIP')
|
|
||||||
Convert '\' to '' in ServerIP
|
|
||||||
|
|
||||||
If SRP_TcpClient(TcpClientHandle, 'CONNECT', ServerIP, '20779') then
|
|
||||||
SRP_TcpClient(TcpClientHandle, 'SEND_SES', Command)
|
|
||||||
SRP_TcpClient(TcpClientHandle, 'CLOSE_SES')
|
|
||||||
end
|
|
||||||
|
|
||||||
end else
|
|
||||||
// This transaction most likely won't replicate due to a schema mapping issue or because
|
|
||||||
// the record no longer exists in OI, so remove this transaction from the pending queue.
|
|
||||||
Delete pTable, Key else null
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
Repeat
|
NonCriticalTables = Database_Services('ReadDataRow', 'APP_INFO', 'NONCRITICAL_SQL_TABLES')
|
||||||
end
|
Open "SQL_PENDING" to pTable then
|
||||||
Unlock hSysLists, 'Copy_Pending_Records_To_SQL' else Null
|
|
||||||
end
|
ClearSelect
|
||||||
end
|
Select pTable
|
||||||
|
Done = False$
|
||||||
|
Loop
|
||||||
|
ReadNext Key else Done = True$
|
||||||
|
Command = ''
|
||||||
|
Until Done
|
||||||
|
|
||||||
|
Read Rec from pTable, Key then
|
||||||
|
TransDtm = Rec<1>
|
||||||
|
ElapSecs = (CurrDtm - TransDtm) * SECONDS_PER_DAY$
|
||||||
|
If ElapSecs LT THIRTY_MINUTES$ then
|
||||||
|
// Retry recent pending transactions (i.e., those submitted in the last 30 minutes)
|
||||||
|
Table = Key[1, "*"]
|
||||||
|
Locate Table in NonCriticalTables using @FM setting Dummy then
|
||||||
|
ID = Key[Col2() + 1, Len(Key)]
|
||||||
|
Begin Case
|
||||||
|
Case ID[-7, 7] EQ "*DELETE"
|
||||||
|
ID[-7, 7] = ""
|
||||||
|
Command := 'RUN DELETE_RECORD_FROM_SQL ':Quote(Table):', ':Quote(ID):', 1, ':Quote(Key)
|
||||||
|
Case ID[-6, 6] EQ "*WRITE"
|
||||||
|
ID[-6, 6] = ""
|
||||||
|
Command := 'RUN COPY_RECORD_TO_SQL ':Quote(Table):', ':Quote(ID):', 1, ':Quote(Key)
|
||||||
|
End Case
|
||||||
|
end else
|
||||||
|
TempKey = Key
|
||||||
|
TempKey[1, Len(Table) + 1] = ''
|
||||||
|
TransTime = TempKey[-1, 'B*']
|
||||||
|
TempKey[-1, Neg(Len(TransTime) + 1)] = ''
|
||||||
|
TransDate = TempKey[-1, 'B*']
|
||||||
|
TempKey[-1, Neg(Len(TransDate) + 1)] = ''
|
||||||
|
Process = TempKey[-1, 'B*']
|
||||||
|
TempKey[-1, Neg(Len(Process) + 1)] = ''
|
||||||
|
ID = TempKey
|
||||||
|
If Process EQ 'DELETE' then
|
||||||
|
Command := 'RUN DELETE_RECORD_FROM_SQL ':Quote(Table):', ':Quote(ID):', 1, ':Quote(Key)
|
||||||
|
end else
|
||||||
|
Command := 'RUN COPY_RECORD_TO_SQL ':Quote(Table):', ':Quote(ID):', 1, ':Quote(Key)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
TcpClientHandle = 0
|
||||||
|
ServerIP = Environment_Services('GetApplicationRootIP')
|
||||||
|
ServerPort = Environment_Services('GetScrapeServerPort')
|
||||||
|
Convert '\' to '' in ServerIP
|
||||||
|
|
||||||
|
If SRP_TcpClient(TcpClientHandle, 'CONNECT', ServerIP, ServerPort) then
|
||||||
|
SRP_TcpClient(TcpClientHandle, 'SEND_SES', Command)
|
||||||
|
SRP_TcpClient(TcpClientHandle, 'CLOSE_SES')
|
||||||
|
end
|
||||||
|
|
||||||
|
end else
|
||||||
|
// This transaction most likely won't replicate due to a schema mapping issue or because
|
||||||
|
// the record no longer exists in OI, so remove this transaction from the pending queue.
|
||||||
|
Delete pTable, Key else null
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
Repeat
|
||||||
|
end
|
||||||
|
Unlock hSysLists, 'Copy_Pending_Records_To_SQL' else Null
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
Return
|
Return
|
||||||
|
|
||||||
|
|
||||||
|
@ -22,98 +22,107 @@ Compile function Copy_Record_To_SQL(Table, Key, LogError, pKey)
|
|||||||
09/23/2010 KRF Added logic to set @DICT, @ID, and @RECORD so handlers
|
09/23/2010 KRF Added logic to set @DICT, @ID, and @RECORD so handlers
|
||||||
can use symbolics
|
can use symbolics
|
||||||
\*****************************************************************************/
|
\*****************************************************************************/
|
||||||
$insert Microsoft_Ado_Equates
|
$Insert APP_INSERTS
|
||||||
|
$Insert MICROSOFT_ADO_EQUATES
|
||||||
If Assigned(LogError) else LogError = 0
|
|
||||||
|
|
||||||
Declare subroutine SRP_Com, Sql_Services
|
Declare subroutine SRP_Com, Sql_Services
|
||||||
Declare function SRP_Com, Environment_Services, Datetime, Sql_Services, Error_Services, Database_Services
|
Declare function SRP_Com, Environment_Services, Datetime, Sql_Services, Error_Services, Database_Services, Unassigned
|
||||||
Ans = ""
|
|
||||||
|
|
||||||
// Make sure table is uppercase
|
Main:
|
||||||
Convert @LOWER_CASE to @UPPER_CASE in Table
|
|
||||||
|
If Unassigned(LogError) then LogError = False$
|
||||||
|
|
||||||
TablesToSkip = Database_Services('ReadDataRow', 'APP_INFO', 'SQL_TABLES_TO_SKIP')
|
Ans = ""
|
||||||
Locate Table in TablesToSkip by "AL" using "," setting ListPos else
|
Done = False$
|
||||||
|
// Make sure table is uppercase
|
||||||
// The expected name of the handler
|
Convert @LOWER_CASE to @UPPER_CASE in Table
|
||||||
Handler = "COPY_":Table:"_RECORD_TO_SQL"
|
|
||||||
|
TablesToSkip = Database_Services('ReadDataRow', 'APP_INFO', 'SQL_TABLES_TO_SKIP')
|
||||||
// Find the stored procedure that handles this table
|
Locate Table in TablesToSkip by "AL" using "," setting ListPos else
|
||||||
Open "SYSOBJ" to hSysObj then
|
|
||||||
Read ObjCode from hSysObj, "$":Handler:"*LSL2" then
|
Open 'SQL_PENDING' to pTable then
|
||||||
// Connect to the ODBC
|
|
||||||
If SRP_Com(Connection, "CREATE", "ADODB.Connection") then
|
If pKey NE '' then Lock pTable, pKey else Done = True$
|
||||||
ConnectionString = Environment_Services('GetSQLScrapeConnectionString')
|
|
||||||
If SRP_Com(Connection, "CALL", "Open", ConnectionString) EQ "" then
|
If Not(Done) then
|
||||||
// Read the record and call the handler
|
// The expected name of the handler
|
||||||
Open Table to hTable then
|
Handler = "COPY_":Table:"_RECORD_TO_SQL"
|
||||||
Read @RECORD from hTable, Key then
|
|
||||||
If Key NE "" then
|
// Find the stored procedure that handles this table
|
||||||
Open "DICT.":Table to @DICT then null
|
Open "SYSOBJ" to hSysObj then
|
||||||
@ID = Key
|
Read ObjCode from hSysObj, "$":Handler:"*LSL2" then
|
||||||
Ans = Function(@Handler(Connection, Key, @RECORD))
|
// Connect to the ODBC
|
||||||
If Ans EQ '' then
|
If SRP_Com(Connection, "CREATE", "ADODB.Connection") then
|
||||||
If Assigned(pKey) then
|
ConnectionString = Environment_Services('GetSQLScrapeConnectionString')
|
||||||
If pKey NE '' then
|
If SRP_Com(Connection, "CALL", "Open", ConnectionString) EQ "" then
|
||||||
Open 'SQL_PENDING' to pTable then
|
// Read the record and call the handler
|
||||||
Delete pTable, pKey else null
|
Open Table to hTable then
|
||||||
|
Read @RECORD from hTable, Key then
|
||||||
|
If Key NE "" then
|
||||||
|
Open "DICT.":Table to @DICT then null
|
||||||
|
@ID = Key
|
||||||
|
Ans = Function(@Handler(Connection, Key, @RECORD))
|
||||||
|
If Ans EQ '' then
|
||||||
|
If Assigned(pKey) then
|
||||||
|
If pKey NE '' then
|
||||||
|
Delete pTable, pKey else Null
|
||||||
|
Unlock pTable, pKey else Null
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end else
|
||||||
end
|
Ans = 'Unable to read ':Key:' from ':Table:' table.'
|
||||||
end
|
end
|
||||||
end else
|
end
|
||||||
Ans = 'Unable to read ':Key:' from ':Table:' table.'
|
end else
|
||||||
end
|
Ans = 'Unable to open connection to SQL server. SQL connection error: '
|
||||||
end
|
Ans := SRP_Com(Connection, "ERROR")
|
||||||
end else
|
end
|
||||||
Ans = 'Unable to open connection to SQL server. SQL connection error: ':SRP_Com(Connection, "ERROR")
|
SRP_Com(Connection, "CALL", "Close")
|
||||||
end
|
SRP_Com(Connection, "RELEASE")
|
||||||
SRP_Com(Connection, "CALL", "Close")
|
end else
|
||||||
SRP_Com(Connection, "RELEASE")
|
Ans = "Unable to create ADO connection."
|
||||||
end else
|
end
|
||||||
Ans = "Unable to create ADO connection."
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
If LogError and Len(Ans) then
|
|
||||||
Open "SQL_ERROR" to hSqlError then
|
|
||||||
ErrorKey = OConv(Date(), "D4-J")
|
|
||||||
Timestamp = OConv(Datetime(), 'DT')
|
|
||||||
Read Errors from hSqlError, ErrorKey then
|
|
||||||
Errors := @FM:Table:@VM:Key:@VM:Timestamp:@VM:Ans
|
|
||||||
Write Errors to hSqlError, ErrorKey
|
|
||||||
end else
|
|
||||||
Errors = Table:@VM:Key:@VM:Timestamp:@VM:Ans
|
|
||||||
Write Errors to hSqlError, ErrorKey
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
If Assigned(pKey) then
|
|
||||||
If (pKey NE '') then
|
|
||||||
// Always log the result
|
|
||||||
Open 'SQL_LOG' to hLog then
|
|
||||||
If Ans EQ '' then
|
|
||||||
Result = 'PROCESSED'
|
|
||||||
end else
|
|
||||||
Result = Ans
|
|
||||||
end
|
end
|
||||||
CurrDate = Date()
|
|
||||||
Read Log from hLog, CurrDate then
|
If LogError and Len(Ans) then
|
||||||
Log := @FM:pKey:@VM:Result
|
Open "SQL_ERROR" to hSqlError then
|
||||||
end else
|
ErrorKey = OConv(Date(), "D4-J")
|
||||||
Log = pKey:@VM:Result
|
Timestamp = OConv(Datetime(), 'DT')
|
||||||
|
Read Errors from hSqlError, ErrorKey then
|
||||||
|
Errors := @FM:Table:@VM:Key:@VM:Timestamp:@VM:Ans
|
||||||
|
Write Errors to hSqlError, ErrorKey
|
||||||
|
end else
|
||||||
|
Errors = Table:@VM:Key:@VM:Timestamp:@VM:Ans
|
||||||
|
Write Errors to hSqlError, ErrorKey
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
If Assigned(pKey) then
|
||||||
|
If (pKey NE '') then
|
||||||
|
// Always log the result
|
||||||
|
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
|
||||||
Write Log to hLog, CurrDate
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
Return Ans
|
Return Ans
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -18,81 +18,91 @@ Compile function Delete_Record_From_SQL(Table, Key, LogError, pKey)
|
|||||||
-------
|
-------
|
||||||
09/15/2010 KRF Original Programmer
|
09/15/2010 KRF Original Programmer
|
||||||
\*****************************************************************************/
|
\*****************************************************************************/
|
||||||
|
$Insert APP_INSERTS
|
||||||
$insert Microsoft_Ado_Equates
|
$insert MICROSOFT_ADO_EQUATES
|
||||||
|
|
||||||
If Assigned(LogError) else LogError = 0
|
|
||||||
|
|
||||||
Declare subroutine Sql_Services, SRP_COM
|
Declare subroutine Sql_Services, SRP_COM
|
||||||
Declare function Sql_Services, Error_Services, SRP_COM, Environment_Services
|
Declare function Sql_Services, Error_Services, SRP_COM, Environment_Services, Unassigned
|
||||||
Ans = ""
|
|
||||||
|
|
||||||
// Make sure table is uppercase
|
Main:
|
||||||
Convert @LOWER_CASE to @UPPER_CASE in Table
|
|
||||||
|
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
|
If pKey NE '' then Lock pTable, pKey else Done = True$
|
||||||
Handler = "DELETE_":Table:"_RECORD_FROM_SQL"
|
|
||||||
|
If Not(Done) then
|
||||||
|
// The expected name of the handler
|
||||||
|
Handler = "DELETE_":Table:"_RECORD_FROM_SQL"
|
||||||
|
|
||||||
// Find the stored procedure that handles this table
|
// Find the stored procedure that handles this table
|
||||||
Open "SYSOBJ" to hSysObj then
|
Open "SYSOBJ" to hSysObj then
|
||||||
Read ObjCode from hSysObj, "$":Handler:"*LSL2" then
|
Read ObjCode from hSysObj, "$":Handler:"*LSL2" then
|
||||||
// Connect to the ODBC/ADO
|
// Connect to the ODBC/ADO
|
||||||
If SRP_Com(Connection, "CREATE", "ADODB.Connection") then
|
If SRP_Com(Connection, "CREATE", "ADODB.Connection") then
|
||||||
// Connect to the database via ODBC
|
// Connect to the database via ODBC
|
||||||
ConnectionString = Environment_Services('GetSQLScrapeConnectionString')
|
ConnectionString = Environment_Services('GetSQLScrapeConnectionString')
|
||||||
If SRP_Com(Connection, "CALL", "Open", ConnectionString) EQ "" then
|
If SRP_Com(Connection, "CALL", "Open", ConnectionString) EQ "" then
|
||||||
// Read the record and call the handler
|
// Read the record and call the handler
|
||||||
If Key NE "" then
|
If Key NE "" then
|
||||||
Ans = Function(@Handler(Connection, Key))
|
Ans = Function(@Handler(Connection, Key))
|
||||||
If Ans EQ '' then
|
If Ans EQ '' then
|
||||||
If Assigned(pKey) then
|
If Assigned(pKey) then
|
||||||
Open 'SQL_PENDING' to pTable then
|
Delete pTable, pKey else Null
|
||||||
Delete pTable, pKey else null
|
Unlock pTable, pKey else Null
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end else
|
||||||
end else
|
Ans = 'Unable to open connection to SQL server. SQL connection error: ':SRP_Com(Connection, "ERROR")
|
||||||
Ans = 'Unable to open connection to SQL server. SQL connection error: ':SRP_Com(Connection, "ERROR")
|
end
|
||||||
end
|
SRP_Com(Connection, "CALL", "Close")
|
||||||
SRP_Com(Connection, "CALL", "Close")
|
SRP_Com(Connection, "RELEASE")
|
||||||
SRP_Com(Connection, "RELEASE")
|
end else
|
||||||
end else
|
Ans = "Unable to create ADO connection."
|
||||||
Ans = "Unable to create ADO connection."
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
If LogError AND Len(Ans) then
|
If LogError AND Len(Ans) then
|
||||||
Open "SQL_ERROR" to hSqlError then
|
Open "SQL_ERROR" to hSqlError then
|
||||||
Read Errors from hSqlError, Date() then
|
Read Errors from hSqlError, Date() then
|
||||||
Errors := @FM:Table:@VM:Key:@VM:Ans
|
Errors := @FM:Table:@VM:Key:@VM:Ans
|
||||||
Write Errors to hSqlError, Date()
|
Write Errors to hSqlError, Date()
|
||||||
end else
|
end else
|
||||||
Errors = Table:@VM:Key:@VM:Ans
|
Errors = Table:@VM:Key:@VM:Ans
|
||||||
Write Errors to hSqlError, Date()
|
Write Errors to hSqlError, Date()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
// Always log the result
|
// 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
|
|
||||||
|
|
||||||
|
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
|
Return Ans
|
||||||
|
|
||||||
|
@ -565,8 +565,19 @@ Service GetServiceManagerPort()
|
|||||||
|
|
||||||
end service
|
end service
|
||||||
|
|
||||||
|
|
||||||
|
Service GetScrapeServerPort()
|
||||||
|
|
||||||
|
FilePath = Drive():'\SRPEngineServerScrape.ini'
|
||||||
|
OSRead IniFile from FilePath then
|
||||||
|
CharIndex = Index(IniFile, 'Port', 1)
|
||||||
|
Line = IniFile[CharIndex, 'F':CRLF$]
|
||||||
|
Response = Trim(Line[-1, 'B='])
|
||||||
|
end
|
||||||
|
|
||||||
|
end service
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// Internal GoSubs
|
// Internal GoSubs
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user