Ejemplo n.º 1
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());
        }
Ejemplo n.º 2
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());
        }
Ejemplo n.º 3
0
        private Result ProcessCheckpoint(Channel channel)
        {
            channel.CheckAdmin();

            if (_log != null)
            {
                _log.Checkpoint();
            }

            return(new Result());
        }
Ejemplo n.º 4
0
        private Result ProcessShutdown(Tokenizer tokenizer, Channel channel)
        {
            channel.CheckAdmin();

            // don't disconnect system user; need it to save database
            for (int i = 1; i < _channel.Count; i++)
            {
                Channel d = (Channel)_channel[i];

                if (d != null)
                {
                    d.Disconnect();
                }
            }

            _channel.Clear();

            string token = tokenizer.GetString();

            switch (token)
            {
            case "IMMEDIATELY":
                Close(-1);
                break;

            case "COMPACT":
                Close(1);
                break;

            default:
                tokenizer.Back();
                Close(0);
                break;
            }

            ProcessDisconnect(tokenizer, channel);

            return(new Result());
        }
Ejemplo n.º 5
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());
        }
Ejemplo n.º 6
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());
        }
Ejemplo n.º 7
0
        public Result GetScript(bool bDrop, bool bInsert, bool bCached, Channel channel)
        {
            channel.CheckAdmin();

            Result r = new Result(1);

            r.Type[0]  = ColumnType.VarChar;
            r.Table[0] = "SYSTEM_SCRIPT";
            r.Label[0] = "COMMAND";
            r.Name[0]  = "COMMAND";

            StringBuilder a = new StringBuilder();

            for (int i = 0; i < tTable.Count; i++)
            {
                Table t = (Table)tTable[i];

                if (bDrop)
                {
                    AddRow(r, "DROP TABLE \"" + t.Name + "\"");
                }

                a.Remove(0, a.Length);
                a.Append("CREATE ");

                if (t.IsCached)
                {
                    a.Append("CACHED ");
                }

                a.Append("TABLE ");
                a.Append('"');
                a.Append(t.Name);
                a.Append('"');
                a.Append("(");

                int   columns = t.ColumnCount;
                Index pki     = t.GetIndex("SYSTEM_PK");
                int   pk      = (pki == null) ? -1 : pki.Columns[0];

                for (int j = 0; j < columns; j++)
                {
                    a.Append('"');
                    a.Append(t.GetColumnName(j));
                    a.Append('"');
                    a.Append(" ");
                    a.Append(Column.GetColumnTypeString(t.GetType(j)));

                    if (!t.GetColumnIsNullable(j))
                    {
                        a.Append(" NOT NULL");
                    }

                    if (j == t.IdentityColumn)
                    {
                        a.Append(" IDENTITY");
                    }

                    if (j == pk)
                    {
                        a.Append(" PRIMARY KEY");
                    }

                    if (j < columns - 1)
                    {
                        a.Append(",");
                    }
                }

                ArrayList v = t.Constraints;

                for (int j = 0; j < v.Count; j++)
                {
                    Constraint c = (Constraint)v[j];

                    if (c.ConstraintType == ConstraintType.ForeignKey)
                    {
                        a.Append(",FOREIGN KEY");

                        int[] col = c.RefTableColumns;

                        a.Append(GetColumnList(c.RefTable, col, col.Length));
                        a.Append("REFERENCES ");
                        a.Append(c.MainTable.Name);

                        col = c.MainTableColumns;

                        a.Append(GetColumnList(c.MainTable, col, col.Length));
                    }
                    else if (c.ConstraintType == ConstraintType.Unique)
                    {
                        a.Append(",UNIQUE");

                        int[] col = c.MainTableColumns;

                        a.Append(GetColumnList(c.MainTable, col, col.Length));
                    }
                }

                a.Append(")");
                AddRow(r, a.ToString());

                Index index = null;

                while (true)
                {
                    index = t.GetNextIndex(index);

                    if (index == null)
                    {
                        break;
                    }

                    string indexname = index.Name;

                    if (indexname.Equals("SYSTEM_PK"))
                    {
                        continue;
                    }
                    else if (indexname.StartsWith("SYSTEM_FOREIGN_KEY"))
                    {
                        // foreign keys where created in the 'create table'
                        continue;
                    }
                    else if (indexname.StartsWith("SYSTEM_CONSTRAINT"))
                    {
                        // constraints where created in the 'create table'
                        continue;
                    }

                    a.Remove(0, a.Length);
                    a.Append("CREATE ");

                    if (index.IsUnique)
                    {
                        a.Append("UNIQUE ");
                    }

                    a.Append("INDEX ");
                    a.Append(indexname);
                    a.Append(" ON ");
                    a.Append(t.Name);

                    int[] col = index.Columns;
                    int   len = col.Length;

                    if (!index.IsUnique)
                    {
                        len--;
                    }

                    a.Append(GetColumnList(t, col, len));
                    AddRow(r, a.ToString());
                }

                if (bInsert)
                {
                    Index primary   = t.PrimaryIndex;
                    Node  x         = primary.First();
                    bool  integrity = true;

                    if (x != null)
                    {
                        integrity = false;

                        AddRow(r, "SET REFERENTIAL_INTEGRITY FALSE");
                    }

                    while (x != null)
                    {
                        AddRow(r, t.GetInsertStatement(x.GetData()));

                        x = primary.Next(x);
                    }

                    if (!integrity)
                    {
                        AddRow(r, "SET REFERENTIAL_INTEGRITY TRUE");
                    }
                }

                if (bCached && t.IsCached)
                {
                    a.Remove(0, a.Length);
                    a.Append("SET TABLE ");

                    a.Append('"');
                    a.Append(t.Name);
                    a.Append('"');
                    a.Append(" INDEX '");
                    a.Append(t.IndexRoots);
                    a.Append("'");
                    AddRow(r, a.ToString());
                }
            }

            ArrayList uList = aAccess.GetUsers();

            for (int i = 0; i < uList.Count; i++)
            {
                User u = (User)uList[i];

                // todo: this is not a nice implementation
                if (u == null)
                {
                    continue;
                }

                string name = u.Name;

                if (!name.Equals("PUBLIC"))
                {
                    a.Remove(0, a.Length);
                    a.Append("CREATE USER ");

                    a.Append(name);
                    a.Append(" PASSWORD ");
                    a.Append("\"" + u.Password + "\"");

                    if (u.IsAdmin)
                    {
                        a.Append(" ADMIN");
                    }

                    AddRow(r, a.ToString());
                }

                Hashtable rights = u.Rights;

                if (rights == null)
                {
                    continue;
                }

                foreach (string dbObject in rights.Keys)
                {
                    AccessType right = (AccessType)rights[dbObject];

                    if (right == AccessType.None)
                    {
                        continue;
                    }

                    a.Remove(0, a.Length);
                    a.Append("GRANT ");

                    a.Append(Access.GetRight(right));
                    a.Append(" ON ");
                    a.Append(dbObject);
                    a.Append(" TO ");
                    a.Append(u.Name);
                    AddRow(r, a.ToString());
                }
            }

            if (dDatabase.IsIgnoreCase)
            {
                AddRow(r, "SET IGNORECASE TRUE");
            }

            Hashtable h = dDatabase.Alias;

            foreach (string alias in h.Keys)
            {
                string className = (string)h[alias];
                AddRow(r, "CREATE ALIAS " + alias + " FOR \"" + className + "\"");
            }

            return(r);
        }
