out-of-date
This commit is contained in:
parent
ccc2efd456
commit
bff0440b64
@ -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_postgres.yap *
|
||||
* Last rev: *
|
||||
* mods: *
|
||||
* comments: Postgres Predicates *
|
||||
* *
|
||||
*************************************************************************/
|
||||
#ifdef MYDDAS_POSTGRES
|
||||
|
||||
:- module(myddas_postgres,[
|
||||
postgres_result_set/1,
|
||||
postgres_datalog_describe/1,
|
||||
postgres_datalog_describe/2,
|
||||
postgres_describe/3,
|
||||
postgres_describe/2,
|
||||
postgres_datalog_show_tables/1,
|
||||
postgres_datalog_show_tables/0,
|
||||
postgres_show_tables/2,
|
||||
postgres_show_tables/1,
|
||||
postgres_show_database/2,
|
||||
postgres_show_databases/2,
|
||||
postgres_show_databases/1,
|
||||
postgres_change_database/2,
|
||||
postgres_call_procedure/4,
|
||||
postgres_call_procedure/3,
|
||||
postgres_sql_mode/1,
|
||||
postgres_sql_mode/2,
|
||||
postgres_sql_mode/1,
|
||||
postgres_sql_mode/2
|
||||
]).
|
||||
|
||||
:- use_module(myddas,[
|
||||
postgres_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
|
||||
%--------------------------------------------------------
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% postgres_result_set/1
|
||||
%
|
||||
%
|
||||
postgres_result_set(X):-
|
||||
var(X),!,
|
||||
get_value(postgres_result_set,X).
|
||||
postgres_result_set(use_result):-
|
||||
set_value(postgres_result_set,use_result).
|
||||
postgres_result_set(store_result):-
|
||||
set_value(postgres_result_set,store_result).
|
||||
%default value
|
||||
:- postgres_result_set(store_result).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% postgres_describe/2
|
||||
%
|
||||
%
|
||||
postgres_datalog_describe(Relation):-
|
||||
postgres_datalog_describe(myddas,Relation).
|
||||
postgres_datalog_describe(Connection,Relation) :-
|
||||
'$error_checks'(postgres_datalog_describe(Relation,Connection)),
|
||||
'$get_value'(Connection,Conn),
|
||||
'$make_atom'(['DESCRIBE ',Relation],SQL),
|
||||
postgres_result_set(Mode),
|
||||
c_postgres_query(SQL,ResultSet,Conn,Mode,_),
|
||||
c_postgres_table_write(ResultSet).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% postgres_describe/3
|
||||
% postgres_describe/2
|
||||
% gives the results of the DESCRIBE statement
|
||||
% by backtracking
|
||||
postgres_describe(Relation,TableInfo) :-
|
||||
postgres_describe(myddas,Relation,TableInfo).
|
||||
postgres_describe(Connection,Relation,tableinfo(A1,A2,A3,A4,A5,A6)) :-
|
||||
'$error_checks'(postgres_describe(Relation,Connection,_)),
|
||||
'$get_value'(Connection,Conn),
|
||||
'$make_atom'(['DESCRIBE ',Relation],SQL),
|
||||
postgres_result_set(Mode),
|
||||
'$write_or_not'(SQL),
|
||||
c_postgres_query(SQL,ResultSet,Conn,Mode,_),
|
||||
!,c_postgres_row(ResultSet,6,[A1,A2,A3,A4,A5,A6]).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% postgres_datalog_show_tables/1
|
||||
%
|
||||
%
|
||||
postgres_datalog_show_tables:-
|
||||
postgres_datalog_show_tables(myddas).
|
||||
postgres_datalog_show_tables(Connection) :-
|
||||
'$error_checks'(postgres_show_tables(Connection)),
|
||||
'$get_value'(Connection,Conn),
|
||||
postgres_result_set(Mode),
|
||||
'$write_or_not'('SHOW TABLES'),
|
||||
c_postgres_query('SHOW TABLES',ResultSet,Conn,Mode,_),
|
||||
c_postgres_table_write(ResultSet).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% postgres_show_tables/2
|
||||
% postgres_show_tables/1
|
||||
% gives the results of the SHOW TABLES statement
|
||||
% by backtracking
|
||||
postgres_show_tables(Table) :-
|
||||
postgres_show_tables(myddas,Table).
|
||||
postgres_show_tables(Connection,table(Table)) :-
|
||||
'$error_checks'(postgres_show_tables(Connection)),
|
||||
'$get_value'(Connection,Conn),
|
||||
postgres_result_set(Mode),
|
||||
'$write_or_not'('SHOW TABLES'),
|
||||
c_postgres_query('SHOW TABLES',ResultSet,Conn,Mode,_),
|
||||
!,c_postgres_row(ResultSet,1,[Table]).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% postgres_show_database/2
|
||||
%
|
||||
%
|
||||
postgres_show_database(Connection,Database) :-
|
||||
'$error_checks'(postgres_show_database(Connection,Database)),
|
||||
'$get_value'(Connection,Con),
|
||||
c_postgres_get_database(Con,Database).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% postgres_show_databases/2
|
||||
%
|
||||
%
|
||||
postgres_show_databases(Connection,database(Databases)) :-
|
||||
%'$error_checks'(postgres_show_databases(Connection,Database)),
|
||||
'$get_value'(Connection,Conn),
|
||||
postgres_result_set(Mode),
|
||||
'$write_or_not'('SHOW DATABASES'),
|
||||
c_postgres_query('SHOW DATABASES',ResultSet,Conn,Mode,_),
|
||||
!,c_postgres_row(ResultSet,1,[Databases]).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% postgres_show_databases/1
|
||||
% TODO Error Checks
|
||||
%
|
||||
postgres_show_databases(Connection) :-
|
||||
'$error_checks'(postgres_show_databases(Connection)),
|
||||
'$get_value'(Connection,Conn),
|
||||
postgres_result_set(Mode),
|
||||
'$write_or_not'('SHOW DATABASES'),
|
||||
c_postgres_query('SHOW DATABASES',ResultSet,Conn,Mode,_),
|
||||
c_postgres_table_write(ResultSet).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% postgres_change_database/2
|
||||
%
|
||||
%
|
||||
postgres_change_database(Connection,Database) :-
|
||||
'$error_checks'(postgres_change_database(Connection,Database)),
|
||||
'$get_value'(Connection,Con),
|
||||
'$make_atom'(['USE ',Database],SQL),
|
||||
'$write_or_not'(SQL),
|
||||
c_postgres_change_database(Con,Database).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% postgres_call_procedure/4
|
||||
% postgres_call_procedure/3
|
||||
% postgres_call_procedure(+,+,+,?)
|
||||
% Only support in Postgres 5.0 an above
|
||||
% Called procedure must return results via Postgres result set
|
||||
postgres_call_procedure(Procedure,Args,Result) :-
|
||||
postgres_call_procedure(myddas,Procedure,Args,Result).
|
||||
postgres_call_procedure(Connection,Procedure,Args,LA) :-
|
||||
'$error_checks'(postgres_call_procedure(Connection,Procedure,Args,LA)),
|
||||
'$make_atom_args'(Args,ArgsSQL),
|
||||
'$make_atom'(['CALL ',Procedure,'(',ArgsSQL,')'],SQL),
|
||||
postgres_sql(Connection,SQL,LA).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% postgres_sql_mode/1
|
||||
% postgres_sql_mode/2
|
||||
% Possible values : traditional,ansi,strict_trans_tables or '' (empty)
|
||||
postgres_sql_mode(SQLMode):-
|
||||
postgres_sql_mode(SQLMode).
|
||||
postgres_sql_mode(Connection,SQLMode):-
|
||||
postgres_sql_mode(Connection,SQLMode).
|
||||
|
||||
postgres_sql_mode(SQLMode):-
|
||||
postgres_sql_mode(myddas,SQLMode).
|
||||
postgres_sql_mode(Connection,SQLMode):-
|
||||
var(SQLMode),!,
|
||||
'$error_checks'(postgres_sql_mode(Connection,SQLMode)),
|
||||
get_value(Connection,Con),
|
||||
c_postgres_connection_type(Con,postgres), %must be a postgres connection
|
||||
postgres_sql(Connection,'SELECT @@session.sql_mode',[SQLMode]).
|
||||
postgres_sql_mode(Connection,SQLMode):-
|
||||
'$error_checks'(postgres_sql_mode(Connection,SQLMode)),
|
||||
get_value(Connection,Con),
|
||||
c_postgres_connection_type(Con,postgres), %must be a postgres connection
|
||||
'$make_atom'(['SET SESSION sql_mode=`',SQLMode,'`'],FinalSQL),
|
||||
'$write_or_not'(FinalSQL),
|
||||
postgres_result_set(Mode),
|
||||
c_postgres_query(FinalSQL,_,Con,Mode,_).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
|
||||
#endif /* MYDDAS_POSTGRES*/
|
@ -1,215 +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_SQLITE3
|
||||
|
||||
:- module(myddas_sqlite3,[
|
||||
sqlite3_result_set/1,
|
||||
sqlite3_datalog_describe/1,
|
||||
sqlite3_datalog_describe/2,
|
||||
sqlite3_describe/3,
|
||||
sqlite3_describe/2,
|
||||
sqlite3_datalog_show_tables/1,
|
||||
sqlite3_datalog_show_tables/0,
|
||||
sqlite3_show_tables/2,
|
||||
sqlite3_show_tables/1,
|
||||
sqlite3_show_database/2,
|
||||
sqlite3_show_databases/2,
|
||||
sqlite3_show_databases/1,
|
||||
sqlite3_change_database/2,
|
||||
sqlite3_call_procedure/4,
|
||||
sqlite3_call_procedure/3
|
||||
]).
|
||||
|
||||
:- 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
|
||||
%--------------------------------------------------------
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% sqlite3_result_set/1
|
||||
%
|
||||
%
|
||||
sqlite3_result_set(X):-
|
||||
var(X),!,
|
||||
get_value(sqlite3_result_set,X).
|
||||
sqlite3_result_set(use_result):-
|
||||
set_value(sqlite3_result_set,use_result).
|
||||
sqlite3_result_set(store_result):-
|
||||
set_value(sqlite3_result_set,store_result).
|
||||
%default value
|
||||
:- sqlite3_result_set(use_result).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% sqlite3_describe/2
|
||||
%
|
||||
%
|
||||
sqlite3_datalog_describe(Relation):-
|
||||
sqlite3_datalog_describe(myddas,Relation).
|
||||
sqlite3_datalog_describe(Connection,Relation) :-
|
||||
'$error_checks'(sqlite3_datalog_describe(Relation,Connection)),
|
||||
'$get_value'(Connection,Conn),
|
||||
'$make_atom'(['DESCRIBE ',Relation],SQL),
|
||||
sqlite3_result_set(Mode),
|
||||
c_sqlite3_query(SQL,ResultSet,Conn,Mode,_),
|
||||
c_sqlite3_table_write(ResultSet).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% sqlite3_describe/3
|
||||
% sqlite3_describe/2
|
||||
% gives the results of the DESCRIBE statement
|
||||
% by backtracking
|
||||
sqlite3_describe(Relation,TableInfo) :-
|
||||
sqlite3_describe(myddas,Relation,TableInfo).
|
||||
sqlite3_describe(Connection,Relation,tableinfo(A1,A2,A3,A4,A5,A6)) :-
|
||||
'$error_checks'(sqlite3_describe(Relation,Connection,_)),
|
||||
'$get_value'(Connection,Conn),
|
||||
'$make_atom'(['DESCRIBE ',Relation],SQL),
|
||||
sqlite3_result_set(Mode),
|
||||
'$write_or_not'(SQL),
|
||||
c_sqlite3_query(SQL,ResultSet,Conn,Mode,_),
|
||||
!,c_sqlite3_row(ResultSet,6,[A1,A2,A3,A4,A5,A6]).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% sqlite3_datalog_show_tables/1
|
||||
%
|
||||
%
|
||||
sqlite3_datalog_show_tables:-
|
||||
sqlite3_datalog_show_tables(myddas).
|
||||
sqlite3_datalog_show_tables(Connection) :-
|
||||
'$error_checks'(sqlite3_show_tables(Connection)),
|
||||
'$get_value'(Connection,Conn),
|
||||
sqlite3_result_set(Mode),
|
||||
'$write_or_not'('.tables'),
|
||||
c_sqlite3_query('.tables',ResultSet,Conn,Mode,_),
|
||||
c_sqlite3_table_write(ResultSet).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% sqlite3_show_tables/2
|
||||
% sqlite3_show_tables/1
|
||||
% gives the results of the SHOW TABLES statement
|
||||
% by backtracking
|
||||
sqlite3_show_tables(Table) :-
|
||||
sqlite3_show_tables(myddas,Table).
|
||||
sqlite3_show_tables(Connection,table(Table)) :-
|
||||
'$error_checks'(sqlite3_show_tables(Connection)),
|
||||
'$get_value'(Connection,Conn),
|
||||
sqlite3_result_set(Mode),
|
||||
'$write_or_not'('.tables'),
|
||||
c_sqlite3_query('.tables',ResultSet,Conn,Mode,_),
|
||||
!,c_sqlite3_row(ResultSet,1,[Table]).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% sqlite3_show_database/2
|
||||
%
|
||||
%
|
||||
sqlite3_show_database(Connection,Database) :-
|
||||
'$error_checks'(sqlite3_show_database(Connection,Database)),
|
||||
'$get_value'(Connection,Con),
|
||||
c_sqlite3_get_database(Con,Database).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% sqlite3_show_databases/2
|
||||
%
|
||||
%
|
||||
sqlite3_show_databases(Connection,database(Databases)) :-
|
||||
%'$error_checks'(sqlite3_show_databases(Connection,Database)),
|
||||
'$get_value'(Connection,Conn),
|
||||
sqlite3_result_set(Mode),
|
||||
'$write_or_not'('SHOW DATABASES'),
|
||||
c_sqlite3_query('SHOW DATABASES',ResultSet,Conn,Mode,_),
|
||||
!,c_sqlite3_row(ResultSet,1,[Databases]).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% sqlite3_show_databases/1
|
||||
% TODO Error Checks
|
||||
%
|
||||
sqlite3_show_databases(Connection) :-
|
||||
'$error_checks'(sqlite3_show_databases(Connection)),
|
||||
'$get_value'(Connection,Conn),
|
||||
sqlite3_result_set(Mode),
|
||||
'$write_or_not'('SHOW DATABASES'),
|
||||
c_sqlite3_query('SHOW DATABASES',ResultSet,Conn,Mode,_),
|
||||
c_sqlite3_table_write(ResultSet).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% sqlite3_change_database/2
|
||||
%
|
||||
%
|
||||
sqlite3_change_database(Connection,Database) :-
|
||||
'$error_checks'(sqlite3_change_database(Connection,Database)),
|
||||
'$get_value'(Connection,Con),
|
||||
'$make_atom'(['USE ',Database],SQL),
|
||||
'$write_or_not'(SQL),
|
||||
c_sqlite3_change_database(Con,Database).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% sqlite3_call_procedure/4
|
||||
% sqlite3_call_procedure/3
|
||||
% sqlite3_call_procedure(+,+,+,?)
|
||||
% Only support in MySQL 5.0 an above
|
||||
% Called procedure must return results via MySQL result set
|
||||
sqlite3_call_procedure(Procedure,Args,Result) :-
|
||||
sqlite3_call_procedure(myddas,Procedure,Args,Result).
|
||||
sqlite3_call_procedure(Connection,Procedure,Args,LA) :-
|
||||
'$error_checks'(sqlite3_call_procedure(Connection,Procedure,Args,LA)),
|
||||
'$make_atom_args'(Args,ArgsSQL),
|
||||
'$make_atom'(['CALL ',Procedure,'(',ArgsSQL,')'],SQL),
|
||||
sqlite3_sql(Connection,SQL,LA).
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
||||
#endif /* MYDDAS_SQLITE3 */
|
Reference in New Issue
Block a user