예제 #1
0
        private int[] ProcessColumnList(Tokenizer tokenizer, Table table)
        {
            ArrayList v = new ArrayList();

            tokenizer.GetThis("(");

            while (true)
            {
                v.Add(tokenizer.GetString());

                string sToken = tokenizer.GetString();

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

                if (!sToken.Equals(","))
                {
                    throw Trace.Error(Trace.UnexpectedToken, sToken);
                }
            }

            int s = v.Count;

            int[] col = new int[s];

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

            return(col);
        }
예제 #2
0
        private Result ProcessConnect(Tokenizer c,
                                      Channel channel)
        {
            c.GetThis("USER");

            string username = c.GetStringToken();

            c.GetThis("PASSWORD");

            string password = c.GetStringToken();
            User   user     = _access.GetUser(username, password);

            channel.Commit();
            channel.SetUser(user);

            return(new Result());
        }
예제 #3
0
        private Result ProcessGrantOrRevoke(Tokenizer c, Channel channel, bool grant)
        {
            channel.CheckReadWrite();
            channel.CheckAdmin();

            AccessType right = AccessType.None;
            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.UnexpectedToken, 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)
            {
                _access.Grant(user, table, right);

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

                //				command = "REVOKE";
            }

            return(new Result());
        }
예제 #4
0
        private void AddForeignKeyOn(Tokenizer tokenizer, Channel channel, string name, Table table)
        {
            int[] col = ProcessColumnList(tokenizer, table);

            tokenizer.GetThis("REFERENCES");

            Table t2 = GetTable(tokenizer.GetString(), channel);

            int[] col2 = ProcessColumnList(tokenizer, t2);

            if (table.GetIndexForColumns(col) == null)
            {
                CreateIndex(channel, table, col, "SYSTEM_FOREIGN_KEY_" + name, false);
            }

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

            table.AddConstraint(new Constraint(ConstraintType.ForeignKey, t2, table, col2, col));
            t2.AddConstraint(new Constraint(ConstraintType.Main, t2, table, col2, col));
        }
예제 #5
0
        private void ProcessCreateTable(Tokenizer tokenizer, Channel channel, bool cached)
        {
            Table  t;
            string sToken = tokenizer.GetName();

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

            tokenizer.GetThis("(");

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

            while (true)
            {
                bool identity = false;

                sToken = tokenizer.GetString();

                if (sToken.Equals("CONSTRAINT") || sToken.Equals("PRIMARY") ||
                    sToken.Equals("FOREIGN") || sToken.Equals("UNIQUE"))
                {
                    tokenizer.Back();

                    constraint = true;

                    break;
                }

                string     sColumn = sToken;
                ColumnType iType   = Column.GetColumnType(tokenizer.GetString());

                if (iType == ColumnType.VarChar && _ignoreCase)
                {
                    iType = ColumnType.VarCharIgnoreCase;
                }

                sToken = tokenizer.GetString();

                if (iType == ColumnType.DbDouble && sToken.Equals("PRECISION"))
                {
                    sToken = tokenizer.GetString();
                }

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

                    sToken = tokenizer.GetString();
                }

                bool nullable = true;

                if (sToken.Equals("NULL"))
                {
                    sToken = tokenizer.GetString();
                }
                else if (sToken.Equals("NOT"))
                {
                    tokenizer.GetThis("NULL");

                    nullable = false;
                    sToken   = tokenizer.GetString();
                }

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

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

                    sToken           = tokenizer.GetString();
                    primarykeycolumn = column;
                }

                if (sToken.Equals("PRIMARY"))
                {
                    tokenizer.GetThis("KEY");
                    Trace.Check(identity || primarykeycolumn == -1,
                                Trace.SECOND_PRIMARY_KEY, sColumn);

                    primarykeycolumn = column;
                    sToken           = tokenizer.GetString();
                }

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

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

                if (!sToken.Equals(","))
                {
                    throw Trace.Error(Trace.UnexpectedToken, sToken);
                }

                column++;
            }

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

            if (constraint)
            {
                int i = 0;

                while (true)
                {
                    sToken = tokenizer.GetString();

                    string name = "SYSTEM_CONSTRAINT" + i;

                    i++;

                    if (sToken.Equals("CONSTRAINT"))
                    {
                        name   = tokenizer.GetString();
                        sToken = tokenizer.GetString();
                    }

                    if (sToken.Equals("PRIMARY"))
                    {
                        tokenizer.GetThis("KEY");
                        AddUniqueConstraintOn(tokenizer, channel, name, t);
                    }
                    else if (sToken.Equals("UNIQUE"))
                    {
                        AddUniqueConstraintOn(tokenizer, channel, name, t);
                    }
                    else if (sToken.Equals("FOREIGN"))
                    {
                        tokenizer.GetThis("KEY");
                        AddForeignKeyOn(tokenizer, channel, name, t);
                    }

                    sToken = tokenizer.GetString();

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

                    if (!sToken.Equals(","))
                    {
                        throw Trace.Error(Trace.UnexpectedToken, sToken);
                    }
                }
            }

            channel.Commit();
            LinkTable(t);
        }
