bltoolkit icon indicating copy to clipboard operation
bltoolkit copied to clipboard

PostgreSQL improvement SqlProvider

Open rafaelleonel opened this issue 10 years ago • 1 comments

PostgreSQL in the inves SqlProvider to guess the name of the sequence he handle the default value of the column

  • Problem: This may generate error for those not referenced sequence at the default value of the column
  • Alternative: It would use the return already available in version ~ 8 (More would have to identify the version to change the method as version support)

New:

var name =
    attr != null ?
        "'" + attr.SequenceName + "'" :
        Convert(
            string.Format("(  SELECT "
                          + @"   CASE WHEN (pg_attrdef.adsrc ~* 'nextval') is null"
                          + @"   then null"
                          + @"   else SUBSTRING(pg_attrdef.adsrc FROM E'nextval\\(''([^'')]+)''') "
                          + @"   end as NameSequence "
                          + @" FROM pg_attribute "
                          + @" LEFT JOIN pg_attrdef ON (pg_attribute.attrelid = pg_attrdef.adrelid AND pg_attribute.attnum = pg_attrdef.adnum) "
                          + @" INNER JOIN pg_class ON (pg_attribute.attrelid = pg_class.oid) "
                          + @" WHERE lower(pg_class.relname) = lower('{0}') "
                          + @" and lower(pg_attribute.attname) = lower('{1}') "
                          + ")", into.PhysicalName, into.GetIdentityField().PhysicalName),
            ConvertType.NameToQueryField);

AppendIndent(sb)
    .Append("SELECT currval(")
    .Append(name)
    .AppendLine(")");

Old:

var name =
    attr != null ?
        attr.SequenceName :
        Convert(
            string.Format("{0}_{1}_seq", into.PhysicalName, into.GetIdentityField().PhysicalName),
            ConvertType.NameToQueryField);

AppendIndent(sb)
    .Append("SELECT currval('")
    .Append(name)
    .AppendLine("')");

rafaelleonel avatar Jun 10 '15 14:06 rafaelleonel

am I right - this is version specific change and may cause error for server with version lesser then 8?

ili avatar Jun 21 '15 07:06 ili