diff options
author | Bruce Momjian <bruce@momjian.us> | 1997-11-10 05:10:50 +0000 |
---|---|---|
committer | Bruce Momjian <bruce@momjian.us> | 1997-11-10 05:10:50 +0000 |
commit | baeb8790ac976c12abba26766aba25344d29888d (patch) | |
tree | 9605bb2b47a297b52843837fc17ee596a0beaa94 /src/interfaces | |
parent | 0f367cf8c8c07eefc8f9957d4c5328f0d26e9720 (diff) | |
download | postgresql-baeb8790ac976c12abba26766aba25344d29888d.tar.gz postgresql-baeb8790ac976c12abba26766aba25344d29888d.zip |
Fix case issues with quotes.
Diffstat (limited to 'src/interfaces')
-rw-r--r-- | src/interfaces/libpq/fe-connect.c | 65 | ||||
-rw-r--r-- | src/interfaces/libpq/fe-exec.c | 24 |
2 files changed, 60 insertions, 29 deletions
diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c index f5ace69dc07..e1870228281 100644 --- a/src/interfaces/libpq/fe-connect.c +++ b/src/interfaces/libpq/fe-connect.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.43 1997/11/07 20:52:15 momjian Exp $ + * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.44 1997/11/10 05:10:45 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -340,8 +340,9 @@ PQsetdb(const char *pghost, const char *pgport, const char *pgoptions, const cha if (!pghost || pghost[0] == '\0') { - conn->pghost = NULL; - if (tmp = getenv("PGHOST")) conn->pghost = strdup(tmp); + conn->pghost = NULL; + if (tmp = getenv("PGHOST")) + conn->pghost = strdup(tmp); } else conn->pghost = strdup(pghost); @@ -413,14 +414,23 @@ PQsetdb(const char *pghost, const char *pgport, const char *pgoptions, const cha { if (((tmp = (char *) dbName) && (dbName[0] != '\0')) || ((tmp = getenv("PGDATABASE")))) - { conn->dbName = strdup(tmp); - } else conn->dbName = strdup(conn->pguser); - for (i = 0; conn->dbName[i]; i++) - if (isupper(conn->dbName[i])) - conn->dbName[i] = tolower(conn->dbName[i]); + + /* + * if the table name is surrounded by double-quotes, then + * don't convert case + */ + if (*conn->dbName == '"') + { + strcpy(conn->dbName, conn->dbName + 1); + *(conn->dbName + strlen(conn->dbName) - 1) = '\0'; + } + else + for (i = 0; conn->dbName[i]; i++) + if (isupper(conn->dbName[i])) + conn->dbName[i] = tolower(conn->dbName[i]); } else conn->dbName = NULL; @@ -470,7 +480,9 @@ connectDB(PGconn *conn) MsgType msgtype; int laddrlen = sizeof(struct sockaddr); Port *port = conn->port; - int portno, family, len; + int portno, + family, + len; /* * Initialize the startup packet. @@ -498,8 +510,8 @@ connectDB(PGconn *conn) port = (Port *) malloc(sizeof(Port)); MemSet((char *) port, 0, sizeof(Port)); - if (conn->pghost && - (!(hp = gethostbyname(conn->pghost)) || hp->h_addrtype != AF_INET)) + if (conn->pghost && + (!(hp = gethostbyname(conn->pghost)) || hp->h_addrtype != AF_INET)) { (void) sprintf(conn->errorMessage, "connectDB() -- unknown hostname: %s\n", @@ -510,17 +522,17 @@ connectDB(PGconn *conn) portno = atoi(conn->pgport); port->raddr.in.sin_family = family = conn->pghost ? AF_INET : AF_UNIX; if (family == AF_INET) - { - memmove((char *) &(port->raddr.in.sin_addr), - (char *) hp->h_addr, - hp->h_length); - port->raddr.in.sin_port = htons((unsigned short) (portno)); - len = sizeof(struct sockaddr_in); - } + { + memmove((char *) &(port->raddr.in.sin_addr), + (char *) hp->h_addr, + hp->h_length); + port->raddr.in.sin_port = htons((unsigned short) (portno)); + len = sizeof(struct sockaddr_in); + } else - { - len = UNIXSOCK_PATH(port->raddr.un,portno); - } + { + len = UNIXSOCK_PATH(port->raddr.un, portno); + } /* connect to the server */ if ((port->sock = socket(family, SOCK_STREAM, 0)) < 0) { @@ -529,12 +541,12 @@ connectDB(PGconn *conn) errno, strerror(errno)); goto connect_errReturn; } - if (connect(port->sock, (struct sockaddr *) &port->raddr, len) < 0) + if (connect(port->sock, (struct sockaddr *) & port->raddr, len) < 0) { (void) sprintf(conn->errorMessage, - "connectDB() failed: Is the postmaster running at '%s' on port '%s'?\n", - conn->pghost ? conn->pghost : "UNIX Socket", - conn->pgport); + "connectDB() failed: Is the postmaster running at '%s' on port '%s'?\n", + conn->pghost ? conn->pghost : "UNIX Socket", + conn->pgport); goto connect_errReturn; } if (family == AF_INET) @@ -779,7 +791,8 @@ packetSend(Port *port, PacketLen len, bool nonBlocking) { - PacketLen doneLen = write(port->sock, buf, len); + PacketLen doneLen = write(port->sock, buf, len); + if (doneLen < len) { return (STATUS_ERROR); diff --git a/src/interfaces/libpq/fe-exec.c b/src/interfaces/libpq/fe-exec.c index 483644e7457..2f1b55fbd12 100644 --- a/src/interfaces/libpq/fe-exec.c +++ b/src/interfaces/libpq/fe-exec.c @@ -7,7 +7,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.39 1997/11/03 04:21:49 momjian Exp $ + * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.40 1997/11/10 05:10:50 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -17,6 +17,7 @@ #include <signal.h> #include <string.h> #include <errno.h> +#include <ctype.h> #include "postgres.h" #include "libpq/pqcomm.h" #include "libpq/pqsignal.h" @@ -31,12 +32,14 @@ #ifdef TIOCGWINSZ struct winsize screen_size; + #else struct winsize { int ws_row; int ws_col; } screen_size; + #endif /* the rows array in a PGresGroup has to grow to accommodate the rows */ @@ -1674,6 +1677,7 @@ int PQfnumber(PGresult *res, const char *field_name) { int i; + char *field_case; if (!res) { @@ -1686,13 +1690,27 @@ PQfnumber(PGresult *res, const char *field_name) res->attDescs == NULL) return -1; + field_case = strdup(field_name); + if (*field_case == '"') + { + strcpy(field_case, field_case + 1); + *(field_case + strlen(field_case) - 1) = '\0'; + } + else + for (i = 0; field_case; i++) + if (isupper(field_case[i])) + field_case[i] = tolower(field_case[i]); + for (i = 0; i < res->numAttributes; i++) { - if (strcasecmp(field_name, res->attDescs[i].name) == 0) + if (strcmp(field_name, res->attDescs[i].name) == 0) + { + free(field_case); return i; + } } + free(field_case); return -1; - } Oid |