:- table(ancestor/2). ancestor(X,Y) :- odbc_parent(X,Y). ancestor(X,Z) :- ancestor(X,Y), odbc_parent(Y,Z).
This works with drivers that support multiple open cursors to the same connection at the same time. (Sadly, some don't.) In the case of drivers that don't support multiple open cursors, one can often replace each odbc_import-ed predicate call
...,predForTable(A,B,C),...by
...,findall([A,B,C],predForTable(A,B,C),PredList), member([A,B,C],PredList)...and get the desired effect.