예제 #1
0
파일: Table.cs 프로젝트: furesoft/SharpHSQL
        private ArrayList vIndex; // vIndex(0) is always the primary key index

        #endregion Fields

        #region Constructors

        public Table(Database db, bool log, string name, bool cached)
        {
            dDatabase = db;
            lLog = log ? db.Log : null;

            if (cached)
            {
                cCache = lLog.cCache;
                bCached = true;
            }

            sName = name;
            iPrimaryKey = -1;
            iIdentityColumn = -1;
            iTimestampColumn = -1;
            vColumn = new ArrayList();
            vIndex = new ArrayList();
            vConstraint = new ArrayList();
        }
예제 #2
0
파일: Log.cs 프로젝트: furesoft/SharpHSQL
        /// <summary>
        /// Opens the database files.
        /// </summary>
        /// <returns>True if operation is sucessful.</returns>
        public bool Open()
        {
            lock( SyncLock )
            {
                bool newdata = false;

                if (TracingHelper.TraceEnabled)
                    TracingHelper.Write();

                if (!(new FileInfo(sFileProperties)).Exists)
                {
                    Create();
                    // this is a new database
                    newdata = true;
                }

                // todo: some parts are not necessary for read-only access
                LoadProperties();

                if (bReadOnly == true)
                {
                    dDatabase.SetReadOnly();

                    cCache = new Cache(sFileCache);

                    cCache.Open(true);
                    RunScript();

                    return false;
                }

                bool needbackup = false;

                if (sModified.Equals("yes-new-files"))
                {
                    RenameNewToCurrent(sFileScript);
                    RenameNewToCurrent(sFileBackup);
                }
                else if (sModified.Equals("yes"))
                {
                    if (IsAlreadyOpen())
                    {
                        throw TracingHelper.Error(TracingHelper.DATABASE_ALREADY_IN_USE);
                    }

                    // recovering after a crash (or forgot to close correctly)
                    RestoreBackup();

                    needbackup = true;
                }

                sModified = "yes";
                SaveProperties();

                cCache = new Cache(sFileCache);

                cCache.Open(false);
                RunScript();

                if (needbackup)
                {
                    Close(false);
                    sModified = "yes";
                    SaveProperties();
                    cCache.Open(false);
                }

                OpenScript();

                // this is a existing database
                return newdata;
            }
        }