GetFieldType() public méthode

Gets the Type that is the data type of the object.
public GetFieldType ( int i ) : Type
i int
Résultat System.Type
        private MySqlSchemaCollection GetTable(string sql)
        {
            MySqlSchemaCollection c      = new MySqlSchemaCollection();
            MySqlCommand          cmd    = new MySqlCommand(sql, connection);
            MySqlDataReader       reader = cmd.ExecuteReader();

            // add columns
            for (int i = 0; i < reader.FieldCount; i++)
            {
                c.AddColumn(reader.GetName(i), reader.GetFieldType(i));
            }

            using (reader)
            {
                while (reader.Read())
                {
                    MySqlSchemaRow row = c.AddRow();
                    for (int i = 0; i < reader.FieldCount; i++)
                    {
                        row[i] = reader.GetValue(i);
                    }
                }
            }
            return(c);
        }
Exemple #2
0
        public static PyObject DBColumnToPyObject(int index, ref MySqlDataReader reader)
        {
            Type type = reader.GetFieldType(index);

            switch (type.Name)
            {
                case "String":
                    return new PyString(reader.GetString(index));
                case "UInt32":
                case "Int32":
                case "UInt16":
                case "Int16":
                case "SByte":
                case "Byte":
                    return new PyInt(reader.GetInt32(index));
                case "UInt64":
                case "Int64":
                    return new PyLongLong(reader.GetInt64(index));
                case "Byte[]":
                    return new PyBuffer((byte[])reader.GetValue(index));
                case "Double":
                    return new PyFloat(reader.GetDouble(index));
                case "Decimal":
                    return new PyFloat((double)reader.GetDecimal(index));
                case "Boolean":
                    return new PyBool(reader.GetBoolean(index));
                default:
                    Log.Error("Database", "Unhandled MySQL type " + type.Name);
                    break;
            }

            return null;
        }
        /// <summary>
        /// Gets CRUD schema from MySqlReader per particular QuerySource.
        /// If source is null then all columns from reader are copied.
        /// Note: this code was purposely made provider specific because other providers may treat some nuances differently
        /// </summary>
        public static Schema GetSchemaFromReader(string name, QuerySource source, MySqlDataReader reader)
        {
            var table = name;
               var fdefs = new List<Schema.FieldDef>();

               for (int i = 0; i < reader.FieldCount; i++)
               {
                    var fname = reader.GetName(i);
                    var ftype = reader.GetFieldType(i);

                    var def = new Schema.FieldDef(fname, ftype, source!=null ? ( source.HasPragma ? source.ColumnDefs[fname] : null) : null);
                    fdefs.Add( def );
               }

               if (source!=null)
                if (source.HasPragma && source.ModifyTarget.IsNotNullOrWhiteSpace()) table = source.ModifyTarget;

               if (table.IsNullOrWhiteSpace()) table = Guid.NewGuid().ToString();

               return new Schema(table, source!=null ? source.ReadOnly : true,  fdefs);
        }
        private MySqlSchemaCollection GetTable(string sql)
        {
            MySqlSchemaCollection mySqlSchemaCollection = new MySqlSchemaCollection();
            MySqlCommand          mySqlCommand          = new MySqlCommand(sql, this.connection);
            MySqlDataReader       mySqlDataReader       = mySqlCommand.ExecuteReader();

            for (int i = 0; i < mySqlDataReader.FieldCount; i++)
            {
                mySqlSchemaCollection.AddColumn(mySqlDataReader.GetName(i), mySqlDataReader.GetFieldType(i));
            }
            using (mySqlDataReader)
            {
                while (mySqlDataReader.Read())
                {
                    MySqlSchemaRow mySqlSchemaRow = mySqlSchemaCollection.AddRow();
                    for (int j = 0; j < mySqlDataReader.FieldCount; j++)
                    {
                        mySqlSchemaRow[j] = mySqlDataReader.GetValue(j);
                    }
                }
            }
            return(mySqlSchemaCollection);
        }
        public FieldType GetType(int index, ref MySqlDataReader reader)
        {
            Type type = reader.GetFieldType(index);

            switch (type.Name)
            {
                case "String":
                    return FieldType.Str;
                case "UInt32":
                    return FieldType.UI4;
                case "Int32":
                    return FieldType.I4;
                case "UInt16":
                    return FieldType.UI2;
                case "Int16":
                    return FieldType.I2;
                case "UInt64":
                    return FieldType.UI8;
                case "Int64":
                    return FieldType.I8;
                case "Byte[]":
                    return FieldType.Bytes;
                case "SByte":
                    return FieldType.I1; ;
                case "Double":
                    return FieldType.R8;
                case "Decimal":
                    return FieldType.R4;
                case "Boolean":
                    return FieldType.Bool;
                case "Byte":
                    return FieldType.UI1;
                default:
                    throw new Exception("Wrong FieldType");
            }
        }
Exemple #6
0
        /// <summary> 
        /// DataReader格式转换成DataTable 
        /// </summary> 
        /// <param name="DataReader">OleDbDataReader</param> 
        private DataTable GetConvertDataReaderToDataTable(MySqlDataReader reader)
        {
            DataTable objDataTable = new DataTable("TmpDataTable");
            int intCounter;

            try
            {
                //获取当前行中的列数;
                int intFieldCount = reader.FieldCount;

                for (intCounter = 0; intCounter <= intFieldCount - 1; intCounter++)
                {
                    objDataTable.Columns.Add(reader.GetName(intCounter), reader.GetFieldType(intCounter));
                }

                //populate   datatable
                objDataTable.BeginLoadData();

                //object[]   objValues   =   new   object[intFieldCount   -1];
                object[] objValues = new object[intFieldCount];

                while (reader.Read())
                {
                    reader.GetValues(objValues);
                    objDataTable.LoadDataRow(objValues, true);
                }
                reader.Close();

                objDataTable.EndLoadData();

                return objDataTable;

            }
            catch (MySqlException ex)
            {
                throw ex;
            }
        }