- June 25, 2015
- 566
- 292
- Home Country
- United Kingdom
Hi ajs
I am starting a new thread in reply to the following from a thread in the MP2 forum:
<-- FanartHandler when start automatically search all new pictures and put it to db, dn have rowid in Image table, and TimeStamp (if i remember its time when picture added in db). -->
The image database does have a time stamp column but it is only a date and is, therefore, not unique. There is also an id column, but it is of type TEXT and is also not unique. What I think would help would be a autoincrement column and I can't see one in the image table.
Here's a bit of code that shows what I'm talking about.
var maxID = listTo.Max(o => o.idPath);
foreach (path item in listFrom.Skip((int)maxID))
{
list.Add(item);
}
We have two lists From and To. I find the highest id in list To then start to read the From list from the record after the highest To ID and add each item to the To list. This works because the ID is numeric and written to the table in arrival mode. This technique wouldn't be needed for a table with a few records. However, when there are thousands of records, like in the image table, this technique massively reduces resource use and the time to process the data.
Here's what I have to do when we don't have an autoincrement ID.
foreach (path item in listFrom)
{
single = listTo.Find(delegate (path d) { return (d.idPath == item.idPath); });
if (single == null)
{
list.Add(item);
}
}
Here, we have to read every record in the From list and check, for each From record, whether it exists in the To list, and if it doesn't exist add the From record to the To list. I hope you can appreciate how great the difference between the two options is.
I will go ahead without the autoincrement column but if one could be added it would be great. The wonderful thing about having autoincrement fields in tables is that you don't have to reference them in your code because the database engine processes these fields automatically. However, you do have to add the field to your column definitions for the table.
Tony
I am starting a new thread in reply to the following from a thread in the MP2 forum:
<-- FanartHandler when start automatically search all new pictures and put it to db, dn have rowid in Image table, and TimeStamp (if i remember its time when picture added in db). -->
The image database does have a time stamp column but it is only a date and is, therefore, not unique. There is also an id column, but it is of type TEXT and is also not unique. What I think would help would be a autoincrement column and I can't see one in the image table.
Here's a bit of code that shows what I'm talking about.
var maxID = listTo.Max(o => o.idPath);
foreach (path item in listFrom.Skip((int)maxID))
{
list.Add(item);
}
We have two lists From and To. I find the highest id in list To then start to read the From list from the record after the highest To ID and add each item to the To list. This works because the ID is numeric and written to the table in arrival mode. This technique wouldn't be needed for a table with a few records. However, when there are thousands of records, like in the image table, this technique massively reduces resource use and the time to process the data.
Here's what I have to do when we don't have an autoincrement ID.
foreach (path item in listFrom)
{
single = listTo.Find(delegate (path d) { return (d.idPath == item.idPath); });
if (single == null)
{
list.Add(item);
}
}
Here, we have to read every record in the From list and check, for each From record, whether it exists in the To list, and if it doesn't exist add the From record to the To list. I hope you can appreciate how great the difference between the two options is.
I will go ahead without the autoincrement column but if one could be added it would be great. The wonderful thing about having autoincrement fields in tables is that you don't have to reference them in your code because the database engine processes these fields automatically. However, you do have to add the field to your column definitions for the table.
Tony
Last edited: