Revision on the MyDDAS Interface

git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@1481 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
tiagosoares
2005-12-19 13:41:15 +00:00
parent b52c6d333e
commit 4630006e9f
10 changed files with 749 additions and 548 deletions

View File

@@ -16,98 +16,101 @@
*************************************************************************/
:- module(myddas_errors,[
'$error_checks'/1,
'$db_my_error'/2
'$error_checks'/1
]).
:- use_module(myddas_util_predicates).
:- use_module(myddas_util_predicates,[
'$make_a_list'/2,
'$check_fields'/2
]).
% must have only one relation
'$error_checks'(db_my_insert3(_,_,_)):-!.
'$error_checks'(db_my_insert2(_,Conn,[query(Att,[rel(Relation,_)],_)])) :- !,
:- use_module(lists,[
is_list/1
]).
'$error_checks'(db_export_view(Connection,TableViewName,SQLorDbGoal,FieldsInf)):-!,
atom(Connection),
( atom(TableViewName) -> atom(SQLorDbGoal) ; true ),
( atom(SQLorDbGoal) -> atom(TableViewName) ; true ),
is_list(FieldsInf).
'$error_checks'(db_create_table(Connection,TableName,FieldsInf)):-!,
atom(Connection),
atom(TableName),
FieldsInf = [_|_].
'$error_checks'(db_insert3(Connection,RelationName,PredName)):-!,
atom(Connection),
atom(RelationName),
atom(PredName).
'$error_checks'(db_insert2(Connection,_,[query(Att,[rel(Relation,_)],_)])) :- !,
atom(Connection),
get_value(Connection,Con),
% Number of fields of the Relation, must be
% equal to the number of attributes
c_db_my_number_of_fields(Relation,Conn,Arity),
c_db_connection_type(Con,ConType),
( ConType == mysql ->
c_db_my_number_of_fields(Relation,Con,Arity)
;
c_db_odbc_number_of_fields(Relation,Con,Arity)
),
length(Att,Arity),
% All fields must be Instanciated ( FALTA POR O NULL )
'$make_a_list'(Arity,FieldsProperties),
c_db_my_get_fields_properties(Relation,Conn,FieldsProperties),
( ConType == mysql ->
c_db_my_get_fields_properties(Relation,Con,FieldsProperties)
;
c_db_odbc_get_fields_properties(Relation,Con,FieldsProperties)
),
'$check_fields'(Att,FieldsProperties).
%'$error_checks'(Preddb_Call):-
%'$do_error'(db_my_error(incompatible_db_predicate,PredCall)).
'$error_checks'(db_my_open(Host,User,Password,Db,Conn)) :- !,
'$error_checks'(db_open(mysql,Connection,Host/Db,User,Password)) :- !,
nonvar(Host), % == \+var(Host)
nonvar(User),
nonvar(Password),
nonvar(Db),
atom(Conn),
get_value(Conn,[]). % Nao pode ter nenhum valor atribuido
'$error_checks'(db_my_close(_)) :- !.
'$error_checks'(db_my_import(RelationName,PredName,_)) :- !,
nonvar(RelationName),
atom(Connection),
get_value(Connection,[]). % Nao pode ter nenhum valor atribuido
'$error_checks'(db_open(odbc,Connection,ODBCEntry,User,Password)) :- !,
nonvar(ODBCEntry), % == \+var(ODBCEntry)
nonvar(User),
nonvar(Password),
atom(Connection),
get_value(Connection,[]). % Nao pode ter nenhum valor atribuido
'$error_checks'(db_view(Connection,PredName,DbGoal)) :- !,
atom(Connection),
nonvar(DbGoal),
nonvar(PredName).
'$error_checks'(db_my_view(PredName,DbGoal,_)) :- !,
nonvar(DbGoal),
nonvar(PredName).
'$error_checks'(db_my_number_of_fields(RelationName,_,_)) :- !,
'$error_checks'(db_import(Connection,RelationName,PredName)) :- !,
atom(Connection),
atom(RelationName),
atom(PredName).
'$error_checks'(db_get_attributes_types(Connection,RelationName,_)) :- !,
atom(Connection),
nonvar(RelationName).
'$error_checks'(db_my_get_attributes_types(RelationName,_,_)) :- !,
'$error_checks'(db_sql_select(Connection,SQL,LA)):- !,
atom(Connection),
nonvar(SQL),
var(LA).
'$error_checks'(db_number_of_fields(Connection,RelationName,_)) :- !,
atom(Connection),
nonvar(RelationName).
'$error_checks'(db_close(Connection)) :- !,
atom(Connection).
% must have only one relation
'$error_checks'(db_my_describe(Relation,_)) :- !,
nonvar(Relation).
'$error_checks'(db_my_show_tables(_)):- !.
'$error_checks'(db_my_sql_select(_,SQL,LA)):- !,
nonvar(SQL),
var(LA).
'$error_checks'(db_is_database_predicate(PredName,Arity,Module)):-!,
nonvar(PredName),
nonvar(Arity),
nonvar(Module).
% Prevent the error of given an atom that has no value
'$error_checks'(get_value(Conn,Connection)) :- !,
'$error_checks'(get_value(Connection,Con)) :- !,
% This also prevents the case of giving the number of the connection
% as an argument
atom(Conn),
var(Connection),
get_value(Conn,Value),
atom(Connection),
var(Con),
get_value(Connection,Value),
Value \== [].
% must have only one relation
%'$error_checks'(db_insert(_,_,_)):-!.
'$error_checks'(db_odbc_insert3(_,_,_)):-!.
'$error_checks'(db_odbc_insert2(PredName,Conn,[query(Att,[rel(Relation,_)],_)])) :- !,
% Number of fields of the Relation, must be
% equal to the number of attributes
c_db_odbc_number_of_fields(Relation,Conn,Arity),
length(Att,Arity),
% All fields must be Instanciated ( FALTA POR O NULL )
'$make_a_list'(Arity,FieldsProperties),
c_db_odbc_get_fields_properties(Relation,Conn,FieldsProperties),
'$check_fields'(Att,FieldsProperties).
%'$error_checks'(PredCall):-
%'$do_error'(db_error(incompatible_db_predicate,PredCall)).
'$error_checks'(db_odbc_open(Host,User,Password,Conn)) :- !,
nonvar(Host), % == \+var(Host)
nonvar(User),
nonvar(Password),
atom(Conn),
get_value(Conn,[]). % Nao pode ter nenhum valor atribuido
'$error_checks'(db_odbc_close(_)) :- !.
'$error_checks'(db_odbc_import(RelationName,PredName,_)) :- !,
nonvar(RelationName),
nonvar(PredName).
'$error_checks'(db_odbc_view(PredName,DbGoal,Connection)) :- !,
nonvar(DbGoal),
nonvar(PredName).
'$error_checks'(db_odbc_number_of_fields(RelationName,Connection,Arity)) :- !,
nonvar(RelationName).
'$error_checks'(db_odbc_get_attributes_types(RelationName,Connection,TypesList)) :- !,
nonvar(RelationName).
'$error_checks'(db_odbc_sql_select(Connection,SQL,LA)):- !,
nonvar(SQL),
var(LA).
% Prevent the error of given an atom that has no value
'$error_checks'(get_value(Conn,Connection)) :- !,
% This also prevents the case of giving the number of the connection
@@ -116,9 +119,3 @@
var(Connection),
get_value(Conn,Value),
Value \== [].
'$db_my_error'(ERROR,_):-var(ERROR),!.
'$db_my_error'(2005,c_db_my_connect(Host,User,Password,Db,Connection)):-!,
write(Host),nl.