예제 #6
0
        private Result ProcessCreate(Tokenizer tokenizer, Channel channel)
        {
            channel.CheckReadWrite();
            channel.CheckAdmin();

            string sToken = tokenizer.GetString();

            switch (sToken)
            {
            case "TABLE":
                ProcessCreateTable(tokenizer, channel, true);
                break;

            case "MEMORY":
                tokenizer.GetThis("TABLE");
                ProcessCreateTable(tokenizer, channel, false);
                break;

            case "CACHED":
                tokenizer.GetThis("TABLE");
                ProcessCreateTable(tokenizer, channel, true);
                break;

            case "USER":
            {
                string u = tokenizer.GetStringToken();

                tokenizer.GetThis("PASSWORD");

                string p = tokenizer.GetStringToken();
                bool   admin;

                if (tokenizer.GetString().Equals("ADMIN"))
                {
                    admin = true;
                }
                else
                {
                    admin = false;
                }

                _access.CreateUser(u, p, admin);
            }
            break;

            case "ALIAS":
            {
                string name = tokenizer.GetString();

                sToken = tokenizer.GetString();

                Trace.Check(sToken.Equals("FOR"), Trace.UnexpectedToken, sToken);

                sToken = tokenizer.GetString();

                _alias[name] = sToken;
            }
            break;

            default:
            {
                bool unique = false;

                if (sToken.Equals("UNIQUE"))
                {
                    unique = true;
                    sToken = tokenizer.GetString();
                }

                if (!sToken.Equals("INDEX"))
                {
                    throw Trace.Error(Trace.UnexpectedToken, sToken);
                }

                string name = tokenizer.GetName();

                tokenizer.GetThis("ON");

                Table t = GetTable(tokenizer.GetString(), channel);

                AddIndexOn(tokenizer, channel, name, t, unique);
            }
            break;
            }

            return(new Result());
        }
예제 #7
0
        private Result ProcessSet(Tokenizer tokenizer, Channel channel)
        {
            string sToken = tokenizer.GetString();

            switch (sToken)
            {
            case "PASSWORD":
                channel.CheckReadWrite();
                channel.SetPassword(tokenizer.GetStringToken());
                break;

            case "READONLY":
                channel.Commit();
                channel.SetReadOnly(ProcessTrueOrFalse(tokenizer));
                break;

            case "LOGSIZE":
            {
                channel.CheckAdmin();

                int i = Int32.Parse(tokenizer.GetString());

                if (_log != null)
                {
                    _log.SetLogSize(i);
                }
            }
            break;

            case "IGNORECASE":
                channel.CheckAdmin();
                _ignoreCase = ProcessTrueOrFalse(tokenizer);
                break;

            case "MAXROWS":
            {
                int i = Int32.Parse(tokenizer.GetString());
                channel.MaxRows = i;
                break;
            }

            case "AUTOCOMMIT":
                channel.SetAutoCommit(ProcessTrueOrFalse(tokenizer));
                break;

            case "TABLE":
            {
                channel.CheckReadWrite();
                channel.CheckAdmin();

                Table t = GetTable(tokenizer.GetString(), channel);

                tokenizer.GetThis("INDEX");
                tokenizer.GetString();
                t.IndexRoots = (string)tokenizer.Value;
            }
            break;

            case "REFERENCIAL_INTEGRITY":
            case "REFERENTIAL_INTEGRITY":
                channel.CheckAdmin();
                _referentialIntegrity = ProcessTrueOrFalse(tokenizer);
                break;

            case "WRITE_DELAY":
            {
                channel.CheckAdmin();

                bool delay = ProcessTrueOrFalse(tokenizer);

                if (_log != null)
                {
                    _log.SetWriteDelay(delay);
                }
            }
            break;

            default:
                if (tokenizer.TokenType == TokenType.VARIABLE)
                {
                    Parser p = new Parser(this, tokenizer, channel);
                    p.ProcessSet(sToken);
                    break;
                }

                throw Trace.Error(Trace.UnexpectedToken, sToken);
            }

            return(new Result());
        }
