2005-11-22 11:25:59 +00:00
|
|
|
/*************************************************************************
|
|
|
|
* *
|
|
|
|
* YAP Prolog *
|
|
|
|
* *
|
|
|
|
* Yap Prolog was developed at NCCUP - Universidade do Porto *
|
|
|
|
* *
|
|
|
|
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
|
|
|
|
* *
|
|
|
|
**************************************************************************
|
|
|
|
* *
|
|
|
|
* File: myddas_errors.yap *
|
|
|
|
* Last rev: *
|
|
|
|
* mods: *
|
|
|
|
* comments: MYDDAS errors checks and errors Messages *
|
|
|
|
* *
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
:- module(myddas_errors,[
|
2005-12-19 13:41:15 +00:00
|
|
|
'$error_checks'/1
|
2005-11-22 11:25:59 +00:00
|
|
|
]).
|
|
|
|
|
2005-12-19 13:41:15 +00:00
|
|
|
:- use_module(myddas_util_predicates,[
|
|
|
|
'$make_a_list'/2,
|
2006-03-09 15:52:06 +00:00
|
|
|
'$check_fields'/2,
|
|
|
|
'$check_list_on_list'/2
|
2005-12-19 13:41:15 +00:00
|
|
|
]).
|
2005-11-22 11:25:59 +00:00
|
|
|
|
2006-02-10 23:42:19 +00:00
|
|
|
'$error_checks'(db_abolish(ModulePredName,Arity)):-!,
|
|
|
|
(ModulePredName = Module:PredName ->
|
|
|
|
atom(Module),
|
|
|
|
atom(PredName)
|
|
|
|
;
|
|
|
|
atom(ModulePredName)
|
|
|
|
),
|
|
|
|
number(Arity).
|
2006-04-30 11:11:25 +01:00
|
|
|
'$error_checks'(db_show_databases(Connection)):- !,
|
|
|
|
atom(Connection).
|
2006-02-05 02:19:15 +00:00
|
|
|
'$error_checks'(db_show_database(Connection,_)):- !,
|
|
|
|
atom(Connection).
|
2006-04-30 11:11:25 +01:00
|
|
|
'$error_checks'(db_my_sql_mode(Connection,_)):- !,
|
|
|
|
atom(Connection).
|
2006-02-05 02:19:15 +00:00
|
|
|
'$error_checks'(db_change_database(Connection,Database)):- !,
|
|
|
|
atom(Connection),
|
|
|
|
atom(Database).
|
2006-01-25 20:40:21 +00:00
|
|
|
'$error_checks'(db_prolog_select_multi(Connection,DbGoalsList,_)):- !,
|
|
|
|
atom(Connection),
|
|
|
|
is_list(DbGoalsList).
|
2006-01-17 22:54:02 +00:00
|
|
|
'$error_checks'(db_multi_queries_number(Connection,Number)):-!,
|
|
|
|
atom(Connection),
|
|
|
|
( var(Number) ->
|
|
|
|
true
|
|
|
|
;
|
|
|
|
number(Number),
|
|
|
|
Number > 0
|
|
|
|
).
|
2006-01-09 13:38:02 +00:00
|
|
|
'$error_checks'(db_command(Connection,SQL)):-!,
|
|
|
|
atom(Connection),
|
|
|
|
nonvar(SQL).
|
2006-05-03 19:02:29 +01:00
|
|
|
#ifdef MYDDAS_STATS
|
2006-01-08 16:30:00 +00:00
|
|
|
'$error_checks'(db_stats(_,List)):-!,
|
|
|
|
var(List).
|
2006-05-03 19:02:29 +01:00
|
|
|
'$error_checks'(db_stats_time(Reference,Time)):-!,
|
|
|
|
number(Reference),
|
|
|
|
var(Time).
|
|
|
|
#endif
|
2005-12-19 13:41:15 +00:00
|
|
|
'$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),
|
2005-11-22 11:25:59 +00:00
|
|
|
% Number of fields of the Relation, must be
|
|
|
|
% equal to the number of attributes
|
2005-12-19 13:41:15 +00:00
|
|
|
c_db_connection_type(Con,ConType),
|
|
|
|
( ConType == mysql ->
|
|
|
|
c_db_my_number_of_fields(Relation,Con,Arity)
|
2015-02-04 10:53:04 +00:00
|
|
|
; ConType == sqlit3 ->
|
|
|
|
c_sqlit3_number_of_fields(Relation,Con,Arity)
|
2005-12-19 13:41:15 +00:00
|
|
|
;
|
|
|
|
c_db_odbc_number_of_fields(Relation,Con,Arity)
|
|
|
|
),
|
2005-11-22 11:25:59 +00:00
|
|
|
length(Att,Arity),
|
|
|
|
% All fields must be Instanciated ( FALTA POR O NULL )
|
|
|
|
'$make_a_list'(Arity,FieldsProperties),
|
2005-12-19 13:41:15 +00:00
|
|
|
( ConType == mysql ->
|
|
|
|
c_db_my_get_fields_properties(Relation,Con,FieldsProperties)
|
2015-02-04 10:53:04 +00:00
|
|
|
;ConType == sqlit3 ->
|
|
|
|
c_sqlit3_get_fields_properties(Relation,Con,FieldsProperties)
|
2005-12-19 13:41:15 +00:00
|
|
|
;
|
|
|
|
c_db_odbc_get_fields_properties(Relation,Con,FieldsProperties)
|
|
|
|
),
|
2005-11-22 11:25:59 +00:00
|
|
|
'$check_fields'(Att,FieldsProperties).
|
2006-03-17 10:41:44 +00:00
|
|
|
'$error_checks'(db_open(mysql,Connection,Host/Db/Port/_,User,Password)) :- !,
|
2005-11-22 11:25:59 +00:00
|
|
|
nonvar(Host), % == \+var(Host)
|
|
|
|
nonvar(User),
|
|
|
|
nonvar(Password),
|
|
|
|
nonvar(Db),
|
2006-03-17 10:41:44 +00:00
|
|
|
integer(Port),
|
2005-12-19 13:41:15 +00:00
|
|
|
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
|
2015-03-04 09:59:42 +00:00
|
|
|
'$error_checks'(db_open(postgres,Connection,_Host/_Db/_Port/_,_User,_Password)) :- !,
|
|
|
|
atom(Connection),
|
|
|
|
get_value(Connection,[]). % Nao pode ter nenhum valor atribuido
|
|
|
|
'$error_checks'(db_open(postgres,Connection,_Host/_Db/_Port/_,_User)) :- !,
|
|
|
|
atom(Connection),
|
|
|
|
get_value(Connection,[]). % Nao pode ter nenhum valor atribuido
|
|
|
|
'$error_checks'(db_open(postgres,Connection,_Host/_Db/_Port/_)) :- !,
|
|
|
|
atom(Connection),
|
|
|
|
get_value(Connection,[]). % Nao pode ter nenhum valor atribuido
|
|
|
|
'$error_checks'(db_open(postgres,Connection)) :- !,
|
|
|
|
atom(Connection),
|
|
|
|
get_value(Connection,[]). % Nao pode ter nenhum valor atribuido
|
|
|
|
'$error_checks'(db_open(sqlite3,Connection,File,_User,_Password)) :- !,
|
2015-02-04 10:53:04 +00:00
|
|
|
nonvar(File), % == \+var(ODBCEntry)
|
|
|
|
atom(Connection),
|
|
|
|
get_value(Connection,[]). % Nao pode ter nenhum valor atribuido
|
2006-03-09 15:52:06 +00:00
|
|
|
'$error_checks'(db_view(Connection,Pred,DbGoal)) :- !,
|
2005-12-19 13:41:15 +00:00
|
|
|
atom(Connection),
|
|
|
|
nonvar(DbGoal),
|
2006-03-09 15:52:06 +00:00
|
|
|
nonvar(Pred),
|
|
|
|
nonvar(DbGoal),
|
2006-06-09 19:32:01 +01:00
|
|
|
Pred =.. [_|_],
|
|
|
|
DbGoal =.. [_|_].
|
2006-04-30 11:11:25 +01:00
|
|
|
%'$check_list_on_list'(PredArgs,DbGoalArgs).
|
2005-12-19 13:41:15 +00:00
|
|
|
'$error_checks'(db_import(Connection,RelationName,PredName)) :- !,
|
|
|
|
atom(Connection),
|
|
|
|
atom(RelationName),
|
|
|
|
atom(PredName).
|
|
|
|
'$error_checks'(db_get_attributes_types(Connection,RelationName,_)) :- !,
|
|
|
|
atom(Connection),
|
2005-11-22 11:25:59 +00:00
|
|
|
nonvar(RelationName).
|
2006-04-30 11:11:25 +01:00
|
|
|
'$error_checks'(db_call_procedure(_,Procedure,Args,LA)) :- !,
|
|
|
|
nonvar(Procedure),
|
|
|
|
ground(Args),
|
|
|
|
not ground(LA).
|
2006-02-10 23:42:19 +00:00
|
|
|
'$error_checks'(db_sql(Connection,SQL,LA)):- !,
|
2005-12-19 13:41:15 +00:00
|
|
|
atom(Connection),
|
|
|
|
nonvar(SQL),
|
2006-01-09 19:07:26 +00:00
|
|
|
not ground(LA).
|
2005-12-19 13:41:15 +00:00
|
|
|
'$error_checks'(db_number_of_fields(Connection,RelationName,_)) :- !,
|
|
|
|
atom(Connection),
|
2005-11-22 11:25:59 +00:00
|
|
|
nonvar(RelationName).
|
2005-12-19 13:41:15 +00:00
|
|
|
'$error_checks'(db_close(Connection)) :- !,
|
|
|
|
atom(Connection).
|
|
|
|
% must have only one relation
|
2006-04-30 11:11:25 +01:00
|
|
|
'$error_checks'(db_datalog_describe(Relation,_)) :- !,
|
2005-11-22 11:25:59 +00:00
|
|
|
nonvar(Relation).
|
2006-05-22 17:45:07 +01:00
|
|
|
'$error_checks'(db_describe(Connection,Relation,_)) :- !,
|
|
|
|
atom(Connection),
|
|
|
|
nonvar(Relation).
|
2005-11-22 11:25:59 +00:00
|
|
|
'$error_checks'(db_my_show_tables(_)):- !.
|
|
|
|
'$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
|
2005-12-19 13:41:15 +00:00
|
|
|
'$error_checks'(get_value(Connection,Con)) :- !,
|
2005-11-22 11:25:59 +00:00
|
|
|
% This also prevents the case of giving the number of the connection
|
|
|
|
% as an argument
|
2005-12-19 13:41:15 +00:00
|
|
|
atom(Connection),
|
|
|
|
var(Con),
|
|
|
|
get_value(Connection,Value),
|
2005-11-22 11:25:59 +00:00
|
|
|
Value \== [].
|
|
|
|
|
|
|
|
% 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
|
|
|
|
% as an argument
|
|
|
|
atom(Conn),
|
|
|
|
var(Connection),
|
|
|
|
get_value(Conn,Value),
|
|
|
|
Value \== [].
|