Example #1
0
 internal override void PrepareRead(NpgsqlBuffer buf, FieldDescription fieldDescription, int len)
 {
     if (fieldDescription.IsBinaryFormat) {
         throw new NotSupportedException("The type {0} currently unknown to Npgsql. You can retrieve it as a string by marking it as unknown, please see the FAQ.");
     }
     base.PrepareRead(buf, fieldDescription, len);
 }
Example #2
0
 internal override void PrepareRead(NpgsqlBuffer buf, FieldDescription fieldDescription, int len)
 {
     if (fieldDescription.IsBinaryFormat) {
         buf.Skip(len);
         throw new SafeReadException(new NotSupportedException(String.Format("The field {0} has a type currently unknown to Npgsql (OID {1}). You can retrieve it as a string by marking it as unknown, please see the FAQ.", fieldDescription.Name, fieldDescription.OID)));
     }
     base.PrepareRead(buf, fieldDescription, len);
 }
Example #3
0
        void ReadArray( ref FieldDescription field )
        {
            byte typeCode = reader.ReadByte();
            if( typeCode == TC_NULL ) return;
            if( typeCode != TC_ARRAY ) ParseError( TC_ARRAY, typeCode );

            ClassDescription desc = ReadClassDescription();
            field.Value = reader.ReadBytes( ReadInt32() );
        }
Example #4
0
 private static string[] GetFieldsNames(FieldDescription[] fields)
 {
     var returnValue = new string[fields.Length];
     for (int index = 0; index < fields.Length; index++)
     {
         returnValue[index] = fields[index].Name;
     }
     return returnValue;
 }
 /// <summary>
 /// 建構式,傳入資料驗證欄位定義,若傳入null則會將相關屬設為空白或是false。
 /// </summary>
 /// <param name="Field"></param>
 public FieldValidatedDescription(FieldDescription Field)
 {
     if (Field != null)
     {
         this.EmptyAlsoValidate = Field.EmptyAlsoValidate;
         this.Name = Field.Name;
         this.Required = Field.Required;
     }
     else
     {
         this.EmptyAlsoValidate = false;
         this.Name = string.Empty;
         this.Required = false;
         this.InSource = false;
         this.InDefinition = false;
     }
 }
		public void AddModifyDeleteFieldDescription()
		{
			FieldDescription fd = new FieldDescription(Cache)
			{	Class = 1,
				Name = "TESTJUNK___NotPresent",
				Type = CellarPropertyType.Boolean
			};
			Assert.AreEqual(fd.Custom, 1, "Wrong value for Custom column in new FD.");
			Assert.AreEqual(0, fd.Id, "new field should not have been assigned a flid yet");

			int flid;
			try
			{
				flid = m_mdc.GetFieldId2(fd.Class, fd.Name, true);
			}
			catch (FDOInvalidFieldException)
			{
				flid = 0;	// the new implementation throws instead of returning zero.
			}
			Assert.AreEqual(0, flid, "new field should not exist");

			fd.UpdateCustomField();
			flid = m_mdc.GetFieldId2(fd.Class, fd.Name, true);
			Assert.AreNotEqual(0, fd.Id, "field should have been assigned a flid");
			Assert.AreEqual(fd.Id, flid, "new field should exist");

			string hs = "Abandon hope all ye who enter here.";
			fd.HelpString = hs;
			fd.UpdateCustomField();
			string help = m_mdc.GetFieldHelp(fd.Id);
			Assert.AreEqual(hs, help, "Help string should have been updated");

			fd.MarkForDeletion = true;
			fd.UpdateCustomField();
			try
			{
				flid = m_mdc.GetFieldId2(fd.Class, fd.Name, true);
			}
			catch (FDOInvalidFieldException)
			{
				flid = 0;	// the new implementation throws instead of returning zero.
			}
			Assert.AreEqual(0, flid, "new field should have been deleted");
		}
        NpgsqlDbColumn SetUpNonColumnField(FieldDescription field)
        {
            var columnName = field.Name.StartsWith("?column?") ? null : field.Name;
            var column = new NpgsqlDbColumn
            {
                ColumnName = columnName,
                BaseCatalogName = _connection.Database,
                BaseColumnName = columnName,
                BaseServerName = _connection.Host,
                IsReadOnly = true,
                DataTypeName = field.DataTypeName,
                TypeOID = field.TypeOID,
                TableOID = field.TableOID,
                ColumnAttributeNumber = field.ColumnAttributeNumber
            };

            ColumnPostConfig(column, field.TypeModifier);

            return column;
        }
