Пример #1
0
        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));
        }
Пример #2
0
 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()}"),
     });