コード例 #1
0
ファイル: Database.cs プロジェクト: weimingtom/sharphsql_svn
        private Result ProcessShow(Tokenizer tokenizer, Channel channel)
        {
            Result r = new Result(1);

            string sToken = tokenizer.GetString();

            if (sToken.Equals("TABLES"))
            {
                System.Collections.ArrayList al = channel.Database.Tables;
                r.Label[0] = "TABLE";
                r.Type[0]  = ColumnType.VarChar;
                for (int x = 0; x < al.Count; x++)
                {
                    Table    table     = (Table)al[x];
                    string[] tablename = new string [1];
                    tablename[0] = table.Name;
                    r.Add(tablename);
                }
                channel.Commit();
            }
            else if (sToken.Equals("DATABASES"))
            {
                r.Label[0] = "DATABASE";
                r.Type[0]  = ColumnType.VarChar;

                System.IO.DirectoryInfo di = new
                                             System.IO.DirectoryInfo(System.IO.Directory.GetCurrentDirectory());
                System.IO.FileInfo[] rgFiles = di.GetFiles("*.data");
                foreach (System.IO.FileInfo fi in rgFiles)
                {
                    string[] databaseName = new string [1];
                    databaseName[0] = fi.Name.ToUpper().Replace(".DATA", "");
                    r.Add(databaseName);
                }

                channel.Commit();
            }
            else if (sToken.Equals("ALIAS"))
            {
                r          = new Result(2);
                r.Label[0] = "NAME";
                r.Type[0]  = ColumnType.VarChar;
                r.Label[1] = "LIBRARY";
                r.Type[1]  = ColumnType.VarChar;

                foreach (DictionaryEntry entry in _alias)
                {
                    string[] alias = new string [2];
                    alias[0] = entry.Key.ToString();
                    alias[1] = entry.Value.ToString();
                    r.Add(alias);
                }

                channel.Commit();
            }
            else if (sToken.Equals("PARAMETERS"))
            {
                string alias = tokenizer.GetString().ToUpper();

                if (!_alias.ContainsKey(alias))
                {
                    throw Trace.Error(Trace.UNKNOWN_FUNCTION, alias);
                }

                string fqn = _alias[alias].ToString();

                Function f = new Function(fqn, channel);

                System.Reflection.MethodInfo mi = f.GetMethodInfo(fqn);

                r          = new Result(4);
                r.Label[0] = "ALIAS";
                r.Type[0]  = ColumnType.VarChar;
                r.Label[1] = "PARAMETER";
                r.Type[1]  = ColumnType.VarChar;
                r.Label[2] = "TYPE";
                r.Type[2]  = ColumnType.VarChar;
                r.Label[3] = "POSITION";
                r.Type[3]  = ColumnType.Integer;

                System.Reflection.ParameterInfo[] parms = mi.GetParameters();

                int rt = 0;

                if (mi.ReturnType != null)
                {
                    object[] p = new object[4];
                    p[0] = alias;
                    p[1] = "RETURN_VALUE";
                    p[2] = Column.GetColumnTypeString(Function.GetDataType(mi.ReturnType));
                    p[3] = 0;
                    r.Add(p);
                    rt = 1;
                }

                foreach (System.Reflection.ParameterInfo pi in parms)
                {
                    object[] p = new object[4];
                    p[0] = alias;
                    p[1] = pi.Name;
                    p[2] = Column.GetColumnTypeString(Function.GetDataType(pi.ParameterType));
                    p[3] = (pi.Position + rt);
                    r.Add(p);
                }

                channel.Commit();
            }
            else if (sToken.Equals("COLUMNS"))
            {
                string t        = tokenizer.GetString().ToUpper();
                Table  theTable = null;

                foreach (Table table in channel.Database.Tables)
                {
                    if (table.Name.ToUpper() == t)
                    {
                        theTable = table;
                        break;
                    }
                }

                if (theTable == null)
                {
                    throw Trace.Error(Trace.TABLE_NOT_FOUND, t);
                }

                r          = new Result(7);
                r.Label[0] = "TABLE";
                r.Type[0]  = ColumnType.VarChar;
                r.Label[1] = "COLUMN";
                r.Type[1]  = ColumnType.VarChar;
                r.Label[2] = "NATIVETYPE";
                r.Type[2]  = ColumnType.VarChar;
                r.Label[3] = "DBTYPE";
                r.Type[3]  = ColumnType.Integer;
                r.Label[4] = "POSITION";
                r.Type[4]  = ColumnType.Integer;
                r.Label[5] = "NULLABLE";
                r.Type[5]  = ColumnType.Bit;
                r.Label[6] = "IDENTITY";
                r.Type[6]  = ColumnType.Bit;

                for (int ix = 0; ix < theTable.ColumnCount; ix++)
                {
                    Column   col     = theTable.GetColumn(ix);
                    object[] coldata = new object[7];
                    coldata[0] = theTable.Name;
                    coldata[1] = col.Name;
                    coldata[2] = Column.GetColumnTypeString(col.ColumnType);
                    coldata[3] = Column.GetDbType(col.ColumnType);
                    coldata[4] = ix;
                    coldata[5] = col.IsNullable;
                    coldata[6] = col.IsIdentity;
                    r.Add(coldata);
                }
                channel.Commit();
            }
            else
            {
                throw Trace.Error(Trace.UnexpectedToken, sToken);
            }

            return(r);
        }