コード例 #1
0
ファイル: CommandExtensions.cs プロジェクト: bojanv91/Marten
 public static NpgsqlCommand Returns(this NpgsqlCommand command, string name, NpgsqlDbType type)
 {
     var parameter = command.AddParameter(name);
     parameter.NpgsqlDbType = type;
     parameter.Direction = ParameterDirection.ReturnValue;
     return command;
 }
コード例 #2
0
ファイル: NpgsqlTypesHelper.cs プロジェクト: nlhepler/mono
        /// <summary>
        /// Find a NpgsqlNativeTypeInfo in the default types map that can handle objects
        /// of the given NpgsqlDbType.
        /// </summary>
        public static NpgsqlNativeTypeInfo GetNativeTypeInfo(NpgsqlDbType NpgsqlDbType)
        {
            NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "GetBackendTypeNameFromNpgsqlDbType");

            VerifyDefaultTypesMap();
            return NativeTypeMapping[NpgsqlDbType];
        }
コード例 #3
0
ファイル: IsOneOf.cs プロジェクト: danielmarbach/marten
        public EnumIsOneOfWhereFragment(object values, EnumStorage enumStorage, string locator)
        {
            var array = values.As<Array>();
            if (enumStorage == EnumStorage.AsInteger)
            {
                var numbers = new int[array.Length];

                for (int i = 0; i < array.Length; i++)
                {
                    numbers[i] = array.GetValue(i).As<int>();
                }

                _values = numbers;
                _dbType = NpgsqlDbType.Integer | NpgsqlDbType.Array;
            }
            else
            {
                var strings = new string[array.Length];

                for (int i = 0; i < array.Length; i++)
                {
                    strings[i] = array.GetValue(i).ToString();
                }

                _values = strings;
                _dbType = NpgsqlDbType.Varchar | NpgsqlDbType.Array;
            }

            _locator = locator;
        }
コード例 #4
0
 public PostgresqlType(string postgresqlColumnType, string infoSchemaName, NpgsqlDbType postgresqlDbType, DbType databaseType, MungTypeCode code)
 {
     InfoSchemaName = infoSchemaName;
     CreateColumnDefinition = postgresqlColumnType;
     PostgresqlDbType = postgresqlDbType;
     DatabaseType = databaseType;
     MungType = MungType.Get(code);
 }
コード例 #5
0
ファイル: BatchCommand.cs プロジェクト: danielmarbach/marten
        public NpgsqlParameter AddParameter(object value, NpgsqlDbType dbType)
        {
            var name = "p" + _counter++;
            var param = Command.AddParameter(name, value);
            param.NpgsqlDbType = dbType;

            return param;
        }
コード例 #6
0
ファイル: SprocCall.cs プロジェクト: danielmarbach/marten
        public SprocCall Param(string argName, object value, NpgsqlDbType dbType)
        {
            var param = _parent.AddParameter(value, dbType);

            _parameters.Add(new ParameterArg(argName, param));

            return this;
        }
コード例 #7
0
        public static NpgsqlParameter MakeParameter(string paramName, string value, NpgsqlDbType dbType, ParameterDirection direction)
        {
            NpgsqlParameter param = new NpgsqlParameter(":" + paramName, dbType);
            param.Direction = direction;
            param.SourceColumn = paramName;
            param.Value = value;

            return param;
        }
コード例 #8
0
ファイル: CommandExtensions.cs プロジェクト: bojanv91/Marten
        public static NpgsqlCommand With(this NpgsqlCommand command, string name, object value, NpgsqlDbType dbType)
        {
            var parameter = command.CreateParameter();
            parameter.ParameterName = name;
            parameter.Value = value ?? DBNull.Value;
            parameter.NpgsqlDbType = dbType;
            command.Parameters.Add(parameter);

            return command;
        }
コード例 #9
0
        /// <summary>
        /// Maps an Npgsql type handler to a PostgreSQL type.
        /// </summary>
        /// <param name="pgName">A PostgreSQL type name as it appears in the pg_type table.</param>
        /// <param name="npgsqlDbType">
        /// A member of <see cref="NpgsqlDbType"/> which represents this PostgreSQL type.
        /// An <see cref="NpgsqlParameter"/> with <see cref="NpgsqlParameter.NpgsqlDbType"/> set to
        /// this value will be sent with the type handler mapped by this attribute.
        /// </param>
        /// <param name="dbTypes">
        /// All members of <see cref="DbType"/> which represent this PostgreSQL type.
        /// An <see cref="NpgsqlParameter"/> with <see cref="NpgsqlParameter.DbType"/> set to
        /// one of these values will be sent with the type handler mapped by this attribute.
        /// </param>
        /// <param name="clrTypes">
        /// Any .NET type which corresponds to this PostgreSQL type.
        /// An <see cref="NpgsqlParameter"/> with <see cref="NpgsqlParameter.Value"/> set to
        /// one of these values will be sent with the type handler mapped by this attribute.
        /// </param>
        /// <param name="inferredDbType">
        /// The "primary" <see cref="DbType"/> which best corresponds to this PostgreSQL type.
        /// When <see cref="NpgsqlParameter.NpgsqlDbType"/> or <see cref="NpgsqlParameter.Value"/>
        /// set, <see cref="NpgsqlParameter.DbType"/> will be set to this value.
        /// </param>
        internal TypeMappingAttribute(string pgName, NpgsqlDbType? npgsqlDbType, [CanBeNull] DbType[] dbTypes, [CanBeNull] Type[] clrTypes, DbType? inferredDbType)
        {
            if (String.IsNullOrWhiteSpace(pgName))
                throw new ArgumentException("pgName can't be empty", nameof(pgName));
            Contract.EndContractBlock();

            PgName = pgName;
            NpgsqlDbType = npgsqlDbType;
            DbTypes = dbTypes ?? new DbType[0];
            ClrTypes = clrTypes ?? new Type[0];
            InferredDbType = inferredDbType;
        }
