MyDDAS: Changed the syntax of db_update/2

git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@1507 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
tiagosoares 2006-01-09 19:07:26 +00:00
parent 6ec25f8520
commit 4e1a9d0588
3 changed files with 34 additions and 31 deletions

View File

@ -29,7 +29,7 @@
db_insert/2,
db_create_table/3,
db_export_view/4,
db_update/3,
db_update/2,
db_get_attributes_types/3,
db_number_of_fields/3,
@ -90,7 +90,7 @@
'$make_a_list'/2,
'$make_list_of_args'/4,
'$get_table_name'/2,
'$get_values_for_update'/5,
'$get_values_for_update'/4,
'$extract_args'/4
]).
@ -325,25 +325,33 @@ db_export_view(Connection,TableViewName,SQLorDbGoal,FieldsInf):-
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% db_update/3
% UpdaList = [X,1,Y,2,T,0]
% db_update/2
%
%
db_update(UpdateList,Relation,Connection):-
get_value(Connection,Conn),
db_update(Connection,WherePred-SetPred):-
%TODO: error_checks
functor(Relation,PredName,Arity),
get_value(Connection,Conn),
% Match and Values must be "unifiable"
functor(WherePred,PredName,Arity),
functor(SetPred,PredName,Arity),
functor(NewRelation,PredName,Arity),
'$extract_args'(Relation,1,Arity,ArgsList1),
copy_term(ArgsList1,ArgsList2),
'$make_list_of_args'(1,Arity,NewRelation,ArgsList2),
'$extract_args'(WherePred,1,Arity,WhereArgs),
'$extract_args'(SetPred,1,Arity,SetArgs),
copy_term(WhereArgs,WhereArgsTemp),
'$make_list_of_args'(1,Arity,NewRelation,WhereArgsTemp),
translate(NewRelation,NewRelation,Code),
'$get_values_for_update'(Code,SetArgs,SetCondition,WhereCondition),
'$get_table_name'(Code,TableName),
'$get_values_for_update'(Code,SetCondition,ArgsList1,UpdateList,WhereCondition),
append(SetCondition,WhereCondition,Conditions),
'$make_atom'(['UPDATE ',TableName,' '|Conditions],SQL),
'$write_or_not'(SQL),
c_db_my_query_no_result(SQL,Conn).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

View File

@ -93,7 +93,7 @@
'$error_checks'(db_sql_select(Connection,SQL,LA)):- !,
atom(Connection),
nonvar(SQL),
var(LA).
not ground(LA).
'$error_checks'(db_number_of_fields(Connection,RelationName,_)) :- !,
atom(Connection),
nonvar(RelationName).

View File

@ -24,7 +24,7 @@
'$make_atom'/2,
'$write_or_not'/1,
'$abolish_all'/1,
'$get_values_for_update'/5,
'$get_values_for_update'/4,
'$get_table_name'/2,
'$extract_args'/4,
'$copy_term_nv'/4,
@ -248,31 +248,26 @@
% '$get_values_for_update'(+SQLQueryTerm,-SetFields,+ArgList,+Updatelist,-WhereCondition)
% It will unify with the first clause
% only on the first call of the predicate
'$get_values_for_update'([query(Fields,_,[])],[' SET '|SQLSet],ArgList,UpdateList,[]):-!,
'$get_values_for_set'(Fields,ArgList,UpdateList,Set),
% only on the first call of the predicate
'$get_values_for_update'([query(Fields,_,[])],SetArgs,[' SET '|SQLSet],[]):-!,
'$get_values_for_set'(Fields,SetArgs,Set),
'$build_set_condition'(Set,SQLSet).
'$get_values_for_update'([query(Fields,_,Comp)],[' SET '|SQLSet],ArgList,UpdateList,[' WHERE '|Where]):-!,
'$get_values_for_set'(Fields,ArgList,UpdateList,Set),
'$get_values_for_update'([query(Fields,_,Comp)],SetArgs,[' SET '|SQLSet],[' WHERE '|Where]):-!,
'$get_values_for_set'(Fields,SetArgs,Set),
'$build_set_condition'(Set,SQLSet),
'$get_values_for_where'(Comp,Where).
'$get_values_for_set'([],[],[]).
'$get_values_for_set'([att(_,Field)|FieldList],[Value|ValueList],[Field,Value|FieldValueList]):-
ground(Value),!,
'$get_values_for_set'(FieldList,ValueList,FieldValueList).
'$get_values_for_set'([_|FieldList],[_|ValueList],FieldValueList):-!,
'$get_values_for_set'(FieldList,ValueList,FieldValueList).
'$get_values_for_where'([comp(att(_,Field),'=','$const$'(Atom))],[' ',Field,' = "',Atom,'" ']).
'$get_values_for_where'([comp(att(_,Field),'=','$const$'(Atom))|Comp],[' ',Field,' = "',Atom,'" '|Rest]):-
'$get_values_for_where'(Comp,Rest).
'$get_values_for_set'([],[],_,[]).
'$get_values_for_set'([att(_,Field)|FieldList],[Var|ArgList],UpdateList,[Field,Value|ValueList]):-!,
'$lookup_variable_value'(Var,UpdateList,Value),
'$get_values_for_set'(FieldList,ArgList,UpdateList,ValueList).
'$get_values_for_set'([_|FieldList],[_|ArgList],UpdateList,ValueList):-
'$get_values_for_set'(FieldList,ArgList,UpdateList,ValueList).
'$lookup_variable_value'(Var,[TestVar,Value|_],Value):-
Var==TestVar,!.
'$lookup_variable_value'(Var,[_,_|List],Value):-
'$lookup_variable_value'(Var,List,Value).
'$build_set_condition'([Field,Value|FieldValues],[SQLFirst|SQLRest]):-
'$make_atom'([' ',Field,' = "',Value,'" '],SQLFirst),
'$build_set_condition_with_comma'(FieldValues,SQLRest).