Exemplo n.º 1
0
        public PreparedContext(uint statementId, SqlStringTemplate sqlStringTemplate, TableHeader tableHeader)
        {
            this.statementId   = statementId;
            _sqlStringTemplate = sqlStringTemplate;
            _keys = _sqlStringTemplate.GetValueKeys();
            //----------------------------------------------
            _tableHeader = tableHeader;
            int serverFieldCount = tableHeader.ColumnCount;
            //add field information to _keys
            List <FieldPacket> fields = tableHeader.GetFields();
            //----------------------------------------------
            int bindingCount = 0;

            for (int i = 0; i < serverFieldCount; ++i)
            {
                FieldPacket f = fields[i];
                if (f.name == "?") //
                {
                    //this is binding field
                    _keys[bindingCount].fieldInfo = f;
                    bindingCount++;
                }
            }
            //some field from server is not binding field
            //so we select only binding field
            if (bindingCount != _keys.Count)
            {
                throw new Exception("key num not matched!");
            }
            //-------------------------------------------------
            _preparedValues = new MyStructData[bindingCount]; //***
        }
Exemplo n.º 2
0
        public override void ParsePacket(PacketParser parser)
        {
            var fieldInfos  = _tableHeader.GetFields();
            int columnCount = _tableHeader.ColumnCount;

            ParsePacketHeader(parser);
            parser.ParseFiller(1);                         //skip start packet byte [00]
            parser.ParseFiller((columnCount + 7 + 2) / 8); //skip null-bitmap, length:(column-count+7+2)/8
            for (int i = 0; i < columnCount; i++)
            {
                ParseValues(parser, fieldInfos[i], ref _myDataList[i]);
            }
        }
Exemplo n.º 3
0
        public void Setup(TableHeader tableHeader)
        {
            _tableHeader = tableHeader;

            int fieldCount = tableHeader.ColumnCount;

            _preparedValues = new MyStructData[fieldCount];


            if (_keys.Count != fieldCount)
            {
                throw new Exception("key num not matched!");
            }
            //add field information to _keys

            List <FieldPacket> fields = tableHeader.GetFields();

            for (int i = 0; i < fieldCount; ++i)
            {
                _keys[i].fieldInfo = fields[i];
            }
        }
Exemplo n.º 4
0
 public PreparedContext(uint statementId, SqlStringTemplate sqlStringTemplate, TableHeader tableHeader)
 {
     this.statementId = statementId;
     _sqlStringTemplate = sqlStringTemplate;
     _keys = _sqlStringTemplate.GetValueKeys();
     //----------------------------------------------
     _tableHeader = tableHeader;
     int serverFieldCount = tableHeader.ColumnCount;
     //add field information to _keys
     List<FieldPacket> fields = tableHeader.GetFields();
     //----------------------------------------------
     int bindingCount = 0;
     for (int i = 0; i < serverFieldCount; ++i)
     {
         FieldPacket f = fields[i];
         if (f.name == "?") //
         {
             //this is binding field
             _keys[bindingCount].fieldInfo = f;
             bindingCount++;
         }
     }
     //some field from server is not binding field
     //so we select only binding field
     if (bindingCount != _keys.Count)
     {
         throw new Exception("key num not matched!");
     }
     //-------------------------------------------------
     _preparedValues = new MyStructData[bindingCount]; //***
 }
Exemplo n.º 5
0
        public override void ParsePacket(PacketParser parser)
        {
            //function parse(parser, fieldPackets, typeCast, nestTables, connection) {
            //  var self = this;
            //  var next = function () {
            //    return self._typeCast(fieldPacket, parser, connection.config.timezone, connection.config.supportBigNumbers, connection.config.bigNumberStrings, connection.config.dateStrings);
            //  };

            //  for (var i = 0; i < fieldPackets.length; i++) {
            //    var fieldPacket = fieldPackets[i];
            //    var value;


            //---------------------------------------------
            //danger!
            //please note that  ***
            //data in each slot is not completely cleared

            //because we don't want to copy entire MyStructData back and forth
            //we just replace some part of it ***
            //---------------------------------------------


            ParsePacketHeader(parser);

            var  fieldInfos = _tableHeader.GetFields();
            int  j          = _tableHeader.ColumnCount;
            bool typeCast   = _tableHeader.TypeCast;
            bool nestTables = _tableHeader.NestTables;

            if (!nestTables && typeCast)
            {
                for (int i = 0; i < j; i++)
                {
                    ReadCellWithTypeCast(parser, fieldInfos[i], ref _myDataList[i]);
                }
            }
            else
            {
                //may be nestTables or type cast
                //

                for (int i = 0; i < j; i++)
                {
                    // MyStructData value;
                    if (typeCast)
                    {
                        ReadCellWithTypeCast(parser, fieldInfos[i], ref _myDataList[i]);
                    }
                    else if (fieldInfos[i].charsetNr == (int)CharSets.BINARY)
                    {
                        _myDataList[i].myBuffer = parser.ParseLengthCodedBuffer();
                        _myDataList[i].type     = (Types)fieldInfos[i].type;

                        //value = new MyStructData();
                        //value.myBuffer = parser.ParseLengthCodedBuffer();
                        //value.type = (Types)fieldInfos[i].type;
                    }
                    else
                    {
                        _myDataList[i].myString = parser.ParseLengthCodedString();
                        _myDataList[i].type     = (Types)fieldInfos[i].type;

                        //value = new MyStructData();
                        //value.myString = parser.ParseLengthCodedString();
                        //value.type = (Types)fieldInfos[i].type;
                    }
                    //    if (typeof typeCast == "function") {
                    //      value = typeCast.apply(connection, [ new Field({ packet: fieldPacket, parser: parser }), next ]);
                    //    } else {
                    //      value = (typeCast)
                    //        ? this._typeCast(fieldPacket, parser, connection.config.timezone, connection.config.supportBigNumbers, connection.config.bigNumberStrings, connection.config.dateStrings)
                    //        : ( (fieldPacket.charsetNr === Charsets.BINARY)
                    //          ? parser.parseLengthCodedBuffer()
                    //          : parser.parseLengthCodedString() );
                    //    }


                    //TODO: review here
                    //nestTables=?


                    //if (nestTables)
                    //{
                    //    //      this[fieldPacket.table] = this[fieldPacket.table] || {};
                    //    //      this[fieldPacket.table][fieldPacket.name] = value;
                    //}
                    //else
                    //{
                    //    //      this[fieldPacket.name] = value;
                    //    myDataList[i] = value;
                    //}


                    //    if (typeof nestTables == "string" && nestTables.length) {
                    //      this[fieldPacket.table + nestTables + fieldPacket.name] = value;
                    //    } else if (nestTables) {
                    //      this[fieldPacket.table] = this[fieldPacket.table] || {};
                    //      this[fieldPacket.table][fieldPacket.name] = value;
                    //    } else {
                    //      this[fieldPacket.name] = value;
                    //    }
                    //  }
                    //}
                }
            }
        }