Я хочу перечислить все таблицы на сервере метаданных. Я пробовал со следующим шагом данных, но он только рисует одну таблицу в библиотеке, и я не могу понять, почему.Получение таблиц, расположенных на сервере метаданных с помощью SAS
Это код, который я использую:
options metaserver="xxxx"
metaport=8561
metauser="xxxx"
metapass="xxxx"
METAPROTOCOL=BRIDGE
metarepository="Foundation";
data meta_libraries;
length uri serveruri conn_uri domainuri libname ServerContext AuthDomain path_schema
usingpkguri type tableuri coluri $256 id $17
desc $200 libref engine $8 isDBMS $1 table colname coltype collen $32;
keep libname desc libref engine ServerContext path_schema AuthDomain table colname coltype collen
IsPreassigned IsDBMSLibname id;
nobj=.;
n=1;
uri='';
serveruri='';
conn_uri='';
domainuri='';
/***Determine how many libraries there are***/
nobj=metadata_getnobj("omsobj:[email protected] contains '.'",n,uri);
/***Retrieve the attributes for all libraries, if there are any***/
if n>0 then do n=1 to nobj;
libname='';
ServerContext='';
AuthDomain='';
desc='';
libref='';
engine='';
isDBMS='';
IsPreassigned='';
IsDBMSLibname='';
path_schema='';
usingpkguri='';
type='';
id='';
nobj=metadata_getnobj("omsobj:[email protected] contains '.'",n,uri);
rc= metadata_getattr(uri, "Name", libname);
rc= metadata_getattr(uri, "Desc", desc);
rc= metadata_getattr(uri, "Libref", libref);
rc= metadata_getattr(uri, "Engine", engine);
/*rc= metadata_getattr(uri, "IsDBMSLibname", isDBMS);*/
rc= metadata_getattr(uri, "IsDBMSLibname", IsDBMSLibname);
rc= metadata_getattr(uri, "IsPreassigned", IsPreassigned);
rc= metadata_getattr(uri, "Id", Id);
/*** Get associated ServerContext ***/
i=1;
rc= metadata_getnasn(uri, "DeployedComponents", i, serveruri);
if rc > 0 then rc2= metadata_getattr(serveruri, "Name", ServerContext);
else ServerContext='';
/*** If the library is a DBMS library, get the Authentication Domain
associated with the DBMS connection credentials ***/
if isDBMS="1" then do;
i=1;
rc= metadata_getnasn(uri, "LibraryConnection", i, conn_uri);
if rc > 0 then do;
rc2= metadata_getnasn(conn_uri, "Domain", i, domainuri);
if rc2 > 0 then rc3= metadata_getattr(domainuri, "Name", AuthDomain);
end;
end;
/*** Get the path/database schema for this library ***/
rc=metadata_getnasn(uri, "UsingPackages", 1, usingpkguri);
if rc>0 then do;
rc=metadata_resolve(usingpkguri,type,id);
if type='Directory' then rc=metadata_getattr(usingpkguri, "DirectoryName", path_schema);
else if type='DatabaseSchema' then rc=metadata_getattr(usingpkguri, "Name", path_schema);
else path_schema="unknown";
end;
/*** Get the tables associated with this library ***/
/*** If DBMS, tables are associated with DatabaseSchema ***/
if type='DatabaseSchema' then do;
t=1;
ntab=metadata_getnasn(usingpkguri, "Tables", t, tableuri);
if ntab>0 then do t=1 to ntab;
tableuri='';
table='';
ntab=metadata_getnasn(usingpkguri, "Tables", t, tableuri);
tabrc= metadata_getattr(tableuri, "Name", table);
output;
end;
else do;
put 'Library ' libname ' has no tables registered';
output;
end;
end;
end;
else if type='Directory' then do;
t=1;
ntab=metadata_getnasn(uri, "Tables", t, tableuri);
if ntab>0 then do t=1 to ntab;
tableuri='';
table='';
ntab=metadata_getnasn(uri, "Tables", t, tableuri);
tabrc= metadata_getattr(tableuri, "Name", table);
output;
end;
else put 'Library ' libname ' has no tables registered';
end;
/***If there aren't any libraries, write a message to the log***/
else put 'There are no libraries defined in this metadata repository.';
run;
Я был бы признателен, если кто-то имеет какие-либо предложения?
Этот код не работает для меня. У нас есть SAS 9.2 в моей компании, а xmlv2 - в 9.3. Я попытался использовать XML92 вместо этого, но затем я получаю сообщение об ошибке, что xmlmap неправильно сформирован. Ты знаешь почему? – user3270069
Извините за задержку в ответе, но я только заметил, что вы задали вопрос сегодня. Эти ошибки, как правило, связаны с изменением типа данных определения столбца xmlmap (тот, который был представлен выше, был автоматически сгенерирован «преобразователем XML SAS», и поскольку он работал, я не уделял слишком много внимания параметрам на каждом из определения). Я бы предложил вам отладить код, комментируя и раскомментируя операторы put, которые пишут каждый столбец xmlmap. Надеюсь, это поможет. – user3110787
Это только возвращает таблицы, зарегистрированные в библиотеках, которые используют BASE-движок. Это не приведет к возврату таблиц в другие типы файлов библиотеки, например ODBC или OLEDB. –