postgres
This commit is contained in:
parent
5b19e9546a
commit
65c97e7072
|
@ -149,7 +149,7 @@ c_db_my_connect( USES_REGS1 ) {
|
|||
else
|
||||
{
|
||||
/* 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){
|
||||
#ifdef DEBUG
|
||||
|
|
|
@ -861,54 +861,201 @@ You can see the available SQL Modes at the MySQL homepage at
|
|||
append/3
|
||||
]).
|
||||
|
||||
:- use_module(library(parameters)).
|
||||
|
||||
|
||||
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
% 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
|
||||
#if MYDDAS_DECLARATIONS
|
||||
:- db_open(Protocol) extra_arguments
|
||||
db=Db,
|
||||
port=Port,
|
||||
socket=Socket,
|
||||
user=User,
|
||||
password=Password,
|
||||
% next arguments all refer to the data access point,
|
||||
% so they are all are mutually exclusive
|
||||
data:file=File,
|
||||
data:host=Host/Db,
|
||||
data:host=Host/Db/Port,
|
||||
data:host=Host/Db/Socket,
|
||||
data:odbc=ODBC_DSN
|
||||
|
||||
#ifdef MYDDAS_POSTGRES
|
||||
db_open(postgres,Connection,Host/Db/Port/Socket,User,Password) :- !,
|
||||
'$error_checks'(db_open(postgres,Connection,Host/Db/Port/Socket,User,Password)),
|
||||
c_db_my_connect(Host,User,Password,Db,Port,Socket,Con),
|
||||
set_value(Connection,Con).
|
||||
db_open(postgres,Connection,Host/Db/Port,User,Password) :-
|
||||
integer(Port),!,
|
||||
db_open(postgres,Connection,Host/Db/Port/_,User,Password). % Var to be NULL, the default socket
|
||||
db_open(postgres,Connection,Host/Db/Socket,User,Password) :- !,
|
||||
db_open(postgres,Connection,Host/Db/0/Socket,User,Password). % 0 is default port
|
||||
db_open(postgres,Connection,Host/Db,User,Password) :-
|
||||
db_open(postgres,Connection,Host/Db/0/_,User,Password). % 0 is default port and Var to be NULL, the default socket
|
||||
#endif
|
||||
/* specify conditions */
|
||||
such_that
|
||||
|
||||
/** implicit, types are conditioned on start
|
||||
|
||||
atom(Db),
|
||||
positive_or_zero_integer(Port),
|
||||
atom(Socket),
|
||||
atom(User),
|
||||
atom(Password),
|
||||
file(File),
|
||||
atom(ODBC_DSN),
|
||||
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
|
||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
|
|
|
@ -114,7 +114,19 @@
|
|||
nonvar(Password),
|
||||
atom(Connection),
|
||||
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)
|
||||
atom(Connection),
|
||||
get_value(Connection,[]). % Nao pode ter nenhum valor atribuido
|
||||
|
|
Reference in New Issue