Attribute updation problem!!!
I am making an application where I have to copy the values of some of the tuples(which are not already copied into the files) from my database in MySQL into two files.Now I have an attribute with name "Replication_Done". This is an integer type of attribute and its initial value is 0, meaning that this tuple has not been copied into any of the 2 files.
Now whenever a tuple is copied into one of the file, the value of this "Replication_Done" is incremented by 1. This means from 0 to 1, and then if copied to the other, then from 1 to 2.
Now the condition is that, this whole replication mechanism may not complete in one sitting, i.e. I should be able to close my application any time I want, and then whenever I am back, it should start this replication from where it left. For example say I have 3 tuples with say primary key as "User_ID" as 1001,1002,1003 and say
Now next time my application should copy the 1002 tuple to file 2 and then 1003 tuple to file 1 and file 2.
Actually I am able to achieve all these requirements, but the problem is something different.
What I do is:
I have a function named databaseStudy() and it does a study of my database and gives me information about tuples 1002 and 1003 that their value of Replication_Done are less than 2, so they should be copied to files. So for this I create a MYSQL *handle and get the values of the attributes of the tuples in say variable char tuple, as there are 5 attributes in the tables. Now in 1 iteration I copy the values of 1 tuple into this array and pass this array to another function say tupleReplicate(tuple). Now inside this function I have a for loop which copies the values of this tuple into the files, and in doing so it checks whether this tuple is already copied into that file(this is done by checking the 1st 4 chars of each line in the file), if so it skips this file and copies the tuple into the other file(again checking as above).Once a tuple is copied into any of the file, the value of Replication_Done is incremented. After the tuple is copied into both the files, this tupleReplicate(tuple) closes the MYSQL handle and returns and now the databaseStudy() again calls the tupleReplicate(tuple) for other tuples, if any of the tuple has Replication_Done less than 2.
Now the problem is I open another handle to MYSQL inside tupleReplicate(tuple) to see the value of Replication_Done as if I check the value with the value passed to this function, then its not proper as the value of Replication_Done in tuple array is the older value. So I reads the table again here for this User_ID. Now on 1st iteration, it gives the correct value, i.e. before copy it gives Replication_Done = 0, then after copy to 1st file, it gives Replication_Done =1. But after returning from this function, I dont know what it does, but the final value of Replication_Done is 0. Thus next time if I again starts the application, it again starts copying this tuple, which it should not do.
Please tell me a solution, or where I am doing the error. Is it because I have opened a new Handle inside the function with another handle already opened. I do close the inner handle when returning from the function.
Code is in simple C++.
Database used is MySQL
Functions are like this :
/*does the replication
/*studies the table and calls
Last edited by ppuniversal; 03-15-2007 at 01:05 AM.
By Michael in forum ASP.NET
Last Post: 02-24-2006, 09:54 AM
By aesoprock00 in forum Java
Last Post: 01-28-2006, 07:18 PM
Last Post: 10-30-2002, 05:40 AM
By Wade Balzer in forum VB Classic
Last Post: 06-23-2000, 03:17 PM
By Thomas Rademacher in forum XML
Last Post: 04-17-2000, 04:34 AM
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center