Main Page   Modules   Alphabetical List   Data Structures   File List   Data Fields   Globals   Related Pages  

db_conn.c

Go to the documentation of this file.
00001 
00005 /* GtkSQL -- an interactive graphical query tool for PostgreSQL and MySQL. 
00006  * Copyright (C) 1998-2003  Lionel ULMER, Darryl Luff
00007  * MySQL "driver" (C) 1998 Des Herriott (des@ops.netcom.net.uk)
00008  *
00009  * This program is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  * GNU General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU General Public License
00020  * along with this program; if not, write to the Free Software
00021  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00022  */
00023 
00024 #include "../config.h"
00025 
00026 #include <stdlib.h>
00027 #include <string.h>
00028 
00029 #include "db_conn.h"
00030 
00035 void add_keyword(DBConnection * conn, char *key, int type)
00036 {
00037     Keyword *cur, *prev = NULL, *now = conn->keylist;
00038 
00039     cur = (Keyword *) malloc(sizeof(Keyword));
00040     cur->key = strdup(key);
00041     cur->type = type;
00042 
00043     while (now != NULL) {
00044         int cmp = strcasecmp(cur->key, now->key);
00045 
00046         if (cmp < 0) {
00047             cur->next = now;
00048             if (prev != NULL)
00049                 prev->next = cur;
00050             else
00051                 conn->keylist = cur;
00052             break;
00053         }
00054         else if (cmp == 0) {
00055             if (cur->type < now->type) {
00056                 cur->next = now;
00057                 if (prev != NULL)
00058                     prev->next = cur;
00059                 else
00060                     conn->keylist = cur;
00061                 break;
00062             }
00063             else if (cur->type == now->type) {
00064                 break;
00065             }
00066         }
00067         prev = now;
00068         now = now->next;
00069     }
00070     if (now == NULL) {
00071         cur->next = NULL;
00072         if (prev != NULL)
00073             prev->next = cur;
00074         else
00075             conn->keylist = cur;
00076     }
00077 }
00078 
00083 DBConnector *dbconnector_find(char *key) {
00084     int i = 1;
00085     DBConnector *dbc;
00086     dbc = connectorTable[i];
00087     while (dbc != NULL) {
00088         if (strcasecmp(dbc->dbtype, key) == 0)
00089             return dbc;
00090 
00091         i++;
00092         dbc = connectorTable[i];
00093     }
00094     return NULL;
00095 }
00096 
00099 void keywords_remove_all(DBConnection * conn)
00100 {
00101     Keyword *next, *cur = conn->keylist;
00102 
00103     while (cur != NULL) {
00104         next = cur->next;
00105 
00106         free(cur->key);
00107         free(cur);
00108 
00109         cur = next;
00110     }
00111 }
00112 
00116 void keywords_remove(DBConnection * conn, int type)
00117 {
00118     Keyword *prev = NULL, *cur = conn->keylist, *next;
00119 
00120     while (cur != NULL) {
00121         next = cur->next;
00122 
00123         if (cur->type == type) {
00124             if (prev == NULL)
00125                 conn->keylist = cur->next;
00126             else
00127                 prev->next = cur->next;
00128             free(cur->key);
00129             free(cur);
00130         }
00131         else {
00132             prev = cur;
00133         }
00134         cur = next;
00135     }
00136 }

Generated on Sun May 9 19:19:16 2004 for GtkSQL by doxygen1.2.18