コード例 #1
0
        public CRowset(DBRowDescriptor descriptor)
        {
            this.Header = descriptor;
            this.Rows   = new PyList();

            this.PrepareColumnNames();
        }
コード例 #2
0
        public CRowset(DBRowDescriptor descriptor, PyList rows)
        {
            this.Header = descriptor;
            this.Rows   = rows;

            this.PrepareColumnNames();
        }
コード例 #3
0
ファイル: PyPackedRow.cs プロジェクト: lanicon/EVESharp
        public PyPackedRow(DBRowDescriptor descriptor, Dictionary <string, PyDataType> values)
        {
            this.Header = descriptor;

            if (values.Count != this.Header.Columns.Count)
            {
                throw new Exception("PackedRow must have the same value count as DBRowDescriptor");
            }

            this.mValues = values;
        }
コード例 #4
0
        /// <summary>
        /// Simple helper method that creates the correct PackedRowList data off a result row and
        /// returns it's PyDataType representation, ready to be sent to the EVE Online client
        /// </summary>
        /// <param name="reader"></param>
        public static PyList FromMySqlDataReader(MySqlDataReader reader)
        {
            DBRowDescriptor descriptor = DBRowDescriptor.FromMySqlReader(reader);
            PyList          list       = new PyList();

            while (reader.Read() == true)
            {
                list.Add(PyPackedRow.FromMySqlDataReader(reader, descriptor));
            }

            return(list);
        }
コード例 #5
0
        /// <summary>
        /// Simple helper method that creates the correct PackedRowList data off a result row and
        /// returns it's PyDataType representation, ready to be sent to the EVE Online client
        /// </summary>
        /// <param name="connection">The connection used</param>
        /// <param name="reader"></param>
        public static PyList <PyPackedRow> FromMySqlDataReader(IDatabaseConnection connection, MySqlDataReader reader)
        {
            DBRowDescriptor      descriptor = DBRowDescriptor.FromMySqlReader(connection, reader);
            PyList <PyPackedRow> list       = new PyList <PyPackedRow>();

            while (reader.Read() == true)
            {
                list.Add(PyPackedRow.FromMySqlDataReader(reader, descriptor));
            }

            return(list);
        }
コード例 #6
0
        /// <summary>
        /// Simple helper method that creates a correct IntegerIntegerListDictionary and returns
        /// it's PyDataType representation, ready to be sent to the EVE Online client
        ///
        /// IMPORTANT: The first field MUST be ordered (direction doesn't matter) for this method
        /// to properly work
        /// </summary>
        /// <param name="connection">The connection used</param>
        /// <param name="reader">The MySqlDataReader to read the data from</param>
        /// <param name="keyColumnIndex">The column to use as index for the IntPackedRowListDictionary</param>
        /// <returns></returns>
        public static PyDataType FromMySqlDataReader(IDatabaseConnection connection, MySqlDataReader reader, int keyColumnIndex)
        {
            DBRowDescriptor descriptor = DBRowDescriptor.FromMySqlReader(connection, reader);
            PyDictionary    result     = new PyDictionary();

            Type keyType = reader.GetFieldType(keyColumnIndex);

            if (keyType != typeof(long) && keyType != typeof(int) && keyType != typeof(short) &&
                keyType != typeof(byte) && keyType != typeof(ulong) && keyType != typeof(uint) &&
                keyType != typeof(ushort) && keyType != typeof(sbyte))
            {
                throw new InvalidDataException("Expected key type of integer");
            }

            // get first key and start preparing the values
            int key = 0;

            PyList currentList = new PyList();

            while (reader.Read() == true)
            {
                // ignore null keys
                if (reader.IsDBNull(keyColumnIndex) == true)
                {
                    continue;
                }

                int newKey = reader.GetInt32(keyColumnIndex);

                // if the read key doesn't match the one read earlier
                if (newKey != key)
                {
                    // do not add an entry to the dict unless the old id was present
                    if (key != 0)
                    {
                        result[key] = currentList;
                    }

                    currentList = new PyList();
                    key         = newKey;
                }

                // add the current value to the list
                currentList.Add(PyPackedRow.FromMySqlDataReader(reader, descriptor));
            }

            // ensure the last key is saved to the list
            result[key] = currentList;

            return(result);
        }
コード例 #7
0
        public PyPackedRow(DBRowDescriptor descriptor, PyDataType[] values) : base(PyObjectType.PackedRow)
        {
            this.Header = descriptor;

            if (values.Length != this.Header.Columns.Count)
            {
                throw new Exception("PackedRow must have the same value count as DBRowDescriptor");
            }

            int index = 0;

            foreach (DBRowDescriptor.Column column in descriptor.Columns)
            {
                switch (column.Type)
                {
                case FieldType.I1:
                case FieldType.I2:
                case FieldType.I4:
                case FieldType.I8:
                case FieldType.UI1:
                case FieldType.UI2:
                case FieldType.UI4:
                case FieldType.UI8:
                case FieldType.FileTime:
                case FieldType.CY:
                    this.mValues.Add(column.Name, values[index++] as PyInteger);
                    break;

                case FieldType.Bool:
                    this.mValues.Add(column.Name, values[index++] as PyBool);
                    break;

                case FieldType.Bytes:
                    this.mValues.Add(column.Name, values[index++] as PyBuffer);
                    break;

                case FieldType.WStr:
                case FieldType.Str:
                    this.mValues.Add(column.Name, values[index++] as PyString);
                    break;

                case FieldType.Null:
                    this.mValues.Add(column.Name, values[index++] as PyNone);
                    break;

                default:
                    throw new Exception($"Unknown column type {column.Type}");
                }
            }
        }
コード例 #8
0
ファイル: DBRowDescriptor.cs プロジェクト: sn0opy/EVESharp
        /// <summary>
        /// Creates a new DBRowDescriptor based off a specific result set from a MySqlDataReader
        /// </summary>
        /// <param name="reader">The MySqlDataReader to use when creating the DBRowDescriptor</param>
        /// <returns>Instance of a new DBRowDescriptor</returns>
        /// <exception cref="InvalidDataException">If any error was found on the creation</exception>
        public static DBRowDescriptor FromMySqlReader(MySqlDataReader reader)
        {
            DBRowDescriptor descriptor = new DBRowDescriptor();

            for (int i = 0; i < reader.FieldCount; i++)
            {
                FieldType fieldType = Utils.GetFieldType(reader, i);

                descriptor.Columns.Add(
                    new Column(reader.GetName(i), fieldType)
                    );
            }

            return(descriptor);
        }
コード例 #9
0
ファイル: DBRowDescriptor.cs プロジェクト: ozatomic/EVESharp
        /// <summary>
        /// Creates a new DBRowDescriptor based off a specific result set from a MySqlDataReader
        /// </summary>
        /// <param name="reader">The MySqlDataReader to use when creating the DBRowDescriptor</param>
        /// <returns>Instance of a new DBRowDescriptor</returns>
        /// <exception cref="InvalidDataException">If any error was found on the creation</exception>
        public static DBRowDescriptor FromMySqlReader(MySqlDataReader reader)
        {
            DBRowDescriptor descriptor = new DBRowDescriptor();

            for (int i = 0; i < reader.FieldCount; i++)
            {
                Type      type      = reader.GetFieldType(i);
                FieldType fieldType = FieldType.Error;

                if (type == typeof(string))
                {
                    // TODO: PROPERLY SPECIFY THE STRING TYPE
                    fieldType = FieldType.WStr;
                }
                else if (type == typeof(ulong))
                {
                    fieldType = FieldType.UI8;
                }
                else if (type == typeof(long))
                {
                    fieldType = FieldType.I8;
                }
                else if (type == typeof(uint))
                {
                    fieldType = FieldType.UI4;
                }
                else if (type == typeof(int))
                {
                    fieldType = FieldType.I4;
                }
                else if (type == typeof(ushort))
                {
                    fieldType = FieldType.UI2;
                }
                else if (type == typeof(short))
                {
                    fieldType = FieldType.I2;
                }
                else if (type == typeof(sbyte))
                {
                    fieldType = FieldType.I1;
                }
                else if (type == typeof(byte))
                {
                    fieldType = FieldType.UI1;
                }
                else if (type == typeof(byte[]))
                {
                    fieldType = FieldType.Bytes;
                }
                else if (type == typeof(double))
                {
                    fieldType = FieldType.R8;
                }
                else if (type == typeof(float))
                {
                    fieldType = FieldType.R4;
                }
                else if (type == typeof(bool))
                {
                    fieldType = FieldType.Bool;
                }
                else
                {
                    throw new InvalidDataException("Unknown field type");
                }

                descriptor.Columns.Add(
                    new Column(reader.GetName(i), fieldType)
                    );
            }

            return(descriptor);
        }
コード例 #10
0
 public PyPackedRow(DBRowDescriptor descriptor) : base(PyObjectType.PackedRow)
 {
     this.Header = descriptor;
 }
コード例 #11
0
ファイル: PyPackedRow.cs プロジェクト: lanicon/EVESharp
 public PyPackedRow(DBRowDescriptor descriptor)
 {
     this.Header = descriptor;
 }