Example #8
0
 long INpgsqlSimpleTypeHandler <long> .Read(NpgsqlReadBuffer buf, int len, [CanBeNull] FieldDescription fieldDescription)
 => (long)Read(buf, len, fieldDescription);
 /// <summary>
 /// Reads a column as the type handler's provider-specific type, assuming that it is already entirely
 /// in memory (i.e. no I/O is necessary). Called by <see cref="NpgsqlDefaultDataReader"/>, which
 /// buffers entire rows in memory.
 /// </summary>
 internal virtual object ReadPsvAsObject(NpgsqlReadBuffer buf, int len, FieldDescription fieldDescription = null)
 => ReadAsObject(buf, len, fieldDescription);
Example #10
0
 NpgsqlDateTime ISimpleTypeReader <NpgsqlDateTime> .Read(NpgsqlBuffer buf, int len, FieldDescription fieldDescription)
 {
     return(ReadTimeStamp(buf, len, fieldDescription));
 }
 /// <summary>
 /// Reads a value of type <typeparamref name="T"/> with the given length from the provided buffer,
 /// using either sync or async I/O.
 /// </summary>
 /// <param name="buf">The buffer from which to read.</param>
 /// <param name="len">The byte length of the value. The buffer might not contain the full length, requiring I/O to be performed.</param>
 /// <param name="async">If I/O is required to read the full length of the value, whether it should be performed synchronously or asynchronously.</param>
 /// <param name="fieldDescription">Additional PostgreSQL information about the type, such as the length in varchar(30).</param>
 /// <returns>The fully-read value.</returns>
 protected internal abstract Task <T> Read <T>(NpgsqlReadBuffer buf, int len, bool async, FieldDescription fieldDescription = null);
 /// <summary>
 /// Reads a column as the type handler's default read type, assuming that it is already entirely
 /// in memory (i.e. no I/O is necessary). Called by <see cref="NpgsqlDefaultDataReader"/>, which
 /// buffers entire rows in memory.
 /// </summary>
 internal abstract object ReadAsObject(NpgsqlReadBuffer buf, int len, FieldDescription fieldDescription = null);
Example #13
0
 public IPAddress Read(NpgsqlBuffer buf, FieldDescription fieldDescription, int len)
 {
     return(((ISimpleTypeReader <NpgsqlInet>) this).Read(buf, fieldDescription, len).Address);
 }
 internal abstract Type GetFieldType(FieldDescription fieldDescription = null);
