- Posts: 6
Deleted Items
- Niel Bullock
- Topic Author
- Offline
- User
Less
More
13 years 3 months ago #2150
by Niel Bullock
Deleted Items - Post(2150) was created by Niel Bullock
How can I remove items in the Write side that have been deleted from the Read side?
Please Log in or Create an account to join the conversation.
- FlowHeater-Team
- Offline
- Admin
13 years 3 months ago #2151
by FlowHeater-Team
Best wishes
Robert Stark
Replied by FlowHeater-Team on topic Re:Deleted Items - Post(2151)
Hi Niel,
FlowHeater can’t synchronize deleted records between READ and WRITE! It’s possible to delete records on the READ and/or the WRITE with the help of the .NET Script Heater and an additional deleted flag field.
I’ve made a little example. In the ZIP archive a small access database (mdb) file are also included.
The script in the .NET Script Heater gets the Primary Key and the deleted Flag field. In case of the deleted flag is set to true the script execute a custom SQL delete statement on both sides.
CAUTION: Please take care when making use of this method. If an incorrect SQL WHERE condition is entered here you could inadvertently delete the wrong database rows or even the entire table contents!
FlowHeater can’t synchronize deleted records between READ and WRITE! It’s possible to delete records on the READ and/or the WRITE with the help of the .NET Script Heater and an additional deleted flag field.
I’ve made a little example. In the ZIP archive a small access database (mdb) file are also included.
Code:
public object DoWork()
{
if (InValues.Length != 2)
{
throw new Exception("2 input parameter expected");
}
// don't execute SQL delete statements in test mode!
if (AdapterWrite.OnlyTest == false)
{
// get field value "ID" = first input parameter
int iID = (int)InValues[0].GetInt();
// get field value "DeleteFlag" = second input parameter
bool bDelete = (bool)InValues[1].GetBoolean();
if (bDelete)
{
string sql1 = "delete from Your_Table_on_READ where id = " + iID.ToString("0");
string sql2 = "delete from Your_Table_on_WRITE where id = " + iID.ToString("0");
// Execute the delete SQL statement on the READ database
AdapterRead.Execute(sql1);
// Execute the delete SQL statement on the WRITE database
AdapterWrite.Execute(sql2);
}
}
// just returning the first input parameter = field ID
return InValues[0].GetValue();
}
The script in the .NET Script Heater gets the Primary Key and the deleted Flag field. In case of the deleted flag is set to true the script execute a custom SQL delete statement on both sides.
CAUTION: Please take care when making use of this method. If an incorrect SQL WHERE condition is entered here you could inadvertently delete the wrong database rows or even the entire table contents!
Attachment delete_records.zip not found
Best wishes
Robert Stark
Attachments:
Please Log in or Create an account to join the conversation.
- Niel Bullock
- Topic Author
- Offline
- User
Less
More
- Posts: 6
13 years 3 months ago #2152
by Niel Bullock
Replied by Niel Bullock on topic Re:Deleted Items - Post(2152)
I can see how this can work however, my Read DB is a bought application and I don't have the ability to add. I will need to research that db and look for a delete field.
Please Log in or Create an account to join the conversation.
Time to create page: 0.254 seconds