public KDPgValueTypeEnum(TypeRegistry.EnumEntry enumEntry) { EnumEntry = enumEntry; PostgresTypeName = enumEntry.EnumName == null ? "text" : EscapeUtils.QuoteTable(enumEntry.EnumName, enumEntry.Schema); }
public static TypedExpression CurrSeqValueOfTable(KdPgColumnDescriptor column) { RawQuery rq = new RawQuery(); rq.Append("currval(pg_get_serial_sequence("); rq.Append(EscapeUtils.EscapePostgresString(EscapeUtils.QuoteTable(column.Table.Name, column.Table.Schema))); rq.Append(","); rq.Append(EscapeUtils.EscapePostgresString(column.Name)); rq.Append("))"); return(new TypedExpression(rq, KDPgValueTypeInstances.Integer)); }
public static string ConvertToPgString(object value) { return(value switch { string s => "'" + s.Replace("'", "''") + "'", short v => v.ToString(), int v => v.ToString(), long v => v.ToString(), float v => v.ToString(CultureInfo.InvariantCulture), double v => v.ToString(CultureInfo.InvariantCulture), DateTime v => EscapeUtils.EscapePostgresString(v.ToString("yyyy-MM-dd HH:mm:ss.ffffff")), byte[] v => @$ "E'\x{v.Select(x => x.ToString(" x2 ")).JoinString()}'", IEnumerable v => @$ "ARRAY[{v.Cast<object>().Select(ConvertToPgString).JoinString(", ")}]", _ => throw new ArgumentException($"unable to escape value of type: {value.GetType()}"), });
public Driver(string dsn, string schema, string appName = null, int minPoolSize = 1, int maxPoolSize = 10) { UrlUtils.ParseUri(dsn, out _, out var user, out var pass, out var host, out int port, out string path); path = path.TrimStart('/'); // ReSharper disable once HeapView.ObjectAllocation.Evident _connString = new NpgsqlConnectionStringBuilder { Database = path, Username = user, Password = pass, Host = host, Port = port, ApplicationName = appName, Pooling = true, MinPoolSize = minPoolSize, MaxPoolSize = maxPoolSize, SearchPath = EscapeUtils.QuoteObjectName(schema), }.ToString(); }