コード例 #10
0
ファイル: WSqlCommand.cs プロジェクト: dioptre/nkd
		/// <summary>
		/// Adds parameter to Sql Command.
		/// </summary>
		/// <param name="name">Parameter name.</param>
		/// <param name="dbType">Parameter datatype.</param>
		/// <param name="value">Parameter value.</param>
		public void AddParameter(string name,NpgsqlDbType dbType,object value)
		{		
            /*
			SqlDbType dbTyp = dbType;
			object val = value;
			
			if(dbType == SqlDbType.UniqueIdentifier){
				dbTyp = SqlDbType.NVarChar;
				string guid = val.ToString();
				if(guid.Length < 1){
					return;
				}
			}*/

			m_SqlCmd.Parameters.Add(name,dbType).Value = value;
		}
コード例 #11
0
        /// <summary>
        /// Construct a new NpgsqlTypeInfo with the given attributes and conversion handlers.
        /// </summary>
        /// <param name="OID">Type OID provided by the backend server.</param>
        /// <param name="Name">Type name provided by the backend server.</param>
        /// <param name="NpgsqlDbType">NpgsqlDbType</param>
        /// <param name="DbType">DbType</param>
        /// <param name="Type">System type to convert fields of this type to.</param>
        /// <param name="ConvertBackendTextToNative">Data conversion handler for text encoding.</param>
        /// <param name="ConvertBackendBinaryToNative">Data conversion handler for binary data.</param>
        public NpgsqlBackendTypeInfo(Int32 OID, String Name, NpgsqlDbType NpgsqlDbType, DbType DbType, Type Type,
                                        ConvertBackendTextToNativeHandler ConvertBackendTextToNative = null,
                                        ConvertBackendBinaryToNativeHandler ConvertBackendBinaryToNative = null)
        {
            if (Type == null)
            {
                throw new ArgumentNullException("Type");
            }

            _OID = OID;
            _Name = Name;
            _NpgsqlDbType = NpgsqlDbType;
            _DbType = DbType;
            _Type = Type;
            _frameworkType = Type;
            _ConvertBackendTextToNative = ConvertBackendTextToNative;
            _ConvertBackendBinaryToNative = ConvertBackendBinaryToNative;
        }
コード例 #12
0
        // http://www.npgsql.org/doc/types.html
        private static KeyValuePair<string, bool> NpgsqlDbType2CSharpType(NpgsqlDbType npgsqlDbType)
        {
            string str;
            bool flag;
            switch (npgsqlDbType)
            {
                case NpgsqlDbType.Boolean:
                    str = "bool";
                    flag = true;
                    break;
                case NpgsqlDbType.Smallint:
                    str = "short";
                    flag = true;
                    break;
                case NpgsqlDbType.Integer:
                    str = "int";
                    flag = true;
                    break;
                case NpgsqlDbType.Bigint:
                    str = "long";
                    flag = true;
                    break;
                case NpgsqlDbType.Real:
                    str = "float";
                    flag = true;
                    break;
                case NpgsqlDbType.Double:
                    str = "double";
                    flag = true;
                    break;
                case NpgsqlDbType.Money:
                case NpgsqlDbType.Numeric:
                    str = "decimal";
                    flag = true;
                    break;
                case NpgsqlDbType.Date:
                case NpgsqlDbType.Timestamp:
                case NpgsqlDbType.TimestampTZ:
                case NpgsqlDbType.Abstime:
                    str = "DateTime";
                    flag = true;
                    break;
                case NpgsqlDbType.Time:
                case NpgsqlDbType.Interval:
                case NpgsqlDbType.TimeTZ:
                    str = "TimeSpan";
                    flag = true;
                    break;
                case NpgsqlDbType.Uuid:
                    str = "Guid";
                    flag = false;
                    break;
                case NpgsqlDbType.Bytea:
                case NpgsqlDbType.Bit:
                    str = "byte[]";
                    flag = true;
                    break;
                case NpgsqlDbType.Oidvector:
                    str = "uint[]";
                    flag = true;
                    break;

                case NpgsqlDbType.Array:
                    str = "Array";
                    flag = false;
                    break;
                case NpgsqlDbType.Char:
                case NpgsqlDbType.Text:
                case NpgsqlDbType.Varchar:
                case NpgsqlDbType.Inet:
                case NpgsqlDbType.Xml:
                case NpgsqlDbType.Name:
                case NpgsqlDbType.MacAddr:
                case NpgsqlDbType.Json:
                case NpgsqlDbType.Jsonb:
                case NpgsqlDbType.Hstore:
                    str = "string";
                    flag = false;
                    break;
                case NpgsqlDbType.Box:
                case NpgsqlDbType.Circle:
                case NpgsqlDbType.Line:
                case NpgsqlDbType.LSeg:
                case NpgsqlDbType.Path:
                case NpgsqlDbType.Point:
                case NpgsqlDbType.Polygon:
                case NpgsqlDbType.Refcursor:
                    str = "object";
                    flag = false;
                    break;
                default:
                    str = "object";
                    flag = false;
                    break;
            }
            return new KeyValuePair<string, bool>(str, flag);
        }
