diff --git a/contrib/shark/expected/objectproperty.out b/contrib/shark/expected/objectproperty.out index 21719f109e55cf01eaf060d8012838d42d4f71b9..5cf1f111c8d65d0cacac828f83dde06a54725f4c 100644 --- a/contrib/shark/expected/objectproperty.out +++ b/contrib/shark/expected/objectproperty.out @@ -74,6 +74,24 @@ select object_id('sys.trigger_update_total_grade'); (1 row) set search_path = 'sys'; +select object_id('contrib_regression.students'); + object_id +----------- + +(1 row) + +select object_id('contrib_regression..students'); + object_id +----------- +--?.* +(1 row) + +select object_id('contrib_regression...students'); + object_id +----------- + +(1 row) + select object_id('students', 'U'); object_id ----------- @@ -117,8 +135,11 @@ select object_id('sys.students'); (1 row) select object_id('contrib_regression.sys.students'); -ERROR: Can only do lookup in current database. -CONTEXT: referenced column: object_id + object_id +----------- +--?.* +(1 row) + select objectproperty(object_id('students'), 'istable') as istable; istable --------- @@ -937,8 +958,11 @@ select object_id('othersys.students'); (1 row) select object_id('otherdb.sys.students'); -ERROR: Can only do lookup in current database. -CONTEXT: referenced column: object_id + object_id +----------- + +(1 row) + select objectproperty('', 'istable') as istable; istable --------- diff --git a/contrib/shark/sql/objectproperty.sql b/contrib/shark/sql/objectproperty.sql index 59b39703799395950b0a5f4748103652a9171759..8c6bc109b56f92b1821bca2a6509d98995ef94a3 100644 --- a/contrib/shark/sql/objectproperty.sql +++ b/contrib/shark/sql/objectproperty.sql @@ -49,6 +49,9 @@ select object_id('sys.insert_student'); select object_id('sys.trigger_update_total_grade'); set search_path = 'sys'; +select object_id('contrib_regression.students'); +select object_id('contrib_regression..students'); +select object_id('contrib_regression...students'); select object_id('students', 'U'); select object_id('students_pkey', 'PK'); diff --git a/contrib/shark/varlena.cpp b/contrib/shark/varlena.cpp index 66064376b41e66dbf7b0e8fa8d0e05338a8eb062..61952ef498b2ab20a128a1a9cfa0f04273fdd698 100644 --- a/contrib/shark/varlena.cpp +++ b/contrib/shark/varlena.cpp @@ -567,42 +567,68 @@ object_id_internal(PG_FUNCTION_ARGS) if (strlen(object_name) < 1) { PG_RETURN_NULL(); } - - List* nameList = stringToQualifiedNameList(object_name); - + char* db_name = NULL; char* schema_name = NULL; char* obj_name = NULL; - switch (list_length(nameList)) - { - case 1: - obj_name = strVal(linitial(nameList)); - break; - case 2: - obj_name = strVal(lsecond(nameList)); - schema_name = get_current_physical_schema_name(strVal(linitial(nameList))); - break; - case 3: - obj_name = strVal(lthird(nameList)); - schema_name = get_current_physical_schema_name(strVal(lsecond(nameList))); - db_name = strVal(linitial(nameList)); - break; - default: - ereport(ERROR, - (errcode(ERRCODE_SYNTAX_ERROR), - errmsg("improper qualified name (too many dotted names): %s", NameListToString(nameList)))); - break; + + char *tok = object_name; + while (*tok) { + // Detected two consecutive points + if (*tok == '.' && *(tok + 1) == '.') { + *tok = '\0'; + db_name = object_name; + tok += 2; + break; + } else { + tok++; + } + } + if(db_name != NULL) { + obj_name = tok; + } else { + List* nameList; + PG_TRY(); + { + nameList = stringToQualifiedNameList(object_name); + } + PG_CATCH(); + { + FlushErrorState(); + PG_RETURN_NULL(); + } + PG_END_TRY(); + switch (list_length(nameList)) + { + case 1: + obj_name = strVal(linitial(nameList)); + break; + case 2: + obj_name = strVal(lsecond(nameList)); + schema_name = get_current_physical_schema_name(strVal(linitial(nameList))); + break; + case 3: + obj_name = strVal(lthird(nameList)); + schema_name = get_current_physical_schema_name(strVal(lsecond(nameList))); + db_name = strVal(linitial(nameList)); + break; + default: + PG_RETURN_NULL(); + break; + } } if (obj_name == NULL || strlen(obj_name) < 1) { PG_RETURN_NULL(); } - if (db_name != NULL && db_name != get_and_check_db_name(u_sess->proc_cxt.MyDatabaseId, true)) { - ereport(ERROR, - (errcode(ERRCODE_UNDEFINED_DATABASE), - errmsg("Can only do lookup in current database."))); + char* current_db = get_and_check_db_name(u_sess->proc_cxt.MyDatabaseId, false); + if (db_name != NULL && strcmp(db_name, current_db) != 0) { + pfree_ext(current_db); + PG_RETURN_NULL(); } + pfree_ext(current_db); + Oid id = search_oid_in_schema(schema_name, obj_name, object_type); if (id == InvalidOid) { PG_RETURN_NULL();