Changeset: 49729eb8f31f for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=49729eb8f31f Modified Files: clients/ChangeLog clients/src/mapilib/Mapi.mx Branch: default Log Message:
mapi: add mapi_get_uri() function Construct a mapi URI upon initialisation of the Mapi handle, and return it using mapi_get_uri(). diffs (122 lines): diff -r f84d11a7df55 -r 49729eb8f31f clients/ChangeLog --- a/clients/ChangeLog Wed Dec 29 09:15:46 2010 +0100 +++ b/clients/ChangeLog Tue Jan 04 11:16:31 2011 +0100 @@ -1,6 +1,9 @@ # ChangeLog file for clients # This file is updated with Maddlog +* Tue Jan 4 2011 Fabian Groffen <[email protected]> +- Added mapi_get_uri function to retrieve mapi URI for the connection + * Fri Dec 10 2010 Fabian Groffen <[email protected]> - Allow to dump table data using INSERT INTO statements, rather than COPY INTO + CSV data using the -N/--inserts flag of mclient and msqldump. diff -r f84d11a7df55 -r 49729eb8f31f clients/src/mapilib/Mapi.mx --- a/clients/src/mapilib/Mapi.mx Wed Dec 29 09:15:46 2010 +0100 +++ b/clients/src/mapilib/Mapi.mx Tue Jan 04 11:16:31 2011 +0100 @@ -1012,6 +1012,7 @@ char *password; char *language; char *database; /* to obtain from server */ + char *uri; int languageId; int versionId; /* Monet 4 or 5 */ char *motd; /* welcome message from server */ @@ -1264,6 +1265,7 @@ mapi_export char *mapi_fetch_line(MapiHdl hdl); mapi_export int mapi_split_line(MapiHdl hdl); mapi_export char *mapi_get_lang(Mapi mid); +mapi_export char *mapi_get_uri(Mapi mid); mapi_export char *mapi_get_dbname(Mapi mid); mapi_export char *mapi_get_host(Mapi mid); mapi_export char *mapi_get_user(Mapi mid); @@ -1303,6 +1305,7 @@ static int mapi_slice_row(struct MapiResultSet *result, int cr); static void mapi_store_bind(struct MapiResultSet *result, int cr); static void parse_uri_query(Mapi mid, char *uri); +static void set_uri(Mapi mid); static int mapi_initialized = 0; @@ -2166,6 +2169,8 @@ if (mid->database == NULL && dbname != NULL) mid->database = strdup(dbname); + set_uri(mid); + return mid; } @@ -2232,6 +2237,8 @@ free(mid->database); mid->database = dbname ? strdup(dbname) : NULL; + set_uri(mid); + return mid; } @@ -2265,6 +2272,8 @@ free(mid->database); if (mid->server) free(mid->server); + if (mid->uri) + free(mid->uri); r = mid->redirects; while (*r) { @@ -2320,6 +2329,41 @@ } while (uri != NULL); } +/* construct the uri field of a Mapi struct */ +static void +set_uri(Mapi mid) +{ + char uri[1024]; + + /* uri looks as follows: + * mapi:monetdb://host:port/database + * or + * mapi:monetdb:///some/path/to?database=database + */ + + if (mid->database != NULL) { + if (mid->hostname[0] == '/') { + snprintf(uri, sizeof(uri), "mapi:monetdb://%s?database=%s", + mid->hostname, mid->database); + } else { + snprintf(uri, sizeof(uri), "mapi:monetdb://%s:%d/%s", + mid->hostname, mid->port, mid->database); + } + } else { + if (mid->hostname[0] == '/') { + snprintf(uri, sizeof(uri), "mapi:monetdb://%s", + mid->hostname); + } else { + snprintf(uri, sizeof(uri), "mapi:monetdb://%s:%d", + mid->hostname, mid->port); + } + } + + if (mid->uri != NULL) + free(mid->uri); + mid->uri = strdup(uri); +} + @- Channel Constructor The first call of an application is to establish a connection with an already server. The username and password are sent as part of @@ -5483,6 +5527,12 @@ } char * +mapi_get_uri(Mapi mid) +{ + return mid->uri; +} + +char * mapi_get_mapi_version(Mapi mid) { return mid->mapiversion; _______________________________________________ Checkin-list mailing list [email protected] http://mail.monetdb.org/mailman/listinfo/checkin-list