コード例 #13
0
        public void duplicated_field_enum_storage_should_be_taken_from_store_options_enum_storage_by_default(EnumStorage enumStorage, NpgsqlDbType expectedNpgsqlDbType)
        {
            var storeOptions = new StoreOptions();

            storeOptions.UseDefaultSerialization(enumStorage);

            var mapping = new DocumentMapping <Target>(storeOptions);

            var duplicatedField = mapping.DuplicateField(nameof(Target.Color));

            duplicatedField.DbType.ShouldBe(expectedNpgsqlDbType);
        }
コード例 #14
0
        public void duplicated_field_date_time_db_type_should_be_taken_from_store_options_useTimestampWithoutTimeZoneForDateTime(bool useTimestampWithoutTimeZoneForDateTime, NpgsqlDbType expectedNpgsqlDbType)
        {
            var storeOptions = new StoreOptions();

            storeOptions.Advanced.DuplicatedFieldUseTimestampWithoutTimeZoneForDateTime = useTimestampWithoutTimeZoneForDateTime;

            var mapping = new DocumentMapping <Target>(storeOptions);

            var duplicatedField = mapping.DuplicateField(nameof(Target.Date));

            duplicatedField.DbType.ShouldBe(expectedNpgsqlDbType);
        }
コード例 #15
0
 /// <summary>
 /// Reads the current column, returns its value according to <paramref name="type"/> and
 /// moves ahead to the next column.
 /// If the column is null an exception is thrown.
 /// </summary>
 /// <param name="type">
 /// In some cases <typeparamref name="T"/> isn't enough to infer the data type coming in from the
 /// database. This parameter can be used to unambiguously specify the type. An example is the JSONB
 /// type, for which <typeparamref name="T"/> will be a simple string but for which
 /// <paramref name="type"/> must be specified as <see cref="NpgsqlDbType.Jsonb"/>.
 /// </param>
 /// <param name="cancellationToken">
 /// An optional token to cancel the asynchronous operation. The default value is <see cref="CancellationToken.None"/>.
 /// </param>
 /// <typeparam name="T">The .NET type of the column to be read.</typeparam>
 /// <returns>The value of the column</returns>
 public ValueTask <T> ReadAsync <T>(NpgsqlDbType type, CancellationToken cancellationToken = default)
 {
     using (NoSynchronizationContextScope.Enter())
         return(Read <T>(type, true, cancellationToken));
 }
コード例 #16
0
ファイル: NpgsqlParameter.cs プロジェクト: Qorpent/Npgsql2
 /// <summary>
 /// Initializes a new instance of the <see cref="Npgsql.NpgsqlParameter">NpgsqlParameter</see>
 /// class with the parameter m_Name, the <see cref="System.Data.DbType">DbType</see>, and the size.
 /// </summary>
 /// <param m_Name="parameterName">The m_Name of the parameter to map.</param>
 /// <param m_Name="parameterType">One of the <see cref="System.Data.DbType">DbType</see> values.</param>
 /// <param m_Name="size">The length of the parameter.</param>
 public NpgsqlParameter(String parameterName, NpgsqlDbType parameterType, Int32 size)
     : this(parameterName, parameterType, size, String.Empty)
 {
 }
コード例 #17
0
ファイル: utils.cs プロジェクト: katshann/ogen
			public static DbType PgsqlDbType2DbType(NpgsqlDbType pgsqlDbType_in) {
				switch (pgsqlDbType_in) {
					case NpgsqlDbType.Bigint:
						return DbType.Int64;
					case NpgsqlDbType.Integer:
						return DbType.Int32;
					case NpgsqlDbType.Smallint:
						return DbType.Int16;
					case NpgsqlDbType.Boolean:
						return DbType.Boolean;

					case NpgsqlDbType.Varchar:
					case NpgsqlDbType.Text:
						return DbType.String;

					case NpgsqlDbType.TimestampTZ:
					case NpgsqlDbType.Timestamp:
						return DbType.DateTime;

					case NpgsqlDbType.Real:
						return DbType.Single;
					case NpgsqlDbType.Double:
						return DbType.Double;
					case NpgsqlDbType.Numeric:
						return DbType.Decimal;
					case NpgsqlDbType.Bytea:
						return DbType.Binary;
					case NpgsqlDbType.Date:
						return DbType.Date;
					case NpgsqlDbType.Time:
						return DbType.Time;
					case NpgsqlDbType.Money:
						return DbType.Decimal;

					#region default: throw new Exception("...");
					default: {
						throw new Exception(string.Format(
							"undefined variable type: {0}",
							pgsqlDbType_in.ToString()
						));
					}
					#endregion
				}
			}
