]> jfr.im git - irc/quakenet/newserv.git/commitdiff
attempt 2
authorPaul <redacted>
Sun, 1 Jul 2007 18:09:07 +0000 (18:09 +0000)
committerPaul <redacted>
Sun, 1 Jul 2007 18:09:07 +0000 (18:09 +0000)
pqsql/pqsql.c
pqsql/pqsql.h

index afba1e1c68c4f946fe4a95f76d33c3f639641f4a..e15cd1b7a491f011fb19e1a9e98af83610931997 100644 (file)
@@ -321,18 +321,16 @@ int pqconnected(void) {
   return dbconnected;
 }
 
-char* pqlasterror(PGconn * pgconn)
-{
-  static char errormsg[PQ_ERRORMSG_LENGTH];
+char* pqlasterror(PGconn * pgconn) {
+  static char errormsg[PQ_ERRORMSG_LENGTH + 1];
   int i;
-  char *error = PQerrorMessage(pgconn);
-  int len = min(sizeof(errormsg),strlen(error));
-  strncpy(errormsg, error, len - 1);
-  errormsg[len - 1] = '\0';
-  for(i=0;i<len-1;i++) {
-    if ((errormsg[i] == '\r') || (errormsg[i] == '\n')) {
+  if(!pgconn) 
+    return "PGCONN NULL";
+  strlcpy(errormsg, PQerrorMessage(pgconn), PQ_ERRORMSG_LENGTH);
+  for(i=0;i<errormsg[i];i++) {
+    if((errormsg[i] == '\r') || (errormsg[i] == '\n'))
       errormsg[i] = ' ';
-    }
+    
   }
   return errormsg;
 }
index 57cdefa7c4628933b8d5721be6eaae8e4624cba4..8eb2608f6eb042c925178e92e3e1ac1510a880d6 100644 (file)
@@ -14,7 +14,6 @@ void pqloadtable(char *tablename, PQQueryHandler init, PQQueryHandler data, PQQu
 #define pqasyncquery(handler, tag, format, ...) pqasyncqueryf(handler, tag, 0, format , ##__VA_ARGS__)
 #define pqcreatequery(format, ...) pqasyncqueryf(NULL, NULL, QH_CREATE, format , ##__VA_ARGS__)
 #define pqquery(format, ...) pqasyncqueryf(NULL, NULL, 0, format , ##__VA_ARGS__)
-#define min(a,b) ((a > b) ? b : a)
 
 int pqconnected(void);
 char* pqlasterror(PGconn * pgconn);