Example #1
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());
        }
Example #2
0
        private Result ProcessDrop(Tokenizer tokenizer, Channel channel)
        {
            channel.CheckReadWrite();
            channel.CheckAdmin();

            string sToken = tokenizer.GetString();

            if (sToken.Equals("TABLE"))
            {
                sToken = tokenizer.GetString();

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

                    DropTable(sToken, true);
                }
                else
                {
                    DropTable(sToken, false);
                }
                channel.Commit();
            }
            else if (sToken.Equals("USER"))
            {
                _access.DropUser(tokenizer.GetStringToken());
            }
            else if (sToken.Equals("INDEX"))
            {
                sToken = tokenizer.GetString();

                if (!tokenizer.WasLongName)
                {
                    throw Trace.Error(Trace.UnexpectedToken, sToken);
                }

                string table = tokenizer.LongNameFirst;
                string index = tokenizer.LongNameLast;
                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.UnexpectedToken, sToken);
            }

            return(new Result());
        }
Example #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());
        }
Example #4
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());
        }
Example #5
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());
        }
Example #6
0
        private Result ProcessDrop(Tokenizer tokenizer, Channel channel)
        {
            channel.CheckReadWrite();
            channel.CheckAdmin();

            string sToken = tokenizer.GetString();

            if (sToken.Equals("TABLE"))
            {
                sToken = tokenizer.GetString();

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

                    DropTable(sToken, true);
                }
                else
                {
                    DropTable(sToken, false);
                }
                channel.Commit();
            }
            else if (sToken.Equals("USER"))
            {
                _access.DropUser(tokenizer.GetStringToken());
            }
            else if (sToken.Equals("INDEX"))
            {
                sToken = tokenizer.GetString();

                if (!tokenizer.WasLongName)
                {
                    throw TracingHelper.Error(TracingHelper.UnexpectedToken, sToken);
                }

                string table = tokenizer.LongNameFirst;
                string index = tokenizer.LongNameLast;
                Table  t = GetTable(table, channel);

                t.CheckDropIndex(index);

                Table tn = t.MoveDefinition(index);

                tn.MoveData(t);
                DropTable(table);
                LinkTable(tn);
                channel.Commit();
            }
            else
            {
                throw TracingHelper.Error(TracingHelper.UnexpectedToken, sToken);
            }

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