예제 #1
0
        /**
         * Method declaration
         *
         *
         * @param c
         * @param channel
         *
         * @return
         *
         * @throws Exception
         */
        private Result processDrop(Tokenizer c,
                                   Channel channel)
        {
            channel.checkReadWrite();
            channel.checkAdmin();

            string sToken = c.getstring();

            if (sToken.Equals("TABLE"))
            {
                sToken = c.getstring();

                if (sToken.Equals("IF"))
                {
                    sToken = c.getstring();                        // EXISTS
                    sToken = c.getstring();                        // <table>

                    dropTable(sToken, true);
                }
                else
                {
                    dropTable(sToken, false);
                }
                channel.commit();
            }
            else if (sToken.Equals("USER"))
            {
                aAccess.dropUser(c.getstringToken());
            }
            else if (sToken.Equals("INDEX"))
            {
                sToken = c.getstring();

                if (!c.wasLongName())
                {
                    throw Trace.error(Trace.UNEXPECTED_TOKEN, sToken);
                }

                string table = c.getLongNameFirst();
                string index = c.getLongNameLast();
                Table  t     = getTable(table, channel);

                t.checkDropIndex(index);

                Table tn = t.moveDefinition(index);

                tn.moveData(t);
                dropTable(table);
                linkTable(tn);
                channel.commit();
            }
            else
            {
                throw Trace.error(Trace.UNEXPECTED_TOKEN, sToken);
            }

            return(new Result());
        }
예제 #2
0
        /**
         * Method declaration
         *
         *
         * @param c
         * @param channel
         *
         * @return
         *
         * @throws Exception
         */
        private Result processCommit(Tokenizer c,
                                     Channel channel)
        {
            string sToken = c.getstring();

            if (!sToken.Equals("WORK"))
            {
                c.back();
            }

            channel.commit();

            return(new Result());
        }
예제 #3
0
        /**
         * Method declaration
         *
         *
         * @param c
         * @param channel
         *
         * @return
         *
         * @throws Exception
         */
        private Result processConnect(Tokenizer c,
                                      Channel channel)
        {
            c.getThis("USER");

            string username = c.getstringToken();

            c.getThis("PASSWORD");

            string password = c.getstringToken();
            User   user     = aAccess.getUser(username, password);

            channel.commit();
            channel.setUser(user);

            return(new Result());
        }
예제 #4
0
        /**
         * Method declaration
         *
         *
         * @param channel
         * @param t
         * @param col
         * @param name
         * @param unique
         *
         * @throws Exception
         */
        private void createIndex(Channel channel, Table t, int[] col,
                                 string name,
                                 bool unique)
        {
            channel.commit();

            if (t.isEmpty())
            {
                t.createIndex(col, name, unique);
            }
            else
            {
                Table tn = t.moveDefinition(null);

                tn.createIndex(col, name, unique);
                tn.moveData(t);
                dropTable(t.getName());
                linkTable(tn);
            }
        }
