I'm trying to get patching working for one of our products.  The problem
is that there are currently 2 more files in the latest version than were
in the original version.  This is causing the patch to fail.  I read
that the new files sequence have to be at the end of the file table. So
I'm trying to write a utility to change the sequence values
appropriately. When I try to update the view I get an error. "cursor in
invalid state".

Is this the best way to solve my problem? If so why am I getting this
error?

Here is my source code.

 

public static bool ReOrderFileTable(string original, string upgrade)

        {

            Database originalDb = null;

            Database upgradeDb = null;

            View originalFileView = null;

            View upgradeFileView = null;

            

            try

            {

                // set dbs 

                originalDb = new Database(original);

                upgradeDb = new
Database(upgrade,DatabaseOpenMode.Direct);

 

                // create view of file table

                originalFileView = originalDb.OpenView("SELECT * FROM
`File` ORDER BY `Sequence`");

                upgradeFileView = upgradeDb.OpenView("SELECT * FROM
`File` ORDER BY `Sequence`");

 

                // execute view

                originalFileView.Execute();

                upgradeFileView.Execute();

            }

            catch { }

 

            if ((originalFileView != null)&&(upgradeFileView != null))

            {

                if (originalFileView.Count() == upgradeFileView.Count())

                { return true; } // same amount of files so should not
need to re order

 

                if (originalFileView.Count() > upgradeFileView.Count())

                { return false; } // can't remove files with a patch

 

                int offset = 0;

                int x=1;

                Record originalRecord = null;

                Record upgradeRecord = null;

                int originalCount = originalFileView.Count();

                int upgradeCount = upgradeFileView.Count();

                while(x <= originalCount + offset)

                {

                    // get next record from view

                    originalRecord = originalFileView.Fetch();

                    upgradeRecord = upgradeFileView.Fetch();

 

                    // while upgrade file name != original file name
change sequence to be last and get new upgrade file

                    while (originalRecord["File"].ToString() !=
upgradeRecord["File"].ToString())

                    {

                        offset++;

                        upgradeRecord["Sequence"] = upgradeCount +
offset;

                        upgradeFileView.Update(upgradeRecord);

                        upgradeRecord = upgradeFileView.Fetch();

                    }

                    // if there are no more original files adjust
upgrade file sequence to remove gap

                    if (originalRecord == null)

                    {

                        upgradeRecord["Sequence"] =
(int)upgradeRecord["Sequence"] - offset;

                    }

                    // if sequence is off fix upgrade sequence

                    if ((int)originalRecord["Sequence"] !=
(int)upgradeRecord["Sequence"])

                    {

                        upgradeRecord["Sequence"] =
(int)originalRecord["Sequence"];

                    }

                    x++;

                }

                // close records

                originalRecord.Close();

                upgradeRecord.Close();

            }

            upgradeDb.Commit();

 

            originalDb.Close();

            upgradeDb.Close();

            return true;

        }

    }

------------------------------------------------------------------------------
SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
The future of the web can't happen without you.  Join us at MIX09 to help
pave the way to the Next Web now. Learn more and register at
http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/
_______________________________________________
WiX-users mailing list
WiX-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wix-users

Reply via email to