Advertisement
Guest User

Untitled

a guest
Jul 26th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.03 KB | None | 0 0
  1. diff --git a/src/backend/parser/parse_relation.c b/src/backend/parser/parse_relation.c
  2. index 1e3ecbc..7958f9e 100644
  3. --- a/src/backend/parser/parse_relation.c
  4. +++ b/src/backend/parser/parse_relation.c
  5. @@ -3083,7 +3083,7 @@ errorMissingColumn(ParseState *pstate,
  6. errmsg("column %s.%s does not exist", relname, colname) :
  7. errmsg("column \"%s\" does not exist", colname),
  8. state->rfirst ? closestfirst ?
  9. - errhint("Perhaps you meant to reference the column \"%s.%s\".",
  10. + errhint("Perhaps you meant to reference the column \"%s\".\"%s\".",
  11. state->rfirst->eref->aliasname, closestfirst) :
  12. errhint("There is a column named \"%s\" in table \"%s\", but it cannot be referenced from this part of the query.",
  13. colname, state->rfirst->eref->aliasname) : 0,
  14. @@ -3102,7 +3102,7 @@ errorMissingColumn(ParseState *pstate,
  15. relname ?
  16. errmsg("column %s.%s does not exist", relname, colname) :
  17. errmsg("column \"%s\" does not exist", colname),
  18. - errhint("Perhaps you meant to reference the column \"%s.%s\" or the column \"%s.%s\".",
  19. + errhint("Perhaps you meant to reference the column \"%s\".\"%s\" or the column \"%s\".\"%s\".",
  20. state->rfirst->eref->aliasname, closestfirst,
  21. state->rsecond->eref->aliasname, closestsecond),
  22. parser_errposition(pstate, location)));
  23. diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c
  24. index 3f2cebf..d39b85c 100644
  25. --- a/src/bin/psql/command.c
  26. +++ b/src/bin/psql/command.c
  27. @@ -613,6 +613,105 @@ exec_command(const char *cmd,
  28. }
  29. }
  30.  
  31. + else if (strcmp(cmd, "yes") == 0)
  32. + {
  33. + if (!query_buf)
  34. + {
  35. + psql_error("no query buffer\n");
  36. + status = PSQL_CMD_ERROR;
  37. + }
  38. + else
  39. + {
  40. + bool found = false;
  41. +
  42. + if (pset.last_error_result != NULL ||
  43. + PQresultStatus(pset.last_error_result) != PGRES_NONFATAL_ERROR)
  44. + {
  45. + char *hint = PQresultErrorField(pset.last_error_result,
  46. + PG_DIAG_MESSAGE_HINT);
  47. + char *position = PQresultErrorField(pset.last_error_result,
  48. + PG_DIAG_STATEMENT_POSITION);
  49. +
  50. + /*
  51. + * Here follows some truly awful code that depends on the
  52. + * exact wording of a hint, only works for English, and then
  53. + * does horrific pointer arithmetic string manipulation.
  54. + * - Anonymous
  55. + */
  56. +
  57. + if (position != NULL &&
  58. + hint != NULL &&
  59. + strstr(hint, "Perhaps you meant to reference the ") == hint)
  60. + {
  61. + int begin_old = atoi(position);
  62. + int end_old = begin_old;
  63. + int begin_new = -1;
  64. + int end_new = -1;
  65. + char *s;
  66. +
  67. + /* Find the end of the old indentifier. */
  68. + for (;;)
  69. + {
  70. + /** TODO: Deal with quoted identifiers */
  71. + if (query_buf->data[end_old] == '\0' ||
  72. + query_buf->data[end_old] == ' ')
  73. + break;
  74. + end_old++;
  75. + }
  76. +
  77. + /* Find the new identifier. */
  78. + s = strchr(hint, '\"');
  79. + if (s != NULL)
  80. + {
  81. + begin_new = s - hint;
  82. + s = strchr(s + 1, '"');
  83. + if (s != NULL)
  84. + {
  85. + ++s;
  86. + /* May be followed by ."xxx" */
  87. + if (*s == '.')
  88. + {
  89. + ++s;
  90. + if (*s == '"' && (s = strchr(s + 1, '"')) != NULL)
  91. + {
  92. + ++s;
  93. + end_new = s - hint;
  94. + }
  95. + }
  96. + else
  97. + end_new = s - hint;
  98. + }
  99. + }
  100. +
  101. + if (begin_new != -1 && end_new != -1)
  102. + {
  103. + char *new_query = malloc(begin_old +
  104. + (end_new - begin_new) +
  105. + (strlen(query_buf->data) - end_old) +
  106. + 1);
  107. +
  108. + new_query[0] = '\0';
  109. + strncat(new_query, query_buf->data, begin_old - 1);
  110. + strncat(new_query, hint + begin_new, end_new - begin_new);
  111. + strcat(new_query, query_buf->data + end_old);
  112. +
  113. + resetPQExpBuffer(query_buf);
  114. + appendPQExpBuffer(query_buf, "%s", new_query);
  115. + free(new_query);
  116. + status = PSQL_CMD_NEWEDIT;
  117. + found = true;
  118. + }
  119. + }
  120. + }
  121. +
  122. + if (!found)
  123. + {
  124. + psql_error("there is no suggested correction\n");
  125. + status = PSQL_CMD_ERROR;
  126. + }
  127. + }
  128. + }
  129. +
  130. /*
  131. * \ef -- edit the named function, or present a blank CREATE FUNCTION
  132. * template if no argument is given
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement