예제 #1
0
        public void GetRecordData(IDBRecord dbRecord, object oFlag)
        {
            IDBRecord x      = dbRecord;
            Object    oValue = null;

            if (oFlag != null)
            {
                if (oFlag is String)
                {
                    oValue = x[oFlag as String];
                }
                else if (oFlag is Int32)
                {
                    oValue = x[(Int32)oFlag];
                }
                else
                {
                    oValue = x[0];
                }
            }
            else
            {
                oValue = x[0];
            }

            DBValue dbValue = DBValue.Convert(oValue);

            Value = dbValue.GetValue <T>();
        }
예제 #2
0
        private void buttonApply_Click(object sender, EventArgs e)
        {
            if (0 == this.textBoxUserID.Text.Length ||
                (0 == this.textBoxLimitedKey.Text.Length && 0 == this.textBoxFullKey.Text.Length) ||
                0 == this.textBoxUserName.Text.Length
                )
            {
                MessageBox.Show("You must enter a UserID, a Limited or Full Key, and select a character.");
                return;
            }

            if (-1 != this.listBoxCharacters.SelectedIndex)
            { // update
                Character ch  = new Character((CharacterObject)this.listBoxCharacters.SelectedItem);
                IDBRecord rec = (IDBRecord)ch;
                rec.SetValueString((ulong)Character.QueryValues.UserID, this.textBoxUserID.Text);
                rec.SetValueString((ulong)Character.QueryValues.LimitedKey, this.textBoxLimitedKey.Text);
                rec.SetValueString((ulong)Character.QueryValues.FullKey, this.textBoxFullKey.Text);
                rec.SetValueString((ulong)Character.QueryValues.RegCode, this.textBoxRegCode.Text);
                this.m_db.UpdateRecord(ch);
            }
            else if (null != this.m_SelectedObject)
            { // insert new
                Character ch  = new Character(this.m_SelectedObject);
                IDBRecord rec = (IDBRecord)ch;
                rec.SetValueString((ulong)Character.QueryValues.UserID, this.textBoxUserID.Text);
                rec.SetValueString((ulong)Character.QueryValues.LimitedKey, this.textBoxLimitedKey.Text);
                rec.SetValueString((ulong)Character.QueryValues.FullKey, this.textBoxFullKey.Text);
                rec.SetValueString((ulong)Character.QueryValues.RegCode, this.textBoxRegCode.Text);
                this.m_db.InsertRecord(ch);
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
        }
예제 #3
0
        private static string CheckRequestCache(Database db, RequestID rid, string UserID, string url)
        {
            DateTime dt = TimeZone.CurrentTimeZone.ToUniversalTime(DateTime.Now);
            RequestCacheCollection col  = new RequestCacheCollection();
            IDBCollection          icol = (IDBCollection)col;

            icol.SetConstraint((long)RequestCache.QueryValues.UserID,
                               new DBConstraint(DBConstraint.QueryConstraints.Equal, UserID));
            icol.SetConstraint((long)RequestCache.QueryValues.ValidUntil,
                               new DBConstraint(DBConstraint.QueryConstraints.Greater, dt.ToOADate().ToString()));
            icol.SetConstraint((long)RequestCache.QueryValues.url,
                               new DBConstraint(DBConstraint.QueryConstraints.Equal, url));

            db.ReadRecord((IDBCollection)col);
            IDBCollectionContents ccol = (IDBCollectionContents)col;

            if (0 == ccol.Count())
            {
                return(null);
            }
            IDBRecord     rec = ccol.GetRecordInterface(0);
            RequestObject obj = (RequestObject)rec.GetDataObject();

            Logger.ReportNotice("Using cached response, can make a new call after " + obj.ValidUntil.ToString());
            return(Compression.Decompress(obj.Response));
        }
예제 #4
0
 protected virtual void ReadCollectionFromXmlDoc(XmlDocument xmlDoc, params object[] ids)
 {
     foreach (XmlNode row in xmlDoc.SelectNodes(SelectNodeString()))
     {
         IDBRecord rec = CreateRecordFromXmlNode(row, ids);
         m_Collection.Add(rec.GetRecordKey(), rec);
     }
 }
예제 #5
0
        public MemberTrackingSettings(SQLiteDataReader reader)
        {
            IDBRecord iobj = (IDBRecord)this;

            foreach (QueryValues val in Enum.GetValues(typeof(QueryValues)))
            {
                iobj.SetValue((long)val, reader[val.ToString()]);
            }//foreach
        }
예제 #6
0
        public CharacterSheetSkills(SQLiteDataReader reader)
        {
            IDBRecord iobj = (IDBRecord)this;

            foreach (QueryValues val in Enum.GetValues(typeof(QueryValues)))
            {
                iobj.SetValue((long)val, reader[iobj.GetFieldName((long)val)]);
            }//foreach
        }
예제 #7
0
        private void buttonSelectCharacter_Click(object sender, EventArgs e)
        {
            if (0 == this.textBoxUserID.Text.Length ||
                (0 == this.textBoxLimitedKey.Text.Length && 0 == this.textBoxFullKey.Text.Length)
                )
            {
                MessageBox.Show("You must enter a UserID, and a Key before selecting a character.");
                return;
            }
            EveApiId id = new EveApiId(this.textBoxUserID.Text,
                                       (0 != textBoxFullKey.Text.Length) ? textBoxFullKey.Text : textBoxLimitedKey.Text);
            CharacterCollection   col = EveApi.GetCharacterList(m_db, id);
            IDBCollectionContents con = (IDBCollectionContents)col;

            if (1 > con.Count())
            {
                return;
            }

            ListSelectDlg ls = new ListSelectDlg();

            for (int i = 0; i < con.Count(); ++i)
            {
                IDBRecord rec = con.GetRecordInterface(i);
                rec.SetValueString((ulong)Character.QueryValues.UserID, this.textBoxUserID.Text);
                rec.SetValueString((ulong)Character.QueryValues.LimitedKey, this.textBoxLimitedKey.Text);
                rec.SetValueString((ulong)Character.QueryValues.FullKey, this.textBoxFullKey.Text);
                rec.SetValueString((ulong)Character.QueryValues.RegCode, this.textBoxRegCode.Text);
                CharacterObject obj  = (CharacterObject)rec.GetDataObject();
                string          test = obj.ToString();
                ls.List.Items.Add(obj);
            }

            Button btn = (Button)sender;

            ls.Location = this.PointToScreen(new Point(btn.Location.X, btn.Location.Y + btn.Height));
            DialogResult ret = ls.ShowDialog();

            if (DialogResult.OK == ret)
            {
                CharacterObject newObj = (CharacterObject)ls.List.SelectedItem;
                foreach (CharacterObject obj in this.listBoxCharacters.Items)
                {
                    if (0 == obj.ToString().CompareTo(newObj.ToString()))
                    {
                        this.listBoxCharacters.SelectedItem = obj;
                        this.textBoxLimitedKey.Text         = this.textBoxLimitedKey.Text;
                        this.textBoxFullKey.Text            = this.textBoxFullKey.Text;
                        return;
                    }
                }
                this.listBoxCharacters.SelectedIndex = -1;
                m_SelectedObject = newObj;
                FillFromNewCharacter();
            }
        }
예제 #8
0
        private void CharacterEditor_Load(object sender, EventArgs e)
        {
            CharacterCollection charcol = new CharacterCollection();

            m_db.ReadRecord(charcol);
            IDBCollectionContents col = (IDBCollectionContents)charcol;

            for (long idx = 0; idx < col.Count(); idx++)
            {
                IDBRecord rec = col.GetRecordInterface(idx);
                this.listBoxCharacters.Items.Add(rec.GetDataObject());
            }
        }
예제 #9
0
        public DatabaseError InsertOrUpdateRecord(IDBRecord record)
        {
            ulong val = ulong.Parse(record.GetValueString(record.GetIDQueryValue()));

            if (val == 0)
            {
                InsertRecord(record);
            }
            else
            {
                UpdateRecord(record);
            }
            return(m_ErrorCode);
        }
예제 #10
0
        public static void InitConstants(Database db)
        {
            ReferenceTypeCollection col = new ReferenceTypeCollection();

            db.ReadRecord(col as IDBCollection);
            IDBCollectionContents icol = col as IDBCollectionContents;

            for (long i = 0; i < icol.Count(); ++i)
            {
                IDBRecord           rec = icol.GetRecordInterface(i);
                ReferenceTypeObject obj = rec.GetDataObject() as ReferenceTypeObject;
                m_RefValues.Add((int)obj.refTypeID, obj.refTypeName);
            }
        }
예제 #11
0
        void IDBCollection.FillRecords(SQLiteDataReader reader)
        {
            DBMasterTable empty = new DBMasterTable();

            do
            {
                OnRecordRead(this, new DBEventArgs(empty, reader));
                if (!bEventOnly)
                {
                    DBMasterTable obj  = new DBMasterTable(reader);
                    IDBRecord     iobj = (IDBRecord)obj;
                    m_Collection.Add(0, iobj);
                    OnRecordCollectionAdd(this, new DBEventArgs(iobj, null));
                }
            } while (reader.Read());
        }
예제 #12
0
        void IDBRecord.PrepareCommandDelete(Database.DatabaseCommand dbCommand)
        {
            IDBRecord iobj = this as IDBRecord;

            dbCommand.SetCommand(String.Format(
                                     "DELETE FROM {0} " +
                                     "WHERE {1}=? AND {2}=? AND {3}=? AND {4}=? AND {5}=? AND {6}=? AND {7}=?;",
                                     TableName,
                                     iobj.GetFieldName((long)QueryValues.CharID),
                                     iobj.GetFieldName((long)QueryValues.refID),
                                     iobj.GetFieldName((long)QueryValues.refTypeID),
                                     iobj.GetFieldName((long)QueryValues.date),
                                     iobj.GetFieldName((long)QueryValues.ownerID1),
                                     iobj.GetFieldName((long)QueryValues.ownerID2),
                                     iobj.GetFieldName((long)QueryValues.argID)));
        }
예제 #13
0
        public Form1()
        {
            InitializeComponent();

            //if (!AppData.bDEBUG)
            //    this.debugToolStripMenuItem.Visible = false;

            Logger.SetLogger(this.richTextBoxLogging);
            m_db = new Database();
            if (!m_db.IsOpen())
            {
                return;
            }

            CharacterCollection charcol = new CharacterCollection();

            m_db.ReadRecord(charcol);
            IDBCollectionContents col = (IDBCollectionContents)charcol;

            for (long idx = 0; idx < col.Count(); idx++)
            {
                IDBRecord rec = col.GetRecordInterface(idx);
                this.toolStripComboBoxCharacterSelection.Items.Add(rec.GetDataObject());
            }
            if (0 != this.toolStripComboBoxCharacterSelection.Items.Count)
            {
                this.toolStripComboBoxCharacterSelection.SelectedIndex = 0;
            }

            Logger.ReportNotice("Initializing Reference Types Collection");
            ReferenceTypeCollection refCol = EveApi.GetRefTypesList(m_db, false);

            //m_db.InsertRecord(refCol);
            Logger.ReportNotice("Using BulkLoader");
            refCol.DoBulkLoader(m_db);
            Logger.ReportNotice("Done With BulkLoader");

            AppData.InitConstants(m_db);
            CharJournalInit();
            CharTransactionInit();
            CorpJournalInit();
            CorpTransInit();

            if (AppData.bAutoFetch)
            {
            }
        }
예제 #14
0
        public DatabaseError UpdateRecord(IDBRecord record)
        {
            m_ErrorCode = DatabaseError.NoError;
            SQLiteCommand sqlite_cmd = (SQLiteCommand)m_conn.CreateCommand();

            try
            {
                sqlite_cmd.CommandText = record.GetDBUpdate();
                sqlite_cmd.ExecuteNonQuery();
            }
            catch (System.Data.SQLite.SQLiteException e)
            {
                string msg = e.Message;
                m_ErrorCode = DatabaseError.ExceptionSQL;
            }
            return(m_ErrorCode);
        }
예제 #15
0
 public DatabaseError InsertOrUpdateRecord(IDBCollectionContents contents)
 {
     for (int i = 0; i < contents.Count(); ++i)
     {
         IDBRecord irec = contents.GetRecordInterface(i);
         ulong     val  = ulong.Parse(irec.GetValueString(irec.GetIDQueryValue()));
         if (val == 0)
         {
             InsertRecord(irec);
         }
         else
         {
             UpdateRecord(irec);
         }
     }
     return(m_ErrorCode);
 }
예제 #16
0
        void IDBOperability.SetRecordData(IDBRecord dbRecord, Object oFlag)
        {
            IDBRecord x = dbRecord;

            //x["ID"] = ID; // 0 Int32
            x["Guid"]     = Guid;         // 1 String
            x["Name"]     = Name;         // 2 String
            x["Birthday"] = Birthday;     // 3 DateTime
            x["Photo"]    = Photo;        // 4 Byte[]

            /*
             * //x[0] = ID; // ID Int32
             * x[1] = Guid; // Guid String
             * x[2] = Name; // Name String
             * x[3] = Birthday; // Birthday DateTime
             * x[4] = Photo; // Photo Byte[]
             */
        }
예제 #17
0
        void IDBOperability.GetRecordData(IDBRecord dbRecord, Object oFlag)
        {
            IDBRecord x = dbRecord;

            ID       = DBValue.Convert(x["ID"]);       // 0 Int32
            Guid     = DBValue.Convert(x["Guid"]);     // 1 String
            Name     = DBValue.Convert(x["Name"]);     // 2 String
            Birthday = DBValue.Convert(x["Birthday"]); // 3 DateTime
            Photo    = DBValue.Convert(x["Photo"]);    // 4 Byte[]

            /*
             * ID = DBValue.Convert(x[0]) // ID Int32
             * Guid = DBValue.Convert(x[1]) // Guid String
             * Name = DBValue.Convert(x[2]) // Name String
             * Birthday = DBValue.Convert(x[3]) // Birthday DateTime
             * Photo = DBValue.Convert(x[4]) // Photo Byte[]
             */
        }
예제 #18
0
        public DatabaseError InsertRecord(IDBRecord record)
        {
            m_ErrorCode = DatabaseError.NoError;
            SQLiteCommand sqlite_cmd = (SQLiteCommand)m_conn.CreateCommand();

            try
            {
                sqlite_cmd.CommandText = record.GetDBInsert();
                sqlite_cmd.ExecuteNonQuery();
                sqlite_cmd.CommandText = "SELECT last_insert_rowid();";
                record.SetValueString(record.GetIDQueryValue(), sqlite_cmd.ExecuteScalar());
            }
            catch (System.Data.SQLite.SQLiteException e)
            {
                string msg = e.Message;
                m_ErrorCode = DatabaseError.ExceptionSQL;
            }
            return(m_ErrorCode);
        }
예제 #19
0
        void IDBRecord.PrepareCommandUpdate(Database.DatabaseCommand dbCommand)
        {
            IDBRecord iobj = this as IDBRecord;

            dbCommand.SetCommand(String.Format(
                                     "UPDATE {0} SET {1}=?, {2}=?, {3}=?, {4}=?, {5}=?, {6}=? " +
                                     "WHERE {7}=? AND {8}=? AND {9}=? AND {10}=? AND {11}=? AND {12}=? AND {13}=?;",
                                     TableName,
                                     // data
                                     iobj.GetFieldName((long)QueryValues.ownerName1),
                                     iobj.GetFieldName((long)QueryValues.ownerName2),
                                     iobj.GetFieldName((long)QueryValues.argName1),
                                     iobj.GetFieldName((long)QueryValues.amount),
                                     iobj.GetFieldName((long)QueryValues.balance),
                                     iobj.GetFieldName((long)QueryValues.reason),
                                     // key
                                     iobj.GetFieldName((long)QueryValues.CharID),
                                     iobj.GetFieldName((long)QueryValues.refID),
                                     iobj.GetFieldName((long)QueryValues.refTypeID),
                                     iobj.GetFieldName((long)QueryValues.date),
                                     iobj.GetFieldName((long)QueryValues.ownerID1),
                                     iobj.GetFieldName((long)QueryValues.ownerID2),
                                     iobj.GetFieldName((long)QueryValues.argID)));


            // data
            dbCommand.AddParameter((long)QueryValues.ownerName1);
            dbCommand.AddParameter((long)QueryValues.ownerName2);
            dbCommand.AddParameter((long)QueryValues.argName1);
            dbCommand.AddParameter((long)QueryValues.amount);
            dbCommand.AddParameter((long)QueryValues.balance);
            dbCommand.AddParameter((long)QueryValues.reason);
            // key
            dbCommand.AddParameter((long)QueryValues.CharID);
            dbCommand.AddParameter((long)QueryValues.refID);
            dbCommand.AddParameter((long)QueryValues.refTypeID);
            dbCommand.AddParameter((long)QueryValues.date);
            dbCommand.AddParameter((long)QueryValues.ownerID1);
            dbCommand.AddParameter((long)QueryValues.ownerID2);
            dbCommand.AddParameter((long)QueryValues.argID);
        }
예제 #20
0
        void IDBRecord.PrepareCommandInsert(Database.DatabaseCommand dbCommand)
        {
            IDBRecord iobj = this as IDBRecord;

            dbCommand.SetCommand(String.Format(
                                     "INSERT INTO {0} ({1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}" +
                                     "{9}, {10}, {11}, {12}, {13}) " +
                                     "VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);",
                                     TableName,
                                     iobj.GetFieldName((long)QueryValues.CharID),
                                     iobj.GetFieldName((long)QueryValues.refID),
                                     iobj.GetFieldName((long)QueryValues.refTypeID),
                                     iobj.GetFieldName((long)QueryValues.date),
                                     iobj.GetFieldName((long)QueryValues.ownerID1),
                                     iobj.GetFieldName((long)QueryValues.ownerID2),
                                     iobj.GetFieldName((long)QueryValues.argID),
                                     iobj.GetFieldName((long)QueryValues.ownerName1),
                                     iobj.GetFieldName((long)QueryValues.ownerName2),
                                     iobj.GetFieldName((long)QueryValues.argName1),
                                     iobj.GetFieldName((long)QueryValues.amount),
                                     iobj.GetFieldName((long)QueryValues.balance),
                                     iobj.GetFieldName((long)QueryValues.reason)));


            // key
            dbCommand.AddParameter((long)QueryValues.CharID);
            dbCommand.AddParameter((long)QueryValues.refID);
            dbCommand.AddParameter((long)QueryValues.refTypeID);
            dbCommand.AddParameter((long)QueryValues.date);
            dbCommand.AddParameter((long)QueryValues.ownerID1);
            dbCommand.AddParameter((long)QueryValues.ownerID2);
            dbCommand.AddParameter((long)QueryValues.argID);
            // data
            dbCommand.AddParameter((long)QueryValues.ownerName1);
            dbCommand.AddParameter((long)QueryValues.ownerName2);
            dbCommand.AddParameter((long)QueryValues.argName1);
            dbCommand.AddParameter((long)QueryValues.amount);
            dbCommand.AddParameter((long)QueryValues.balance);
            dbCommand.AddParameter((long)QueryValues.reason);
        }
예제 #21
0
        void IDBCollection.FillRecords(SQLiteDataReader reader)
        {
            IDBRecord empty = CreateRecord();

            do
            {
                if (null != OnRecordRead)
                {
                    OnRecordRead(this, new DBEventArgs(empty, reader));
                }

                if (!bEventOnly)
                {
                    IDBRecord iobj = CreateRecord(reader);
                    m_Collection.Add(iobj.GetRecordKey(), iobj);
                    if (null != OnRecordCollectionAdd)
                    {
                        OnRecordCollectionAdd(this, new DBEventArgs(iobj, null));
                    }
                }
            } while (reader.Read());
        }
예제 #22
0
        private void MarkTableVersion(IDBCollection col)
        {
            VersionCollection vcol  = new VersionCollection();
            IDBCollection     ivcol = vcol as IDBCollection;

            ivcol.SetConstraint((long)Version.QueryValues.TableName,
                                new DBConstraint(DBConstraint.QueryConstraints.Equal, col.GetTableName()));

            if (Database.DatabaseError.NoError == this.ReadRecord(ivcol))
            {
                IDBCollectionContents icont = vcol as IDBCollectionContents;
                (icont.GetRecordInterface(0).GetDataObject() as VersionObjectInternal).VersionNumber = col.GetVersionNumber();
                InsertOrUpdateRecord(vcol);
            }
            else
            {
                IDBRecord             irec = ivcol.CreateBlankRecord();
                VersionObjectInternal obj  = irec.GetDataObject() as VersionObjectInternal;
                obj.TableName     = col.GetTableName();
                obj.VersionNumber = col.GetVersionNumber();
                InsertOrUpdateRecord(irec);
            }
        }
예제 #23
0
        public void SetRecordData(IDBRecord dbRecord, object oFlag)
        {
            IDBRecord x = dbRecord;

            if (oFlag != null)
            {
                if (oFlag is String)
                {
                    x[oFlag as String] = Value;
                }
                else if (oFlag is Int32)
                {
                    x[(Int32)oFlag] = Value;
                }
                else
                {
                    x[0] = Value;
                }
            }
            else
            {
                x[0] = Value;
            }
        }
예제 #24
0
 DBEventArgs(IDBRecord record, SQLiteDataReader reader)
 {
     m_record = record;
     m_reader = reader;
 }
예제 #25
0
 public DatabaseError CreateTable(IDBRecord record)
 {
     return(ExecuteCommand(record.GetDBCreateTable() + ";"));
 }
예제 #26
0
        void IDBRecord.FillCommandDelete(Database.DatabaseCommand dbCommand)
        {
            IDBRecord iobj = this as IDBRecord;

            dbCommand.SetParamValue((long)QueryValues.Key_ID, m_DataObject.Key_ID);
        }
        public static CharacterJournalCollection GetCharacterJournalList(Database db, EveApiId id,
                                                                         string CharID, string beforeRefID, bool bAutoWalk, bool bUseCache)
        {
            if (!id.IsFullKey())
            {
                return(new CharacterJournalCollection()); // return empty
            }
            CharacterJournalCollection journal = null;
            long remainder = 0;
            long lastCount = 0;

            do
            {
                string url = String.Format("{0}{1}?userID={2}&characterID={3}&apiKey={4}&accountKey=1000",
                                           ApiSite, CharJournalEntries, id.UserId, CharID, id.Key);
                if (null != beforeRefID && 0 < long.Parse(beforeRefID))
                {
                    url += String.Format("&beforeRefID={0}", beforeRefID);
                }

                string str = CheckRequestCache(db, RequestID.CharacterJournal, id.UserId, url);
                if (null == str)
                {
                    Stream s = openUrl(url);
                    if (null == s)
                    {
                        return((null != journal) ? journal : (new CharacterJournalCollection()));
                    }
                    str = new StreamReader(s).ReadToEnd();
                    WriteRequestCache(db, RequestID.CharacterJournal, id.UserId, url, str);
                }
                else if (!bUseCache)
                {
                    break; // not allowed to use caching
                }

                XmlDocument xmlDoc = GetXml(new StringReader(str));
                if (null == xmlDoc)
                {
                    break;
                }

                if (null == journal)
                {
                    journal = new CharacterJournalCollection(CharID, xmlDoc);
                }
                else
                {
                    journal.AppendList(CharID, xmlDoc);
                }

                if (null == journal)
                {
                    remainder = -1;
                }
                else
                {
                    IDBCollectionContents con = (IDBCollectionContents)journal;
                    if (0 == con.Count())
                    {
                        remainder = -1;
                    }
                    else if (lastCount == con.Count())
                    {
                        remainder = -1;
                    }
                    else
                    {
                        lastCount = con.Count();
                        remainder = con.Count() % 1000;
                        if (0 == remainder)
                        {
                            IDBRecord     rec1 = con.GetRecordInterface(con.Count() - 1000);
                            JournalObject obj1 = (JournalObject)rec1.GetDataObject();
                            IDBRecord     rec2 = con.GetRecordInterface(con.Count() - 1);
                            JournalObject obj2 = (JournalObject)rec2.GetDataObject();
                            beforeRefID = Math.Min(obj1.refID, obj2.refID).ToString();
                            TimeSpan span = (obj2.date > obj1.date) ? obj2.date.Subtract(obj1.date) :
                                            obj1.date.Subtract(obj2.date);
                            if (span.Days >= 7)
                            {
                                remainder = -1; // more than a week, so no more accessable
                            }
                        }
                    }
                }
            } while (0 == remainder && bAutoWalk);

            if (null == journal)
            {
                return(new CharacterJournalCollection()); // create empty
            }
            return(journal);
        }
예제 #28
0
        private DatabaseError RepairDatabaseVersion()
        {
            DatabaseError err = m_ErrorCode;

            if (err != DatabaseError.CheckFailed_IncorrectVersion &&
                err != DatabaseError.CheckFailed_Unidentifiable
                )
            {
                return(m_ErrorCode = DatabaseError.Unexpected);
            }

            DialogResult ret = DialogResult.No;

            if (err == DatabaseError.CheckFailed_Unidentifiable)
            {
                ret = MessageBox.Show(String.Format(DBUpgradeWarning, "Your database version was not reconized.\r\n"),
                                      "Upgrade Database Version?", MessageBoxButtons.YesNo);
            }
            else
            {
                ret = MessageBox.Show(String.Format(DBUpgradeWarning, "Your database version is out-of-date."),
                                      "Upgrade Database Version?", MessageBoxButtons.YesNo);
            }

            if (ret != DialogResult.Yes)
            {
                return(m_ErrorCode = DatabaseError.UserAborted);
            }

            if (err == DatabaseError.CheckFailed_Unidentifiable)
            {
                this.ExecuteCommand("DROP TABLE " + Version.TableName);
                Version v = new Version();
                CreateTable(v);
                ExecuteCommand(String.Format(
                                   "INSERT INTO Version (TableName) SELECT name FROM sqlite_master; " +
                                   "UPDATE Version SET VersionNumber=0; " +
                                   "UPDATE Version SET VersionNumber={0} WHERE TableName='{1}'",
                                   Version.VersionNumber, Version.TableName));
            }

            foreach (IDBCollection col in m_Tables)
            {
                VersionCollection vercol  = new VersionCollection();
                IDBCollection     ivercol = vercol as IDBCollection;
                ivercol.SetConstraint((long)Version.QueryValues.TableName,
                                      new DBConstraint(DBConstraint.QueryConstraints.Equal, col.GetTableName()));
                DatabaseError colErr = ReadRecord(vercol);

                if (DatabaseError.NoError == colErr)
                {
                    IDBCollectionContents iconVercol = vercol as IDBCollectionContents;
                    IDBRecord             rec        = iconVercol.GetRecordInterface(0);
                    VersionObjectInternal obj        = rec.GetDataObject() as VersionObjectInternal;
                    if (obj.VersionNumber == col.GetVersionNumber())
                    {
                        Logger.ReportNotice(String.Format("Table '{0}' version is up to date.", col.GetTableName()));
                    }
                    else
                    {
                        Logger.ReportNotice(String.Format("Table '{0}' version mismatch ({1}!={2}). Recreating",
                                                          col.GetTableName(), obj.VersionNumber, col.GetVersionNumber()));
                        IDBUpgrade icolUpgrade = col as IDBUpgrade;
                        colErr = icolUpgrade.Upgrade(this, obj.VersionNumber);
                        if (colErr != DatabaseError.NoError)
                        {
                            return(m_ErrorCode = DatabaseError.Unexpected);
                        }
                        obj.VersionNumber = col.GetVersionNumber();
                        this.UpdateRecord(rec);
                    }
                }
                else if (DatabaseError.NoRecordsFound == colErr)
                {
                    Logger.ReportNotice(String.Format("Table '{0}' missing. Creating new", col.GetTableName()));
                    colErr = this.CreateTable(col.CreateBlankRecord());
                    if (colErr != DatabaseError.NoError)
                    {
                        return(m_ErrorCode = DatabaseError.Unexpected);
                    }

                    IDBRecord             rec = ivercol.CreateBlankRecord();
                    VersionObjectInternal obj = rec.GetDataObject() as VersionObjectInternal;
                    obj.TableName     = col.GetTableName();
                    obj.VersionNumber = col.GetVersionNumber();
                    InsertRecord(rec);
                }
                else
                {
                    return(m_ErrorCode = DatabaseError.Unexpected);
                }
            }

            return(m_ErrorCode = DatabaseError.NoError);
        }