コード例 #18
0
        /// <summary>
        /// Adds a <see cref="Npgsql.NpgsqlParameter">NpgsqlParameter</see> to the <see cref="Npgsql.NpgsqlParameterCollection">NpgsqlParameterCollection</see> given the specified parameter name and value.
        /// </summary>
        /// <param name="parameterName">The name of the <see cref="Npgsql.NpgsqlParameter">NpgsqlParameter</see>.</param>
        /// <param name="value">The Value of the <see cref="Npgsql.NpgsqlParameter">NpgsqlParameter</see> to add to the collection.</param>
        /// <param name="parameterType">One of the NpgsqlDbType values.</param>
        /// <param name="size">The length of the column.</param>
        /// <param name="sourceColumn">The name of the source column.</param>
        /// <returns>The paramater that was added.</returns>
        public NpgsqlParameter AddWithValue(string parameterName, NpgsqlDbType parameterType, int size, string sourceColumn, object value)
        {
            NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "AddWithValue", parameterName, parameterType, size, sourceColumn, value);

            NpgsqlParameter param = new NpgsqlParameter(parameterName, parameterType, size, sourceColumn);

            param.Value = value;

            return this.Add(param);
        }
コード例 #19
0
 public ColumnInfo(string columnName, int columnID, DataType dataType, int lineageID, int bufferIndex, int length, int precision, int scale, string externalColumnName, NpgsqlDbType externalSqlDbType)
 {
     _columnName         = columnName;
     _columnID           = columnID;
     _dataType           = dataType;
     _lineageID          = lineageID;
     _bufferIndex        = bufferIndex;
     _precision          = precision;
     _scale              = scale;
     _length             = length;
     _externalColumnName = externalColumnName;
     _externalSqlDbType  = externalSqlDbType;
 }
 protected NpgsqlVarbitTypeMapping(RelationalTypeMappingParameters parameters, NpgsqlDbType npgsqlDbType)
     : base(parameters, npgsqlDbType)
 {
 }
コード例 #21
0
ファイル: TypeMappingAttribute.cs プロジェクト: zhnc/npgsql
 internal TypeMappingAttribute(string pgName, NpgsqlDbType npgsqlDbType, DbType[] dbTypes, Type clrType, DbType inferredDbType)
     : this(pgName, npgsqlDbType, dbTypes, new[] { clrType }, inferredDbType)
 {
 }
コード例 #22
0
ファイル: TypeMappingAttribute.cs プロジェクト: zhnc/npgsql
 internal TypeMappingAttribute(string pgName, NpgsqlDbType npgsqlDbType, Type[] clrTypes)
     : this(pgName, npgsqlDbType, new DbType[0], clrTypes, null)
 {
 }
コード例 #23
0
ファイル: TypeMappingAttribute.cs プロジェクト: zhnc/npgsql
 internal TypeMappingAttribute(string pgName, NpgsqlDbType npgsqlDbType, DbType dbType, Type clrType = null)
     : this(pgName, npgsqlDbType, new[] { dbType }, clrType == null ? null : new[] { clrType }, dbType)
 {
 }
コード例 #24
0
ファイル: TypeMappingAttribute.cs プロジェクト: zhnc/npgsql
 internal TypeMappingAttribute(string pgName, NpgsqlDbType npgsqlDbType, DbType dbType, Type[] clrTypes)
     : this(pgName, npgsqlDbType, new[] { dbType }, clrTypes, dbType)
 {
 }
コード例 #25
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NpgsqlParameter">NpgsqlParameter</see>.
 /// </summary>
 /// <param name="parameterName">The name of the parameter to map.</param>
 /// <param name="parameterType">One of the <see cref="NpgsqlTypes.NpgsqlDbType">NpgsqlDbType</see> values.</param>
 /// <param name="size">The length of the parameter.</param>
 public NpgsqlParameter(string parameterName, NpgsqlDbType parameterType, int size)
     : this(parameterName, parameterType, size, String.Empty)
 {
 }
コード例 #26
0
ファイル: SQLCommand.cs プロジェクト: nolanlum/MyRiotControl
 void Add(string name, NpgsqlDbType type)
 {
     Command.Parameters.Add(new NpgsqlParameter(name, type));
 }
コード例 #27
0
ファイル: SQLCommand.cs プロジェクト: nolanlum/MyRiotControl
 void Set(NpgsqlDbType type, object value)
 {
     Enumerator.MoveNext();
     Command.Parameters.Add(new NpgsqlParameter(Enumerator.Current, type));
     Command.Parameters[Command.Parameters.Count - 1].Value = value;
 }
コード例 #28
0
 public ExceptionColumnWriter(NpgsqlDbType dbType = NpgsqlDbType.Text, int?columnLength = null) : base(dbType, columnLength)
 {
 }
コード例 #29
0
ファイル: CommandTests.cs プロジェクト: baondp/Npgsql
        public void InsertValue(DbType? dbType, NpgsqlDbType? npgsqlDbType, string fieldName, object value)
        {
            if (dbType.HasValue && npgsqlDbType.HasValue || (!dbType.HasValue && !npgsqlDbType.HasValue))
                Assert.Fail("Exactly one of dbType and npgsqlDbType must be specified");

            using (var command = new NpgsqlCommand(String.Format("INSERT INTO data ({0}) values (:a)", fieldName), Conn))
            {
                if (dbType.HasValue)
                    command.Parameters.Add(new NpgsqlParameter("a", dbType.Value));
                else
                    command.Parameters.Add(new NpgsqlParameter("a", npgsqlDbType.Value));
                command.Parameters[0].Value = value;
                var rowsAdded = command.ExecuteNonQuery();
                Assert.AreEqual(1, rowsAdded);
            }

            var result = ExecuteScalar(String.Format("SELECT {0} FROM data", fieldName));
            Assert.AreEqual(value, result);
        }
コード例 #30
0
 public PropertiesColumnWriter(NpgsqlDbType dbType = NpgsqlDbType.Jsonb, int?columnLength = null) : base(dbType, columnLength)
 {
 }
