示例#1
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);
        }
示例#2
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());
        }