Example #15
0
        public override decimal Read(NpgsqlReadBuffer buf, int len, FieldDescription fieldDescription = null)
        {
            var result = new DecimalRaw();
            var groups = buf.ReadInt16();
            var weight = buf.ReadInt16() - groups + 1;
            var sign   = buf.ReadUInt16();

            if (sign == SignNan)
            {
                throw new NpgsqlSafeReadException(new InvalidCastException("Numeric NaN not supported by System.Decimal"));
            }
            else if (sign == SignNegative)
            {
                DecimalRaw.Negate(ref result);
            }

            var scale = buf.ReadInt16();

            if (scale > MaxDecimalScale)
            {
                throw new NpgsqlSafeReadException(new OverflowException("Numeric value does not fit in a System.Decimal"));
            }

            result.Scale = scale;

            try
            {
                var scaleDifference = scale + weight * MaxGroupScale;
                if (groups == MaxGroupCount)
                {
                    while (groups-- > 1)
                    {
                        DecimalRaw.Multiply(ref result, MaxGroupSize);
                        DecimalRaw.Add(ref result, buf.ReadUInt16());
                    }

                    var group     = buf.ReadUInt16();
                    var groupSize = DecimalRaw.Powers10[-scaleDifference];
                    if (group % groupSize != 0)
                    {
                        throw new NpgsqlSafeReadException(new OverflowException("Numeric value does not fit in a System.Decimal"));
                    }

                    DecimalRaw.Multiply(ref result, MaxGroupSize / groupSize);
                    DecimalRaw.Add(ref result, group / groupSize);
                }
                else
                {
                    while (groups-- > 0)
                    {
                        DecimalRaw.Multiply(ref result, MaxGroupSize);
                        DecimalRaw.Add(ref result, buf.ReadUInt16());
                    }

                    if (scaleDifference < 0)
                    {
                        DecimalRaw.Divide(ref result, DecimalRaw.Powers10[-scaleDifference]);
                    }
                    else
                    {
                        while (scaleDifference > 0)
                        {
                            var scaleChunk = Math.Min(DecimalRaw.MaxUInt32Scale, scaleDifference);
                            DecimalRaw.Multiply(ref result, DecimalRaw.Powers10[scaleChunk]);
                            scaleDifference -= scaleChunk;
                        }
                    }
                }
            }
            catch (OverflowException e)
            {
                throw new NpgsqlSafeReadException(e);
            }

            return(Unsafe.As <DecimalRaw, decimal>(ref result));
        }
Example #16
0
 public override void PrepareRead(ReadBuffer buf, int len, FieldDescription fieldDescription)
 {
     _readBuf          = buf;
     _fieldDescription = fieldDescription;
     _state            = State.Count;
 }
Example #17
0
        BigInteger INpgsqlSimpleTypeHandler <BigInteger> .Read(NpgsqlReadBuffer buf, int len, FieldDescription fieldDescription)
        {
            var result = new BigInteger();
            var groups = buf.ReadInt16();
            var weight = buf.ReadInt16() - groups + 1;
            var sign   = buf.ReadUInt16();

            if (sign == SignNan)
            {
                throw new NpgsqlSafeReadException(new InvalidCastException("Numeric NaN not supported by System.Numerics.BigInteger"));
            }

            var scale = buf.ReadInt16();

            if (scale > 0)
            {
                throw new NpgsqlSafeReadException(new OverflowException("Numeric value does not fit in a System.Numerics.BigInteger"));
            }

            try
            {
                var scaleDifference = scale + weight * MaxGroupScale;
                if (groups == MaxGroupCount)
                {
                    while (groups-- > 1)
                    {
                        result = result * MaxGroupSize;
                        result = result + buf.ReadUInt16();
                    }

                    var group     = buf.ReadUInt16();
                    var groupSize = DecimalRaw.Powers10[-scaleDifference];
                    if (group % groupSize != 0)
                    {
                        throw new NpgsqlSafeReadException(new OverflowException("Numeric value does not fit in a System.Numerics.BigInteger"));
                    }

                    result = result * (MaxGroupSize / groupSize);
                    result = result + (group / groupSize);
                }
                else
                {
                    while (groups-- > 0)
                    {
                        result = result * MaxGroupSize;
                        result = result + buf.ReadUInt16();
                    }

                    if (scaleDifference < 0)
                    {
                        result = result / (BigInteger)Math.Pow(10, -scaleDifference);
                    }
                    else
                    {
                        while (scaleDifference > 0)
                        {
                            var scaleChunk = Math.Min(DecimalRaw.MaxUInt32Scale, scaleDifference);
                            result           = result * (BigInteger)Math.Pow(10, scaleChunk);
                            scaleDifference -= scaleChunk;
                        }
                    }
                }
            }
            catch (OverflowException e)
            {
                throw new NpgsqlSafeReadException(e);
            }

            if (sign == SignNegative)
            {
                result = result * -1;
            }

            return(result);
        }
