postgres
This commit is contained in:
parent
5b19e9546a
commit
65c97e7072
|
@ -149,7 +149,7 @@ c_db_my_connect( USES_REGS1 ) {
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Criar um novo no na lista de ligacoes*/
|
/* Criar um novo no na lista de ligacoes*/
|
||||||
new = myddas_util_add_connection(conn,NULL,MYDDAS_API);
|
new = myddas_util_add_connection(conn,NULL,MYDDAS_MYSQL);
|
||||||
|
|
||||||
if (new == NULL){
|
if (new == NULL){
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
|
|
@ -861,54 +861,201 @@ You can see the available SQL Modes at the MySQL homepage at
|
||||||
append/3
|
append/3
|
||||||
]).
|
]).
|
||||||
|
|
||||||
|
:- use_module(library(parameters)).
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
% db_open/5
|
% db_open/5
|
||||||
% db_open/4
|
% db_open/4
|
||||||
%
|
%
|
||||||
db_open(Interface,HostDb,User,Password):-
|
|
||||||
db_open(Interface,myddas,HostDb,User,Password).
|
|
||||||
|
|
||||||
#ifdef MYDDAS_MYSQL
|
#if MYDDAS_DECLARATIONS
|
||||||
db_open(mysql,Connection,Host/Db/Port/Socket,User,Password) :- !,
|
:- db_open(Protocol) extra_arguments
|
||||||
'$error_checks'(db_open(mysql,Connection,Host/Db/Port/Socket,User,Password)),
|
db=Db,
|
||||||
c_db_my_connect(Host,User,Password,Db,Port,Socket,Con),
|
port=Port,
|
||||||
set_value(Connection,Con).
|
socket=Socket,
|
||||||
db_open(mysql,Connection,Host/Db/Port,User,Password) :-
|
user=User,
|
||||||
integer(Port),!,
|
password=Password,
|
||||||
db_open(mysql,Connection,Host/Db/Port/_,User,Password). % Var to be NULL, the default socket
|
% next arguments all refer to the data access point,
|
||||||
db_open(mysql,Connection,Host/Db/Socket,User,Password) :- !,
|
% so they are all are mutually exclusive
|
||||||
db_open(mysql,Connection,Host/Db/0/Socket,User,Password). % 0 is default port
|
data:file=File,
|
||||||
db_open(mysql,Connection,Host/Db,User,Password) :-
|
data:host=Host/Db,
|
||||||
db_open(mysql,Connection,Host/Db/0/_,User,Password). % 0 is default port and Var to be NULL, the default socket
|
data:host=Host/Db/Port,
|
||||||
#endif
|
data:host=Host/Db/Socket,
|
||||||
|
data:odbc=ODBC_DSN
|
||||||
|
|
||||||
#ifdef MYDDAS_POSTGRES
|
/* specify conditions */
|
||||||
db_open(postgres,Connection,Host/Db/Port/Socket,User,Password) :- !,
|
such_that
|
||||||
'$error_checks'(db_open(postgres,Connection,Host/Db/Port/Socket,User,Password)),
|
|
||||||
c_db_my_connect(Host,User,Password,Db,Port,Socket,Con),
|
/** implicit, types are conditioned on start
|
||||||
set_value(Connection,Con).
|
|
||||||
db_open(postgres,Connection,Host/Db/Port,User,Password) :-
|
atom(Db),
|
||||||
integer(Port),!,
|
positive_or_zero_integer(Port),
|
||||||
db_open(postgres,Connection,Host/Db/Port/_,User,Password). % Var to be NULL, the default socket
|
atom(Socket),
|
||||||
db_open(postgres,Connection,Host/Db/Socket,User,Password) :- !,
|
atom(User),
|
||||||
db_open(postgres,Connection,Host/Db/0/Socket,User,Password). % 0 is default port
|
atom(Password),
|
||||||
db_open(postgres,Connection,Host/Db,User,Password) :-
|
file(File),
|
||||||
db_open(postgres,Connection,Host/Db/0/_,User,Password). % 0 is default port and Var to be NULL, the default socket
|
atom(ODBC_DSN),
|
||||||
#endif
|
internet_host(Host), */
|
||||||
|
|
||||||
|
/* general theory, type hierarchy
|
||||||
|
atom(X) ==> nonvar(X),
|
||||||
|
\+ atom(X) * nonvar(X) ==> error(atom, X),
|
||||||
|
var(X) ==> error(var, X),
|
||||||
|
|
||||||
|
internet_host(X) <=> atom(X),
|
||||||
|
|
||||||
|
integer(X) ==> nonvar(X),
|
||||||
|
\+ integer(X) * nonvar(X) ==> error(integer, X),
|
||||||
|
var(X) ==> error(var, X)
|
||||||
|
|
||||||
|
positive_or_zero_integer(X) ==> integer(X),
|
||||||
|
positive_or_zero_integer(X) ==> positive_or_zero(X)
|
||||||
|
|
||||||
|
positive_or_zero(X) ==> number(X),
|
||||||
|
|
||||||
|
integer(X) ==> number(X),
|
||||||
|
|
||||||
|
float(X) ==> number(X),
|
||||||
|
rational(X) => number(X),
|
||||||
|
number(X) ==> nonvar(X),
|
||||||
|
\+ number(X) * nonvar(X) ==> error(number, X),
|
||||||
|
var(X) ==> error(var, X),
|
||||||
|
*/
|
||||||
|
|
||||||
|
/************
|
||||||
|
this unfolds to
|
||||||
|
P == ( (Protocol = mysql) + Protocol = powstgres + Protocol = odbc + Protocol = sqlite3 ),
|
||||||
|
|
||||||
|
Protocol = mysql ==> \+ Protocol = postgres,
|
||||||
|
Protocol = mysql ==> \+ Protocol = odbc,
|
||||||
|
Protocol = mysql ==> \+ Protocol = sqlite3,
|
||||||
|
Protocol = postgres ==> \+ Protocol = mysql,
|
||||||
|
|
||||||
|
% P(X,D)
|
||||||
|
P ==> atom(Protocol),
|
||||||
|
atom(X) * not P ==> error(domain, X, D),
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* problem specific axioms */
|
||||||
|
Connection?=myddas,
|
||||||
|
Host ?= localhost,
|
||||||
|
User ?= '',
|
||||||
|
Password ?= '',
|
||||||
|
|
||||||
|
|
||||||
|
t_atom(X) =:= atom(X) \/ t_var(X) \/ type_err(atom(X)),
|
||||||
|
t_var(X) =:= err(var(X)),
|
||||||
|
t_integer(X) =:= integer(X) \/ t_var(X) \/ err(integer(X)),
|
||||||
|
i_atom(X) =:= atom(X) \/ i_var(X) \/ t(atom(X)),
|
||||||
|
i_var(X) =:= i(var(X)),
|
||||||
|
i_integer(X) =:= integer(X) \/ i_var(X) \/ err(integer(X)),
|
||||||
|
|
||||||
|
|
||||||
|
( list( X ) =:= ( nil(X) + ( X = cons( A, Y ) * L ) ) ),
|
||||||
|
|
||||||
|
list( Protocol ) .
|
||||||
|
|
||||||
|
/*
|
||||||
|
((Protocol = odbc) :-
|
||||||
|
c^c_db_odbc_connect(ODBCEntry,User,Password,Handle) ),
|
||||||
|
|
||||||
|
((Protocol = mysql) :-
|
||||||
|
c^c_db_my_connect(Host,User,Password,Db,Port,Socket,Handle)),
|
||||||
|
|
||||||
|
((Protocol = postgres) :- c^c_postgres_connect(Host/Db/Port/Socket,User,Password, Handle)),
|
||||||
|
|
||||||
|
((Protocol = sqlite3) :-
|
||||||
|
c^c_sqlite3_connect(File,User,Password,Handle),
|
||||||
|
t_atom(File), i_atom(User)),
|
||||||
|
|
||||||
|
Protocol in [ mysql, postgres, odbc, sqlite3 ],
|
||||||
|
|
||||||
|
(- (c^c_sqlite3_connect(File,User,Password,Handle)) :- (c ^fail) ).
|
||||||
|
|
||||||
|
/*
|
||||||
|
( c^c_db_my_connect(Host,User,Password,Db,Port,Socket,Handle) ==
|
||||||
|
-(Protocol = odbc)*
|
||||||
|
(Protocol = mysql) *
|
||||||
|
-(Protocol = sqlite3)*
|
||||||
|
-(Protocol = postgres) ),
|
||||||
|
|
||||||
|
|
||||||
|
% t_internet_host(Host),
|
||||||
|
% i_atom(User) *
|
||||||
|
% i_atom(Password) *
|
||||||
|
% i_positive_or_zero_integer(Port) *
|
||||||
|
% i_atom(Db) *
|
||||||
|
% i_atom(Socket)
|
||||||
|
|
||||||
|
( c^c_db_odbc_connect(ODBCEntry,User,Password,Handle) ==
|
||||||
|
(Protocol = odbc)*
|
||||||
|
-(Protocol = mysql) *
|
||||||
|
-(Protocol = sqlite3)*
|
||||||
|
-(Protocol = postgres) ),
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
( c^c_postgres_connect(Host/Db/Port/Socket,User,Password, Handle) ==
|
||||||
|
-(Protocol = odbc)*
|
||||||
|
-(Protocol = mysql) *
|
||||||
|
-(Protocol = sqlite3)*
|
||||||
|
(Protocol = posgrtgres) ),
|
||||||
|
|
||||||
|
% t_internet_host(Host)*
|
||||||
|
% i_atom(User) *
|
||||||
|
% i_atom(Password) *
|
||||||
|
% i_positive_or_zero_integer(Port) *
|
||||||
|
% i_atom(Db) *
|
||||||
|
% i_atom(Socket) *
|
||||||
|
|
||||||
|
% 0 is default port and Var to be NULL, the default socket
|
||||||
|
(c^c_sqlite3_connect(File,User,Password,Handle)
|
||||||
|
==
|
||||||
|
-(Protocol = odbc)*
|
||||||
|
-(Protocol = mysql) *
|
||||||
|
(Protocol = sqlite3)*
|
||||||
|
-(Protocol = postgres)).
|
||||||
|
%(Protocol = sqlite3),
|
||||||
|
% t_file( File ) *
|
||||||
|
%
|
||||||
|
% i_atom(User) *
|
||||||
|
% i_atom(Password).
|
||||||
|
/*
|
||||||
|
integer(Handle) ==
|
||||||
|
c^c_db_my_connect(Host,User,Password,Db,Port,Socket,Handle) +
|
||||||
|
c^c_db_odbc_connect(ODBCEntry,User,Password,Handle) +
|
||||||
|
c^c_postgres_connect(Host/Db/Port/Socket,User,Password, Handle) +
|
||||||
|
c^c_sqlite3_connect(File,User,Password,Handle).
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
db_open(Protocol) :- true.
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
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)
|
||||||
|
;ConType == postgres ->
|
||||||
|
c_postgres_disconnect(Con)
|
||||||
|
;ConType == sqlite3 ->
|
||||||
|
c_sqlite3_disconnect(Con)
|
||||||
|
;
|
||||||
|
c_db_odbc_disconnect(Con)
|
||||||
|
),
|
||||||
|
set_value(Connection,[]). % "deletes" atom
|
||||||
|
|
||||||
#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
|
|
||||||
#ifdef MYDDAS_SQLITE3
|
|
||||||
db_open(sqlite3,Connection,File,User,Password) :-
|
|
||||||
'$error_checks'(db_open(odbc,Connection,File,User,Password)),
|
|
||||||
c_sqlite3_connect(File,User,Password,Con),
|
|
||||||
set_value(Connection,Con).
|
|
||||||
#endif
|
#endif
|
||||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
|
|
||||||
|
|
|
@ -114,7 +114,19 @@
|
||||||
nonvar(Password),
|
nonvar(Password),
|
||||||
atom(Connection),
|
atom(Connection),
|
||||||
get_value(Connection,[]). % Nao pode ter nenhum valor atribuido
|
get_value(Connection,[]). % Nao pode ter nenhum valor atribuido
|
||||||
'$error_checks'(db_open(sqlit3,Connection,File,_User,_Password)) :- !,
|
'$error_checks'(db_open(postgres,Connection,_Host/_Db/_Port/_,_User,_Password)) :- !,
|
||||||
|
atom(Connection),
|
||||||
|
get_value(Connection,[]). % Nao pode ter nenhum valor atribuido
|
||||||
|
'$error_checks'(db_open(postgres,Connection,_Host/_Db/_Port/_,_User)) :- !,
|
||||||
|
atom(Connection),
|
||||||
|
get_value(Connection,[]). % Nao pode ter nenhum valor atribuido
|
||||||
|
'$error_checks'(db_open(postgres,Connection,_Host/_Db/_Port/_)) :- !,
|
||||||
|
atom(Connection),
|
||||||
|
get_value(Connection,[]). % Nao pode ter nenhum valor atribuido
|
||||||
|
'$error_checks'(db_open(postgres,Connection)) :- !,
|
||||||
|
atom(Connection),
|
||||||
|
get_value(Connection,[]). % Nao pode ter nenhum valor atribuido
|
||||||
|
'$error_checks'(db_open(sqlite3,Connection,File,_User,_Password)) :- !,
|
||||||
nonvar(File), % == \+var(ODBCEntry)
|
nonvar(File), % == \+var(ODBCEntry)
|
||||||
atom(Connection),
|
atom(Connection),
|
||||||
get_value(Connection,[]). % Nao pode ter nenhum valor atribuido
|
get_value(Connection,[]). % Nao pode ter nenhum valor atribuido
|
||||||
|
|
Reference in New Issue