Example #1
0
        /* REIMPLIMENTATION OF getTableDescription using sp_MS procedures */
        public override FieldDescriptor[] getTableDescription(string table)
        {
            try
            {
                System.Collections.Specialized.ListDictionary al = new System.Collections.Specialized.ListDictionary();
                System.Data.Odbc.OdbcDataReader odr = this._dbObj.getNewConnection().GetDatabaseConnector().getResult(String.Format("sp_MShelpcolumns '{0}'", this._dbObj.GetDatabaseConnector().DoTopLevelSqlTranslations(ref table)));

                Database iterationWorker = this._dbObj.getNewConnection();
                while (odr.Read())
                {
                    string fieldname = Convert.ToString(odr["col_name"]);
                    string fieldTypeStr = Convert.ToString(odr["col_typename"]);
                    int fieldMaxLen = Convert.ToInt32(odr["col_len"]);
                    string fieldAllowNull = Convert.ToString(odr["col_null"]); //0 = no, 1 = nullable
                    string isIdentity = Convert.ToString(odr["col_identity"]);
                    string isPrimaryKey = (this.isPKCol(this._dbObj.GetDatabaseConnector().DoTopLevelSqlTranslations(ref table),fieldname) == true) ? "True" : "False";
                    FieldDescriptor fd = new FieldDescriptor();
                    fd.name = fieldname;
                    fd.type = this.typeStrToField(fieldTypeStr).type;

                    fd.maxlen = fieldMaxLen;
                    System.Collections.ArrayList modList = new System.Collections.ArrayList();
                    if (fieldAllowNull.ToLower().Equals("false"))
                        modList.Add(ABSTRACTFIELDMODIFIERS.NotNull);
                    if (isPrimaryKey.ToLower().Equals("true"))
                        modList.Add(ABSTRACTFIELDMODIFIERS.PrimaryKey);
                    if (isIdentity.ToLower().Equals("true"))
                        modList.Add(ABSTRACTFIELDMODIFIERS.AutoIncrement);

                    fd.modifiers = new ABSTRACTFIELDMODIFIERS[modList.Count];
                    Array.Copy(modList.ToArray(), fd.modifiers, modList.Count);
                    //fd.defaultval = fieldDefaultVal;
                    al.Add(fd.name, fd);
                }

                odr = null;

                //odr.Close();
                FieldDescriptor[] returnArray = new FieldDescriptor[al.Count];
                //Array.Copy(al.Values., returnArray, al.Count);

                al.Values.CopyTo(returnArray, 0);
                if (returnArray.Length == 0) return null;
                //Array.Reverse(returnArray);

                return returnArray;
            }
            catch(Exception e)
            {
                System.Diagnostics.Debug.Print(e.Message);
            }
            return null;
        }
Example #2
0
        public override FieldDescriptor[] getTableDescription(string table)
        {
            try
            {
                System.Collections.ArrayList al = new System.Collections.ArrayList(5);
                System.Data.Odbc.OdbcDataReader odr = this._dbObj.GetDatabaseConnector().getResult(String.Format("describe {0};", table));
                while (odr.Read())
                {
                    string fieldname = Convert.ToString(odr[0]);
                    string fieldTypeStr = Convert.ToString(odr[1]);
                    string fieldAllowNull = Convert.ToString(odr[2]);
                    string fieldKeyType = Convert.ToString(odr[3]);
                    string fieldDefaultVal = Convert.ToString(odr[4]);
                    string fieldExtraFlags = Convert.ToString(odr[5]);
                    FieldDescriptor fd = new FieldDescriptor();
                    fd.name = fieldname;
                    fd.type = this._dbObj.GetDatabaseProvider().typeStrToField(fieldTypeStr).type;
                    fd.maxlen = this._dbObj.GetDatabaseProvider().typeStrToField(fieldTypeStr).maxsize;

                    System.Collections.ArrayList modList = new System.Collections.ArrayList();
                    if (!fieldAllowNull.Equals("YES"))
                        modList.Add(ABSTRACTFIELDMODIFIERS.NotNull);
                    if (fieldKeyType.Equals("PRI"))
                        modList.Add(ABSTRACTFIELDMODIFIERS.PrimaryKey);
                    if (fieldKeyType.Equals("MUL"))
                        modList.Add(ABSTRACTFIELDMODIFIERS.IndexKey);
                    if (fieldExtraFlags.Contains("auto_increment"))
                        modList.Add(ABSTRACTFIELDMODIFIERS.AutoIncrement);
                    fd.modifiers = new ABSTRACTFIELDMODIFIERS[modList.Count];
                    Array.Copy(modList.ToArray(), fd.modifiers, modList.Count);
                    fd.defaultval = fieldDefaultVal;
                    al.Add(fd);

                }
                odr.Close();
                FieldDescriptor[] returnArray = new FieldDescriptor[al.Count];
                Array.Copy(al.ToArray(), returnArray, al.Count);
                return returnArray;
            }
            catch(Exception e)
            {
                System.Diagnostics.Debug.Print(e.Message);
                return null;
            }
        }
