* DefineTask * Create a new cron task. */
| 45 | * Create a new cron task. |
| 46 | */ |
| 47 | ObjectAddress |
| 48 | DefineTask(ParseState *pstate, CreateTaskStmt * stmt) |
| 49 | { |
| 50 | ObjectAddress address; |
| 51 | char *dbname = NULL; |
| 52 | char *username = NULL; |
| 53 | ListCell *option; |
| 54 | DefElem *d_dbname = NULL; |
| 55 | DefElem *d_username = NULL; |
| 56 | Oid jobid = InvalidOid; |
| 57 | AclResult aclresult; |
| 58 | |
| 59 | /* must have CREATE privilege on database */ |
| 60 | aclresult = pg_database_aclcheck(MyDatabaseId, GetUserId(), ACL_CREATE); |
| 61 | if (aclresult != ACLCHECK_OK) |
| 62 | aclcheck_error(aclresult, OBJECT_DATABASE, |
| 63 | get_database_name(MyDatabaseId)); |
| 64 | |
| 65 | foreach(option, stmt->options) |
| 66 | { |
| 67 | DefElem *defel = (DefElem *) lfirst(option); |
| 68 | |
| 69 | if (strcmp(defel->defname, "dbname") == 0) |
| 70 | { |
| 71 | if (d_dbname) |
| 72 | ereport(ERROR, |
| 73 | (errcode(ERRCODE_SYNTAX_ERROR), |
| 74 | errmsg("conflicting or redundant options"), |
| 75 | parser_errposition(pstate, defel->location))); |
| 76 | d_dbname = defel; |
| 77 | } |
| 78 | else if (strcmp(defel->defname, "username") == 0) |
| 79 | { |
| 80 | if (d_username) |
| 81 | ereport(ERROR, |
| 82 | (errcode(ERRCODE_SYNTAX_ERROR), |
| 83 | errmsg("conflicting or redundant options"), |
| 84 | parser_errposition(pstate, defel->location))); |
| 85 | d_username = defel; |
| 86 | } |
| 87 | else |
| 88 | elog(ERROR, "option \"%s\" not recognized", |
| 89 | defel->defname); |
| 90 | } |
| 91 | |
| 92 | /* use the specified or current user */ |
| 93 | if (d_username != NULL && d_username->arg) |
| 94 | { |
| 95 | username = defGetString(d_username); |
| 96 | if (!OidIsValid(get_role_oid(username, false))) |
| 97 | ereport(ERROR, |
| 98 | (errcode(ERRCODE_UNDEFINED_OBJECT), |
| 99 | errmsg("role \"%s\" does not exist", username))); |
| 100 | } |
| 101 | else |
| 102 | username = GetUserNameFromId(GetUserId(), false); |
| 103 | |
| 104 | /* use the specified or current database */ |
no test coverage detected