Example #18
0
 double INpgsqlSimpleTypeHandler <double> .Read(NpgsqlReadBuffer buf, int len, [CanBeNull] FieldDescription fieldDescription)
 => (double)Read(buf, len, fieldDescription);
Example #19
0
 float INpgsqlSimpleTypeHandler <float> .Read(NpgsqlReadBuffer buf, int len, [CanBeNull] FieldDescription fieldDescription)
 => (float)Read(buf, len, fieldDescription);
 public override NpgsqlCircle Read(NpgsqlReadBuffer buf, int len, FieldDescription fieldDescription = null)
 => new NpgsqlCircle(buf.ReadDouble(), buf.ReadDouble(), buf.ReadDouble());
Example #21
0
 NpgsqlInet ISimpleTypeReader <NpgsqlInet> .Read(NpgsqlBuffer buf, FieldDescription fieldDescription, int len)
 {
     return(DoRead(buf, fieldDescription, len, false));
 }
Example #22
0
 double ISimpleTypeReader <double> .Read(NpgsqlBuffer buf, FieldDescription fieldDescription, int len)
 {
     return(Read(buf, fieldDescription, len));
 }
Example #23
0
 string ISimpleTypeReader <string> .Read(NpgsqlBuffer buf, FieldDescription fieldDescription, int len)
 {
     return(((ISimpleTypeReader <NpgsqlInet>) this).Read(buf, fieldDescription, len).ToString());
 }
 internal abstract Type GetProviderSpecificFieldType(FieldDescription fieldDescription = null);
Example #25
0
 public override bool Read(ReadBuffer buf, int len, FieldDescription fieldDescription)
 {
     return(buf.ReadByte() != 0);
 }
 /// <summary>
 /// Reads a value of type <typeparamref name="T"/> with the given length from the provided buffer,
 /// with the assumption that it is entirely present in the provided memory buffer and no I/O will be
 /// required. This can save the overhead of async functions and improves performance.
 /// </summary>
 /// <param name="buf">The buffer from which to read.</param>
 /// <param name="len">The byte length of the value. The buffer might not contain the full length, requiring I/O to be performed.</param>
 /// <param name="fieldDescription">Additional PostgreSQL information about the type, such as the length in varchar(30).</param>
 /// <returns>The fully-read value.</returns>
 internal abstract T Read <T>(NpgsqlReadBuffer buf, int len, FieldDescription fieldDescription = null);
		public void AddNewFieldDescriptionWithOldName()
		{
			// Setup test
			var origName = "zCustom Field";
			var newName = "zNew Custom Field User label";
			var customField1 = CreateCustomFieldAndRelabel(origName, newName);
			var firstFlid = m_mdc.GetFieldId2(1, origName, true);
			var secondUserLabel = "unrelatedUserLabel";
			var customField2 = new FieldDescription(Cache)
			{
				Class = 1,
				Name = origName,
				Userlabel = secondUserLabel,
				Type = CellarPropertyType.String
			};

			// SUT
			customField2.UpdateCustomField(); // should change Name slightly

			// Verify
			var newExpectedName = origName + "1";
			var secondFlid = m_mdc.GetFieldId2(customField2.Class, newExpectedName, true);
			Assert.AreNotEqual(0, secondFlid, "Field not, or incorrectly, installed.");
			var actualNewName = m_mdc.GetFieldName(secondFlid);
			Assert.AreEqual(newExpectedName, actualNewName,
				string.Format("Field Name should be changed to {0}.", newExpectedName));
			Assert.AreEqual(secondUserLabel, m_mdc.GetFieldLabel(secondFlid), "User label shouldn't change.");

			// Cleanup
			m_mdc.DeleteCustomField(firstFlid);
			m_mdc.DeleteCustomField(secondFlid);
		}
 /// <summary>
 /// Reads a column as the type handler's default read type. If it is not already entirely in
 /// memory, sync or async I/O will be performed as specified by <paramref name="async"/>.
 /// </summary>
 internal abstract Task <object> ReadAsObject(NpgsqlReadBuffer buf, int len, bool async, FieldDescription fieldDescription = null);
		public void CreatingNumberCustomField_MakesInstancesDirty()
		{
			var fd = new FieldDescription(Cache)
			{
				Class = MoStemAllomorphTags.kClassId,
				Name = "MyNumber",
				Type = CellarPropertyType.Integer
			};

			var le = Cache.ServiceLocator.GetInstance<ILexEntryFactory>().Create();
			var morph = Cache.ServiceLocator.GetInstance<IMoStemAllomorphFactory>().Create();
			le.LexemeFormOA = morph;
			m_actionHandler.EndUndoTask();

			UndoableUnitOfWorkHelper.Do("undo", "redo", m_actionHandler,
				() =>
					{
						fd.UpdateCustomField();
						Assert.That(((UndoStack) m_actionHandler).m_currentBundle.DirtyObjects, Has.Member(morph));
					});
		}
