MyDDAS: Added some new functionalitys to MyDDAS

git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@1526 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
tiagosoares 2006-01-25 20:40:21 +00:00
parent 08d6e238fb
commit e66348b44c
6 changed files with 100 additions and 17 deletions

View File

@ -52,6 +52,7 @@ STATIC_PROTO(int c_db_my_row,(void));
STATIC_PROTO(int c_db_my_row_cut,(void));
STATIC_PROTO(int c_db_my_get_fields_properties,(void));
STATIC_PROTO(int c_db_my_number_of_fields_in_query,(void));
STATIC_PROTO(int c_db_my_get_next_result_set,(void));
static void n_print(int, char);
@ -80,7 +81,7 @@ c_db_my_connect(void) {
return FALSE;
}
if (mysql_real_connect(conn, host, user, passwd, database,0, NULL, 0) == NULL) {
if (mysql_real_connect(conn, host, user, passwd, database,0, NULL, CLIENT_MULTI_STATEMENTS) == NULL) {
printf("erro no connect\n");
return FALSE;
}
@ -639,6 +640,21 @@ c_db_my_get_fields_properties(void) {
return TRUE;
}
/* c_db_my_get_next_result_set: Connection * NextResSet */
static int
c_db_my_get_next_result_set(void) {
Term arg_conn = Deref(ARG1);
Term arg_next_res_set = Deref(ARG2);
MYSQL *conn = (MYSQL *) (IntegerOfTerm(arg_conn));
MYSQL_RES *res_set=NULL;
if (mysql_next_result(conn) == 0){
res_set = mysql_store_result(conn);
Yap_unify(arg_next_res_set, MkIntegerTerm((int) res_set));
}
return TRUE;
}
void Yap_InitMYDDAS_MySQLPreds(void)
{
@ -665,6 +681,9 @@ void Yap_InitMYDDAS_MySQLPreds(void)
/* db_get_fields_properties: PredName x Connnection x PropertiesList*/
Yap_InitCPred("c_db_my_get_fields_properties",3,c_db_my_get_fields_properties,0);
/* db_get_fields_properties: PredName x Connnection x PropertiesList*/
Yap_InitCPred("c_db_my_get_next_result_set",2,c_db_my_get_next_result_set,0);
}
void Yap_InitBackMYDDAS_MySQLPreds(void)

View File

@ -99,7 +99,10 @@ myddas_current_time(void) {
/* to get time as Yap */
Int now, interval;
Yap_cputime_interval(&now, &interval);
//Yap_cputime_interval(&now, &interval);
//milliseconds
Yap_walltime_interval(&now, &interval);
//return ((realtime)now);
return (now);

View File

@ -26,6 +26,7 @@
db_sql_select/3,
db_prolog_select/3,
db_prolog_select_multi/3,
db_command/2,
db_insert/2,
db_create_table/3,
@ -85,6 +86,9 @@
]).
:- use_module(myddas_util_predicates,[
'$prolog2sql'/3,
'$create_multi_query'/3,
'$get_multi_results'/4,
'$process_sql_goal'/4,
'$process_fields'/3,
'$get_values_for_insert'/3,
@ -157,12 +161,11 @@ db_close(Connection) :-
db_verbose(X):-
var(X),!,
get_value(db_verbose,X).
db_verbose(1):-!,
set_value(db_verbose,1).
db_verbose(_):-
set_value(db_verbose,0).
db_verbose(N):-!,
set_value(db_verbose,N).
%default value
:- db_verbose(0).
:- set_value(db_verbose,0).
:- set_value(db_verbose_filename,myddas_queries).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@ -249,9 +252,7 @@ db_prolog_select(Connection,LA,DbGoal):-
% build arg list for viewname/Arity
'$make_list_of_args'(1,Arity,ViewName,LA),
copy_term((ViewName,DbGoal),(CopyView,CopyGoal)),
translate(CopyView,CopyGoal,Code),
queries_atom(Code,SQL),
'$prolog2sql'(ViewName,DbGoal,SQL),
get_value(Connection,Con),
c_db_connection_type(Con,ConType),
@ -267,6 +268,28 @@ db_prolog_select(Connection,LA,DbGoal):-
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% db_prolog_select_multi(+,+,-)
% db_prolog_select_multi(guest,[(ramos(A,C),A=C),(ramos(D,B),B=10)],[[A],[D,B]]).
%
db_prolog_select_multi(Connection,DbGoalsList,ListOfResults) :-
'$error_checks'(db_prolog_select_multi(Connection,DbGoalsList,ListOfResults)),
'$create_multi_query'(ListOfResults,DbGoalsList,SQL),
get_value(Connection,Con),
c_db_connection_type(Con,ConType),
'$write_or_not'(SQL),
( ConType == mysql ->
db_my_result_set(Mode),
c_db_my_query(SQL,ResultSet,Con,Mode)
;
true
),
'$get_multi_results'(Con,ConType,ResultSet,ListOfResults).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% db_command/2
%
@ -432,7 +455,7 @@ db_number_of_fields(Connection,RelationName,Arity) :-
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% db_multi_queries_number(+,+)
% TO
% TODO: EVERITHING
%
db_multi_queries_number(Connection,Number) :-
'$error_checks'(db_multi_queries_number(Connection,Number)),
@ -441,3 +464,4 @@ db_multi_queries_number(Connection,Number) :-
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

View File

@ -28,6 +28,9 @@
is_list/1
]).
'$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) ->

