I got it working finally.  There were several problems that were all
contributing and it was not until Kees suggested looking at the
begins/commits to see if errors were happening that I saw the whole
picture.  As mentioned in my past response to the thread, the code worked
when saving after starting a new game but not after loading an already
started game.  The problem was both in the loading code and in the way in
which I was loading the data through my calls in my Database class.

In my loading code I have several areas where I must close and re-open a
connection to the database because of how some things are loaded (some
elements are loaded in as only ID values which I then get the data for from
my Database sqlite file which contains non-player/game instance specific
data like weapons information or message).  Well there was a problem here
where the database connection could not be closed because there were
unfinalized statements.  This is where the second area of problems comes
in.  I was not placing my calls to my finalize function at the end of the
query functions.  This meant that if there was a problem, finalize would
not be called and the prepared statement would not be destroyed.

Another problem was in my getRows function.  The same issue as above
existed except that there were multiple chances for the statement to not be
finalized as I was returning 0 at any point an error was found.  After
placing the calls to finalize in their correct places I found the final
thorn in my program which were the database closes in dataSystem in lData.
I had them setup so that they would be called even if the database was not
actually closed.  This caused even more problems by invalidating previous
database connections and creating new ones.  The end result was that by the
time sData in Database was called the database connection was mutilated.

Fixed everything up and ran the loading process and I was able to rid
myself of several bugs at once including getting the Delete From query to
execute properly.

Thanks for the suggestions and feedback you have all given me, it helped
tremendously.


On Fri, Feb 21, 2014 at 2:15 PM, Geo Wil <geowi...@gmail.com> wrote:

> Hello,
>
> Yesterday, while working on my game, I noticed that my game data was not
> updating in my save SQLite3 database.  So I started tracking down what was
> going on and eventually my search lead me to my dData function.
>
> How this function works is that you pass a table name and a bool, the bool
> is just there in case errors happen to notify the player.  I did exhaustive
> tests yesterday on this block of code and found that it was not functioning
> properly, it was not deleting the data from my tables.
>
> I checked to see if sqlite3_step was producing an error but it was sending
> back a value of 101 or SQLITE_DONE but the table data remained unchanged.
> I also commented out the code I use to replace the deleted data just to
> make sure the data retrieval code was not at fault.  With just the dData
> call and nothing else the data still would not delete from the table.
>
> Here is the code I am using for my dData function:
>
> void Database::dData(string table, bool* bErrors)
> {
>     sqlStr2 = "Delete From " + table;
>
>     sqlite3_exec(dBase,"BEGIN TRANSACTION",NULL,NULL,&error);
>
>     if (sqlite3_prepare_v2(dBase, sqlStr2.c_str(), sqlStr2.size(),
> &statement2, 0) == SQLITE_OK)
>     {
>         sqlite3_step(statement2);
>         *bErrors = false;
>
>         finalize(statement2, bErrors);
>     }
>
>     else
>     {
>         *bErrors = true;
>         createBInfo();
>         d.createBReport("SQL Code 3",sqlite3_errmsg(dBase),bLocale +
> to_string(__LINE__),bTDate,"./SC_Log.txt");
>     }
>
>     sqlite3_exec(dBase,"END TRANSACTION",NULL,NULL,&error);
> }
>
> I am also going to link to my save database in case it itself is to blame
> although I tested this on several different files with the same results.
>
> http://sc.lmpgames.com/scSave.sqlite
>
> I already have posted about this on StackOverflow and so far everyone that
> has attempted to figure this out has been stumped.  I am using Microsoft
> Visual Studio 2012 and C++.
>
> Thanks.
>
> --
> "I though what I'd do was, I'd pretend I was one of those Deaf-Mutes...Or
> should I?" -- Laughing Man
> ______________________________
>
> Laughing Man Productions² Entertainment and Gaming 
> Network<http://www.lmpgames.com>
>



-- 
"I though what I'd do was, I'd pretend I was one of those Deaf-Mutes...Or
should I?" -- Laughing Man
______________________________

Laughing Man Productions² Entertainment and Gaming
Network<http://www.lmpgames.com>
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to