예제 #8
0
        private Result ProcessCreate(Tokenizer tokenizer, Channel channel)
        {
            channel.CheckReadWrite();
            channel.CheckAdmin();

            string sToken = tokenizer.GetString();

            switch(sToken)
            {
                case "TABLE":
                    ProcessCreateTable(tokenizer, channel, true);
                    break;
                case "MEMORY":
                    tokenizer.GetThis("TABLE");
                    ProcessCreateTable(tokenizer, channel, false);
                    break;
                case "CACHED":
                    tokenizer.GetThis("TABLE");
                    ProcessCreateTable(tokenizer, channel, true);
                    break;
                case "USER":
                {
                    string u = tokenizer.GetStringToken();

                    tokenizer.GetThis("PASSWORD");

                    string  p = tokenizer.GetStringToken();
                    bool admin;

                    if (tokenizer.GetString().Equals("ADMIN"))
                    {
                        admin = true;
                    }
                    else
                    {
                        admin = false;
                    }

                    _access.CreateUser(u, p, admin);
                }
                    break;
                case "ALIAS":
                {
                    string name = tokenizer.GetString();

                    sToken = tokenizer.GetString();

                    TracingHelper.Check(sToken.Equals("FOR"), TracingHelper.UnexpectedToken, sToken);

                    sToken = tokenizer.GetString();

                    _alias[name] = sToken;
                }
                    break;
                default:
                {
                    bool unique = false;

                    if (sToken.Equals("UNIQUE"))
                    {
                        unique = true;
                        sToken = tokenizer.GetString();
                    }

                    if (!sToken.Equals("INDEX"))
                    {
                        throw TracingHelper.Error(TracingHelper.UnexpectedToken, sToken);
                    }

                    string name = tokenizer.GetName();

                    tokenizer.GetThis("ON");

                    Table t = GetTable(tokenizer.GetString(), channel);

                    AddIndexOn(tokenizer, channel, name, t, unique);
                }
                    break;
            }

            return new Result();
        }
예제 #9
0
        private void ProcessCreateTable(Tokenizer tokenizer, Channel channel, bool cached)
        {
            Table  t;
            string sToken = tokenizer.GetName();

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

            tokenizer.GetThis("(");

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

            while (true)
            {
                bool identity = false;

                sToken = tokenizer.GetString();

                if (sToken.Equals("CONSTRAINT") || sToken.Equals("PRIMARY")
                    || sToken.Equals("FOREIGN") || sToken.Equals("UNIQUE"))
                {
                    tokenizer.Back();

                    constraint = true;

                    break;
                }

                string sColumn = sToken;
                ColumnType iType = Column.GetColumnType(tokenizer.GetString());

                if (iType == ColumnType.VarChar && _ignoreCase)
                {
                    iType = ColumnType.VarCharIgnoreCase;
                }

                sToken = tokenizer.GetString();

                if (iType == ColumnType.DbDouble && sToken.Equals("PRECISION"))
                {
                    sToken = tokenizer.GetString();
                }

                if (sToken.Equals("("))
                {

                    // overread length
                    do
                    {
                        sToken = tokenizer.GetString();
                    } while (!sToken.Equals(")"));

                    sToken = tokenizer.GetString();
                }

                bool nullable = true;

                if (sToken.Equals("NULL"))
                {
                    sToken = tokenizer.GetString();
                }
                else if (sToken.Equals("NOT"))
                {
                    tokenizer.GetThis("NULL");

                    nullable = false;
                    sToken = tokenizer.GetString();
                }

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

                    TracingHelper.Check(primarykeycolumn == -1, TracingHelper.SECOND_PRIMARY_KEY,
                        sColumn);

                    sToken = tokenizer.GetString();
                    primarykeycolumn = column;
                }

                if (sToken.Equals("PRIMARY"))
                {
                    tokenizer.GetThis("KEY");
                    TracingHelper.Check(identity || primarykeycolumn == -1,
                        TracingHelper.SECOND_PRIMARY_KEY, sColumn);

                    primarykeycolumn = column;
                    sToken = tokenizer.GetString();
                }

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

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

                if (!sToken.Equals(","))
                {
                    throw TracingHelper.Error(TracingHelper.UnexpectedToken, sToken);
                }

                column++;
            }

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

            if (constraint)
            {
                int i = 0;

                while (true)
                {
                    sToken = tokenizer.GetString();

                    string name = "SYSTEM_CONSTRAINT" + i;

                    i++;

                    if (sToken.Equals("CONSTRAINT"))
                    {
                        name = tokenizer.GetString();
                        sToken = tokenizer.GetString();
                    }

                    if (sToken.Equals("PRIMARY"))
                    {
                        tokenizer.GetThis("KEY");
                        AddUniqueConstraintOn(tokenizer, channel, name, t);
                    }
                    else if (sToken.Equals("UNIQUE"))
                    {
                        AddUniqueConstraintOn(tokenizer, channel, name, t);
                    }
                    else if (sToken.Equals("FOREIGN"))
                    {
                        tokenizer.GetThis("KEY");
                        AddForeignKeyOn(tokenizer, channel, name, t);
                    }

                    sToken = tokenizer.GetString();

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

                    if (!sToken.Equals(","))
                    {
                        throw TracingHelper.Error(TracingHelper.UnexpectedToken, sToken);
                    }
                }
            }

            channel.Commit();
            LinkTable(t);
        }