Example #30
0
        static void ParseFieldDescription(int idx)
        {
            byte[] fieldDescriptionBytes = new byte[FieldDescriptionLength];

            Array.Copy(ibtBytes, idx, fieldDescriptionBytes, 0, FieldDescriptionLength);

            FieldDescription field = new FieldDescription();

            field.DataType = GetIntFromBytes(fieldDescriptionBytes, FieldDescriptionLengthStart, FieldDescriptionLengthLength);
            field.Position = GetIntFromBytes(fieldDescriptionBytes, FieldDescriptionPositionStart, FieldDescriptionPositionLength);
            field.Name = GetTextFromBytes(fieldDescriptionBytes, FieldDescriptionNameStart, FieldDescriptionNameLength);
            field.Description = GetTextFromBytes(fieldDescriptionBytes, FieldDescriptionDescriptionStart, FieldDescriptionDescriptionLength);
            field.Unit = GetTextFromBytes(fieldDescriptionBytes, FieldDescriptionUnitStart, FieldDescriptionUnitLength);

            Fields.Add(field);

            //Console.WriteLine("{0,-3}) {1,-32} {2,-64} {3,-32} {4,-4} {5,-4}", Fields.Count.ToString(), field.Name, field.Description, field.Unit, field.DataType.ToString(), field.Position.ToString());
        }
Example #31
0
 public override NpgsqlPoint Read(ReadBuffer buf, int len, FieldDescription fieldDescription)
 {
     return(new NpgsqlPoint(buf.ReadDouble(), buf.ReadDouble()));
 }
