Merge branch 'master' of ssh://git.dcc.fc.up.pt/yap-6.3
Conflicts: library/dialect/swi/fli/swi.c packages/real
This commit is contained in:
@@ -1,81 +0,0 @@
|
||||
AC_ARG_ENABLE(myddas,
|
||||
[ --enable-myddas[[=DIR]] enable the MYDDAS library],
|
||||
if test "$enableval" = yes; then
|
||||
yap_cv_myddas=/usr
|
||||
elif test "$enableval" = no; then
|
||||
yap_cv_myddas=no
|
||||
else
|
||||
yap_cv_myddas=$enable_myddas
|
||||
LDFLAGS="$LDFLAGS -L${yap_cv_myddas}/lib "
|
||||
CPPFLAGS="$CPPFLAGS -I${yap_cv_myddas}/include "
|
||||
ODBC_LDFLAGS="-L${yap_cv_myddas}/lib "
|
||||
ODBC_CFLAGS="-I${yap_cv_myddas}/include "
|
||||
fi,
|
||||
[yap_cv_myddas=/usr])
|
||||
|
||||
AC_ARG_ENABLE(myddas-stats,
|
||||
[ --enable-myddas-stats enable the MYDDAS library statistics support],
|
||||
if test "$yap_cv_myddas" = no; then
|
||||
myddasstats=no
|
||||
else
|
||||
myddasstats="$enableval"
|
||||
fi, myddasstats=no)
|
||||
|
||||
AC_ARG_ENABLE(myddas-top-level,
|
||||
[ --enable-myddas-top-level enable the MYDDAS top-level support to MySQL],
|
||||
if test "$yap_cv_myddas" = no; then
|
||||
myddastoplevel=no
|
||||
else
|
||||
myddastoplevel="$enableval"
|
||||
fi, myddastoplevel=no)
|
||||
|
||||
if test "$yap_cv_myddas" != "no"
|
||||
then
|
||||
dnl check for mysql
|
||||
AC_SEARCH_LIBS(mysql_init, [mysqlclient], [yap_cv_mysql="yes"], [yap_cv_mysql="no"])
|
||||
if test "$yap_cv_mysql" = yes
|
||||
then
|
||||
YAP_EXTRAS="$YAP_EXTRAS -DMYDDAS_MYSQL"
|
||||
fi
|
||||
|
||||
dnl check for odbc
|
||||
case "$target_os" in
|
||||
*darwin*)
|
||||
LIBS="$LIBS -framework CoreFoundation"
|
||||
;;
|
||||
**)
|
||||
;;
|
||||
esac
|
||||
AC_SEARCH_LIBS(SQLAllocHandle, [odbc], [yap_cv_odbc="yes"], [yap_cv_odbc="no"])
|
||||
if test "$yap_cv_odbc" = yes
|
||||
then
|
||||
ODBC_LIBS="$ODBC_LIBS -lodbc"
|
||||
else
|
||||
AC_SEARCH_LIBS(SQLAllocHandle, [iodbc], [yap_cv_odbc="yes"], [yap_cv_odbc="no"])
|
||||
if test "$yap_cv_odbc" = yes
|
||||
then
|
||||
ODBC_LIBS="$ODBC_LIBS -liodbc"
|
||||
fi
|
||||
fi
|
||||
if test "$yap_cv_odbc" = yes
|
||||
then
|
||||
YAP_EXTRAS="$YAP_EXTRAS -DMYDDAS_ODBC"
|
||||
fi
|
||||
|
||||
if test "$myddasstats" = "yes"
|
||||
then
|
||||
YAP_EXTRAS="$YAP_EXTRAS -DMYDDAS_STATS"
|
||||
fi
|
||||
|
||||
if test "$myddastoplevel" = "yes"
|
||||
then
|
||||
YAP_EXTRAS="$YAP_EXTRAS -DMYDDAS_TOP_LEVEL"
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
if test "$yap_cv_myddas" != "no"
|
||||
then
|
||||
AC_CHECK_HEADERS(mysql/mysql.h)
|
||||
fi
|
||||
|
@@ -1,576 +0,0 @@
|
||||
/*************************************************************************
|
||||
* *
|
||||
* 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.yap *
|
||||
* Last rev: *
|
||||
* mods: *
|
||||
* comments: Global predicates for the MyDDAS Interface *
|
||||
* *
|
||||
*************************************************************************/
|
||||
|
||||
#if defined MYDDAS_MYSQL || defined MYDDAS_ODBC
|
||||
|
||||
/* Initialize MYDDAS GLOBAL STRUCTURES */
|
||||
:- c_db_initialize_myddas.
|
||||
|
||||
#ifdef DEBUG
|
||||
:- yap_flag(single_var_warnings,on).
|
||||
#endif
|
||||
|
||||
:- module(myddas,[
|
||||
db_open/5,
|
||||
db_open/4,
|
||||
db_close/1,
|
||||
db_close/0,
|
||||
|
||||
db_verbose/1,
|
||||
db_module/1,
|
||||
db_is_database_predicate/3,
|
||||
#ifdef MYDDAS_STATS
|
||||
db_stats/1,
|
||||
db_stats/2,
|
||||
db_stats_time/2,
|
||||
#endif
|
||||
db_sql/2,
|
||||
db_sql/3,
|
||||
db_sql_select/3,
|
||||
db_prolog_select/2,
|
||||
db_prolog_select/3,
|
||||
db_prolog_select_multi/3,
|
||||
db_command/2,
|
||||
db_assert/2,
|
||||
db_assert/1,
|
||||
db_create_table/3,
|
||||
db_export_view/4,
|
||||
db_update/2,
|
||||
|
||||
db_get_attributes_types/2,
|
||||
db_get_attributes_types/3,
|
||||
db_number_of_fields/2,
|
||||
db_number_of_fields/3,
|
||||
|
||||
db_multi_queries_number/2,
|
||||
|
||||
% myddas_top_level.ypp
|
||||
#ifdef MYDDAS_TOP_LEVEL
|
||||
db_top_level/4,
|
||||
db_top_level/5,
|
||||
db_datalog_select/3,
|
||||
#endif
|
||||
% myddas_assert_predicates.ypp
|
||||
db_import/2,
|
||||
db_import/3,
|
||||
db_view/2,
|
||||
db_view/3,
|
||||
db_insert/2,
|
||||
db_insert/3,
|
||||
db_abolish/2,
|
||||
db_listing/0,
|
||||
db_listing/1
|
||||
#ifdef MYDDAS_MYSQL
|
||||
% myddas_mysql.ypp
|
||||
,
|
||||
db_my_result_set/1,
|
||||
db_datalog_describe/1,
|
||||
db_datalog_describe/2,
|
||||
db_describe/3,
|
||||
db_describe/2,
|
||||
db_datalog_show_tables/1,
|
||||
db_datalog_show_tables/0,
|
||||
db_show_tables/2,
|
||||
db_show_tables/1,
|
||||
db_show_database/2,
|
||||
db_show_databases/2,
|
||||
db_show_databases/1,
|
||||
db_change_database/2,
|
||||
db_call_procedure/4,
|
||||
db_call_procedure/3,
|
||||
db_my_sql_mode/1,
|
||||
db_my_sql_mode/2,
|
||||
db_sql_mode/1,
|
||||
db_sql_mode/2
|
||||
#endif
|
||||
]).
|
||||
|
||||
#ifdef MYDDAS_TOP_LEVEL
|
||||
:- use_module(myddas_top_level,[
|
||||
db_top_level/4,
|
||||
db_top_level/5,
|
||||
db_datalog_select/3
|
||||
]).
|
||||
#endif
|
||||
|
||||
:- use_module(myddas_assert_predicates,[
|
||||
db_import/2,
|
||||
db_import/3,
|
||||
db_view/2,
|
||||
db_view/3,
|
||||
db_insert/2,
|
||||
db_insert/3,
|
||||
db_abolish/2,
|
||||
db_listing/0,
|
||||
db_listing/1
|
||||
]).
|
||||
|
||||
#ifdef MYDDAS_MYSQL
|
||||
:- use_module(myddas_mysql,[
|
||||
db_my_result_set/1,
|
||||
db_datalog_describe/1,
|
||||
db_datalog_describe/2,
|
||||
db_describe/3,
|
||||
db_describe/2,
|
||||
db_datalog_show_tables/1,
|
||||
db_datalog_show_tables/0,
|
||||
db_show_tables/2,
|
||||
db_show_tables/1,
|
||||
db_show_database/2,
|
||||
db_show_databases/2,
|
||||
db_show_databases/1,
|
||||
db_change_database/2,
|
||||
db_call_procedure/4,
|
||||
db_call_procedure/3,
|
||||
db_my_sql_mode/1,
|
||||
db_my_sql_mode/2,
|
||||
db_sql_mode/1,
|
||||
db_sql_mode/2
|
||||
]).
|
||||
#endif /* MYDDAS_MYSQL */
|
||||
|
||||
:- 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,
|
||||
'$make_atom'/2,
|
||||
'$write_or_not'/1,
|
||||
'$abolish_all'/1,
|
||||
'$make_a_list'/2,
|
||||
'$get_table_name'/2,
|
||||
'$get_values_for_update'/4,
|
||||
'$extract_args'/4,
|
||||
#ifdef MYDDAS_STATS
|
||||
'$make_stats_list'/2,
|
||||
#endif
|
||||
'$lenght'/2
|
||||
]).
|
||||
|
||||
:- use_module(myddas_errors,[
|
||||
'$error_checks'/1
|
||||
]).
|
||||
|
||||
:- use_module(myddas_prolog2sql,[
|
||||
translate/3,
|
||||
queries_atom/2
|
||||
]).
|
||||
|
||||
:- use_module(lists,[
|
||||
append/3
|
||||
]).
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% db_open/5
|
||||
% db_open/4
|
||||
%
|
||||
db_open(Interface,HostDb,User,Password):-
|
||||
db_open(Interface,myddas,HostDb,User,Password).
|
||||
|
||||
#ifdef MYDDAS_MYSQL
|
||||
db_open(mysql,Connection,Host/Db/Port/Socket,User,Password) :- !,
|
||||
'$error_checks'(db_open(mysql,Connection,Host/Db/Port/Socket,User,Password)),
|
||||
c_db_my_connect(Host,User,Password,Db,Port,Socket,Con),
|
||||
set_value(Connection,Con).
|
||||
db_open(mysql,Connection,Host/Db/Port,User,Password) :-
|
||||
integer(Port),!,
|
||||
db_open(mysql,Connection,Host/Db/Port/_,User,Password). % Var to be NULL, the default socket
|
||||
db_open(mysql,Connection,Host/Db/Socket,User,Password) :- !,
|
||||
db_open(mysql,Connection,Host/Db/0/Socket,User,Password). % 0 is default port
|
||||
db_open(mysql,Connection,Host/Db,User,Password) :-
|
||||
db_open(mysql,Connection,Host/Db/0/_,User,Password). % 0 is default port and Var to be NULL, the default socket
|
||||
#endif
|
||||
|
||||
#ifdef MYDDAS_ODBC
|
||||
db_open(odbc,Connection,ODBCEntry,User,Password) :-
|
||||
'$error_checks'(db_open(odbc,Connection,ODBCEntry,User,Password)),
|
||||
c_db_odbc_connect(ODBCEntry,User,Password,Con),
|
||||
set_value(Connection,Con).
|
||||
#endif
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% db_close/1
|
||||
% db_close/0
|
||||
%
|
||||
db_close:-
|
||||
db_close(myddas).
|
||||
db_close(Connection):-
|
||||
'$error_checks'(db_close(Connection)),
|
||||
get_value(Connection,Con),
|
||||
'$abolish_all'(Con).
|
||||
db_close(Connection) :-
|
||||
'$error_checks'(db_close(Connection)),
|
||||
get_value(Connection,Con),
|
||||
c_db_connection_type(Con,ConType),
|
||||
( ConType == mysql ->
|
||||
c_db_my_disconnect(Con)
|
||||
;
|
||||
c_db_odbc_disconnect(Con)
|
||||
),
|
||||
set_value(Connection,[]). % "deletes" atom
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% db_verbose/1
|
||||
%
|
||||
%
|
||||
db_verbose(X):-
|
||||
var(X),!,
|
||||
get_value(db_verbose,X).
|
||||
db_verbose(N):-!,
|
||||
set_value(db_verbose,N).
|
||||
%default value
|
||||
:- set_value(db_verbose,0).
|
||||
:- set_value(db_verbose_filename,myddas_queries).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% db_module/1
|
||||
%
|
||||
%
|
||||
db_module(X):-
|
||||
var(X),!,
|
||||
get_value(db_module,X).
|
||||
db_module(ModuleName):-
|
||||
set_value(db_module,ModuleName).
|
||||
% default value
|
||||
:- db_module(user).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% db_is_database_predicate(+,+,+)
|
||||
%
|
||||
%
|
||||
db_is_database_predicate(Module,PredName,Arity):-
|
||||
'$error_checks'(db_is_database_predicate(PredName,Arity,Module)),
|
||||
c_db_check_if_exists_pred(PredName,Arity,Module).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
#ifdef MYDDAS_STATS
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% db_stats(+,-)
|
||||
%
|
||||
%
|
||||
db_stats(List):-
|
||||
db_stats(myddas,List).
|
||||
|
||||
db_stats(Connection,List):-
|
||||
'$error_checks'(db_stats(Connection,List)),
|
||||
NumberOfStats = 10,
|
||||
'$make_a_list'(NumberOfStats,ListX1),
|
||||
( var(Connection) ->
|
||||
c_db_stats(0,ListX1)
|
||||
;
|
||||
get_value(Connection,Conn),
|
||||
c_db_stats(Conn,ListX1)
|
||||
),
|
||||
'$make_stats_list'(ListX1,List).
|
||||
|
||||
#ifdef DEBUG
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% db_stats_time(+,-)
|
||||
% Reference is C pointer (memory reference)
|
||||
%
|
||||
db_stats_time(Reference,Time):-
|
||||
'$error_checks'(db_stats_time(Reference,Time)),
|
||||
c_db_stats_time(Reference,Time).
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
#endif /* DEBUG */
|
||||
|
||||
#endif /* MYDDAS_STATS */
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% db_sql(+,+,-)
|
||||
%
|
||||
%
|
||||
|
||||
%compatibility
|
||||
db_sql_select(Connection,SQL,LA):-
|
||||
db_sql(Connection,SQL,LA).
|
||||
|
||||
db_sql(SQL,LA):-
|
||||
db_sql(myddas,SQL,LA).
|
||||
db_sql(Connection,SQL,LA):-
|
||||
'$error_checks'(db_sql(Connection,SQL,LA)),
|
||||
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,Arity)
|
||||
;
|
||||
c_db_odbc_number_of_fields_in_query(SQL,Con,Arity)
|
||||
),
|
||||
'$make_a_list'(Arity,LA),
|
||||
( ConType == mysql ->
|
||||
!,c_db_my_row(ResultSet,Arity,LA)
|
||||
;
|
||||
'$make_a_list'(Arity,BindList),
|
||||
c_db_odbc_query(SQL,ResultSet,Arity,BindList,Con),!,
|
||||
c_db_odbc_row(ResultSet,BindList,LA)
|
||||
).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% db_prolog_select(+,+,+)
|
||||
%
|
||||
%
|
||||
db_prolog_select(LA,DbGoal):-
|
||||
db_prolog_select(myddas,LA,DbGoal).
|
||||
db_prolog_select(Connection,LA,DbGoal):-
|
||||
|
||||
'$lenght'(LA,Arity),
|
||||
Name=viewname,
|
||||
functor(ViewName,Name,Arity),
|
||||
% build arg list for viewname/Arity
|
||||
ViewName=..[Name|LA],
|
||||
|
||||
'$prolog2sql'(ViewName,DbGoal,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,_),
|
||||
!,c_db_my_row(ResultSet,Arity,LA)
|
||||
;
|
||||
true
|
||||
).
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% 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
|
||||
%
|
||||
%
|
||||
db_command(Connection,SQL):-
|
||||
'$error_checks'(db_command(Connection,SQL)),
|
||||
get_value(Connection,Con),
|
||||
'$write_or_not'(SQL),
|
||||
c_db_connection_type(Con,ConType),
|
||||
( ConType == mysql ->
|
||||
db_my_result_set(Mode),
|
||||
c_db_my_query(SQL,_,Con,Mode,_)
|
||||
;
|
||||
true
|
||||
).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% db_assert/2
|
||||
% db_assert/1
|
||||
%
|
||||
db_assert(PredName):-
|
||||
db_assert(myddas,PredName).
|
||||
|
||||
db_assert(Connection,PredName):-
|
||||
translate(PredName,PredName,Code),
|
||||
'$error_checks'(db_insert2(Connection,PredName,Code)),
|
||||
'$get_values_for_insert'(Code,ValuesList,RelName),
|
||||
'$make_atom'(['INSERT INTO `',RelName,'` VALUES '|ValuesList],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,_,Con,Mode,_)
|
||||
;
|
||||
c_db_odbc_query(SQL,_,_,_,Con)
|
||||
).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% db_create_table/3
|
||||
% FieldsList = [field(Name,Type,Null,Key,DefaultValue)]
|
||||
% Example [field(campo1,'char(12)',y,y,a),field(campo2,int,y,y,0)]
|
||||
% TODO Test with ODBC & Type Checks
|
||||
db_create_table(Connection,TableName,FieldsInf):-
|
||||
'$error_checks'(db_create_table(Connection,TableName,FieldsInf)),
|
||||
get_value(Connection,Con),
|
||||
|
||||
'$process_fields'(FieldsInf,FieldString,KeysSQL),
|
||||
'$make_atom'(['CREATE TABLE `',TableName,'` ( ',FieldString,KeysSQL,' )'],FinalSQL),
|
||||
|
||||
c_db_connection_type(Con,ConType),
|
||||
'$write_or_not'(FinalSQL),
|
||||
( ConType == mysql ->
|
||||
db_my_result_set(Mode),
|
||||
c_db_my_query(FinalSQL,_,Con,Mode,_)
|
||||
;
|
||||
c_db_odbc_query(FinalSQL,_,_,_,Con)
|
||||
).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% db_export_view/4
|
||||
% TODO Test with ODBC
|
||||
%
|
||||
db_export_view(Connection,TableViewName,SQLorDbGoal,FieldsInf):-
|
||||
'$error_checks'(db_export_view(Connection,TableViewName,SQLorDbGoal,FieldsInf)),
|
||||
get_value(Connection,Con),
|
||||
'$process_sql_goal'(TableViewName,SQLorDbGoal,TableName,SQL),
|
||||
|
||||
% Case there's some information about the
|
||||
% attribute fields of the relation given
|
||||
% by the user
|
||||
( FieldsInf == [] ->
|
||||
'$make_atom'(['CREATE TABLE ',TableName,' AS ',SQL],FinalSQL)
|
||||
;
|
||||
'$process_fields'(FieldsInf,FieldString,KeysSQL),
|
||||
'$make_atom'(['CREATE TABLE ',TableName,' (',FieldString,KeysSQL,') AS ',SQL],FinalSQL)
|
||||
),
|
||||
|
||||
c_db_connection_type(Con,ConType),
|
||||
'$write_or_not'(FinalSQL),
|
||||
( ConType == mysql ->
|
||||
db_my_result_set(Mode),
|
||||
c_db_my_query(FinalSQL,_,Con,Mode,_)
|
||||
;
|
||||
c_db_odbc_query(FinalSQL,_,_,_,Con)
|
||||
).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% db_update/2
|
||||
% BUG: db_update dosen't work for this case, just an example
|
||||
% db_update(my1,edge(1,3)-edge(99,99)).
|
||||
% The case where the set condition is "set" to change all the fields
|
||||
db_update(Connection,WherePred-SetPred):-
|
||||
%TODO: error_checks
|
||||
get_value(Connection,Conn),
|
||||
|
||||
% Match and Values must be "unifiable"
|
||||
functor(WherePred,PredName,Arity),
|
||||
functor(SetPred,PredName,Arity),
|
||||
|
||||
functor(NewRelation,PredName,Arity),
|
||||
|
||||
'$extract_args'(WherePred,1,Arity,WhereArgs),
|
||||
'$extract_args'(SetPred,1,Arity,SetArgs),
|
||||
|
||||
copy_term(WhereArgs,WhereArgsTemp),
|
||||
NewRelation=..[PredName|WhereArgsTemp],
|
||||
translate(NewRelation,NewRelation,Code),
|
||||
|
||||
'$get_values_for_update'(Code,SetArgs,SetCondition,WhereCondition),
|
||||
|
||||
'$get_table_name'(Code,TableName),
|
||||
append(SetCondition,WhereCondition,Conditions),
|
||||
'$make_atom'(['UPDATE `',TableName,'` '|Conditions],SQL),
|
||||
'$write_or_not'(SQL),
|
||||
db_my_result_set(Mode),
|
||||
c_db_my_query(SQL,_,Conn,Mode,_).
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% db_get_attributes_types/3
|
||||
% db_get_attributes_types/2
|
||||
%
|
||||
db_get_attributes_types(RelationName,TypesList) :-
|
||||
db_get_attributes_types(myddas,RelationName,TypesList).
|
||||
db_get_attributes_types(Connection,RelationName,TypesList) :-
|
||||
'$error_checks'(db_get_attributes_types(Connection,RelationName,TypesList)),
|
||||
get_value(Connection,Con),
|
||||
c_db_connection_type(Con,ConType),
|
||||
( ConType == mysql ->
|
||||
c_db_my_number_of_fields(RelationName,Con,Arity)
|
||||
;
|
||||
c_db_odbc_number_of_fields(RelationName,Con,Arity)
|
||||
),
|
||||
Size is 2*Arity,
|
||||
'$make_a_list'(Size,TypesList),
|
||||
c_db_connection_type(Con,ConType),
|
||||
( ConType == mysql ->
|
||||
c_db_my_get_attributes_types(RelationName,Con,TypesList)
|
||||
;
|
||||
c_db_odbc_get_attributes_types(RelationName,Con,TypesList)
|
||||
).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% db_number_of_fields/3
|
||||
%
|
||||
%
|
||||
db_number_of_fields(RelationName,Arity) :-
|
||||
db_number_of_fields(myddas,RelationName,Arity).
|
||||
db_number_of_fields(Connection,RelationName,Arity) :-
|
||||
'$error_checks'(db_number_of_fields(Connection,RelationName,Arity)),
|
||||
get_value(Connection,Con),
|
||||
c_db_connection_type(Con,ConType),
|
||||
( ConType == mysql ->
|
||||
c_db_my_number_of_fields(RelationName,Con,Arity)
|
||||
;
|
||||
c_db_odbc_number_of_fields(RelationName,Con,Arity)
|
||||
).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% db_multi_queries_number(+,+)
|
||||
% TODO: EVERITHING
|
||||
%
|
||||
db_multi_queries_number(Connection,Number) :-
|
||||
'$error_checks'(db_multi_queries_number(Connection,Number)),
|
||||
get_value(Connection,Con),
|
||||
c_db_multi_queries_number(Con,Number).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
#endif /*MYDDAS_MYSQL || MYDDAS_ODBC*/
|
@@ -1,293 +0,0 @@
|
||||
/*************************************************************************
|
||||
* *
|
||||
* 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_assert_predicates.yap *
|
||||
* Last rev: *
|
||||
* mods: *
|
||||
* comments: Predicates that assert other for the MyDDAS Interface *
|
||||
* *
|
||||
*************************************************************************/
|
||||
|
||||
:- module(myddas_assert_predicates,[
|
||||
db_import/2,
|
||||
db_import/3,
|
||||
db_view/2,
|
||||
db_view/3,
|
||||
db_insert/2,
|
||||
db_insert/3,
|
||||
db_abolish/2,
|
||||
db_listing/0,
|
||||
db_listing/1
|
||||
]).
|
||||
|
||||
|
||||
:- use_module(myddas,[
|
||||
db_module/1
|
||||
]).
|
||||
|
||||
:- use_module(myddas_errors,[
|
||||
'$error_checks'/1
|
||||
]).
|
||||
|
||||
:- use_module(myddas_util_predicates,[
|
||||
'$get_values_for_insert'/3,
|
||||
'$make_atom'/2,
|
||||
'$write_or_not'/1,
|
||||
'$copy_term_nv'/4,
|
||||
'$assert_attribute_information'/4,
|
||||
'$make_a_list'/2,
|
||||
'$where_exists'/2,
|
||||
'$build_query'/5
|
||||
]).
|
||||
|
||||
:- use_module(myddas_prolog2sql,[
|
||||
translate/3,
|
||||
queries_atom/2
|
||||
]).
|
||||
:- use_module(myddas_mysql,[
|
||||
db_my_result_set/1
|
||||
]).
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% db_import/3
|
||||
% db_import/2
|
||||
%
|
||||
db_import(RelationName,PredName):-
|
||||
db_import(myddas,RelationName,PredName).
|
||||
db_import(Connection,RelationName,PredName) :-
|
||||
'$error_checks'(db_import(Connection,RelationName,PredName)),
|
||||
get_value(Connection,Con),
|
||||
c_db_connection_type(Con,ConType),
|
||||
|
||||
% get relation arity
|
||||
( ConType == mysql ->
|
||||
c_db_my_number_of_fields(RelationName,Con,Arity)
|
||||
;
|
||||
c_db_odbc_number_of_fields(RelationName,Con,Arity)
|
||||
),
|
||||
db_module(Module),
|
||||
not c_db_check_if_exists_pred(PredName,Arity,Module),
|
||||
|
||||
R=..[relation,PredName,Arity,RelationName],
|
||||
% assert relation fact
|
||||
assert(myddas_prolog2sql:R),
|
||||
|
||||
Size is 2*Arity,
|
||||
'$make_a_list'(Size,TypesList),
|
||||
% get attributes types in TypesList [field0,type0,field1,type1...]
|
||||
( ConType == mysql ->
|
||||
c_db_my_get_attributes_types(RelationName,Con,TypesList)
|
||||
;
|
||||
c_db_odbc_get_attributes_types(RelationName,Con,TypesList)
|
||||
),
|
||||
|
||||
% assert attributes facts
|
||||
'$assert_attribute_information'(0,Arity,RelationName,TypesList),
|
||||
|
||||
% build PredName functor
|
||||
functor(P,PredName,Arity),
|
||||
P=..[PredName|LA],
|
||||
|
||||
M=myddas_assert_predicates,
|
||||
%build PredName clause
|
||||
( ConType == mysql ->
|
||||
|
||||
Assert =..[':-',P,','(M:'$copy_term_nv'(P,[],G,_),
|
||||
','(M:translate(G,G,Code),
|
||||
','(M:queries_atom(Code,FinalSQL),
|
||||
','(M:db_my_result_set(Mode),
|
||||
','(M:'$write_or_not'(FinalSQL),
|
||||
','(M:c_db_my_query(FinalSQL,ResultSet,Con,Mode,_),
|
||||
','(!,M:c_db_my_row(ResultSet,Arity,LA))))))))]
|
||||
|
||||
;
|
||||
'$make_a_list'(Arity,BindList),
|
||||
Assert =..[':-',P,','(M:'$copy_term_nv'(P,[],G,_),
|
||||
','(M:translate(G,G,Code),
|
||||
','(M:queries_atom(Code,FinalSQL),
|
||||
','(M:c_db_odbc_query(FinalSQL,ResultSet,Arity,BindList,Con),
|
||||
','(M:'$write_or_not'(FinalSQL),
|
||||
','(!,M:c_db_odbc_row(ResultSet,BindList,LA)))))))]
|
||||
),
|
||||
|
||||
assert(Module:Assert),
|
||||
c_db_add_preds(PredName,Arity,Module,Con).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% db_view/3
|
||||
% db_view/2
|
||||
%
|
||||
db_view(PredName,DbGoal) :-
|
||||
db_view(myddas,PredName,DbGoal).
|
||||
db_view(Connection,PredName,DbGoal) :-
|
||||
'$error_checks'(db_view(Connection,PredName,DbGoal)),
|
||||
get_value(Connection,Con),
|
||||
|
||||
% get arity of projection term
|
||||
functor(PredName,ViewName,Arity),
|
||||
db_module(Module),
|
||||
not c_db_check_if_exists_pred(ViewName,Arity,Module),
|
||||
|
||||
% This copy_term is done to prevent the unification
|
||||
% with top-level variables A='var('A')' error
|
||||
copy_term((PredName,DbGoal),(CopyView,CopyGoal)),
|
||||
|
||||
CopyView=..[ViewName|LA],
|
||||
|
||||
M=myddas_assert_predicates,
|
||||
c_db_connection_type(Con,ConType),
|
||||
|
||||
% build view clause
|
||||
( ConType == mysql ->
|
||||
Assert =..[':-',CopyView,
|
||||
','(M:'$copy_term_nv'(CopyView,[],ProjT,Dic),
|
||||
','(M:'$copy_term_nv'(CopyGoal,Dic,NG,_),
|
||||
','(M:translate(ProjT,NG,Code),
|
||||
','(M:queries_atom(Code,FinalSQL),
|
||||
','(M:db_my_result_set(Mode),
|
||||
','(M:'$write_or_not'(FinalSQL),
|
||||
','(M:c_db_my_query(FinalSQL,ResultSet,Con,Mode,_),
|
||||
','(!,M:c_db_my_row(ResultSet,Arity,LA)))))))))]
|
||||
;
|
||||
% Assert =..[':-',NewName,
|
||||
% ','(M:translate(CopyView,CopyGoal,Code),
|
||||
% ','(M:queries_atom(Code,FinalSQL),
|
||||
% ','(M:'$make_a_list'(Arity,BindList),
|
||||
% ','(M:'$write_or_not'(FinalSQL),
|
||||
% ','(M:c_db_odbc_query(FinalSQL,ResultSet,Arity,BindList,Con),
|
||||
% ','(!,M:c_db_odbc_row(ResultSet,BindList,LA)))))))]
|
||||
true
|
||||
),
|
||||
assert(Module:Assert),
|
||||
c_db_add_preds(ViewName,Arity,Module,Con).
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% db_insert/3
|
||||
%
|
||||
%
|
||||
db_insert(RelationName,PredName) :-
|
||||
db_insert(myddas,RelationName,PredName).
|
||||
db_insert(Connection,RelationName,PredName) :-
|
||||
'$error_checks'(db_insert3(Connection,RelationName,PredName)),
|
||||
get_value(Connection,Con),
|
||||
c_db_connection_type(Con,ConType),
|
||||
|
||||
% get relation arity
|
||||
( ConType == mysql ->
|
||||
c_db_my_number_of_fields(RelationName,Con,Arity)
|
||||
;
|
||||
c_db_odbc_number_of_fields(RelationName,Con,Arity)
|
||||
),
|
||||
db_module(Module),
|
||||
not c_db_check_if_exists_pred(PredName,Arity,Module),
|
||||
|
||||
R=..[relation,PredName,Arity,RelationName],
|
||||
% assert relation fact
|
||||
assert(myddas_prolog2sql:R),
|
||||
|
||||
% build PredName functor
|
||||
functor(Predicate,PredName,Arity),
|
||||
Predicate=..[PredName|LA],
|
||||
|
||||
Size is 2*Arity,
|
||||
'$make_a_list'(Size,TypesList),
|
||||
|
||||
% get attributes types in TypesList [field0,type0,field1,type1...]
|
||||
% and build PredName clause
|
||||
( ConType == mysql ->
|
||||
c_db_my_get_attributes_types(RelationName,Con,TypesList),
|
||||
Assert =..[':-',Predicate,','(myddas_assert_predicates:'$get_values_for_insert'(TypesList,LA,ValuesList),
|
||||
','(myddas_assert_predicates:'$make_atom'(['INSERT INTO `',RelationName,'` VALUES ('|ValuesList],SQL),
|
||||
','(myddas_assert_predicates:db_my_result_set(Mode),
|
||||
','(myddas_assert_predicates:'$write_or_not'(SQL),
|
||||
myddas_assert_predicates:c_db_my_query(SQL,_,Con,Mode,_)))))]
|
||||
;
|
||||
c_db_odbc_get_attributes_types(RelationName,Con,TypesList),
|
||||
Assert =..[':-',Predicate,','(myddas_assert_predicates:'$get_values_for_insert'(TypesList,LA,ValuesList),
|
||||
','(myddas_assert_predicates:'$make_atom'(['INSERT INTO `',RelationName,'` VALUES ('|ValuesList],SQL),
|
||||
','(myddas_assert_predicates:'$write_or_not'(SQL),
|
||||
myddas_assert_predicates:c_db_odbc_query(SQL,_,_,_,Con))))]
|
||||
),
|
||||
assert(Module:Assert),
|
||||
c_db_add_preds(PredName,Arity,Module,Con).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% db_abolish(+,+)
|
||||
%
|
||||
%
|
||||
db_abolish(Module:PredName,Arity):-!,
|
||||
'$error_checks'(db_abolish(Module:PredName,Arity)),
|
||||
c_db_delete_predicate(Module,PredName,Arity),
|
||||
abolish(Module:PredName,Arity).
|
||||
db_abolish(PredName,Arity):-
|
||||
'$error_checks'(db_abolish(PredName,Arity)),
|
||||
db_module(Module),
|
||||
c_db_delete_predicate(Module,PredName,Arity),
|
||||
abolish(Module:PredName,Arity).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% db_abolish(+,+)
|
||||
%
|
||||
%
|
||||
db_abolish(Module:PredName,Arity):-!,
|
||||
'$error_checks'(db_abolish(Module:PredName,Arity)),
|
||||
c_db_delete_predicate(Module,PredName,Arity),
|
||||
abolish(Module:PredName,Arity).
|
||||
db_abolish(PredName,Arity):-
|
||||
'$error_checks'(db_abolish(PredName,Arity)),
|
||||
db_module(Module),
|
||||
c_db_delete_predicate(Module,PredName,Arity),
|
||||
abolish(Module:PredName,Arity).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% db_listing.
|
||||
%
|
||||
%
|
||||
db_listing:-
|
||||
c_db_connection(Con),
|
||||
c_db_preds_conn(Con,Module,Name,Arity),
|
||||
listing(Module:Name/Arity),
|
||||
fail.
|
||||
db_listing.
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% db_listing.
|
||||
%
|
||||
%
|
||||
db_listing(Module:Name/Arity):-!,
|
||||
c_db_connection(Con),
|
||||
c_db_preds_conn(Con,Module,Name,Arity),
|
||||
listing(Module:Name/Arity).
|
||||
db_listing(Name/Arity):-!,
|
||||
c_db_connection(Con),
|
||||
c_db_preds_conn(Con,Module,Name,Arity),
|
||||
listing(Module:Name/Arity).
|
||||
db_listing(Name):-
|
||||
c_db_connection(Con),
|
||||
c_db_preds_conn(Con,Module,Name,Arity),
|
||||
listing(Module:Name/Arity).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
@@ -1,168 +0,0 @@
|
||||
/*************************************************************************
|
||||
* *
|
||||
* 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
|
||||
]).
|
||||
|
||||
'$error_checks'(db_abolish(ModulePredName,Arity)):-!,
|
||||
(ModulePredName = Module:PredName ->
|
||||
atom(Module),
|
||||
atom(PredName)
|
||||
;
|
||||
atom(ModulePredName)
|
||||
),
|
||||
number(Arity).
|
||||
'$error_checks'(db_show_databases(Connection)):- !,
|
||||
atom(Connection).
|
||||
'$error_checks'(db_show_database(Connection,_)):- !,
|
||||
atom(Connection).
|
||||
'$error_checks'(db_my_sql_mode(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).
|
||||
#ifdef MYDDAS_STATS
|
||||
'$error_checks'(db_stats(_,List)):-!,
|
||||
var(List).
|
||||
'$error_checks'(db_stats_time(Reference,Time)):-!,
|
||||
number(Reference),
|
||||
var(Time).
|
||||
#endif
|
||||
'$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 =.. [_|_],
|
||||
DbGoal =.. [_|_].
|
||||
%'$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_call_procedure(_,Procedure,Args,LA)) :- !,
|
||||
nonvar(Procedure),
|
||||
ground(Args),
|
||||
not ground(LA).
|
||||
'$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_datalog_describe(Relation,_)) :- !,
|
||||
nonvar(Relation).
|
||||
'$error_checks'(db_describe(Connection,Relation,_)) :- !,
|
||||
atom(Connection),
|
||||
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 \== [].
|
@@ -1,248 +0,0 @@
|
||||
/*************************************************************************
|
||||
* *
|
||||
* 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_mysql.yap *
|
||||
* Last rev: *
|
||||
* mods: *
|
||||
* comments: MySQL Predicates *
|
||||
* *
|
||||
*************************************************************************/
|
||||
#ifdef MYDDAS_MYSQL
|
||||
|
||||
:- module(myddas_mysql,[
|
||||
db_my_result_set/1,
|
||||
db_datalog_describe/1,
|
||||
db_datalog_describe/2,
|
||||
db_describe/3,
|
||||
db_describe/2,
|
||||
db_datalog_show_tables/1,
|
||||
db_datalog_show_tables/0,
|
||||
db_show_tables/2,
|
||||
db_show_tables/1,
|
||||
db_show_database/2,
|
||||
db_show_databases/2,
|
||||
db_show_databases/1,
|
||||
db_change_database/2,
|
||||
db_call_procedure/4,
|
||||
db_call_procedure/3,
|
||||
db_my_sql_mode/1,
|
||||
db_my_sql_mode/2,
|
||||
db_sql_mode/1,
|
||||
db_sql_mode/2
|
||||
]).
|
||||
|
||||
:- use_module(myddas,[
|
||||
db_sql/3
|
||||
]).
|
||||
|
||||
:- use_module(myddas_errors,[
|
||||
'$error_checks'/1
|
||||
]).
|
||||
|
||||
:- use_module(myddas_util_predicates,[
|
||||
'$get_value'/2,
|
||||
'$make_atom'/2,
|
||||
'$make_atom_args'/2,
|
||||
'$make_a_list'/2,
|
||||
'$write_or_not'/1
|
||||
]).
|
||||
|
||||
|
||||
%--------------------------------------------------------
|
||||
% Public Predicates
|
||||
%--------------------------------------------------------
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% db_my_result_set/1
|
||||
%
|
||||
%
|
||||
db_my_result_set(X):-
|
||||
var(X),!,
|
||||
get_value(db_my_result_set,X).
|
||||
db_my_result_set(use_result):-
|
||||
set_value(db_my_result_set,use_result).
|
||||
db_my_result_set(store_result):-
|
||||
set_value(db_my_result_set,store_result).
|
||||
%default value
|
||||
:- db_my_result_set(store_result).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% db_my_describe/2
|
||||
%
|
||||
%
|
||||
db_datalog_describe(Relation):-
|
||||
db_datalog_describe(myddas,Relation).
|
||||
db_datalog_describe(Connection,Relation) :-
|
||||
'$error_checks'(db_datalog_describe(Relation,Connection)),
|
||||
'$get_value'(Connection,Conn),
|
||||
'$make_atom'(['DESCRIBE ',Relation],SQL),
|
||||
db_my_result_set(Mode),
|
||||
c_db_my_query(SQL,ResultSet,Conn,Mode,_),
|
||||
c_db_my_table_write(ResultSet).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% db_describe/3
|
||||
% db_describe/2
|
||||
% gives the results of the DESCRIBE statement
|
||||
% by backtracking
|
||||
db_describe(Relation,TableInfo) :-
|
||||
db_describe(myddas,Relation,TableInfo).
|
||||
db_describe(Connection,Relation,tableinfo(A1,A2,A3,A4,A5,A6)) :-
|
||||
'$error_checks'(db_describe(Relation,Connection,_)),
|
||||
'$get_value'(Connection,Conn),
|
||||
'$make_atom'(['DESCRIBE ',Relation],SQL),
|
||||
db_my_result_set(Mode),
|
||||
'$write_or_not'(SQL),
|
||||
c_db_my_query(SQL,ResultSet,Conn,Mode,_),
|
||||
!,c_db_my_row(ResultSet,6,[A1,A2,A3,A4,A5,A6]).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% db_datalog_show_tables/1
|
||||
%
|
||||
%
|
||||
db_datalog_show_tables:-
|
||||
db_datalog_show_tables(myddas).
|
||||
db_datalog_show_tables(Connection) :-
|
||||
'$error_checks'(db_my_show_tables(Connection)),
|
||||
'$get_value'(Connection,Conn),
|
||||
db_my_result_set(Mode),
|
||||
'$write_or_not'('SHOW TABLES'),
|
||||
c_db_my_query('SHOW TABLES',ResultSet,Conn,Mode,_),
|
||||
c_db_my_table_write(ResultSet).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% db_show_tables/2
|
||||
% db_show_tables/1
|
||||
% gives the results of the SHOW TABLES statement
|
||||
% by backtracking
|
||||
db_show_tables(Table) :-
|
||||
db_show_tables(myddas,Table).
|
||||
db_show_tables(Connection,table(Table)) :-
|
||||
'$error_checks'(db_my_show_tables(Connection)),
|
||||
'$get_value'(Connection,Conn),
|
||||
db_my_result_set(Mode),
|
||||
'$write_or_not'('SHOW TABLES'),
|
||||
c_db_my_query('SHOW TABLES',ResultSet,Conn,Mode,_),
|
||||
!,c_db_my_row(ResultSet,1,[Table]).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% db_show_database/2
|
||||
%
|
||||
%
|
||||
db_show_database(Connection,Database) :-
|
||||
'$error_checks'(db_show_database(Connection,Database)),
|
||||
'$get_value'(Connection,Con),
|
||||
c_db_my_get_database(Con,Database).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% db_show_databases/2
|
||||
%
|
||||
%
|
||||
db_show_databases(Connection,database(Databases)) :-
|
||||
%'$error_checks'(db_show_databases(Connection,Database)),
|
||||
'$get_value'(Connection,Conn),
|
||||
db_my_result_set(Mode),
|
||||
'$write_or_not'('SHOW DATABASES'),
|
||||
c_db_my_query('SHOW DATABASES',ResultSet,Conn,Mode,_),
|
||||
!,c_db_my_row(ResultSet,1,[Databases]).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% db_show_databases/1
|
||||
% TODO Error Checks
|
||||
%
|
||||
db_show_databases(Connection) :-
|
||||
'$error_checks'(db_my_show_databases(Connection)),
|
||||
'$get_value'(Connection,Conn),
|
||||
db_my_result_set(Mode),
|
||||
'$write_or_not'('SHOW DATABASES'),
|
||||
c_db_my_query('SHOW DATABASES',ResultSet,Conn,Mode,_),
|
||||
c_db_my_table_write(ResultSet).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% db_change_database/2
|
||||
%
|
||||
%
|
||||
db_change_database(Connection,Database) :-
|
||||
'$error_checks'(db_change_database(Connection,Database)),
|
||||
'$get_value'(Connection,Con),
|
||||
'$make_atom'(['USE ',Database],SQL),
|
||||
'$write_or_not'(SQL),
|
||||
c_db_my_change_database(Con,Database).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% db_call_procedure/4
|
||||
% db_call_procedure/3
|
||||
% db_call_procedure(+,+,+,?)
|
||||
% Only support in MySQL 5.0 an above
|
||||
% Called procedure must return results via MySQL result set
|
||||
db_call_procedure(Procedure,Args,Result) :-
|
||||
db_call_procedure(myddas,Procedure,Args,Result).
|
||||
db_call_procedure(Connection,Procedure,Args,LA) :-
|
||||
'$error_checks'(db_call_procedure(Connection,Procedure,Args,LA)),
|
||||
'$make_atom_args'(Args,ArgsSQL),
|
||||
'$make_atom'(['CALL ',Procedure,'(',ArgsSQL,')'],SQL),
|
||||
db_sql(Connection,SQL,LA).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% db_my_sql_mode/1
|
||||
% db_my_sql_mode/2
|
||||
% Possible values : traditional,ansi,strict_trans_tables or '' (empty)
|
||||
db_sql_mode(SQLMode):-
|
||||
db_my_sql_mode(SQLMode).
|
||||
db_sql_mode(Connection,SQLMode):-
|
||||
db_my_sql_mode(Connection,SQLMode).
|
||||
|
||||
db_my_sql_mode(SQLMode):-
|
||||
db_my_sql_mode(myddas,SQLMode).
|
||||
db_my_sql_mode(Connection,SQLMode):-
|
||||
var(SQLMode),!,
|
||||
'$error_checks'(db_my_sql_mode(Connection,SQLMode)),
|
||||
get_value(Connection,Con),
|
||||
c_db_connection_type(Con,mysql), %must be a mysql connection
|
||||
db_sql(Connection,'SELECT @@session.sql_mode',[SQLMode]).
|
||||
db_my_sql_mode(Connection,SQLMode):-
|
||||
'$error_checks'(db_my_sql_mode(Connection,SQLMode)),
|
||||
get_value(Connection,Con),
|
||||
c_db_connection_type(Con,mysql), %must be a mysql connection
|
||||
'$make_atom'(['SET SESSION sql_mode=`',SQLMode,'`'],FinalSQL),
|
||||
'$write_or_not'(FinalSQL),
|
||||
db_my_result_set(Mode),
|
||||
c_db_my_query(FinalSQL,_,Con,Mode,_).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
|
||||
#endif /* MYDDAS_MYSQL*/
|
File diff suppressed because it is too large
Load Diff
@@ -1,110 +0,0 @@
|
||||
:- module(myddas_prolog2sql_optimizer,[
|
||||
optimize_sql/2
|
||||
]).
|
||||
|
||||
:- use_module(lists,[
|
||||
append/3,
|
||||
member/2,
|
||||
delete/3,
|
||||
substitute/4
|
||||
]).
|
||||
|
||||
|
||||
|
||||
optimize_sql([],[]).
|
||||
|
||||
optimize_sql([query(Proj,From,Where)|Tail],[query(Proj1,From1,Where1)|SQLTerm]):-
|
||||
optimize_subquery(Proj,Proj1,From,From1,Where,Where1),
|
||||
optimize_sql(Tail,SQLTerm).
|
||||
|
||||
|
||||
|
||||
% --- optimize_subquery(SQLFrom,SQLWhere) -------------------------------
|
||||
%
|
||||
% If there is a subquery on the query,
|
||||
% uses the less number of table necessary in the
|
||||
% FROM token of the SQL Statement. see(EXPLAIN (SQL statemente with subquerie) )
|
||||
%
|
||||
% Optimization: * All variables on the projection term must be on the outer statement
|
||||
% * All variables on the outer query, must have their respective raltions on the outer query
|
||||
% * Try to maintain as more possibles relations on the inner statement
|
||||
% --------------------------------------------------------------------------------------
|
||||
|
||||
%TODO: BUG
|
||||
% BEWARE WHEN THE SUBQUERY HAS NO TABLES AT THE END OF THIS OPTIMIZATION
|
||||
|
||||
optimize_subquery(SQLSelect,OptSelectFinal,F,F,W,W):-
|
||||
once(member(agg_query(Agg,Select,From,Where,Extra),SQLSelect)),!,
|
||||
optimize_subquery(Select,OptSelect,From,OptFrom,Where,OptWhere),
|
||||
substitute(agg_query(Agg,Select,From,Where,Extra),SQLSelect,agg_query(Agg,OptSelect,OptFrom,OptWhere,Extra),OptSelectFinal).
|
||||
|
||||
optimize_subquery(SQLSelect,SQLSelect,SQLFrom,OptFrom,SQLWhere,OptWhere):-
|
||||
%SQLSelect = OptSelect, % In the future, if needed optimize projection term
|
||||
once(member(negated_existential_subquery(_,SubQueryRelations,_),SQLWhere))
|
||||
;
|
||||
once(member(existential_subquery(_,SubQueryRelations,_),SQLWhere))
|
||||
,!,
|
||||
add_relation(SubQueryRelations,[],RelTotalTemp),
|
||||
add_relation(SQLFrom,RelTotalTemp,RelTotal),
|
||||
projection_term_analysis(SQLSelect,From1,RelTotal,RelTotal1),
|
||||
comparasion_analysis(SQLWhere,From1,From2,RelTotal1,RelTotal2),
|
||||
delete_surplous_tables(SQLWhere,RelTotal2,OptWhere),
|
||||
OptFrom = From2.
|
||||
|
||||
optimize_subquery(ProjTerm,ProjTerm,From,From,Where,Where).
|
||||
|
||||
delete_surplous_tables([negated_existential_subquery(A,_,B)|T],Rel,[negated_existential_subquery(A,Rel,B)|T]):-!.
|
||||
delete_surplous_tables([existential_subquery(A,_,B)|T],Rel,[existential_subquery(A,Rel,B)|T]):-!.
|
||||
delete_surplous_tables([H|T],Rel,[H|Final]):-
|
||||
delete_surplous_tables(T,Rel,Final).
|
||||
|
||||
comparasion_analysis([],From,From,RelTotal,RelTotal).
|
||||
|
||||
comparasion_analysis([comp(att(Relation,_),_,att(Relation,_))|Tail],From1,[rel(Name,Relation)|FromFinal],RelTotal,RelTotalFinal):-
|
||||
member(rel(Name,Relation),RelTotal),!,
|
||||
delete(RelTotal,rel(Name,Relation),RelTotal1),
|
||||
comparasion_analysis(Tail,From1,FromFinal,RelTotal1,RelTotalFinal).
|
||||
|
||||
comparasion_analysis([comp(att(Relation1,_),_,att(Relation2,_))|Tail],From1,From4,RelTotal,RelTotal3):-
|
||||
comparasion_analysis(Tail,From1,From2,RelTotal,RelTotal1),
|
||||
!,
|
||||
(member(rel(Name,Relation1),RelTotal1) ->
|
||||
delete(RelTotal1,rel(Name,Relation1),RelTotal2),
|
||||
From3 = [rel(Name,Relation1)|From2]
|
||||
;
|
||||
RelTotal2 = RelTotal1,
|
||||
From3 = From2
|
||||
),
|
||||
(member(rel(Name,Relation2),RelTotal2) ->
|
||||
delete(RelTotal2,rel(Name,Relation1),RelTotal3),
|
||||
From4 = [rel(Name,Relation2)|From3]
|
||||
;
|
||||
RelTotal3 = RelTotal2,
|
||||
From4 = From3
|
||||
).
|
||||
|
||||
comparasion_analysis([_|Tail],From,FromFinal,RelTotal,RelTotalFinal):-
|
||||
comparasion_analysis(Tail,From,FromFinal,RelTotal,RelTotalFinal).
|
||||
|
||||
|
||||
projection_term_analysis([],[],Relation,Relation).
|
||||
|
||||
projection_term_analysis([att(Relation,_)|Tail],[rel(Name,Relation)|FromFinal],RelTotal,RelTotal1):-
|
||||
member(rel(Name,Relation),RelTotal),!,
|
||||
delete(RelTotal,rel(Name,Relation),Residue),
|
||||
projection_term_analysis(Tail,FromFinal,Residue,RelTotal1).
|
||||
|
||||
projection_term_analysis([_|Tail],FromFinal,RelTotal,RelTotal1):-
|
||||
projection_term_analysis(Tail,FromFinal,RelTotal,RelTotal1).
|
||||
|
||||
|
||||
|
||||
add_relation([],Final,Final).
|
||||
|
||||
add_relation([Rel|Tail],RelTotal,RelFinal):-
|
||||
not once(member(Rel,RelTotal)),!,
|
||||
append(RelTotal,[Rel],RelTemp),
|
||||
add_relation(Tail,RelTemp,RelFinal).
|
||||
|
||||
add_relation([_|Tail],RelTotal,RelFinal):-
|
||||
add_relation(Tail,RelTotal,RelFinal).
|
@@ -1,122 +0,0 @@
|
||||
/*************************************************************************
|
||||
* *
|
||||
* 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_top_level.yap *
|
||||
* Last rev: *
|
||||
* mods: *
|
||||
* comments: MYDDAS Top Level predicates *
|
||||
* *
|
||||
*************************************************************************/
|
||||
|
||||
#ifdef MYDDAS_TOP_LEVEL
|
||||
|
||||
:- module(myddas_top_level,[
|
||||
db_top_level/4,
|
||||
db_top_level/5,
|
||||
db_datalog_select/3
|
||||
]).
|
||||
|
||||
:- use_module(myddas_mysql,[
|
||||
db_my_result_set/1
|
||||
]).
|
||||
|
||||
:- use_module(system,[
|
||||
system/2
|
||||
]).
|
||||
|
||||
:- use_module(charsio,[
|
||||
read_from_chars/2
|
||||
]).
|
||||
|
||||
:- use_module(terms,[
|
||||
term_variables/2
|
||||
]).
|
||||
|
||||
:- use_module(myddas_util_predicates,[
|
||||
'$make_atom'/2,
|
||||
'$prolog2sql'/3,
|
||||
'$write_or_not'/1,
|
||||
'$lenght'/2
|
||||
]).
|
||||
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% db_top_level/5
|
||||
% db_top_level/4
|
||||
%
|
||||
db_top_level(mysql,HostDb,User,Password):-
|
||||
db_top_level(mysql,myddas,HostDb,User,Password).
|
||||
|
||||
db_top_level(mysql,Connection,Host/Db/Port/Socket,User,Password) :- !,
|
||||
'$make_atom'(['mysql',' -h ',Host,' -P ',Port,' -S ',Socket,' -u ',User,' --password=',Password,' ',Db],Command),
|
||||
system(Command,_).
|
||||
db_top_level(mysql,Connection,Host/Db/Port,User,Password) :-
|
||||
integer(Port),!,
|
||||
'$make_atom'(['mysql',' -h ',Host,' -P ',Port,' -u ',User,' --password=',Password,' ',Db],Command),
|
||||
system(Command,_).
|
||||
db_top_level(mysql,Connection,Host/Db/Socket,User,Password) :- !,
|
||||
db_top_level(mysql,Connection,Host/Db/0/Socket,User,Password).
|
||||
db_top_level(mysql,Connection,Host/Db,User,Password):-
|
||||
db_top_level(mysql,Connection,Host/Db/0,User,Password).
|
||||
|
||||
|
||||
|
||||
db_top_level(datalog,Connection,_,_,_):-
|
||||
%'$error_checks'(db_open(mysql,Connection,Host/Db,User,Password)),
|
||||
get_value(Connection,Con),
|
||||
Con \= [],!,
|
||||
c_db_connection_type(Con,mysql),
|
||||
Prompt = ' datalog> ',
|
||||
nl,
|
||||
'$top_level_datalog_cicle'(Connection,Prompt).
|
||||
% c_db_tl_readline(Prompt,Line),
|
||||
% name(Line,CharsLine),
|
||||
% read_from_chars(CharsLine,Query),
|
||||
% term_variables(Query,VarList),
|
||||
% db_datalog_select(Connection,VarList,Query).
|
||||
|
||||
'$top_level_datalog_cicle'(Connection,Prompt):-
|
||||
c_db_tl_readline(Prompt,Line),
|
||||
name(Line,CharsLine),
|
||||
catch(read_from_chars(CharsLine,Query),_,'$top_level_datalog_cicle'(Connection,Prompt)),
|
||||
!,'$top_level_datalog'(Connection,Prompt,Query).
|
||||
|
||||
|
||||
'$top_level_datalog'(_,_,halt):-!.
|
||||
'$top_level_datalog'(Connection,Prompt,Query):-
|
||||
term_variables(Query,[]),!,
|
||||
Query =..[_|Args],
|
||||
db_datalog_select(Connection,Args,Query),
|
||||
'$top_level_datalog_cicle'(Connection,Prompt).
|
||||
'$top_level_datalog'(Connection,Prompt,Query):-
|
||||
term_variables(Query,VarList),
|
||||
db_datalog_select(Connection,VarList,Query),
|
||||
!,'$top_level_datalog_cicle'(Connection,Prompt).
|
||||
|
||||
db_datalog_select(Connection,LA,DbGoal):-
|
||||
|
||||
'$lenght'(LA,Arity),
|
||||
Name=viewname,
|
||||
functor(ViewName,Name,Arity),
|
||||
% build arg list for viewname/Arity
|
||||
ViewName=..[Name|LA],
|
||||
|
||||
'$prolog2sql'(ViewName,DbGoal,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,_),
|
||||
c_db_my_table_write(ResultSet).
|
||||
|
||||
#endif MYDDAS_TOP_LEVEL
|
@@ -1,440 +0,0 @@
|
||||
/*************************************************************************
|
||||
* *
|
||||
* 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_util_predicates.yap *
|
||||
* Last rev: *
|
||||
* mods: *
|
||||
* comments: Auxiliary for the MyDDAS MySQL and ODBC library *
|
||||
* *
|
||||
*************************************************************************/
|
||||
|
||||
:- module(myddas_util_predicates,[
|
||||
'$prolog2sql'/3,
|
||||
'$create_multi_query'/3,
|
||||
'$get_multi_results'/4,
|
||||
'$process_sql_goal'/4,
|
||||
'$process_fields'/3,
|
||||
'$check_fields'/2,
|
||||
'$get_value'/2,
|
||||
'$get_values_for_insert'/3,
|
||||
'$make_atom'/2,
|
||||
'$make_atom_args'/2,
|
||||
'$write_or_not'/1,
|
||||
'$abolish_all'/1,
|
||||
'$get_values_for_update'/4,
|
||||
'$get_table_name'/2,
|
||||
'$extract_args'/4,
|
||||
'$copy_term_nv'/4,
|
||||
'$assert_attribute_information'/4,
|
||||
'$make_a_list'/2,
|
||||
'$make_list_of_args'/4,
|
||||
'$where_exists'/2,
|
||||
'$build_query'/5,
|
||||
'$assert_facts'/2,
|
||||
'$lenght'/2,
|
||||
#ifdef MYDDAS_STATS
|
||||
'$make_stats_list'/2,
|
||||
#endif
|
||||
'$check_list_on_list'/2
|
||||
]).
|
||||
|
||||
:- use_module(myddas,[
|
||||
db_verbose/1
|
||||
]).
|
||||
|
||||
:- use_module(myddas_errors,[
|
||||
'$error_checks'/1
|
||||
]).
|
||||
|
||||
:- use_module(myddas_prolog2sql,[
|
||||
translate/3,
|
||||
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),
|
||||
Name=viewname,
|
||||
functor(ViewName,Name,Arity),
|
||||
ViewName=..[Name|ProjTerm],
|
||||
'$prolog2sql'(ViewName,DbGoal,SQL).
|
||||
'$create_multi_query'([ProjTerm|TermList],[DbGoal|GoalList],SQL):-
|
||||
'$lenght'(ProjTerm,Arity),
|
||||
Name=viewname,
|
||||
functor(ViewName,Name,Arity),
|
||||
ViewName=..[Name|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,
|
||||
TableName = TableViewName
|
||||
;
|
||||
% This copy_term is done to prevent the unification
|
||||
% with top-level variables A='var('A')' error
|
||||
copy_term((TableViewName,SQLorDbGoal),(CopyView,CopyGoal)),
|
||||
translate(CopyView,CopyGoal,Code),
|
||||
queries_atom(Code,SQL),
|
||||
functor(TableViewName,TableName,_)
|
||||
).
|
||||
|
||||
'$process_fields'(FieldsInf,FieldString,KeysSQL):-
|
||||
'$create_field_list'(FieldsInf,FieldString,PrimaryKeys),
|
||||
'$process_primary_keys'(PrimaryKeys,KeysSQL).
|
||||
|
||||
|
||||
'$process_primary_keys'([],'').
|
||||
'$process_primary_keys'([FieldName|Fields],KeysSQL):-
|
||||
'$process_primary_keys_put_comma'(Fields,CommaSQL),
|
||||
'$make_atom'([' , PRIMARY KEY ( ',FieldName,CommaSQL,' )'],KeysSQL).
|
||||
|
||||
'$process_primary_keys_put_comma'([],''):-!.
|
||||
'$process_primary_keys_put_comma'([FieldName|Fields],CommaSQL):-!,
|
||||
'$process_primary_keys_put_comma'(Fields,TempSQL),
|
||||
'$make_atom'([' , `',FieldName,'` ',TempSQL],CommaSQL).
|
||||
|
||||
|
||||
'$create_field_list'([field(Name,Type,Null,Key,DefaultValue)],FinalSQL,PrimaryKeys):-!,
|
||||
'$field_extra_options'(Name,Null,Key,[],DefaultValue,TempSQL,PrimaryKeys),
|
||||
'$make_atom'([' `',Name,'` ',Type,TempSQL],FinalSQL).
|
||||
'$create_field_list'([field(Name,Type,Null,Key,DefaultValue)|T],FinalSQL,PrimaryKeys):-
|
||||
%'$check_field_type'
|
||||
'$create_field_list'(T,Result,KeyInfo),
|
||||
'$field_extra_options'(Name,Null,Key,KeyInfo,DefaultValue,TempSQL1,PrimaryKeys),
|
||||
'$make_atom'([' `',Name,'` ',Type,TempSQL1,' , ',Result],FinalSQL).
|
||||
|
||||
|
||||
'$field_extra_options'(Name,Null,Key,KeyInfo,DefaultValue,Result,PrimaryKeys):-
|
||||
( Null == 'y' ->
|
||||
'$make_atom'([' NOT NULL '],TempSQL1)
|
||||
;
|
||||
TempSQL1 = ''
|
||||
),
|
||||
(var(DefaultValue) ->
|
||||
Result = TempSQL1
|
||||
;
|
||||
'$make_atom'([TempSQL1,' DEFAULT \'',DefaultValue,'\' '],Result)
|
||||
),
|
||||
( Key == 'y' ->
|
||||
PrimaryKeys = [Name|KeyInfo]
|
||||
;
|
||||
PrimaryKeys = KeyInfo
|
||||
).
|
||||
|
||||
|
||||
%
|
||||
% Predicate's used to determine if the command 'WHERE' exists in the
|
||||
% query
|
||||
%
|
||||
'$where_exists'(SQL,1):-
|
||||
atom_codes(SQL,ListSQL),
|
||||
% Code for ' WHERE ', the spaces garantee that is the WHERE
|
||||
% command, and not a value of a field
|
||||
'$where_exists_aux'(ListSQL,[32,87,72,69,82,69,32]),!.
|
||||
'$where_exists'(_,0).
|
||||
|
||||
|
||||
'$where_exists_aux'([W|TCodes],[W|TWhere]):-
|
||||
'$where_found'(TCodes,TWhere),!.
|
||||
'$where_exists_aux'([_|TCodes],Where):-
|
||||
'$where_exists_aux'(TCodes,Where).
|
||||
|
||||
|
||||
'$where_found'(_,[]).
|
||||
'$where_found'([Letter|TCodes],[Letter|TWhere]):-
|
||||
'$where_found'(TCodes,TWhere).
|
||||
|
||||
%
|
||||
% Predicates used to build the new string SQL
|
||||
%
|
||||
|
||||
'$build_query'(0,SQL,[query(CodeArgs,_,_)],LA,FinalSQL):-
|
||||
'$build_query_aux'(0,SQL,CodeArgs,LA,FinalSQL).
|
||||
'$build_query'(1,SQL,[query(CodeArgs,_,_)],LA,FinalSQL):-
|
||||
'$build_query_aux'(1,SQL,CodeArgs,LA,FinalSQL).
|
||||
|
||||
|
||||
%Flag it necessary for knowing if it is the first argument
|
||||
%added to where, and if so we do not add 'and'
|
||||
'$build_query_aux'(_,SQL,[],[],SQL).
|
||||
'$build_query_aux'(Flag,SQL,[CodeArg|CodeT],[LArg|LT],FinalSQL):-
|
||||
nonvar(LArg),!,
|
||||
'$concatSQL'(Flag,SQL,CodeArg,LArg,ConcatSQL),
|
||||
'$build_query_aux'(1,ConcatSQL,CodeT,LT,FinalSQL).
|
||||
'$build_query_aux'(Flag,SQL,[_|CodeT],[_|LT],FinalSQL):-
|
||||
'$build_query_aux'(Flag,SQL,CodeT,LT,FinalSQL).
|
||||
|
||||
%This Predicate will concat the SQL query generated to the
|
||||
% moment with the field and it's value
|
||||
'$concatSQL'(Flag,SQL,att(Rel,Field),Value,ConcatSQL) :-
|
||||
number(Value),!,
|
||||
number_atom(Value,Number),
|
||||
'$and_or_where'(Flag,SQL,Temp0),
|
||||
atom_concat(Temp0,Rel,Temp1),
|
||||
atom_concat(Temp1,'.',Temp2),
|
||||
atom_concat(Temp2,Field,Temp3),
|
||||
atom_concat(Temp3,'=',Temp4),
|
||||
atom_concat(Temp4,Number,Temp5),
|
||||
atom_concat(Temp5,' ',ConcatSQL).
|
||||
|
||||
'$concatSQL'(Flag,SQL,att(Rel,Field),Value,ConcatSQL) :-
|
||||
'$and_or_where'(Flag,SQL,Temp0),
|
||||
atom_concat(Temp0,Rel,Temp1),
|
||||
atom_concat(Temp1,'.',Temp2),
|
||||
atom_concat(Temp2,Field,Temp3),
|
||||
atom_concat(Temp3,'=',Temp4),
|
||||
atom_concat(Temp4,'"',Temp5), %"
|
||||
atom_concat(Temp5,Value,Temp6),
|
||||
atom_concat(Temp6,'" ',ConcatSQL). %"
|
||||
|
||||
% This predicate will determin if we should use AND or WHERE
|
||||
'$and_or_where'(1,SQL,ConcatSQL):-
|
||||
atom_concat(SQL,'AND ',ConcatSQL).
|
||||
'$and_or_where'(0,SQL,ConcatSQL):-
|
||||
atom_concat(SQL,' WHERE ',ConcatSQL).
|
||||
|
||||
%
|
||||
% End of Predicates for making the SQL query
|
||||
%
|
||||
'$make_a_list'(0,[]) :- !.
|
||||
'$make_a_list'(N,[_|T]) :-
|
||||
N1 is N-1,
|
||||
'$make_a_list'(N1,T).
|
||||
|
||||
'$assert_attribute_information'(N,N,_,_) :- !.
|
||||
'$assert_attribute_information'(N,M,Relation,[FieldName,HeadType|TailTypes]) :-
|
||||
functor(Attrib,attribute,4),
|
||||
N1 is N+1,
|
||||
arg(1,Attrib,N1),
|
||||
arg(2,Attrib,Relation),
|
||||
arg(3,Attrib,FieldName),
|
||||
arg(4,Attrib,HeadType),
|
||||
'$assert_facts'(myddas_prolog2sql,Attrib),
|
||||
%assert(myddas_prolog2sql:Attrib),
|
||||
'$assert_attribute_information'(N1,M,Relation,TailTypes).
|
||||
|
||||
|
||||
'$copy_term_nv'(T,Dic,NT,[(T,NT)|Dic]) :-
|
||||
var(T),!,
|
||||
'$v_member'(T,Dic,(T,NT)).
|
||||
'$copy_term_nv'(T,Dic,T,Dic) :-
|
||||
functor(T,_,0),!.
|
||||
'$copy_term_nv'(T,Dic,NT,NDic) :-
|
||||
functor(T,F,N),
|
||||
functor(NT,F,N),
|
||||
'$iterate_on_args'(N,T,NT,Dic,NDic).
|
||||
|
||||
'$iterate_on_args'(0,_,_,Dic,Dic) :- !.
|
||||
'$iterate_on_args'(N,T,NT,Dic,NDic2) :-
|
||||
arg(N,T,A),
|
||||
'$copy_term_nv'(A,Dic,NA,NDic),
|
||||
arg(N,NT,NA),
|
||||
N1 is N-1,
|
||||
'$iterate_on_args'(N1,T,NT,NDic,NDic2).
|
||||
|
||||
'$v_member'(T,[],(T,_)).
|
||||
'$v_member'(T,[(V,V1)|_],(T,V1)) :-
|
||||
T == V, !.
|
||||
'$v_member'(T,[_|R],V) :-
|
||||
'$v_member'(T,R,V).
|
||||
|
||||
|
||||
|
||||
% '$extract_args(+Predicate,+FirstArg,+Arity,-ArgList).
|
||||
% extracts args from predicate, to a list
|
||||
'$extract_args'(Predicate,Arity,Arity,[Arg]):-
|
||||
arg(Arity,Predicate,Arg).
|
||||
'$extract_args'(Predicate,ArgNumber,Arity,[Arg|ArgList]):-
|
||||
arg(ArgNumber,Predicate,Arg),
|
||||
NextArg is ArgNumber+1,
|
||||
'$extract_args'(Predicate,NextArg,Arity,ArgList).
|
||||
|
||||
% '$get_table_name'(+SQLQueryTerm,?TableName).
|
||||
% Gets the Table name from the SQLQueryTerm of translate/3
|
||||
'$get_table_name'([query(_,[rel(TableName,_)],_)],TableName).
|
||||
|
||||
|
||||
% '$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,_,[])],SetArgs,[' SET '|SQLSet],[]):-!,
|
||||
'$get_values_for_set'(Fields,SetArgs,Set),
|
||||
'$build_set_condition'(Set,SQLSet).
|
||||
'$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,'" AND '|Rest]):-
|
||||
'$get_values_for_where'(Comp,Rest).
|
||||
|
||||
'$build_set_condition'([Field,Value|FieldValues],[SQLFirst|SQLRest]):-
|
||||
'$make_atom'([' ',Field,' = "',Value,'" '],SQLFirst),
|
||||
'$build_set_condition_with_comma'(FieldValues,SQLRest).
|
||||
|
||||
'$build_set_condition_with_comma'([],[]).
|
||||
'$build_set_condition_with_comma'([Field,Value|FieldValues],[SQL|SQLRest]):-
|
||||
'$make_atom'([' , ',Field,' = "',Value,'" '],SQL),
|
||||
'$build_set_condition_with_comma'(FieldValues,SQLRest).
|
||||
|
||||
|
||||
% This predicate will always fail
|
||||
'$abolish_all'(Con):-
|
||||
c_db_preds_conn(Con,Pred_Module,Pred_Name,Pred_Arity),
|
||||
abolish(Pred_Module:Pred_Name,Pred_Arity),
|
||||
fail.
|
||||
|
||||
'$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),!,
|
||||
'$make_atom'(T,Result),
|
||||
atom_concat(Atom,Result,Final).
|
||||
'$make_atom'([Number|T],Final) :-
|
||||
'$make_atom'(T,Result),
|
||||
number_atom(Number,Atom),
|
||||
atom_concat(Atom,Result,Final).
|
||||
|
||||
'$make_atom_args'([Atom],Atom):-
|
||||
atom(Atom),!.
|
||||
'$make_atom_args'([Number],Atom):-
|
||||
number_atom(Number,Atom),!.
|
||||
'$make_atom_args'([Atom|T],Final) :-
|
||||
atom(Atom),!,
|
||||
'$make_atom_args'(T,Result),
|
||||
atom_concat(',',Result,X1),
|
||||
atom_concat(Atom,X1,Final).
|
||||
'$make_atom_args'([Number|T],Final) :-
|
||||
'$make_atom_args'(T,Result),
|
||||
number_atom(Number,Atom),
|
||||
atom_concat(',',Result,X1),
|
||||
atom_concat(Atom,X1,Final).
|
||||
|
||||
|
||||
|
||||
% for db_my_insert/3
|
||||
% integer,real, string, came from the myddas_mysql.c get_attributes_types function
|
||||
'$get_values_for_insert'([_,_],[Value],['NULL',')']):-var(Value),!.
|
||||
'$get_values_for_insert'([_,integer],[Value],[Value,')']):-!.
|
||||
'$get_values_for_insert'([_,real],[Value],[Value,')']):-!.
|
||||
'$get_values_for_insert'([_,string],[Value],['"',Value,'")']):-!.
|
||||
|
||||
'$get_values_for_insert'([_,_|TTypesList],[Value|TValues],['NULL',','|RestValues]):-
|
||||
var(Value),!,
|
||||
'$get_values_for_insert'(TTypesList,TValues,RestValues).
|
||||
'$get_values_for_insert'([_,integer|TTypesList],[Value|TValues],[Value,','|RestValues]):-!,
|
||||
'$get_values_for_insert'(TTypesList,TValues,RestValues).
|
||||
'$get_values_for_insert'([_,real|TTypesList],[Value|TValues],[Value,','|RestValues]):-!,
|
||||
'$get_values_for_insert'(TTypesList,TValues,RestValues).
|
||||
'$get_values_for_insert'([_,string|TTypesList],[Value|TValues],['"',Value,'",'|RestValues]):-!,
|
||||
'$get_values_for_insert'(TTypesList,TValues,RestValues).
|
||||
|
||||
|
||||
% for db_my_insert/2
|
||||
'$get_values_for_insert'([query(Att,[rel(Relation,_)],_)],['('|ValuesList],Relation):-
|
||||
'$get_values_for_insert_make_list'(Att,ValuesList).
|
||||
|
||||
'$get_values_for_insert_make_list'([att(_,_)],['NULL',')']):-!.
|
||||
'$get_values_for_insert_make_list'(['$const$'(Value)],[Value,')']):-
|
||||
number(Value),!.
|
||||
'$get_values_for_insert_make_list'(['$const$'(Value)],['"',Value,'")']):-!.
|
||||
|
||||
'$get_values_for_insert_make_list'([att(_,_)|TAtt],['NULL',','|TList]):-!,
|
||||
'$get_values_for_insert_make_list'(TAtt,TList).
|
||||
'$get_values_for_insert_make_list'(['$const$'(Value)|TAtt],[Value,','|TList]):-
|
||||
number(Value),!,
|
||||
'$get_values_for_insert_make_list'(TAtt,TList).
|
||||
'$get_values_for_insert_make_list'(['$const$'(Value)|TAtt],['"',Value,'"',','|TList]):-
|
||||
'$get_values_for_insert_make_list'(TAtt,TList).
|
||||
|
||||
|
||||
% Only for making the error tests in all of the calls to
|
||||
% get_value/2
|
||||
'$get_value'(Connection,Con) :-
|
||||
'$error_checks'(get_value(Connection,Con)),
|
||||
get_value(Connection,Con).
|
||||
|
||||
|
||||
'$check_fields'([],[]).
|
||||
'$check_fields'(['$const$'(_)|TAtt],[_|TFields]):-
|
||||
'$check_fields'(TAtt,TFields).
|
||||
% um campo auto_incrementavel, <20> sempre parte da chave, e como <20> auto
|
||||
% pode-se dar valores NULOS
|
||||
'$check_fields'([att(_,Name)|TAtt],[property(Name,_,1,1)|TFields]):-!,
|
||||
'$check_fields'(TAtt,TFields).
|
||||
'$check_fields'([att(_,Name)|TAtt],[property(Name,0,_,_)|TFields]):-!,
|
||||
'$check_fields'(TAtt,TFields).
|
||||
|
||||
|
||||
|
||||
%
|
||||
% This predicate asserts facts in a Module, but if that
|
||||
% fact already exists, it dosen't assert it
|
||||
%
|
||||
'$assert_facts'(Module,Fact):-
|
||||
Module:Fact,!.
|
||||
'$assert_facts'(Module,Fact):-
|
||||
assert(Module:Fact).
|
||||
|
||||
'$lenght'([],0).
|
||||
'$lenght'([_|T],Sum):-
|
||||
'$lenght'(T,Num),
|
||||
Sum is Num + 1.
|
||||
|
||||
'$check_list_on_list'([],_).
|
||||
'$check_list_on_list'([H|T],DbGoalArgs) :-
|
||||
'$member_strick'(H,DbGoalArgs),
|
||||
'$check_list_on_list'(T,DbGoalArgs).
|
||||
|
||||
'$member_strick'(Element1, [Element2|_]) :-
|
||||
Element1 == Element2,!.
|
||||
'$member_strick'(Element, [_|Rest]) :-
|
||||
'$member_strick'(Element, Rest).
|
||||
|
||||
|
||||
'$make_stats_list'([],[]).
|
||||
'$make_stats_list'([Ref|Tail],[Time|Final]):-
|
||||
c_db_stats_time(Ref,Time),
|
||||
'$make_stats_list'(Tail,Final).
|
@@ -84,15 +84,6 @@ PROGRAMS= \
|
||||
$(srcdir)/flags.yap \
|
||||
$(srcdir)/block_diagram.yap
|
||||
|
||||
MYDDAS_PROGRAMS= $(srcdir)/MYDDAS/myddas.ypp \
|
||||
$(srcdir)/MYDDAS/myddas_assert_predicates.ypp \
|
||||
$(srcdir)/MYDDAS/myddas_mysql.ypp \
|
||||
$(srcdir)/MYDDAS/myddas_top_level.ypp \
|
||||
$(srcdir)/MYDDAS/myddas_errors.ypp \
|
||||
$(srcdir)/MYDDAS/myddas_prolog2sql.ypp \
|
||||
$(srcdir)/MYDDAS/myddas_util_predicates.ypp \
|
||||
$(srcdir)/MYDDAS/myddas_prolog2sql_optimizer.ypp
|
||||
|
||||
DIALECT_PROGRAMS= \
|
||||
$(srcdir)/dialect/commons.yap \
|
||||
$(srcdir)/dialect/bprolog.yap \
|
||||
@@ -111,7 +102,7 @@ DIALECT_BP= \
|
||||
$(srcdir)/dialect/bprolog/foreach.pl \
|
||||
$(srcdir)/dialect/bprolog/hashtable.yap
|
||||
|
||||
install: $(PROGRAMS) install_myddas
|
||||
install: $(PROGRAMS)
|
||||
mkdir -p $(DESTDIR)$(SHAREDIR)/Yap
|
||||
mkdir -p $(DESTDIR)$(SHAREDIR)/Yap/dialect
|
||||
mkdir -p $(DESTDIR)$(SHAREDIR)/Yap/dialect/swi
|
||||
@@ -121,16 +112,3 @@ install: $(PROGRAMS) install_myddas
|
||||
for p in $(DIALECT_SWI); do $(INSTALL_DATA) $$p $(DESTDIR)$(SHAREDIR)/Yap/dialect/swi; done
|
||||
for p in $(DIALECT_BP); do $(INSTALL_DATA) $$p $(DESTDIR)$(SHAREDIR)/Yap/dialect/bprolog; done
|
||||
|
||||
install_myddas: $(MYDDAS_PROGRAMS)
|
||||
count=`echo "$(YAP_EXTRAS)" | grep MYDDAS | wc -l`; \
|
||||
if [ $$count -ne 0 ]; then \
|
||||
mkdir -p $(DESTDIR)$(SHAREDIR)/Yap; \
|
||||
for p in $(MYDDAS_PROGRAMS); \
|
||||
do $(INSTALL_DATA) $$p $(DESTDIR)$(SHAREDIR)/Yap; \
|
||||
done; \
|
||||
for p in $(DESTDIR)$(SHAREDIR)/Yap/myddas*.ypp; \
|
||||
do name=`basename $$p .ypp`; \
|
||||
cpp $(YAP_EXTRAS) -P -E -w $$p > $(DESTDIR)$(SHAREDIR)/Yap/$$name.yap; \
|
||||
rm -fr $$p; \
|
||||
done; \
|
||||
fi
|
||||
|
@@ -211,6 +211,32 @@ X_API int PL_get_arg(int index, term_t ts, term_t a)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* SWI: int PL_get_arg(int index, term_t t, term_t a)
|
||||
YAP: YAP_Term YAP_ArgOfTerm(int argno, YAP_Term t)*/
|
||||
X_API int PL_get_compound_name_arity(term_t ts, atom_t *ap, int *ip)
|
||||
{
|
||||
CACHE_REGS
|
||||
YAP_Term t = Yap_GetFromSlot(ts PASS_REGS);
|
||||
if ( !YAP_IsApplTerm(t) ) {
|
||||
if (YAP_IsPairTerm(t)) {
|
||||
if (ip)
|
||||
*ip = 2;
|
||||
if (ap)
|
||||
*ap = ATOM_nil;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
} else {
|
||||
Functor f = FunctorOfTerm( t );
|
||||
if (IsExtensionFunctor(f)) return FALSE;
|
||||
if (ip)
|
||||
*ip = ArityOfFunctor( f );
|
||||
if (ap)
|
||||
*ap = AtomToSWIAtom( NameOfFunctor( f ));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
X_API int _PL_get_arg(int index, term_t ts, term_t a)
|
||||
{
|
||||
CACHE_REGS
|
||||
@@ -344,10 +370,14 @@ X_API int PL_get_float(term_t ts, double *f) /* SAM type check*/
|
||||
{
|
||||
CACHE_REGS
|
||||
YAP_Term t = Yap_GetFromSlot(ts PASS_REGS);
|
||||
if ( YAP_IsFloatTerm(t)) {
|
||||
*f = YAP_FloatOfTerm(t);
|
||||
} else if ( YAP_IsIntTerm(t)) {
|
||||
*f = YAP_IntOfTerm(t);
|
||||
if ( IsFloatTerm(t)) {
|
||||
*f = FloatOfTerm(t);
|
||||
} else if ( IsIntegerTerm(t)) {
|
||||
*f = IntegerOfTerm(t);
|
||||
#if USE_GMP
|
||||
} else if (IsBigIntTerm(t)) {
|
||||
*f = Yap_gmp_to_float( t );
|
||||
#endif
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
@@ -438,7 +468,7 @@ X_API int PL_get_long(term_t ts, long *i)
|
||||
|
||||
X_API int PL_get_int64(term_t ts, int64_t *i)
|
||||
{
|
||||
#if SIZE_OF_LONG_INT==8
|
||||
#if SIZE_OF_INT_P==8
|
||||
return PL_get_long(ts, (long *)i);
|
||||
#else
|
||||
CACHE_REGS
|
||||
@@ -1442,7 +1472,7 @@ int PL_unify_termv(term_t l, va_list ap)
|
||||
*pt++ = MkIntegerTerm((Int)va_arg(ap, intptr_t));
|
||||
break;
|
||||
case PL_INT64:
|
||||
#if SIZEOF_LONG_INT==8
|
||||
#if SIZEOF_INT_P==8
|
||||
*pt++ = MkIntegerTerm((Int)va_arg(ap, long int));
|
||||
#elif USE_GMP
|
||||
{
|
||||
@@ -1646,14 +1676,14 @@ X_API int PL_is_atomic(term_t ts)
|
||||
{
|
||||
CACHE_REGS
|
||||
YAP_Term t = Yap_GetFromSlot(ts PASS_REGS);
|
||||
return !YAP_IsVarTerm(t) || !YAP_IsApplTerm(t) || !YAP_IsPairTerm(t);
|
||||
return !IsVarTerm(t) || !IsApplTerm(t) || !IsPairTerm(t);
|
||||
}
|
||||
|
||||
X_API int PL_is_compound(term_t ts)
|
||||
{
|
||||
CACHE_REGS
|
||||
YAP_Term t = Yap_GetFromSlot(ts PASS_REGS);
|
||||
return (YAP_IsApplTerm(t) || YAP_IsPairTerm(t));
|
||||
return (IsApplTerm(t) || IsPairTerm(t));
|
||||
}
|
||||
|
||||
X_API int PL_is_functor(term_t ts, functor_t f)
|
||||
@@ -1673,7 +1703,7 @@ X_API int PL_is_float(term_t ts)
|
||||
{
|
||||
CACHE_REGS
|
||||
YAP_Term t = Yap_GetFromSlot(ts PASS_REGS);
|
||||
return YAP_IsFloatTerm(t);
|
||||
return !IsVarTerm(t) && IsFloatTerm(t);
|
||||
}
|
||||
|
||||
X_API int PL_is_integer(term_t ts)
|
||||
@@ -1740,7 +1770,7 @@ X_API int PL_is_number(term_t ts)
|
||||
{
|
||||
CACHE_REGS
|
||||
YAP_Term t = Yap_GetFromSlot(ts PASS_REGS);
|
||||
return YAP_IsIntTerm(t) || YAP_IsBigNumTerm(t) || YAP_IsFloatTerm(t);
|
||||
return IsIntegerTerm(t) || IsBigIntTerm(t) || IsFloatTerm(t);
|
||||
}
|
||||
|
||||
X_API int PL_is_string(term_t ts)
|
||||
@@ -2635,7 +2665,7 @@ PL_eval_expression_to_int64_ex(term_t t, int64_t *val)
|
||||
if (IsIntegerTerm(res)) {
|
||||
*val = IntegerOfTerm(res);
|
||||
return TRUE;
|
||||
#if SIZEOF_LONG_INT==4 && USE_GMP
|
||||
#if SIZEOF_INT_P==4 && USE_GMP
|
||||
} else if (YAP_IsBigNumTerm(res)) {
|
||||
MP_INT g;
|
||||
char s[64];
|
||||
|
@@ -53,7 +53,7 @@ Comments: This file provides a set of functions to convert a prolog term to a C
|
||||
|
||||
#endif
|
||||
|
||||
struct buffer_ds buffer;
|
||||
struct buffer_ds buffers[1024];
|
||||
|
||||
/*********************************************************************************************/
|
||||
// prototypes
|
||||
@@ -100,7 +100,6 @@ expand_buffer(const size_t space ) {
|
||||
*/
|
||||
void
|
||||
change_buffer_size(const size_t newsize) {
|
||||
|
||||
if ( BUFFER_SIZE>=BLOCK_SIZE && BUFFER_SIZE>=newsize)
|
||||
return;
|
||||
if (BUFFER_PTR) {
|
||||
@@ -143,6 +142,7 @@ size_t
|
||||
write_term_to_stream(const int fd,const YAP_Term term) {
|
||||
|
||||
RESET_BUFFER;
|
||||
printf("BUFFER_PTR=%p\n", BUFFER_PTR);
|
||||
p2c_putt(term);
|
||||
if (write(fd,(void*)BUFFER_PTR,BUFFER_LEN) < 0) { // write term
|
||||
YAP_Error(0,0,"Prolog2Term: IO error in write.\n");
|
||||
|
@@ -70,6 +70,8 @@ void write_msg(const char *fun,const char *file, int line,const char *format, ..
|
||||
|
||||
extern int BLOCK_SIZE;
|
||||
|
||||
#define buffer (buffers[YAP_ThreadSelf()])
|
||||
|
||||
// deletes the buffer (all fields) but does not release the memory of the buffer.ptr
|
||||
#define DEL_BUFFER {buffer.ptr=NULL;buffer.size=0;buffer.len=0;buffer.pos=0;}
|
||||
// informs the prologterm2c module that the buffer is now used and should not be messed
|
||||
@@ -92,6 +94,7 @@ struct buffer_ds {
|
||||
char *ptr; // pointer to the buffer
|
||||
size_t pos; // position (used while reading)
|
||||
};
|
||||
extern struct buffer_ds buffer;
|
||||
extern struct buffer_ds buffers[1024];
|
||||
|
||||
|
||||
#endif
|
||||
|
@@ -71,7 +71,9 @@ typedef struct broadcast_req BroadcastRequest;
|
||||
/********************************************************************
|
||||
* Auxiliary data
|
||||
********************************************************************/
|
||||
static int mpi_status;
|
||||
static int mpi_statuss[1024];
|
||||
#define mpi_status (mpi_statuss[YAP_ThreadSelf()])
|
||||
|
||||
extern int GLOBAL_argc;
|
||||
|
||||
#define HASHSIZE 1777
|
||||
@@ -110,7 +112,11 @@ static double total_time_spent; // total time spend in communication code
|
||||
|
||||
#define RETURN(p) {PAUSE_TIMER();return (p);}
|
||||
|
||||
static struct timeval _tstart, _tend;
|
||||
static struct timeval _tstarts[1024], _tends[1024];
|
||||
|
||||
#define _tsart (_tstarts[YAP_ThreadSelf()])
|
||||
#define _tend (_tends[YAP_ThreadSelf()])
|
||||
|
||||
#include <sys/time.h>
|
||||
#include <sys/resource.h>
|
||||
#include <unistd.h>
|
||||
@@ -260,7 +266,7 @@ mpi_init(void){
|
||||
char ** my_argv;
|
||||
int my_argc = YAP_Argv(&my_argv);
|
||||
// MPI_Init(&GLOBAL_argc, &GLOBAL_argv);
|
||||
MPI_Init_thread(&my_argc, &my_argv, MPI_THREAD_SINGLE, &thread_level);
|
||||
MPI_Init_thread(&my_argc, &my_argv, MPI_THREAD_MULTIPLE, &thread_level);
|
||||
#ifdef DEBUG
|
||||
write_msg(__FUNCTION__,__FILE__,__LINE__,"Thread level: %d\n",thread_level);
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user