예제 #10
0
        private Result ProcessConnect(Tokenizer c,
            Channel channel)
        {
            c.GetThis("USER");

            string username = c.GetStringToken();

            c.GetThis("PASSWORD");

            string password = c.GetStringToken();
            User   user = _access.GetUser(username, password);

            channel.Commit();
            channel.SetUser(user);

            return new Result();
        }
예제 #11
0
        private int[] ProcessColumnList(Tokenizer tokenizer, Table table)
        {
            ArrayList v = new ArrayList();

            tokenizer.GetThis("(");

            while (true)
            {
                v.Add(tokenizer.GetString());

                string sToken = tokenizer.GetString();

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

                if (!sToken.Equals(","))
                {
                    throw TracingHelper.Error(TracingHelper.UnexpectedToken, sToken);
                }
            }

            int s = v.Count;
            int[] col = new int[s];

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

            return col;
        }
예제 #12
0
        private void AddForeignKeyOn(Tokenizer tokenizer, Channel channel, string name, Table table)
        {
            int[] col = ProcessColumnList(tokenizer, table);

            tokenizer.GetThis("REFERENCES");

            Table t2 = GetTable(tokenizer.GetString(), channel);
            int[]   col2 = ProcessColumnList(tokenizer, t2);

            if (table.GetIndexForColumns(col) == null)
            {
                CreateIndex(channel, table, col, "SYSTEM_FOREIGN_KEY_" + name, false);
            }

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

            table.AddConstraint(new Constraint(ConstraintType.ForeignKey, t2, table, col2,	col));
            t2.AddConstraint(new Constraint(ConstraintType.Main, t2, table, col2, col));
        }
예제 #13
0
        private Result ProcessSet(Tokenizer tokenizer, Channel channel)
        {
            string sToken = tokenizer.GetString();

            switch(sToken)
            {
                case "PASSWORD":
                    channel.CheckReadWrite();
                    channel.SetPassword(tokenizer.GetStringToken());
                    break;
                case "READONLY":
                    channel.Commit();
                    channel.SetReadOnly(ProcessTrueOrFalse(tokenizer));
                    break;
                case "LOGSIZE":
                {
                    channel.CheckAdmin();

                    int i = Int32.Parse(tokenizer.GetString());

                    if (_log != null)
                    {
                        _log.SetLogSize(i);
                    }
                }
                    break;
                case "IGNORECASE":
                    channel.CheckAdmin();
                    _ignoreCase = ProcessTrueOrFalse(tokenizer);
                    break;
                case "MAXROWS":
                {
                    int i = Int32.Parse(tokenizer.GetString());
                    channel.MaxRows = i;
                    break;
                }
                case "AUTOCOMMIT":
                    channel.SetAutoCommit(ProcessTrueOrFalse(tokenizer));
                    break;
                case "TABLE":
                {
                    channel.CheckReadWrite();
                    channel.CheckAdmin();

                    Table t = GetTable(tokenizer.GetString(), channel);

                    tokenizer.GetThis("INDEX");
                    tokenizer.GetString();
                    t.IndexRoots = (string)tokenizer.Value;
                }
                    break;
                case "REFERENCIAL_INTEGRITY":
                case "REFERENTIAL_INTEGRITY":
                    channel.CheckAdmin();
                    _referentialIntegrity = ProcessTrueOrFalse(tokenizer);
                    break;
                case "WRITE_DELAY":
                {
                    channel.CheckAdmin();

                    bool delay = ProcessTrueOrFalse(tokenizer);

                    if (_log != null)
                    {
                        _log.SetWriteDelay(delay);
                    }
                }
                    break;
                default:
                    if( tokenizer.TokenType == TokenType.VARIABLE )
                    {
                        Parser p = new Parser(this, tokenizer, channel);
                        p.ProcessSet( sToken );
                        break;
                    }

                    throw TracingHelper.Error(TracingHelper.UnexpectedToken, sToken);
            }

            return new Result();
        }
예제 #14
0
        private Result ProcessGrantOrRevoke(Tokenizer c, Channel channel, bool grant)
        {
            channel.CheckReadWrite();
            channel.CheckAdmin();

            AccessType    right = AccessType.None;
            string sToken;

            do
            {
                string sRight = c.GetString();

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

            if (!sToken.Equals("ON"))
            {
                throw TracingHelper.Error(TracingHelper.UnexpectedToken, 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)
            {
                _access.Grant(user, table, right);

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

                //				command = "REVOKE";
            }

            return new Result();
        }