コード例 #31
0
ファイル: NpgsqlParameter.cs プロジェクト: rwrz/npgsql
        /// <summary>
        /// Initializes a new instance of the <see cref="NpgsqlParameter">NpgsqlParameter</see>.
        /// </summary>
        /// <param name="parameterName">The name of the parameter to map.</param>
        /// <param name="parameterType">One of the <see cref="NpgsqlTypes.NpgsqlDbType">NpgsqlDbType</see> values.</param>
        /// <param name="size">The length of the parameter.</param>
        /// <param name="sourceColumn">The name of the source column.</param>
        /// <param name="direction">One of the <see cref="System.Data.ParameterDirection">ParameterDirection</see> values.</param>
        /// <param name="isNullable"><b>true</b> if the value of the field can be null, otherwise <b>false</b>.</param>
        /// <param name="precision">The total number of digits to the left and right of the decimal point to which
        /// <see cref="NpgsqlParameter.Value">Value</see> is resolved.</param>
        /// <param name="scale">The total number of decimal places to which
        /// <see cref="NpgsqlParameter.Value">Value</see> is resolved.</param>
        /// <param name="sourceVersion">One of the <see cref="System.Data.DataRowVersion">DataRowVersion</see> values.</param>
        /// <param name="value">An <see cref="System.Object">Object</see> that is the value
        /// of the <see cref="NpgsqlParameter">NpgsqlParameter</see>.</param>
        public NpgsqlParameter(string parameterName, NpgsqlDbType parameterType, int size, string sourceColumn,
                               ParameterDirection direction, bool isNullable, byte precision, byte scale,
                               DataRowVersion sourceVersion, object value)
            : this()
        {
            ParameterName = parameterName;
            Size = size;
            SourceColumn = sourceColumn;
            Direction = direction;
            IsNullable = isNullable;
            Precision = precision;
            Scale = scale;
            SourceVersion = sourceVersion;
            Value = value;

            NpgsqlDbType = parameterType;
        }
コード例 #32
0
 public LogEventSerializedColumnWriter(NpgsqlDbType dbType = NpgsqlDbType.Jsonb, int?columnLength = null) : base(dbType, columnLength)
 {
 }
コード例 #33
0
ファイル: NpgsqlParameter.cs プロジェクト: Qorpent/Npgsql2
        /// <summary>
        /// Initializes a new instance of the <see cref="Npgsql.NpgsqlParameter">NpgsqlParameter</see>
        /// class with the parameter m_Name, the <see cref="System.Data.DbType">DbType</see>, the size,
        /// the source column m_Name, a <see cref="System.Data.ParameterDirection">ParameterDirection</see>,
        /// the precision of the parameter, the scale of the parameter, a
        /// <see cref="System.Data.DataRowVersion">DataRowVersion</see> to use, and the
        /// value of the parameter.
        /// </summary>
        /// <param m_Name="parameterName">The m_Name of the parameter to map.</param>
        /// <param m_Name="parameterType">One of the <see cref="System.Data.DbType">DbType</see> values.</param>
        /// <param m_Name="size">The length of the parameter.</param>
        /// <param m_Name="sourceColumn">The m_Name of the source column.</param>
        /// <param m_Name="direction">One of the <see cref="System.Data.ParameterDirection">ParameterDirection</see> values.</param>
        /// <param m_Name="isNullable"><b>true</b> if the value of the field can be null, otherwise <b>false</b>.</param>
        /// <param m_Name="precision">The total number of digits to the left and right of the decimal point to which
        /// <see cref="Npgsql.NpgsqlParameter.Value">Value</see> is resolved.</param>
        /// <param m_Name="scale">The total number of decimal places to which
        /// <see cref="Npgsql.NpgsqlParameter.Value">Value</see> is resolved.</param>
        /// <param m_Name="sourceVersion">One of the <see cref="System.Data.DataRowVersion">DataRowVersion</see> values.</param>
        /// <param m_Name="value">An <see cref="System.Object">Object</see> that is the value
        /// of the <see cref="Npgsql.NpgsqlParameter">NpgsqlParameter</see>.</param>
        public NpgsqlParameter(String parameterName, NpgsqlDbType parameterType, Int32 size, String sourceColumn,
                               ParameterDirection direction, bool isNullable, byte precision, byte scale,
                               DataRowVersion sourceVersion, object value)
        {
            this.ParameterName = parameterName;
            this.Size = size;
            this.SourceColumn = sourceColumn;
            this.Direction = direction;
            this.IsNullable = isNullable;
            this.Precision = precision;
            this.Scale = scale;
            this.SourceVersion = sourceVersion;
            this.Value = value;

            if (this.value == null)
            {
                this.value = DBNull.Value;
                type_info = NpgsqlTypesHelper.GetNativeTypeInfo(typeof(String));
            }
            else
            {
                NpgsqlDbType = parameterType; //allow the setter to catch exceptions if necessary.
            }
        }
コード例 #34
0
 protected ColumnWriterBase(NpgsqlDbType dbType, int?columnLength = null)
 {
     DbType       = dbType;
     ColumnLength = columnLength;
 }