예제 #5
0
        /**
         * Method declaration
         *
         *
         * @param c
         * @param channel
         * @param cached
         *
         * @throws Exception
         */
        private void processCreateTable(Tokenizer c, Channel channel,
                                        bool cached)
        {
            Table  t;
            string sToken = c.getName();

            if (cached && lLog != null)
            {
                t = new Table(this, true, sToken, true);
            }
            else
            {
                t = new Table(this, true, sToken, false);
            }

            c.getThis("(");

            int  primarykeycolumn = -1;
            int  column           = 0;
            bool constraint       = false;

            while (true)
            {
                bool identity = false;

                sToken = c.getstring();

                if (sToken.Equals("CONSTRAINT") || sToken.Equals("PRIMARY") ||
                    sToken.Equals("FOREIGN") || sToken.Equals("UNIQUE"))
                {
                    c.back();

                    constraint = true;

                    break;
                }

                string sColumn = sToken;
                int    iType   = Column.getTypeNr(c.getstring());

                if (iType == Column.VARCHAR && bIgnoreCase)
                {
                    iType = Column.VARCHAR_IGNORECASE;
                }

                sToken = c.getstring();

                if (iType == Column.DOUBLE && sToken.Equals("PRECISION"))
                {
                    sToken = c.getstring();
                }

                if (sToken.Equals("("))
                {
                    // overread length
                    do
                    {
                        sToken = c.getstring();
                    } while (!sToken.Equals(")"));

                    sToken = c.getstring();
                }

                bool nullable = true;

                if (sToken.Equals("NULL"))
                {
                    sToken = c.getstring();
                }
                else if (sToken.Equals("NOT"))
                {
                    c.getThis("NULL");

                    nullable = false;
                    sToken   = c.getstring();
                }

                if (sToken.Equals("IDENTITY"))
                {
                    identity = true;

                    Trace.check(primarykeycolumn == -1, Trace.SECOND_PRIMARY_KEY,
                                sColumn);

                    sToken           = c.getstring();
                    primarykeycolumn = column;
                }

                if (sToken.Equals("PRIMARY"))
                {
                    c.getThis("KEY");
                    Trace.check(identity || primarykeycolumn == -1,
                                Trace.SECOND_PRIMARY_KEY, sColumn);

                    primarykeycolumn = column;
                    sToken           = c.getstring();
                }

                t.addColumn(sColumn, iType, nullable, identity);

                if (sToken.Equals(")"))
                {
                    break;
                }

                if (!sToken.Equals(","))
                {
                    throw Trace.error(Trace.UNEXPECTED_TOKEN, sToken);
                }

                column++;
            }

            if (primarykeycolumn != -1)
            {
                t.createPrimaryKey(primarykeycolumn);
            }
            else
            {
                t.createPrimaryKey();
            }

            if (constraint)
            {
                int i = 0;

                while (true)
                {
                    sToken = c.getstring();

                    string name = "SYSTEM_CONSTRAINT" + i;

                    i++;

                    if (sToken.Equals("CONSTRAINT"))
                    {
                        name   = c.getstring();
                        sToken = c.getstring();
                    }

                    if (sToken.Equals("PRIMARY"))
                    {
                        c.getThis("KEY");
                        addUniqueConstraintOn(c, channel, name, t);
                    }
                    else if (sToken.Equals("UNIQUE"))
                    {
                        addUniqueConstraintOn(c, channel, name, t);
                    }
                    else if (sToken.Equals("FOREIGN"))
                    {
                        c.getThis("KEY");
                        addForeignKeyOn(c, channel, name, t);
                    }

                    sToken = c.getstring();

                    if (sToken.Equals(")"))
                    {
                        break;
                    }

                    if (!sToken.Equals(","))
                    {
                        throw Trace.error(Trace.UNEXPECTED_TOKEN, sToken);
                    }
                }
            }

            channel.commit();
            linkTable(t);
        }
예제 #6
0
        /**
         * Method declaration
         *
         *
         * @param c
         * @param channel
         *
         * @return
         *
         * @throws Exception
         */
        private Result processSet(Tokenizer c,
                                  Channel channel)
        {
            string sToken = c.getstring();

            if (sToken.Equals("PASSWORD"))
            {
                channel.checkReadWrite();
                channel.setPassword(c.getstringToken());
            }
            else if (sToken.Equals("READONLY"))
            {
                channel.commit();
                channel.setReadOnly(processTrueOrFalse(c));
            }
            else if (sToken.Equals("LOGSIZE"))
            {
                channel.checkAdmin();

                int i = Int32.FromString(c.getstring());

                if (lLog != null)
                {
                    lLog.setLogSize(i);
                }
            }
            else if (sToken.Equals("IGNORECASE"))
            {
                channel.checkAdmin();

                bIgnoreCase = processTrueOrFalse(c);
            }
            else if (sToken.Equals("MAXROWS"))
            {
                int i = Int32.FromString(c.getstring());

                channel.setMaxRows(i);
            }
            else if (sToken.Equals("AUTOCOMMIT"))
            {
                channel.setAutoCommit(processTrueOrFalse(c));
            }
            else if (sToken.Equals("TABLE"))
            {
                channel.checkReadWrite();
                channel.checkAdmin();

                Table t = getTable(c.getstring(), channel);

                c.getThis("INDEX");
                c.getstring();
                t.setIndexRoots((string)c.getAsValue());
            }
            else if (sToken.Equals("REFERENCIAL_INTEGRITY") ||
                     sToken.Equals("REFERENTIAL_INTEGRITY"))
            {
                channel.checkAdmin();

                bReferentialIntegrity = processTrueOrFalse(c);
            }
            else if (sToken.Equals("WRITE_DELAY"))
            {
                channel.checkAdmin();

                bool delay = processTrueOrFalse(c);

                if (lLog != null)
                {
                    lLog.setWriteDelay(delay);
                }
            }
            else
            {
                throw Trace.error(Trace.UNEXPECTED_TOKEN, sToken);
            }

            return(new Result());
        }