1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
|
/*************************************************************************
* *
* 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,[
'$error_checks'/1
]).
:- use_module(myddas_util_predicates,[
'$make_a_list'/2,
'$check_fields'/2,
'$check_list_on_list'/2
]).
:- use_module(lists,[
is_list/1
]).
'$error_checks'(db_abolish(ModulePredName,Arity)):-!,
(ModulePredName = Module:PredName ->
atom(Module),
atom(PredName)
;
atom(ModulePredName)
),
number(Arity).
'$error_checks'(db_show_database(Connection,_)):- !,
atom(Connection).
'$error_checks'(db_change_database(Connection,Database)):- !,
atom(Connection),
atom(Database).
'$error_checks'(db_prolog_select_multi(Connection,DbGoalsList,_)):- !,
atom(Connection),
is_list(DbGoalsList).
'$error_checks'(db_multi_queries_number(Connection,Number)):-!,
atom(Connection),
( var(Number) ->
true
;
number(Number),
Number > 0
).
'$error_checks'(db_command(Connection,SQL)):-!,
atom(Connection),
nonvar(SQL).
'$error_checks'(db_stats(_,List)):-!,
var(List).
'$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_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),
( 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'(db_open(mysql,Connection,Host/Db/Port/_,User,Password)) :- !,
nonvar(Host), % == \+var(Host)
nonvar(User),
nonvar(Password),
nonvar(Db),
integer(Port),
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,Pred,DbGoal)) :- !,
atom(Connection),
nonvar(DbGoal),
nonvar(Pred),
nonvar(DbGoal),
Pred =.. [_|PredArgs],
DbGoal =.. [_|DbGoalArgs],
'$check_list_on_list'(PredArgs,DbGoalArgs).
'$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_sql(Connection,SQL,LA)):- !,
atom(Connection),
nonvar(SQL),
not ground(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_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(Connection,Con)) :- !,
% This also prevents the case of giving the number of the connection
% as an argument
atom(Connection),
var(Con),
get_value(Connection,Value),
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 \== [].
|