Example #32
0
        /// <summary>
        /// Upcast field description subclass and drop attributes.
        /// </summary>
        private static FieldDescription UpcastFieldDescriptionSubclassAndDropAttributes(FieldDescription fieldDescription1)
        {
            // Upcasts derived types back to FieldDescription type and throws away attributes.

            // Create a new field description object.
            FieldDescription fieldDescription2 = new FieldDescription(fieldDescription1.Name);

            // Copy the fields not initialized during construction.
            fieldDescription2.Label        = fieldDescription1.Label;
            fieldDescription2.HelpMessage  = fieldDescription1.HelpMessage;
            fieldDescription2.IsMandatory  = fieldDescription1.IsMandatory;
            fieldDescription2.DefaultValue = fieldDescription1.DefaultValue;

            // Set the type related fields.
            fieldDescription2.SetParameterTypeName(fieldDescription1.ParameterTypeName);
            fieldDescription2.SetParameterTypeFullName(fieldDescription1.ParameterTypeFullName);
            fieldDescription2.SetParameterAssemblyFullName(fieldDescription1.ParameterAssemblyFullName);

            return(fieldDescription2);
        }
        private string PromptForSingleItem(Type fieldType,
                                           string printFieldPrompt,
                                           string fieldPrompt,
                                           string caption,
                                           string message,
                                           FieldDescription desc,
                                           bool fieldEchoOnPrompt,
                                           bool listInput,
                                           out bool endListInput,
                                           out bool cancelInput,
                                           out object convertedObj
                                           )
        {
            cancelInput  = false;
            endListInput = false;
            convertedObj = null;

            if (fieldType.Equals(typeof(SecureString)))
            {
                WriteToConsole(printFieldPrompt, true);
                SecureString secureString = ReadLineAsSecureString();
                convertedObj = secureString;
                cancelInput  = (convertedObj == null);
                if ((secureString != null) && (secureString.Length == 0) && listInput)
                {
                    endListInput = true;
                }
            }
            else if (fieldType.Equals(typeof(PSCredential)))
            {
                WriteLineToConsole(WrapToCurrentWindowWidth(fieldPrompt));
                PSCredential credential = null;
                // the earlier implementation contained null
                // for caption and message in the call below
                // Passing null is a potential security risk
                // as any modifications made with security in
                // mind is lost. This can lead to a malicious
                // server prompting the user for a request
                // which can appear to come from locally.
                // [danthom] BUGBUG: don't know how to compensate for lack of access to ModifiedByRemotingProtocol
                //if (!PromptUsingConsole() && desc.ModifiedByRemotingProtocol)
                if (!PromptUsingConsole())
                {
                    credential =
                        PromptForCredential(
                            caption,
                            message,
                            null,
                            string.Empty);
                }
                else
                {
                    credential =
                        PromptForCredential(
                            null,   // caption already written
                            null,   // message already written
                            null,
                            string.Empty);
                }
                convertedObj = credential;
                cancelInput  = (convertedObj == null);
                if ((credential != null) && (credential.Password.Length == 0) && listInput)
                {
                    endListInput = true;
                }
            }
            else
            {
                string inputString = null;
                do
                {
                    inputString = PromptReadInput(
                        printFieldPrompt, desc, fieldEchoOnPrompt,
                        listInput, out endListInput, out cancelInput);
                }
                // [danthom]
                //while (!cancelInput && !endListInput && PromptTryConvertTo(fieldType, desc.IsFromRemoteHost, inputString, out convertedObj) !=
                while (!cancelInput && !endListInput && PromptTryConvertTo(fieldType, false, inputString, out convertedObj) !=
                       PromptCommonInputErrors.None);
                return(inputString);
            }

            return(null);
        }