コード例 #35
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Npgsql.NpgsqlParameter">NpgsqlParameter</see>
 /// class with the parameter m_Name and the data type.
 /// </summary>
 /// <param m_Name="parameterName">The m_Name of the parameter to map.</param>
 /// <param m_Name="parameterType">One of the <see cref="System.Data.DbType">DbType</see> values.</param>
 public NpgsqlParameter(String parameterName, NpgsqlDbType parameterType)
     : this(parameterName, parameterType, 0, String.Empty)
 {
 }
コード例 #36
0
 public TimestampColumnWriter(NpgsqlDbType dbType = NpgsqlDbType.Timestamp) : base(dbType)
 {
 }
コード例 #37
0
        public void duplicated_field_enum_storage_should_be_taken_from_store_options_duplicated_field_enum_storage_when_it_was_changed(EnumStorage enumStorage, NpgsqlDbType expectedNpgsqlDbType)
        {
            var storeOptions = new StoreOptions();

            storeOptions.Advanced.DuplicatedFieldEnumStorage = enumStorage;

            var mapping = new DocumentMapping <Target>(storeOptions);

            var duplicatedField = mapping.DuplicateField(nameof(Target.Color));

            duplicatedField.DbType.ShouldBe(expectedNpgsqlDbType);
        }
コード例 #38
0
 public RenderedMessageColumnWriter(NpgsqlDbType dbType = NpgsqlDbType.Text, int?columnLength = null) : base(dbType, columnLength)
 {
 }
コード例 #39
0
 /// <summary>
 /// Add a new NpgsqlBackendTypeInfo with the given attributes and conversion handlers to this mapping.
 /// </summary>
 /// <param name="OID">Type OID provided by the backend server.</param>
 /// <param name="Name">Type name provided by the backend server.</param>
 /// <param name="NpgsqlDbType">NpgsqlDbType</param>
 /// <param name="DbType">DbType</param>
 /// <param name="Type">System type to convert fields of this type to.</param>
 /// <param name="BackendTextConvert">Data conversion handler for text encoding.</param>
 /// <param name="BackendBinaryConvert">Data conversion handler for binary data.</param>
 public void AddType(Int32 OID, String Name, NpgsqlDbType NpgsqlDbType, DbType DbType, Type Type,
                     ConvertBackendTextToNativeHandler BackendTextConvert = null,
                     ConvertBackendBinaryToNativeHandler BackendBinaryConvert = null)
 {
     AddType(new NpgsqlBackendTypeInfo(OID, Name, NpgsqlDbType, DbType, Type, BackendTextConvert = null, BackendBinaryConvert = null));
 }
コード例 #40
0
 public MessageTemplateColumnWriter(NpgsqlDbType dbType = NpgsqlDbType.Text, int?columnLength = null) : base(dbType, columnLength)
 {
 }
コード例 #41
0
 internal DbType ToDbType(NpgsqlDbType npgsqlDbType)
 => _npgsqlDbTypeToDbType.TryGetValue(npgsqlDbType, out var dbType) ? dbType : DbType.Object;
コード例 #42
0
 public LevelColumnWriter(bool renderAsText = false, NpgsqlDbType dbType = NpgsqlDbType.Integer, int?columnLength = null) : base(dbType, columnLength)
 {
     _renderAsText = renderAsText;
 }
コード例 #43
0
ファイル: SQLCommand.cs プロジェクト: nolanlum/MyRiotControl
 void Set(string name, NpgsqlDbType type, object value)
 {
     if(!Command.Parameters.Contains(name))
         Command.Parameters.Add(new NpgsqlParameter(name, type));
     Command.Parameters[name].Value = value;
 }
コード例 #44
0
 internal NpgsqlTypeHandler GetByNpgsqlDbType(NpgsqlDbType npgsqlDbType)
 => _byNpgsqlDbType.TryGetValue(npgsqlDbType, out var handler)
         ? handler
         : throw new NpgsqlException($"The NpgsqlDbType '{npgsqlDbType}' isn't present in your database. " +
                                     "You may need to install an extension or upgrade to a newer version.");
コード例 #45
0
        private static string toUpdateBatchMethod(DocumentMapping mapping, NpgsqlDbType idNpgsqlDbType, string typeName)
        {
            var extras =
                mapping.DuplicatedFields.Select(x => x.ToUpdateBatchParam()).Join("");

            return
                $@"
BLOCK:public void RegisterUpdate(UpdateBatch batch, object entity)
var document = ({typeName
                    })entity;
batch.Sproc(`{mapping.UpsertName}`).Param(document.{mapping.IdMember.Name
                    }, NpgsqlDbType.{idNpgsqlDbType}).JsonEntity(document){extras
                    };
END

BLOCK:public void RegisterUpdate(UpdateBatch batch, object entity, string json)
var document = ({
                    typeName})entity;
batch.Sproc(`{mapping.UpsertName}`).Param(document.{mapping.IdMember.Name
                    }, NpgsqlDbType.{idNpgsqlDbType}).JsonBody(json){extras};
END
";
        }
コード例 #46
0
 public CommandParameter(object value, NpgsqlDbType npgsqlDbType)
 {
     Value  = value;
     DbType = npgsqlDbType;
 }
