Iam developing an app, which works as a attendance terminal- user is saving records about attendance, and then send it to server. Every record, has its user and time. The problem is, that the interface on server is accepting only records, with unique timestamp(for same user). If there are two records with same user and same timestamp, it saves only first record. So i need some elegant way to prevent records from being duplicated. Checking every record in database, every time the new record is saved seems like a overkill to me, and it would have negative impact on performance of the app. Any ideas how to solve this?
There is no other definitive way to do this as there is a constraint on the database, so the only way to check for it is to look into the database.
I’m not seeing the problem here. If the server wants to treat two records with the same user and timestamp as one record, the app doesn’t need to care whether there’s a duplicate or not. It just sends what it has, and the server decides whether it’s relevant or not.
could you do something simple like using the user’s index in your database as an ‘id’ property in your app, and write a quick function to ignore duplicate id’s? Or get the length of the database and not allow records with an id that falls in that range to be posted to the database?
Another possibility is posting the user’s id to whatever site/service/whatever you’re using and if that index exists in the database, delete where id = idProperty or update where id = idProperty.
If I’m catching what you’re throwing.
Yea thats right, the problem is i need to know, which records and save and which where not. Servers interface, which is receiving data, is very bad designed - it returns only number of records, that were saved. So why i send 10 records, and one of them is duplicate, it just returns 9. But i need information which records were saved, and which were not, so i can mark them in the app, and stop sending them again. In this case, i cant discover, which record is the, that wasnt accepted. And thats the whole problem…
That is incredibly inconvenient. So are you saying you literally can’t access specific data? only the number of records saved?
If so, the only thing I can think of right now is creating a model of the database in your app. When a record is posted to the db, also store it in an object/array of your own design. At least you would have a basis for comparing/preventing posts.
Maybe use local or even session storage? Do you have access to ANY domain that you could set up to run your own php? You could write your data to a text file, and pull that text from the file when your app is initialized, but that sounds pretty dicey. It’s easy, and works, but security could be an issue. If it’s not “important” data, both local storage and writing to text are workable solutions.
Personally, I’d try to create some kind of data-model (thank you again, rapropos. The interfaces are awesome) in your app.
You definitely were not set up for success on this one.
Are there any other conditions whereby the server properly receives a record (i.e., we know that there are no network connection problems) yet refuses to record it?
If not, what I would do is ignore the return value from the server, and only pay attention to the return status code. If it indicates no error, I would assume that means that there is no need to resend any of the records sent in that request.
Well a very simple, but interesting idea There are not any conditions, only combination of userID and timestamp must be unique. Maybe ill solve it like that. Thx for your help