Example #34
0
        private void DrawValueFor(FieldDescription field, BytesAndOffset bytesAndOffset)
        {
            var typeDescription = _unpackedCrawl.typeDescriptions[field.typeIndex];

            try
            {
                switch (typeDescription.name)
                {
                case "System.Int32":
                    GUILayout.Label(_primitiveValueReader.ReadInt32(bytesAndOffset).ToString());
                    break;

                case "System.Int64":
                    GUILayout.Label(_primitiveValueReader.ReadInt64(bytesAndOffset).ToString());
                    break;

                case "System.UInt32":
                    GUILayout.Label(_primitiveValueReader.ReadUInt32(bytesAndOffset).ToString());
                    break;

                case "System.UInt64":
                    GUILayout.Label(_primitiveValueReader.ReadUInt64(bytesAndOffset).ToString());
                    break;

                case "System.Int16":
                    GUILayout.Label(_primitiveValueReader.ReadInt16(bytesAndOffset).ToString());
                    break;

                case "System.UInt16":
                    GUILayout.Label(_primitiveValueReader.ReadUInt16(bytesAndOffset).ToString());
                    break;

                case "System.Byte":
                    GUILayout.Label(_primitiveValueReader.ReadByte(bytesAndOffset).ToString());
                    break;

                case "System.SByte":
                    GUILayout.Label(_primitiveValueReader.ReadSByte(bytesAndOffset).ToString());
                    break;

                case "System.Char":
                    GUILayout.Label(_primitiveValueReader.ReadChar(bytesAndOffset).ToString());
                    break;

                case "System.Boolean":
                    GUILayout.Label(_primitiveValueReader.ReadBool(bytesAndOffset).ToString());
                    break;

                case "System.Single":
                    GUILayout.Label(_primitiveValueReader.ReadSingle(bytesAndOffset).ToString());
                    break;

                case "System.Double":
                    GUILayout.Label(_primitiveValueReader.ReadDouble(bytesAndOffset).ToString());
                    break;

                case "System.IntPtr":
                    GUILayout.Label(_primitiveValueReader.ReadPointer(bytesAndOffset).ToString("X"));
                    break;

                default:
                    if (!typeDescription.isValueType)
                    {
                        ThingInMemory item = GetThingAt(bytesAndOffset.ReadPointer());
                        if (item == null)
                        {
                            EditorGUI.BeginDisabledGroup(true);
                            GUILayout.Button("Null");
                            EditorGUI.EndDisabledGroup();
                        }
                        else
                        {
                            DrawLinks(new ThingInMemory[] { item });
                        }
                    }
                    else
                    {
                        DrawFields(typeDescription, bytesAndOffset);
                    }
                    break;
                }
            }
            catch (Exception ex)
            {
                GUILayout.Label(string.Format("<bad_entry> type: {0}, len: {1}, offset: {2}, ex: {3}", typeDescription.name, bytesAndOffset.bytes.Length, bytesAndOffset.offset, ex.GetType().Name));
                Debug.LogFormat("<bad_entry> type: {0}, len: {1}, offset: {2}, ex: {3}", typeDescription.name, bytesAndOffset.bytes.Length, bytesAndOffset.offset, ex.GetType().Name);
            }
        }
Example #35
0
 string ISimpleTypeHandler <string> .Read(ReadBuffer buf, int len, FieldDescription fieldDescription)
 {
     return(Read(buf, len, fieldDescription).ToString());
 }
		private FieldDescription CreateCustomFieldAndRelabel(string fieldname, string ultimateUserLabel)
		{
			// Phase 1: Create 1st Custom Field with original name
			var fd = new FieldDescription(Cache)
			{
				Class = 1,
				Name = fieldname,
				Type = CellarPropertyType.String
			};
			Assert.AreEqual(fd.Custom, 1, "Wrong value for Custom column in new FD.");
			Assert.AreEqual(0, fd.Id, "new field should not have been assigned a flid yet");

			int flid;
			try
			{
				flid = m_mdc.GetFieldId2(fd.Class, fd.Name, true);
			}
			catch (FDOInvalidFieldException)
			{
				flid = 0;	// the new implementation throws instead of returning zero.
			}
			Assert.AreEqual(0, flid, "new field should not exist");

			fd.UpdateCustomField();
			flid = m_mdc.GetFieldId2(fd.Class, fd.Name, true);
			Assert.AreNotEqual(0, fd.Id, "field should have been assigned a flid");
			Assert.AreEqual(fd.Id, flid, "new field should exist");

			// Phase 2: Replace 1st Custom field's User label
			fd.Userlabel = ultimateUserLabel;
			fd.UpdateCustomField();
			Assert.AreEqual(flid, m_mdc.GetFieldId2(fd.Class, fd.Name, true),
				"Flid should not have changed.");
			Assert.AreEqual(fieldname, fd.Name, "Internal field name must not change!");
			Assert.AreEqual(fd.Userlabel, ultimateUserLabel, "Field User label should have changed.");
			return fd;
		}
Example #37
0
 public int Read(NpgsqlBuffer buf, int len, FieldDescription fieldDescription)
 {
     buf.ReadInt32();
     throw new SafeReadException(new Exception("Safe read exception as requested"));
 }
Example #38
0
 public int Read(NpgsqlBuffer buf, int len, FieldDescription fieldDescription)
 {
     throw new Exception("Non-safe read exception as requested");
 }