コード例 #47
0
ファイル: NpgsqlParameter.cs プロジェクト: dstimac/revenj
		/// <summary>
		/// Initializes a new instance of the <see cref="Npgsql.NpgsqlParameter">NpgsqlParameter</see>
		/// class with the parameter m_Name, the <see cref="System.Data.DbType">DbType</see>, the size,
		/// and the source column m_Name.
		/// </summary>
		/// <param m_Name="parameterName">The m_Name of the parameter to map.</param>
		/// <param m_Name="parameterType">One of the <see cref="System.Data.DbType">DbType</see> values.</param>
		/// <param m_Name="size">The length of the parameter.</param>
		/// <param m_Name="sourceColumn">The m_Name of the source column.</param>
		public NpgsqlParameter(String parameterName, NpgsqlDbType parameterType, Int32 size, String sourceColumn)
		{
			this.ParameterName = parameterName;

			NpgsqlDbType = parameterType; //Allow the setter to catch any exceptions.

			this.size = size;
			source_column = sourceColumn;
		}
コード例 #48
0
 /// <summary>
 /// Adds a <see cref="Npgsql.NpgsqlParameter">NpgsqlParameter</see> to the <see cref="Npgsql.NpgsqlParameterCollection">NpgsqlParameterCollection</see> given the parameter name and the data type.
 /// </summary>
 /// <param name="parameterName">The name of the parameter.</param>
 /// <param name="parameterType">One of the DbType values.</param>
 /// <returns>The index of the new <see cref="Npgsql.NpgsqlParameter">NpgsqlParameter</see> object.</returns>
 public NpgsqlParameter Add(string parameterName, NpgsqlDbType parameterType)
 {
     NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "Add", parameterName, parameterType);
     return this.Add(new NpgsqlParameter(parameterName, parameterType));
 }
コード例 #49
0
ファイル: CommandTests.cs プロジェクト: baondp/Npgsql
        public void InsertNullValue(DbType? dbType, NpgsqlDbType? npgsqlDbType, string fieldName)
        {
            if (dbType.HasValue && npgsqlDbType.HasValue || (!dbType.HasValue && !npgsqlDbType.HasValue))
                Assert.Fail("Exactly one of dbType and npgsqlDbType must be specified");

            using (var command = new NpgsqlCommand(String.Format("INSERT INTO data ({0}) values (:a)", fieldName), Conn))
            {
                if (dbType.HasValue)
                    command.Parameters.Add(new NpgsqlParameter("a", dbType.Value));
                else
                    command.Parameters.Add(new NpgsqlParameter("a", npgsqlDbType.Value));
                command.Parameters[0].Value = DBNull.Value;
                var rowsAdded = command.ExecuteNonQuery();
                Assert.AreEqual(1, rowsAdded);
            }

            var result = ExecuteScalar(String.Format("SELECT COUNT(*) FROM data WHERE {0} IS NULL", fieldName));
            // The missed cast is needed as Server7.2 returns Int32 and Server7.3+ returns Int64
            Assert.AreEqual(1, result);
        }
コード例 #50
0
 /// <summary>
 /// Writes a single column in the current row as type <paramref name="npgsqlDbType"/>.
 /// </summary>
 /// <param name="value">The value to be written</param>
 /// <param name="npgsqlDbType">
 /// In some cases <typeparamref name="T"/> isn't enough to infer the data type to be written to
 /// the database. This parameter and be used to unambiguously specify the type. An example is
 /// the JSONB type, for which <typeparamref name="T"/> will be a simple string but for which
 /// <paramref name="npgsqlDbType"/> must be specified as <see cref="NpgsqlDbType.Jsonb"/>.
 /// </param>
 /// <typeparam name="T">The .NET type of the column to be written.</typeparam>
 public void Write <T>(T value, NpgsqlDbType npgsqlDbType) => DoWrite(value, npgsqlDbType);
コード例 #51
0
ファイル: NpgsqlParameter.cs プロジェクト: rwrz/npgsql
 /// <summary>
 /// Initializes a new instance of the <see cref="NpgsqlParameter">NpgsqlParameter</see>
 /// </summary>
 /// <param name="parameterName">The name of the parameter to map.</param>
 /// <param name="parameterType">One of the <see cref="NpgsqlTypes.NpgsqlDbType">NpgsqlDbType</see> values.</param>
 /// <param name="size">The length of the parameter.</param>
 /// <param name="sourceColumn">The name of the source column.</param>
 public NpgsqlParameter(string parameterName, NpgsqlDbType parameterType, int size, string sourceColumn)
     : this()
 {
     ParameterName = parameterName;
     NpgsqlDbType = parameterType;
     _size = size;
     SourceColumn = sourceColumn;
 }
コード例 #52
0
ファイル: TypeMappingAttribute.cs プロジェクト: zloom/npgsql
 internal TypeMappingAttribute(string pgName, NpgsqlDbType npgsqlDbType, DbType inferredDbType)
     : this(pgName, npgsqlDbType, new DbType[0], new Type[0], inferredDbType)
 {
 }
コード例 #53
0
ファイル: NpgsqlParameter.cs プロジェクト: Qorpent/Npgsql2
 /// <summary>
 /// Initializes a new instance of the <see cref="Npgsql.NpgsqlParameter">NpgsqlParameter</see>
 /// class with the parameter m_Name and the data type.
 /// </summary>
 /// <param m_Name="parameterName">The m_Name of the parameter to map.</param>
 /// <param m_Name="parameterType">One of the <see cref="System.Data.DbType">DbType</see> values.</param>
 public NpgsqlParameter(String parameterName, NpgsqlDbType parameterType)
     : this(parameterName, parameterType, 0, String.Empty)
 {
 }
