mirror of
https://github.com/psycopg/psycopg2.git
synced 2025-01-31 09:24:07 +03:00
Applied COPY patch from Alejandro Dubrovsky (missing files and project)
This commit is contained in:
parent
c1d6073531
commit
4e359f6f05
43
psycopg/utils.c
Normal file
43
psycopg/utils.c
Normal file
|
@ -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;
|
||||
}
|
16
psycopg/utils.h
Normal file
16
psycopg/utils.h
Normal file
|
@ -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) */
|
||||
|
||||
|
|
@ -134,6 +134,8 @@
|
|||
<File name="tests/Makefile" subtype="Code" buildaction="Nothing" />
|
||||
<File name="tests/runtests.py" subtype="Code" buildaction="Nothing" />
|
||||
<File name="tests/types_extras.py" subtype="Code" buildaction="Nothing" />
|
||||
<File name="psycopg/utils.c" subtype="Code" buildaction="Compile" />
|
||||
<File name="psycopg/utils.h" subtype="Code" buildaction="Nothing" />
|
||||
</Contents>
|
||||
<compiler ctype="GccCompiler" />
|
||||
<MonoDevelop.ChangeLogAddIn.ChangeLogInfo policy="UpdateNearestChangeLog" />
|
||||
|
|
Loading…
Reference in New Issue
Block a user