From 4e359f6f0542a7baee86408521ef6d6c5ca64baf Mon Sep 17 00:00:00 2001 From: Federico Di Gregorio Date: Tue, 25 Nov 2008 17:46:15 +0100 Subject: [PATCH] Applied COPY patch from Alejandro Dubrovsky (missing files and project) --- psycopg/utils.c | 43 +++++++++++++++++++++++++++++++++++++++++++ psycopg/utils.h | 16 ++++++++++++++++ psycopg2.mdp | 2 ++ 3 files changed, 61 insertions(+) create mode 100644 psycopg/utils.c create mode 100644 psycopg/utils.h diff --git a/psycopg/utils.c b/psycopg/utils.c new file mode 100644 index 00000000..981a4b45 --- /dev/null +++ b/psycopg/utils.c @@ -0,0 +1,43 @@ +/* utils.c - miscellaneous utility functions + * + */ + +#include "psycopg/config.h" +#include "psycopg/utils.h" +#include "psycopg/psycopg.h" +#include "psycopg/connection.h" +#include "psycopg/pgtypes.h" +#include "psycopg/pgversion.h" +#include +#include + +char *psycopg_internal_escape_string(connectionObject *conn, const char *string) +{ + char *buffer; + size_t string_length; + int equote; /* buffer offset if E'' quotes are needed */ + + string_length = strlen(string); + + buffer = (char *) malloc((string_length * 2 + 4) * sizeof(char)); + if (buffer == NULL) { + return NULL; + } + + equote = (conn && (conn->equote)) ? 1 : 0; + + { + size_t qstring_length; + + qstring_length = qstring_escape(buffer + equote + 1, string, string_length, + (conn ? conn->pgconn : NULL)); + + if (equote) + buffer[0] = 'E'; + buffer[equote] = '\''; + buffer[qstring_length + equote + 1] = '\''; + buffer[qstring_length + equote + 2] = 0; + } + + return buffer; +} diff --git a/psycopg/utils.h b/psycopg/utils.h new file mode 100644 index 00000000..43d8217e --- /dev/null +++ b/psycopg/utils.h @@ -0,0 +1,16 @@ +/* utils.h - miscellaneous utility functions + * + */ + +#ifndef PSYCOPG_UTILS_H +#define PSYCOPG_UTILS_H 1 + +#include "psycopg/config.h" +#include "psycopg/connection.h" + + +HIDDEN char *psycopg_internal_escape_string(connectionObject *conn, const char *string); + +#endif /* !defined(PSYCOPG_UTILS_H) */ + + diff --git a/psycopg2.mdp b/psycopg2.mdp index e2f2f6ce..3d70c6be 100644 --- a/psycopg2.mdp +++ b/psycopg2.mdp @@ -134,6 +134,8 @@ + +