コード例 #54
0
 /// <summary>
 /// Adds a <see cref="NpgsqlParameter">NpgsqlParameter</see> to the <see cref="NpgsqlParameterCollection">NpgsqlParameterCollection</see> with the parameter name, the data type, the column length, and the source column name.
 /// </summary>
 /// <param name="parameterName">The name of the parameter.</param>
 /// <param name="parameterType">One of the DbType values.</param>
 /// <param name="size">The length of the column.</param>
 /// <param name="sourceColumn">The name of the source column.</param>
 /// <returns>The index of the new <see cref="NpgsqlParameter">NpgsqlParameter</see> object.</returns>
 public NpgsqlParameter Add(string parameterName, NpgsqlDbType parameterType, int size, string sourceColumn)
 {
     NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "Add", parameterName, parameterType, size, sourceColumn);
     return(this.Add(new NpgsqlParameter(parameterName, parameterType, size, sourceColumn)));
 }
コード例 #55
0
ファイル: NpgsqlParameter.cs プロジェクト: Qorpent/Npgsql2
        /// <summary>
        /// Initializes a new instance of the <see cref="Npgsql.NpgsqlParameter">NpgsqlParameter</see>
        /// class with the parameter m_Name, the <see cref="System.Data.DbType">DbType</see>, the size,
        /// and the source column m_Name.
        /// </summary>
        /// <param m_Name="parameterName">The m_Name of the parameter to map.</param>
        /// <param m_Name="parameterType">One of the <see cref="System.Data.DbType">DbType</see> values.</param>
        /// <param m_Name="size">The length of the parameter.</param>
        /// <param m_Name="sourceColumn">The m_Name of the source column.</param>
        public NpgsqlParameter(String parameterName, NpgsqlDbType parameterType, Int32 size, String sourceColumn)
        {
            NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, CLASSNAME, parameterName, parameterType, size, source_column);

            this.ParameterName = parameterName;

            NpgsqlDbType = parameterType; //Allow the setter to catch any exceptions.

            this.size = size;
            source_column = sourceColumn;
        }
コード例 #56
0
 /// <summary>
 /// Adds a <see cref="NpgsqlParameter">NpgsqlParameter</see> to the <see cref="NpgsqlParameterCollection">NpgsqlParameterCollection</see> given the parameter name and the data type.
 /// </summary>
 /// <param name="parameterName">The name of the parameter.</param>
 /// <param name="parameterType">One of the DbType values.</param>
 /// <returns>The index of the new <see cref="NpgsqlParameter">NpgsqlParameter</see> object.</returns>
 public NpgsqlParameter Add(string parameterName, NpgsqlDbType parameterType)
 {
     NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "Add", parameterName, parameterType);
     return(this.Add(new NpgsqlParameter(parameterName, parameterType)));
 }
コード例 #57
0
ファイル: TypeMappingAttribute.cs プロジェクト: zloom/npgsql
 internal TypeMappingAttribute(string pgName, NpgsqlDbType npgsqlDbType, DbType[] dbTypes, [CanBeNull] Type[] clrTypes, DbType inferredDbType)
     : this(pgName, (NpgsqlDbType?)npgsqlDbType, dbTypes, clrTypes, inferredDbType)
 {
 }
コード例 #58
0
 /// <summary>
 /// Reads the current column, returns its value according to <paramref name="type"/> and
 /// moves ahead to the next column.
 /// If the column is null an exception is thrown.
 /// </summary>
 /// <param name="type">
 /// In some cases <typeparamref name="T"/> isn't enough to infer the data type coming in from the
 /// database. This parameter can be used to unambiguously specify the type. An example is the JSONB
 /// type, for which <typeparamref name="T"/> will be a simple string but for which
 /// <paramref name="type"/> must be specified as <see cref="NpgsqlDbType.Jsonb"/>.
 /// </param>
 /// <typeparam name="T">The .NET type of the column to be read.</typeparam>
 /// <returns>The value of the column</returns>
 public T Read <T>(NpgsqlDbType type) => Read <T>(type, false).GetAwaiter().GetResult();
コード例 #59
0
 /// <summary>
 /// Adds a <see cref="Npgsql.NpgsqlParameter">NpgsqlParameter</see> to the <see cref="Npgsql.NpgsqlParameterCollection">NpgsqlParameterCollection</see> with the parameter name, the data type, the column length, and the source column name.
 /// </summary>
 /// <param name="parameterName">The name of the parameter.</param>
 /// <param name="parameterType">One of the DbType values.</param>
 /// <param name="size">The length of the column.</param>
 /// <param name="sourceColumn">The name of the source column.</param>
 /// <returns>The index of the new <see cref="Npgsql.NpgsqlParameter">NpgsqlParameter</see> object.</returns>
 public NpgsqlParameter Add(string parameterName, NpgsqlDbType parameterType, int size, string sourceColumn)
 {
     NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "Add", parameterName, parameterType, size, sourceColumn);
     return this.Add(new NpgsqlParameter(parameterName, parameterType, size, sourceColumn));
 }
コード例 #60
0
ファイル: TypeMappingAttribute.cs プロジェクト: zloom/npgsql
        //internal TypeMappingAttribute(string pgName, NpgsqlDbType npgsqlDbType, DbType[] dbTypes=null, Type type=null)
        //    : this(pgName, npgsqlDbType, dbTypes, type == null ? null : new[] { type }) {}

        internal TypeMappingAttribute(string pgName, NpgsqlDbType npgsqlDbType)
            : this(pgName, npgsqlDbType, new DbType[0], new Type[0], null)
        {
        }