Example #1
0
        /**
         * Method declaration
         *
         *
         * @param c
         * @param channel
         * @param name
         * @param t
         *
         * @throws Exception
         */
        private void addForeignKeyOn(Tokenizer c, Channel channel, string name,
                                     Table t)
        {
            int[] col = processColumnList(c, t);

            c.getThis("REFERENCES");

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

            int[] col2 = processColumnList(c, t2);

            if (t.getIndexForColumns(col) == null)
            {
                createIndex(channel, t, col, "SYSTEM_FOREIGN_KEY_" + name, false);
            }

            if (t2.getIndexForColumns(col2) == null)
            {
                createIndex(channel, t2, col2, "SYSTEM_REFERENCE_" + name, false);
            }

            t.addConstraint(new Constraint(Constraint.FOREIGN_KEY, t2, t, col2,
                                           col));
            t2.addConstraint(new Constraint(Constraint.MAIN, t2, t, col2, col));
        }
Example #2
0
        /**
         * Method declaration
         *
         *
         * @param c
         * @param t
         *
         * @return
         *
         * @throws Exception
         */
        private int[] processColumnList(Tokenizer c,
                                        Table t)
        {
            ArrayList v = new ArrayList();

            c.getThis("(");

            while (true)
            {
                v.Add(c.getstring());

                string sToken = c.getstring();

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

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

            int s = v.Count;

            int[] col = new int[s];

            for (int i = 0; i < s; i++)
            {
                col[i] = t.getColumnNr((string)v[i]);
            }

            return(col);
        }
Example #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());
        }
Example #4
0
        /**
         * Method declaration
         *
         *
         * @param c
         * @param channel
         * @param grant
         *
         * @return
         *
         * @throws Exception
         */
        private Result processGrantOrRevoke(Tokenizer c, Channel channel,
                                            bool grant)
        {
            channel.checkReadWrite();
            channel.checkAdmin();

            int    right = 0;
            string sToken;

            do
            {
                string sRight = c.getstring();

                right |= Access.getRight(sRight);
                sToken = c.getstring();
            } while (sToken.Equals(","));

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

            string table = c.getstring();

            if (table.Equals("CLASS"))
            {
                // object is saved as 'CLASS "java.lang.Math"'
                // tables like 'CLASS "xy"' should not be created
                table += " \"" + c.getstring() + "\"";
            }
            else
            {
                getTable(table, channel);                    // to make sure the table exists
            }

            c.getThis("TO");

            string user = c.getstringToken();

            //			string command;

            if (grant)
            {
                aAccess.grant(user, table, right);

                //				command = "GRANT";
            }
            else
            {
                aAccess.revoke(user, table, right);

                //				command = "REVOKE";
            }

            return(new Result());
        }
Example #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);
        }
Example #6
0
        /**
         * Method declaration
         *
         *
         * @param c
         * @param channel
         *
         * @return
         *
         * @throws Exception
         */
        private Result processCreate(Tokenizer c,
                                     Channel channel)
        {
            channel.checkReadWrite();
            channel.checkAdmin();

            string sToken = c.getstring();

            if (sToken.Equals("TABLE"))
            {
                processCreateTable(c, channel, false);
            }
            else if (sToken.Equals("MEMORY"))
            {
                c.getThis("TABLE");
                processCreateTable(c, channel, false);
            }
            else if (sToken.Equals("CACHED"))
            {
                c.getThis("TABLE");
                processCreateTable(c, channel, true);
            }
            else if (sToken.Equals("USER"))
            {
                string u = c.getstringToken();

                c.getThis("PASSWORD");

                string p = c.getstringToken();
                bool   admin;

                if (c.getstring().Equals("ADMIN"))
                {
                    admin = true;
                }
                else
                {
                    admin = false;
                }

                aAccess.createUser(u, p, admin);
            }
            else if (sToken.Equals("ALIAS"))
            {
                string name = c.getstring();

                sToken = c.getstring();

                Trace.check(sToken.Equals("FOR"), Trace.UNEXPECTED_TOKEN, sToken);

                sToken = c.getstring();

                hAlias.Add(name, sToken);
            }
            else
            {
                bool unique = false;

                if (sToken.Equals("UNIQUE"))
                {
                    unique = true;
                    sToken = c.getstring();
                }

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

                string name = c.getName();

                c.getThis("ON");

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

                addIndexOn(c, channel, name, t, unique);
            }

            return(new Result());
        }
Example #7
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());
        }