Ejemplo n.º 1
0
        /**
         * Method declaration
         *
         *
         * @return
         *
         * @throws Exception
         */
        public bool open()
        {
            bool newdata = false;

            if (Trace.TRACE)
            {
                Trace.trace();
            }

            if (!(new File(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 Trace.error(Trace.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;
        }
Ejemplo n.º 2
0
        private ArrayList vIndex; // vIndex(0) is always the primary key index

        #endregion Fields

        #region Constructors

        /**
         * Constructor declaration
         *
         *
         * @param db
         * @param log
         * @param name
         * @param cached
         */
        public Table(Database db, bool log, string name, bool cached)
        {
            dDatabase = db;
            lLog = log ? db.getLog() : null;

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

            sName = name;
            iPrimaryKey = -1;
            iIdentityColumn = -1;
            vColumn = new ArrayList();
            vIndex = new ArrayList();
            vConstraint = new ArrayList();
        }