Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PostgreSQL improvement SqlProvider #367

Open
rafaelleonel opened this issue Jun 10, 2015 · 1 comment
Open

PostgreSQL improvement SqlProvider #367

rafaelleonel opened this issue Jun 10, 2015 · 1 comment

Comments

@rafaelleonel
Copy link

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("')");
@ili
Copy link
Collaborator

ili commented Jun 21, 2015

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants