static MultiPartTableName()
 {
     string[] parts = new string[4];
     Null = new MultiPartTableName(parts);
 }
Ejemplo n.º 2
0
        private bool TryProcessOneTable(TdsParserStateObject stateObj, ref int length, out MultiPartTableName multiPartTableName)
        {
            ushort tableLen;
            MultiPartTableName mpt;
            string value;

            multiPartTableName = default(MultiPartTableName);

            mpt = new MultiPartTableName();
            byte nParts;

            // Find out how many parts in the TDS stream
            if (!stateObj.TryReadByte(out nParts))
            {
                return false;
            }
            length--;
            if (nParts == 4)
            {
                if (!stateObj.TryReadUInt16(out tableLen))
                {
                    return false;
                }
                length -= 2;
                if (!stateObj.TryReadString(tableLen, out value))
                {
                    return false;
                }
                mpt.ServerName = value;
                nParts--;
                length -= (tableLen * 2); // wide bytes
            }
            if (nParts == 3)
            {
                if (!stateObj.TryReadUInt16(out tableLen))
                {
                    return false;
                }
                length -= 2;
                if (!stateObj.TryReadString(tableLen, out value))
                {
                    return false;
                }
                mpt.CatalogName = value;
                length -= (tableLen * 2); // wide bytes
                nParts--;
            }
            if (nParts == 2)
            {
                if (!stateObj.TryReadUInt16(out tableLen))
                {
                    return false;
                }
                length -= 2;
                if (!stateObj.TryReadString(tableLen, out value))
                {
                    return false;
                }
                mpt.SchemaName = value;
                length -= (tableLen * 2); // wide bytes
                nParts--;
            }
            if (nParts == 1)
            {
                if (!stateObj.TryReadUInt16(out tableLen))
                {
                    return false;
                }
                length -= 2;
                if (!stateObj.TryReadString(tableLen, out value))
                {
                    return false;
                }
                mpt.TableName = value;
                length -= (tableLen * 2); // wide bytes
                nParts--;
            }
            Debug.Assert(nParts == 0, "ProcessTableName:Unidentified parts in the table name token stream!");

            multiPartTableName = mpt;
            return true;
        }
Ejemplo n.º 3
0
        internal bool TryProcessTableName(int length, TdsParserStateObject stateObj, out MultiPartTableName[] multiPartTableNames) {
            int tablesAdded = 0;

            MultiPartTableName[] tables = new MultiPartTableName[1];
            MultiPartTableName mpt;
            while (length > 0) {
                // 


                if (!TryProcessOneTable(stateObj, ref length, out mpt)) {
                    multiPartTableNames = null;
                    return false;
                }
                if (tablesAdded == 0) {
                    tables[tablesAdded] = mpt;
                }
                else {
                    MultiPartTableName[] newTables = new MultiPartTableName[tables.Length + 1];
                    Array.Copy(tables, 0, newTables, 0, tables.Length);
                    newTables[tables.Length] = mpt;
                    tables = newTables;
                }

                tablesAdded++;
            }

            multiPartTableNames = tables;
            return true;
        }
 static MultiPartTableName()
 {
     string[] parts = new string[4];
     Null = new MultiPartTableName(parts);
 }
 internal MultiPartTableName[] ProcessTableName(int length, TdsParserStateObject stateObj)
 {
     int index = 0;
     MultiPartTableName[] sourceArray = new MultiPartTableName[1];
     while (length > 0)
     {
         MultiPartTableName name = this.ProcessOneTable(stateObj, ref length);
         if (index == 0)
         {
             sourceArray[index] = name;
         }
         else
         {
             MultiPartTableName[] destinationArray = new MultiPartTableName[sourceArray.Length + 1];
             Array.Copy(sourceArray, 0, destinationArray, 0, sourceArray.Length);
             destinationArray[sourceArray.Length] = name;
             sourceArray = destinationArray;
         }
         index++;
     }
     return sourceArray;
 }
        private MultiPartTableName ProcessOneTable(TdsParserStateObject stateObj, ref int length)
        {
            ushort num;
            if (this._isShilohSP1)
            {
                MultiPartTableName name = new MultiPartTableName();
                byte num2 = stateObj.ReadByte();
                length--;
                switch (num2)
                {
                    case 4:
                        num = stateObj.ReadUInt16();
                        length -= 2;
                        name.ServerName = stateObj.ReadString(num);
                        num2 = (byte) (num2 - 1);
                        length -= num * 2;
                        break;

                    case 3:
                        num = stateObj.ReadUInt16();
                        length -= 2;
                        name.CatalogName = stateObj.ReadString(num);
                        length -= num * 2;
                        num2 = (byte) (num2 - 1);
                        break;

                    case 2:
                        num = stateObj.ReadUInt16();
                        length -= 2;
                        name.SchemaName = stateObj.ReadString(num);
                        length -= num * 2;
                        num2 = (byte) (num2 - 1);
                        break;

                    case 1:
                        num = stateObj.ReadUInt16();
                        length -= 2;
                        name.TableName = stateObj.ReadString(num);
                        length -= num * 2;
                        num2 = (byte) (num2 - 1);
                        break;
                }
                return name;
            }
            num = stateObj.ReadUInt16();
            length -= 2;
            string str = stateObj.ReadString(num);
            length -= num * 2;
            return new MultiPartTableName(MultipartIdentifier.ParseMultipartIdentifier(str, "[\"", "]\"", "SQL_TDSParserTableName", false));
        }