00001 00013 /* GtkSQL -- an interactive graphical query tool for PostgreSQL 00014 * Copyright (C) 1998-2003 Lionel ULMER, Darryl Luff 00015 * 00016 * This program is free software; you can redistribute it and/or modify 00017 * it under the terms of the GNU General Public License as published by 00018 * the Free Software Foundation; either version 2 of the License, or 00019 * (at your option) any later version. 00020 * 00021 * This program is distributed in the hope that it will be useful, 00022 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00023 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00024 * GNU General Public License for more details. 00025 * 00026 * You should have received a copy of the GNU General Public License 00027 * along with this program; if not, write to the Free Software 00028 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00029 */ 00030 00031 #include "../config.h" 00032 00033 #include "dbapi.h" 00034 #include "dburl.h" 00035 #include "guiapi.h" 00036 00037 DBConnector **connectorTable; 00038 00042 DBConnection *db_connect_url(char *url) { 00043 DBConnection *conn = NULL; 00044 DBConnector *dbc; 00045 Form *frm; 00046 int return_status; 00047 00048 /* Get a connector for this URL */ 00049 dbc = dburl_get_connector(url); 00050 if (dbc == NULL) { 00051 printf("Could not find a connector for the URL \"%s\"\n", url); 00052 return 0; 00053 } 00054 00055 /* Set the login parameters */ 00056 frm = dbc->db_frm; 00057 dbc->url_to_form(frm, url); 00058 00059 /* Now, connect with it */ 00060 return_status = dbc->db_connect_callback(dbc, &conn); 00061 if (conn != NULL) 00062 conn->connectionStatus = return_status; 00063 return conn; 00064 } 00065 00068 DBConnector *dbconnector_new(void) 00069 { 00070 return (DBConnector *) calloc(1, sizeof(DBConnector)); 00071 } 00072 00076 DBConnection *db_connect(DBConnector *dbc) { 00077 DBConnection *conn = NULL; 00078 int return_status = dbc->db_connect_callback(dbc, &conn); 00079 if (conn != NULL) 00080 conn->connectionStatus = return_status; 00081 00082 return conn; 00083 } 00084 00091 void db_disconnect(DBConnection *conn, void(*display_error) (char *, char *)) { 00092 if (conn == NULL) { 00093 if (display_error != NULL) 00094 display_error("Internal error", 00095 "Internal error : trying to disconnect " 00096 "with no current connection"); 00097 return; 00098 } 00099 conn->DBdisconnect(conn); 00100 }