Beispiel #1
0
        public ArrayList GetTableColumns(string tableName)
        {
            if (metadataCache.ContainsKey(this.htkey + ":" + tableName + ":Columns"))
            {
                return((ArrayList)metadataCache[this.htkey + ":" + tableName + ":Columns"]);
            }
            Connection target = new ConnectionClass();

            target.GetType().InvokeMember("Open", BindingFlags.InvokeMethod, null, target, new object[] { this.connectionString });
            if ((this.defaultDatabase != null) && (this.defaultDatabase != ""))
            {
                target.DefaultDatabase = this.defaultDatabase;
            }
            string str = tableName;

            if (tableName.IndexOf(".") > 0)
            {
                string[] strArray = tableName.Split(new char[] { '.' });
                if (strArray.Length == 2)
                {
                    str = strArray[1];
                }
            }
            object[] objArray3 = new object[4];
            objArray3[2] = tableName;
            object[] objArray = objArray3;
            objArray3    = new object[3];
            objArray3[2] = str;
            object[]  restrictions = objArray3;
            Recordset recordset    = target.OpenSchema(SchemaEnum.adSchemaColumns, restrictions, Missing.Value);
            ArrayList list         = new ArrayList();

            while (!recordset.EOF)
            {
                string            str2     = recordset.Fields["COLUMN_NAME"].Value.ToString();
                DataFieldMetadata metadata = new DataFieldMetadata(recordset.Fields["TABLE_NAME"].Value.ToString(), recordset.Fields["COLUMN_NAME"].Value.ToString(), recordset.Fields["DATA_TYPE"].Value.ToString());
                if (recordset.Fields["CHARACTER_MAXIMUM_LENGTH"].Value != null)
                {
                    string s = recordset.Fields["CHARACTER_MAXIMUM_LENGTH"].Value.ToString();
                    if (s != string.Empty)
                    {
                        metadata.Size = int.Parse(s);
                    }
                }
                try
                {
                    metadata.IsNullable = bool.Parse(recordset.Fields["IS_NULLABLE"].Value.ToString());
                }
                catch
                {
                    metadata.IsNullable = false;
                }
                list.Add(metadata);
                recordset.MoveNext();
            }
            metadataCache.Add(this.htkey + ":" + tableName + ":Columns", list);
            recordset.Close();
            target.Close();
            return(list);
        }
Beispiel #2
0
        public DataFieldMetadata[] GetRecordsetSchema(string query)
        {
            string[]  names     = Enum.GetNames(typeof(DataTypeEnum));
            Array     values    = Enum.GetValues(typeof(DataTypeEnum));
            Recordset recordset = this.ReturnRecordSet(query);

            DataFieldMetadata[] metadataArray = new DataFieldMetadata[recordset.Fields.Count];
            for (int i = 0; i < recordset.Fields.Count; i++)
            {
                int    index = Array.IndexOf <string>(names, recordset.Fields[i].Type.ToString());
                object obj2  = values.GetValue(index);
                metadataArray[i]      = new DataFieldMetadata("tempTable", recordset.Fields[i].Name, obj2);
                metadataArray[i].Size = recordset.Fields[i].DefinedSize;
            }
            recordset.Close();
            this.FreeTempConnection();
            return(metadataArray);
        }