mirror of
https://github.com/psycopg/psycopg2.git
synced 2025-08-03 11:50:08 +03:00
Merge cb6b6d0e68
into 4458c9b4c9
This commit is contained in:
commit
d0d28313a9
40
sandbox/pqcrazyness/escaping.c
Normal file
40
sandbox/pqcrazyness/escaping.c
Normal file
|
@ -0,0 +1,40 @@
|
|||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <libpq-fe.h>
|
||||
|
||||
/* Compile me with:
|
||||
*
|
||||
* gcc -p escaping -I$(pg_config --includedir) escaping.c -lpq"
|
||||
*
|
||||
* then:
|
||||
*
|
||||
* ./escaping dbname=test foo\\\\bar
|
||||
*/
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
PGconn* conn;
|
||||
int rl, len;
|
||||
char* result;
|
||||
|
||||
if (argc != 3) {
|
||||
fprintf(stderr, "Usage: %s [dsn] [string]\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
len = strlen(argv[1]);
|
||||
result = malloc(len * 2 * sizeof(char));
|
||||
|
||||
rl = PQescapeString(result, argv[2], len);
|
||||
result[rl] = '\0';
|
||||
printf("%s\n", result);
|
||||
|
||||
conn = PQconnectdb(argv[1]);
|
||||
|
||||
rl = PQescapeString(result, argv[2], len);
|
||||
result[rl] = '\0';
|
||||
printf("%s\n", result);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
14
setup.py
14
setup.py
|
@ -235,10 +235,12 @@ class psycopg_build_ext(build_ext):
|
|||
"Compile with OpenSSL built PostgreSQL libraries (Windows only)."),
|
||||
('static-libpq', None,
|
||||
"Statically link the PostgreSQL client library"),
|
||||
('use-rpath', None,
|
||||
"Set -rpath to the runtime location of libpq as given by pg_config")
|
||||
])
|
||||
|
||||
boolean_options = build_ext.boolean_options[:]
|
||||
boolean_options.extend(('use-pydatetime', 'have-ssl', 'static-libpq'))
|
||||
boolean_options.extend(('use-pydatetime', 'have-ssl', 'static-libpq', 'use-rpath'))
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
build_ext.__init__(self, *args, **kwargs)
|
||||
|
@ -252,6 +254,7 @@ class psycopg_build_ext(build_ext):
|
|||
self.have_ssl = have_ssl
|
||||
self.static_libpq = static_libpq
|
||||
self.pg_config = None
|
||||
self.use_rpath = 0
|
||||
|
||||
def compiler_is_msvc(self):
|
||||
return self.get_compiler_name().lower().startswith('msvc')
|
||||
|
@ -391,6 +394,8 @@ class psycopg_build_ext(build_ext):
|
|||
os.path.join(pg_config_helper.query("libdir"), "libpq.a"))
|
||||
else:
|
||||
self.libraries.append("pq")
|
||||
if self.use_rpath:
|
||||
self.rpath = [pg_config_helper.query("libdir")]
|
||||
|
||||
try:
|
||||
self.library_dirs.append(pg_config_helper.query("libdir"))
|
||||
|
@ -445,6 +450,13 @@ class psycopg_build_ext(build_ext):
|
|||
if hasattr(self, "finalize_" + sys.platform):
|
||||
getattr(self, "finalize_" + sys.platform)()
|
||||
|
||||
def build_extension(self, ext):
|
||||
# HACK: runtime library dirs are correctly fixed by ccompiler only
|
||||
# if ext.runtime_library_dirs is None, but the build_ext sets it
|
||||
# to null.
|
||||
ext.runtime_library_dirs = None
|
||||
build_ext.build_extension(self, ext)
|
||||
|
||||
def is_py_64():
|
||||
# sys.maxint not available since Py 3.1;
|
||||
# sys.maxsize not available before Py 2.6;
|
||||
|
|
Loading…
Reference in New Issue
Block a user