DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 1 of 1

Thread: Attribute updation problem!!!

  1. #1
    Join Date
    Feb 2007

    Question 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
    User_ID       Replication_Done
    1001            2
    1002            1 
    1003            0
    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[5][45], 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 :

    MYSQL *HND2;
    /*does the replication
    //closes HND2
    MYSQL *HND1;
    /*studies the table and calls 
    //closes HND1
    Please Reply
    Last edited by ppuniversal; 03-15-2007 at 12:05 AM.

Similar Threads

  1. a very weird problem (AGAIN!!!)
    By Michael in forum ASP.NET
    Replies: 14
    Last Post: 02-24-2006, 09:54 AM
  2. Josephus Problem, problem.
    By aesoprock00 in forum Java
    Replies: 2
    Last Post: 01-28-2006, 07:18 PM
  3. Reliability Problem
    By elise in forum Java
    Replies: 0
    Last Post: 10-30-2002, 05:40 AM
  4. Replies: 0
    Last Post: 06-23-2000, 02:17 PM
  5. enum and xerces-parser problem
    By Thomas Rademacher in forum XML
    Replies: 0
    Last Post: 04-17-2000, 03:34 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center