Ejemplo n.º 8
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();
        }
Ejemplo n.º 9
0
        public Result GetScript(bool bDrop, bool bInsert, bool bCached, Channel channel)
        {
            channel.CheckAdmin();

            Result r = new Result(1);

            r.Type[0] = ColumnType.VarChar;
            r.Table[0] = "SYSTEM_SCRIPT";
            r.Label[0] = "COMMAND";
            r.Name[0] = "COMMAND";

            StringBuilder a = new StringBuilder();

            for (int i = 0; i < tTable.Count; i++)
            {
                Table t = (Table) tTable[i];

                if (bDrop)
                {
                    AddRow(r, "DROP TABLE \"" + t.Name + "\"");
                }

                a.Remove(0,a.Length);
                a.Append("CREATE ");

                if (t.IsCached)
                {
                    a.Append("CACHED ");
                }

                a.Append("TABLE ");
                a.Append('"');
                a.Append(t.Name);
                a.Append('"');
                a.Append("(");

                int   columns = t.ColumnCount;
                Index pki = t.GetIndex("SYSTEM_PK");
                int   pk = (pki == null) ? -1 : pki.Columns[0];

                for (int j = 0; j < columns; j++)
                {
                    a.Append('"');
                    a.Append(t.GetColumnName(j));
                    a.Append('"');
                    a.Append(" ");
                    a.Append(Column.GetColumnTypeString(t.GetType(j)));

                    if (!t.GetColumnIsNullable(j))
                    {
                        a.Append(" NOT NULL");
                    }

                    if (j == t.IdentityColumn)
                    {
                        a.Append(" IDENTITY");
                    }

                    if (j == pk)
                    {
                        a.Append(" PRIMARY KEY");
                    }

                    if (j < columns - 1)
                    {
                        a.Append(",");
                    }
                }

                ArrayList v = t.Constraints;

                for (int j = 0; j < v.Count; j++)
                {
                    Constraint c = (Constraint) v[j];

                    if (c.ConstraintType == ConstraintType.ForeignKey)
                    {
                        a.Append(",FOREIGN KEY");

                        int[] col = c.RefTableColumns;

                        a.Append(GetColumnList(c.RefTable, col, col.Length));
                        a.Append("REFERENCES ");
                        a.Append(c.MainTable.Name);

                        col = c.MainTableColumns;

                        a.Append(GetColumnList(c.MainTable, col, col.Length));
                    }
                    else if (c.ConstraintType == ConstraintType.Unique)
                    {
                        a.Append(",UNIQUE");

                        int[] col = c.MainTableColumns;

                        a.Append(GetColumnList(c.MainTable, col, col.Length));
                    }
                }

                a.Append(")");
                AddRow(r, a.ToString());

                Index index = null;

                while (true)
                {
                    index = t.GetNextIndex(index);

                    if (index == null)
                    {
                        break;
                    }

                    string indexname = index.Name;

                    if (indexname.Equals("SYSTEM_PK"))
                    {
                        continue;
                    }
                    else if (indexname.StartsWith("SYSTEM_FOREIGN_KEY"))
                    {

                        // foreign keys where created in the 'create table'
                        continue;
                    }
                    else if (indexname.StartsWith("SYSTEM_CONSTRAINT"))
                    {

                        // constraints where created in the 'create table'
                        continue;
                    }

                    a.Remove(0,a.Length);
                    a.Append("CREATE ");

                    if (index.IsUnique)
                    {
                        a.Append("UNIQUE ");
                    }

                    a.Append("INDEX ");
                    a.Append(indexname);
                    a.Append(" ON ");
                    a.Append(t.Name);

                    int[] col = index.Columns;
                    int len = col.Length;

                    if (!index.IsUnique)
                    {
                        len--;
                    }

                    a.Append(GetColumnList(t, col, len));
                    AddRow(r, a.ToString());
                }

                if (bInsert)
                {
                    Index   primary = t.PrimaryIndex;
                    Node    x = primary.First();
                    bool integrity = true;

                    if (x != null)
                    {
                        integrity = false;

                        AddRow(r, "SET REFERENTIAL_INTEGRITY FALSE");
                    }

                    while (x != null)
                    {
                        AddRow(r, t.GetInsertStatement(x.GetData()));

                        x = primary.Next(x);
                    }

                    if (!integrity)
                    {
                        AddRow(r, "SET REFERENTIAL_INTEGRITY TRUE");
                    }
                }

                if (bCached && t.IsCached)
                {
                    a.Remove(0,a.Length);
                    a.Append("SET TABLE ");

                    a.Append('"');
                    a.Append(t.Name);
                    a.Append('"');
                    a.Append(" INDEX '");
                    a.Append(t.IndexRoots);
                    a.Append("'");
                    AddRow(r, a.ToString());
                }

            }

            ArrayList uList = aAccess.GetUsers();

            for (int i = 0; i < uList.Count; i++)
            {
                User u = (User) uList[i];

                // todo: this is not a nice implementation
                if (u == null)
                {
                    continue;
                }

                string name = u.Name;

                if (!name.Equals("PUBLIC"))
                {
                    a.Remove(0,a.Length);
                    a.Append("CREATE USER ");

                    a.Append(name);
                    a.Append(" PASSWORD ");
                    a.Append("\"" + u.Password + "\"");

                    if (u.IsAdmin)
                    {
                        a.Append(" ADMIN");
                    }

                    AddRow(r, a.ToString());
                }

                Hashtable rights = u.Rights;

                if (rights == null)
                {
                    continue;
                }

                foreach( string dbObject in rights.Keys)
                {
                    AccessType    right = (AccessType) rights[dbObject];

                    if (right == AccessType.None)
                    {
                        continue;
                    }

                    a.Remove(0,a.Length);
                    a.Append("GRANT ");

                    a.Append(Access.GetRight(right));
                    a.Append(" ON ");
                    a.Append(dbObject);
                    a.Append(" TO ");
                    a.Append(u.Name);
                    AddRow(r, a.ToString());
                }
            }

            if (dDatabase.IsIgnoreCase)
            {
                AddRow(r, "SET IGNORECASE TRUE");
            }

            Hashtable   h = dDatabase.Alias;

            foreach(string alias in h.Keys)
            {
                string className = (string) h[alias];
                AddRow(r, "CREATE ALIAS " + alias + " FOR \"" + className + "\"");
            }

            return r;
        }
Ejemplo n.º 10
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();
        }
Ejemplo n.º 11
0
        private Result ProcessCheckpoint(Channel channel)
        {
            channel.CheckAdmin();

            if (_log != null)
            {
                _log.Checkpoint();
            }

            return new Result();
        }
Ejemplo n.º 12
0
        private Result ProcessShutdown(Tokenizer tokenizer, Channel channel)
        {
            channel.CheckAdmin();

            // don't disconnect system user; need it to save database
            for (int i = 1; i < _channel.Count; i++)
            {
                Channel d = (Channel) _channel[i];

                if (d != null)
                {
                    d.Disconnect();
                }
            }

            _channel.Clear();

            string token = tokenizer.GetString();

            switch(token)
            {
                case "IMMEDIATELY":
                    Close(-1);
                    break;
                case "COMPACT":
                    Close(1);
                    break;
                default:
                    tokenizer.Back();
                    Close(0);
                    break;
            }

            ProcessDisconnect(tokenizer, channel);

            return new Result();
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 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();
        }