MYDDAS: db_open/5 support to user specify the TCP/IP port and/or Unix Socket of the MySQL Server to connect to.

git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@1566 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
tiagosoares 2006-03-17 10:41:44 +00:00
parent 32a73796ee
commit cbc94bbaf7
3 changed files with 26 additions and 9 deletions

View File

@ -60,7 +60,7 @@ STATIC_PROTO(Int c_db_my_change_database,(void));
void Yap_InitMYDDAS_MySQLPreds(void)
{
/* db_connect: Host x User x Passwd x Database x Connection x ERROR_CODE */
Yap_InitCPred("c_db_my_connect", 5, c_db_my_connect, 0);
Yap_InitCPred("c_db_my_connect", 7, c_db_my_connect, 0);
/* db_number_of_fields: Relation x Connection x NumberOfFields */
Yap_InitCPred("c_db_my_number_of_fields",3, c_db_my_number_of_fields, 0);
@ -111,7 +111,9 @@ c_db_my_connect(void) {
Term arg_user = Deref(ARG2);
Term arg_passwd = Deref(ARG3);
Term arg_database = Deref(ARG4);
Term arg_conn = Deref(ARG5);
Term arg_port = Deref(ARG5);
Term arg_socket = Deref(ARG6);
Term arg_conn = Deref(ARG7);
MYSQL *conn;
@ -121,15 +123,21 @@ c_db_my_connect(void) {
char *user = AtomName(AtomOfTerm(arg_user));
char *passwd = AtomName(AtomOfTerm(arg_passwd));
char *database = AtomName(AtomOfTerm(arg_database));
Int port = IntegerOfTerm(arg_port);
char *socket;
if (IsNonVarTerm(arg_socket))
socket = AtomName(AtomOfTerm(arg_socket));
else
socket = NULL;
conn = mysql_init(NULL);
if (conn == NULL) {
printf("erro no init\n");
return FALSE;
}
if (mysql_real_connect(conn, host, user, passwd, database,0, NULL, CLIENT_MULTI_STATEMENTS) == NULL) {
if (mysql_real_connect(conn, host, user, passwd, database, port, socket, CLIENT_MULTI_STATEMENTS) == NULL) {
printf("erro no connect\n");
return FALSE;
}

View File

@ -166,10 +166,18 @@
%
db_open(Interface,HostDb,User,Password):-
db_open(Interface,myddas,HostDb,User,Password).
db_open(mysql,Connection,Host/Db,User,Password) :-
'$error_checks'(db_open(mysql,Connection,Host/Db,User,Password)),
c_db_my_connect(Host,User,Password,Db,Con),
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
db_open(odbc,Connection,ODBCEntry,User,Password) :-
'$error_checks'(db_open(odbc,Connection,ODBCEntry,User,Password)),

View File

@ -92,11 +92,12 @@
c_db_odbc_get_fields_properties(Relation,Con,FieldsProperties)
),
'$check_fields'(Att,FieldsProperties).
'$error_checks'(db_open(mysql,Connection,Host/Db,User,Password)) :- !,
'$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)) :- !,