MYDDAS: added new predicates to the MYDDAS interface. db_call_procedure/3 and db_sql_mode/2. Added also a sql_query_optmizer for translate/3
git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@1623 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
@@ -14,14 +14,9 @@
|
||||
* comments: MySQL Predicates *
|
||||
* *
|
||||
*************************************************************************/
|
||||
#ifdef MYDDAS_MYSQL
|
||||
|
||||
:- module(myddas_mysql,[
|
||||
db_my_open/5,
|
||||
db_my_close/1,
|
||||
db_my_import/3,
|
||||
db_my_view/3,
|
||||
db_my_insert/2,
|
||||
db_my_insert/3,
|
||||
db_my_result_set/1,
|
||||
db_datalog_describe/1,
|
||||
db_datalog_describe/2,
|
||||
@@ -35,11 +30,15 @@
|
||||
db_show_databases/2,
|
||||
db_show_databases/1,
|
||||
db_change_database/2,
|
||||
db_my_sql_select/3,
|
||||
db_my_number_of_fields/3,
|
||||
db_my_get_attributes_types/3
|
||||
db_call_procedure/4,
|
||||
db_call_procedure/3,
|
||||
db_my_sql_mode/1,
|
||||
db_my_sql_mode/2
|
||||
]).
|
||||
|
||||
:- use_module(myddas,[
|
||||
db_sql/3
|
||||
]).
|
||||
|
||||
:- use_module(myddas_errors,[
|
||||
'$error_checks'/1
|
||||
@@ -48,6 +47,8 @@
|
||||
:- use_module(myddas_util_predicates,[
|
||||
'$get_value'/2,
|
||||
'$make_atom'/2,
|
||||
'$make_atom_args'/2,
|
||||
'$make_a_list'/2,
|
||||
'$write_or_not'/1
|
||||
]).
|
||||
|
||||
@@ -56,78 +57,6 @@
|
||||
% Public Predicates
|
||||
%--------------------------------------------------------
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% db_my_open/5
|
||||
%
|
||||
%
|
||||
db_my_open(_,_,_,_,_) :-
|
||||
write('WARNING!! Now we use db_open/5'),nl,
|
||||
write('USAGE: db_open(ConType,Connection,Host/Db,User,Password).'),nl,
|
||||
halt.
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% db_my_close/1
|
||||
%
|
||||
%
|
||||
db_my_close(_):-
|
||||
write('WARNING!! Now we use db_close/1'),nl,
|
||||
write('USAGE: db_close(Connection).'),nl,
|
||||
halt.
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% db_my_import/3
|
||||
%
|
||||
%
|
||||
db_my_import(_,_,_) :-
|
||||
write('WARNING!! Now we use db_import/3'),nl,
|
||||
write('USAGE: db_import(Connection,RelationName,PredName).'),nl,
|
||||
halt.
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% db_my_view/3
|
||||
%
|
||||
%
|
||||
db_my_view(_,_,_) :-
|
||||
write('WARNING!! Now we use db_view/3'),nl,
|
||||
write('USAGE: db_import(Connection,RelationName,DBGoal).'),nl,
|
||||
halt.
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% db_my_insert/2
|
||||
%
|
||||
%
|
||||
db_my_insert(_,_):-
|
||||
write('WARNING!! Now we use db_insert/2'),nl,
|
||||
write('USAGE: db_insert(Connection,PredName).'),nl,
|
||||
halt.
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% db_my_insert/3
|
||||
%
|
||||
%
|
||||
db_my_insert(_,_,_) :-
|
||||
write('WARNING!! Now we use db_insert/3'),nl,
|
||||
write('USAGE: db_insert(Connection,RelationName,PredName).'),nl,
|
||||
halt.
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% db_my_result_set/1
|
||||
@@ -153,11 +82,11 @@ db_my_result_set(store_result):-
|
||||
db_datalog_describe(Relation):-
|
||||
db_datalog_describe(myddas,Relation).
|
||||
db_datalog_describe(Connection,Relation) :-
|
||||
'$error_checks'(db_my_describe(Relation,Connection)),
|
||||
'$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_query(SQL,ResultSet,Conn,Mode,_),
|
||||
c_db_my_table_write(ResultSet).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
@@ -176,7 +105,7 @@ db_describe(Connection,Relation,tableinfo(A1,A2,A3,A4,A5,A6)) :-
|
||||
'$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_query(SQL,ResultSet,Conn,Mode,_),
|
||||
!,c_db_my_row(ResultSet,6,[A1,A2,A3,A4,A5,A6]).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
@@ -193,7 +122,7 @@ db_datalog_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_query('SHOW TABLES',ResultSet,Conn,Mode,_),
|
||||
c_db_my_table_write(ResultSet).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
@@ -211,7 +140,7 @@ db_show_tables(Connection,table(Table)) :-
|
||||
'$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_query('SHOW TABLES',ResultSet,Conn,Mode,_),
|
||||
!,c_db_my_row(ResultSet,1,[Table]).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
@@ -236,7 +165,7 @@ db_show_databases(Connection,database(Databases)) :-
|
||||
'$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_query('SHOW DATABASES',ResultSet,Conn,Mode,_),
|
||||
!,c_db_my_row(ResultSet,1,[Databases]).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
@@ -247,11 +176,11 @@ db_show_databases(Connection,database(Databases)) :-
|
||||
% TODO Error Checks
|
||||
%
|
||||
db_show_databases(Connection) :-
|
||||
%'$error_checks'(db_my_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_query('SHOW DATABASES',ResultSet,Conn,Mode,_),
|
||||
c_db_my_table_write(ResultSet).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
@@ -269,37 +198,44 @@ db_change_database(Connection,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,Result)),
|
||||
'$make_atom_args'(Args,ArgsSQL),
|
||||
'$make_atom'(['CALL ',Procedure,'(',ArgsSQL,')'],SQL),
|
||||
db_sql(Connection,SQL,LA).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% db_my_sql_select/3
|
||||
%
|
||||
%
|
||||
db_my_sql_select(_,_,_):-
|
||||
write('WARNING!! Now we use db_sql_select/3'),nl,
|
||||
write('USAGE: db_sql_select(Connection,SQL,ListaArgs).'),nl,
|
||||
halt.
|
||||
% db_my_sql_mode/1
|
||||
% db_my_sql_mode/2
|
||||
% Possible values : traditional,ansi,strict_trans_tables or '' (empty)
|
||||
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,_).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% db_my_number_of_fields/3
|
||||
%
|
||||
%
|
||||
db_my_number_of_fields(_,_,_) :-
|
||||
write('WARNING!! Now we use db_number_of_fields/3'),nl,
|
||||
write('USAGE: db_number_of_fields(Connection,RelationName,Arity).'),nl,
|
||||
halt.
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% db_my_get_attributes_types/3
|
||||
%
|
||||
%
|
||||
db_my_get_attributes_types(_,_,_) :-
|
||||
write('WARNING!! Now we use db_get_attributes_types/3'),nl,
|
||||
write('USAGE: db_get_attributes_types(Connection,RelationName,TypesList).'),nl,
|
||||
halt.
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
#endif /* MYDDAS_MYSQL*/
|
||||
Reference in New Issue
Block a user