Example #3
0
        public override FieldDescriptor[] getTableDescription(string table)
        {
            table = this._dbObj.GetDatabaseConnector().DoTopLevelSqlTranslations(ref table);
            System.Data.DataTable f = new System.Data.DataTable(table);
            string[] restrictions = new string[4]
            { this._dbObj.GetDatabaseConnector().svrinfo._database, null, table, null };

            f = this._dbObj.GetDatabaseConnector().GetRawConnectionObject().GetSchema("Columns", restrictions);
            System.Collections.ArrayList al = new System.Collections.ArrayList(5);

            foreach (System.Data.DataRow odr in f.Rows)
            {

                FieldDescriptor fd = new FieldDescriptor();
                fd.name = Convert.ToString(odr[3]);
                fd.maxlen = Convert.ToInt32(odr[6]);
                fd.type = this._dbObj.GetDatabaseProvider().typeStrToField(Convert.ToString(odr[5])).type;
                System.Collections.ArrayList modList = new System.Collections.ArrayList();
                if (!Convert.ToString(odr[10]).Equals("1"))
                    modList.Add(ABSTRACTFIELDMODIFIERS.NotNull);
                if (Convert.ToString(odr[5]).Equals("COUNTER"))
                    modList.Add(ABSTRACTFIELDMODIFIERS.PrimaryKey);
                fd.modifiers = new ABSTRACTFIELDMODIFIERS[modList.Count];
                Array.Copy(modList.ToArray(), fd.modifiers, modList.Count);
                al.Add(fd);
            }

            FieldDescriptor[] returnArray = new FieldDescriptor[al.Count];
            Array.Copy(al.ToArray(), returnArray, al.Count);
            if (returnArray.Length == 0) return null;
            return returnArray;
        }
Example #4
0
        public override FieldDescriptor[] getTableDescription(string table)
        {
            try
            {
                System.Collections.ArrayList al = new System.Collections.ArrayList(5);

                string tableSQL = (string)this._dbObj.GetDatabaseConnector().getSingleVal("select sql from sqlite_master where name like \"" + table + "\"");

                string fieldString = tableSQL.Substring(tableSQL.IndexOf("(")+1);
                fieldString = fieldString.Substring(0, fieldString.LastIndexOf(")"));
                string[] fields = fieldString.Split(',');

                foreach(string TfieldStr in fields)
                {
                    string fieldStr = TfieldStr.Trim();
                    AField srcField = this.typeStrToField(fieldStr.Substring(fieldStr.IndexOf(" ")));
                    srcField.name = fieldStr.Substring(0, fieldStr.IndexOf(" "));
                    FieldDescriptor fd = new FieldDescriptor();
                    fd.name = srcField.name;
                    fd.type = srcField.type;
                    fd.maxlen = srcField.maxsize;
                    fd.modifiers = srcField.modifiers;

                    fd.defaultval = srcField.defaultval;
                    al.Add(fd);

                }
                FieldDescriptor[] returnArray = new FieldDescriptor[al.Count];
                Array.Copy(al.ToArray(), returnArray, al.Count);
                return returnArray;
            }
            catch(Exception e)
            {
                System.Diagnostics.Debug.Print(e.Message);
                return null;
            }
        }