Example #39
0
 string ISimpleTypeReader <string> .Read(NpgsqlBuffer buf, int len, FieldDescription fieldDescription)
 {
     return(Read(buf, len, fieldDescription).ToString());
 }
Example #40
0
        ClassDescription ReadClassDescription()
        {
            ClassDescription desc = default( ClassDescription );
            byte typeCode = reader.ReadByte();
            if( typeCode == TC_NULL ) return desc;
            if( typeCode != TC_CLASSDESC ) ParseError( TC_CLASSDESC, typeCode );

            desc.ClassName = ReadString();
            reader.ReadUInt64(); // serial version UID
            reader.ReadByte(); // flags
            FieldDescription[] fields = new FieldDescription[ReadInt16()];
            for( int i = 0; i < fields.Length; i++ ) {
                fields[i] = ReadFieldDescription();
            }
            desc.Fields = fields;

            typeCode = reader.ReadByte();
            if( typeCode != TC_ENDBLOCKDATA ) ParseError( TC_ENDBLOCKDATA, typeCode );
            ReadClassDescription(); // super class description
            return desc;
        }
Example #41
0
 public float Read(NpgsqlBuffer buf, FieldDescription fieldDescription, int len)
 {
     return(buf.ReadSingle());
 }
Example #42
0
        void ReadClassData( FieldDescription[] fields )
        {
            for( int i = 0; i < fields.Length; i++ ) {
                switch( fields[i].Type ) {
                    case FieldType.Byte:
                        fields[i].Value = reader.ReadByte(); break;
                    case FieldType.Float:
                        fields[i].Value = ReadInt32(); break; // wrong, but we don't support it anyways
                    case FieldType.Integer:
                        fields[i].Value = ReadInt32(); break;
                    case FieldType.Long:
                        fields[i].Value = ReadInt64(); break;
                    case FieldType.Boolean:
                        fields[i].Value = reader.ReadByte() != 0; break;
                    case FieldType.Object:
                        if( fields[i].FieldName == "blockMap" ) {
                            byte typeCode = reader.ReadByte();
                            // Skip all blockMap data with awful hacks
                            if( typeCode == TC_OBJECT ) {
                                reader.ReadBytes( 315 );
                                int count = ReadInt32();

                                byte[] temp = new byte[17];
                                Stream stream = reader.BaseStream;
                                for( int j = 0; j < count; j++ ) {
                                    stream.Read( temp, 0, temp.Length );
                                }
                                reader.ReadBytes( 152 );
                            }
                        } break;
                    case FieldType.Array:
                        ReadArray( ref fields[i] ); break;
                }
            }
        }
        public override async Task <NpgsqlTsVector> Read(NpgsqlReadBuffer buf, int len, bool async, FieldDescription fieldDescription = null)
        {
            await buf.Ensure(4, async);

            var numLexemes = buf.ReadInt32();

            len -= 4;

            var lexemes = new List <NpgsqlTsVector.Lexeme>();

            for (var lexemePos = 0; lexemePos < numLexemes; lexemePos++)
            {
                await buf.Ensure(Math.Min(len, MaxSingleLexemeBytes), async);

                var posBefore = buf.ReadPosition;

                List <NpgsqlTsVector.Lexeme.WordEntryPos> positions = null;

                var lexemeString = buf.ReadNullTerminatedString();
                int numPositions = buf.ReadInt16();
                for (var i = 0; i < numPositions; i++)
                {
                    var wordEntryPos = buf.ReadInt16();
                    if (positions == null)
                    {
                        positions = new List <NpgsqlTsVector.Lexeme.WordEntryPos>();
                    }
                    positions.Add(new NpgsqlTsVector.Lexeme.WordEntryPos(wordEntryPos));
                }

                lexemes.Add(new NpgsqlTsVector.Lexeme(lexemeString, positions, true));

                len -= buf.ReadPosition - posBefore;
            }

            return(new NpgsqlTsVector(lexemes, true));
        }