summaryrefslogtreecommitdiff
path: root/psycopg/utils.c
diff options
context:
space:
mode:
authorFederico Di Gregorio <fog@initd.org>2008-11-25 17:46:15 +0100
committerFederico Di Gregorio <fog@initd.org>2008-11-25 17:46:15 +0100
commit4e359f6f0542a7baee86408521ef6d6c5ca64baf (patch)
tree86bef788f5793d3597f1f5fbc90875fd2bc2183c /psycopg/utils.c
parentc1d6073531c2d164d2e7d2c8c49278c2987b98fe (diff)
downloadpsycopg2-4e359f6f0542a7baee86408521ef6d6c5ca64baf.tar.gz
Applied COPY patch from Alejandro Dubrovsky (missing files and project)
Diffstat (limited to 'psycopg/utils.c')
-rw-r--r--psycopg/utils.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/psycopg/utils.c b/psycopg/utils.c
new file mode 100644
index 0000000..981a4b4
--- /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 <string.h>
+#include <stdlib.h>
+
+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;
+}