View File

@ -71,10 +71,6 @@ translate(ProjectionTerm,DatabaseGoal,SQLQueryTerm):-
% --- code generation ---------------------------------------------------------------
query_generation(Disjunction,TokenProjectionTerm,SQLQueryTerm).
% --- disjunction(Goal,Disjunction) ----------------------------------------------------
%
% turns original goal into disjunctive normalized form by computing all conjunctions
@ -1012,13 +1008,14 @@ query_atom(query(Select,From,Where),QueryList,Diff):-
clause_atom('SELECT',Select,',',QueryList,X1),
clause_atom('FROM',From,',',X1,X2),
clause_atom('WHERE',Where,'AND',X2,Diff).
% column_atom('LIMIT 1',Diff,Diff2).
query_atom(agg_query(Function,Select,From,Where,Group),QueryList,Diff):-
clause_atom('SELECT',Function,Select,',',QueryList,X1),
clause_atom('FROM',From,',',X1,X2),
clause_atom('WHERE',Where,'AND',X2,Diff).
%ILP : PARA NAO POR OS GROUP BYS. FAZER FLAG PARA ISTO
%clause_atom('GROUP BY',Group,',',X3,Diff).
query_atom(negated_existential_subquery(Select,From,Where),QueryList,Diff):-
column_atom('NOT EXISTS(',QueryList,X1),

View File

@ -16,6 +16,9 @@
*************************************************************************/
:- module(myddas_util_predicates,[
'$prolog2sql'/3,
'$create_multi_query'/3,
'$get_multi_results'/4,
'$process_sql_goal'/4,
'$process_fields'/3,
'$check_fields'/2,
@ -50,6 +53,35 @@
queries_atom/2
]).
'$prolog2sql'(ProjTerm,DbGoal,SQL):-
copy_term((ProjTerm,DbGoal),(CopyTerm,CopyGoal)),
translate(CopyTerm,CopyGoal,Code),
queries_atom(Code,SQL).
'$create_multi_query'([ProjTerm],[DbGoal],SQL):- !,
'$lenght'(ProjTerm,Arity),
functor(ViewName,viewname,Arity),
'$make_list_of_args'(1,Arity,ViewName,ProjTerm),
'$prolog2sql'(ViewName,DbGoal,SQL).
'$create_multi_query'([ProjTerm|TermList],[DbGoal|GoalList],SQL):-
'$lenght'(ProjTerm,Arity),
functor(ViewName,viewname,Arity),
'$make_list_of_args'(1,Arity,ViewName,ProjTerm),
'$prolog2sql'(ViewName,DbGoal,SQLQuery),
'$create_multi_query'(TermList,GoalList,SQLMulti),
'$make_atom'([SQLQuery,' ; ',SQLMulti],SQL).
'$get_multi_results'(_,_,_,[]).
'$get_multi_results'(Con,ConType,ResSet,[List|Results]):-
'$lenght'(List,Arity),
( ConType == mysql ->
c_db_my_row(ResSet,Arity,List),!,
c_db_my_get_next_result_set(Con,NextResSet)
;
true
),
'$get_multi_results'(Con,ConType,NextResSet,Results).
'$process_sql_goal'(TableViewName,SQLorDbGoal,TableName,SQL):-
(atom(SQLorDbGoal) ->
SQL = SQLorDbGoal,
@ -288,9 +320,14 @@
'$write_or_not'(X) :-
get_value(db_verbose,1),!,
write(X),nl.
'$write_or_not'(X) :-
get_value(db_verbose,2),!,
get_value(db_verbose_filename,FileName),
open(FileName,append,Stream),
write(Stream,X),write(Stream,';'),nl(Stream),
close(Stream).
'$write_or_not'(_).
'$make_atom'([],'').
'$make_atom'([Atom|T],Final) :-
atom(Atom),!,