Skip to content

Commit

Permalink
Rename util.escape_string to util.quote_string and use it also in con…
Browse files Browse the repository at this point in the history
…nection.py
  • Loading branch information
mvantellingen committed Oct 15, 2011
1 parent 6eb4b73 commit ae707c4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
9 changes: 2 additions & 7 deletions psycopg2ct/_impl/connection.py
Expand Up @@ -190,9 +190,7 @@ def _get_guc(self, name):
def _set_guc(self, name, value):
"""Set the value of a configuration parameter."""
if value.lower() != 'default':
# TODO: use the string adapter here
value = "'%s'" % value;

value = util.quote_string(self, value)
self._execute_command('SET %s TO %s' % (name, value))

def _set_guc_onoff(self, name, value):
Expand Down Expand Up @@ -591,10 +589,7 @@ def _execute_command(self, command):
libpq.PQclear(pgres)

def _execute_tpc_command(self, command, xid):
from psycopg2ct.extensions import QuotedString
tid = QuotedString(str(xid))
tid.prepare(self)
cmd = '%s %s' % (command, tid)
cmd = '%s %s' % (command, util.quote_string(self, str(xid)))
self._execute_command(cmd)
self._mark += 1

Expand Down
10 changes: 5 additions & 5 deletions psycopg2ct/_impl/cursor.py
Expand Up @@ -569,9 +569,9 @@ def copy_from(self, file, table, sep='\t', null='\N', size=8192,
columns_str = ''

query = "COPY %s%s FROM stdin WITH DELIMITER AS %s" % (
table, columns_str, util.escape_string(self._connection, sep))
table, columns_str, util.quote_string(self._connection, sep))
if null:
query += " NULL AS %s" % util.escape_string(self._connection, null)
query += " NULL AS %s" % util.quote_string(self._connection, null)

self._copysize = size
self._copyfile = file
Expand All @@ -596,9 +596,9 @@ def copy_to(self, file, table, sep='\t', null='\N', columns=None):
columns_str = ''

query = "COPY %s%s TO stdout WITH DELIMITER AS %s" % (
table, columns_str, util.escape_string(self._connection, sep))
table, columns_str, util.quote_string(self._connection, sep))
if null:
query += " NULL AS %s" % util.escape_string(self._connection, null)
query += " NULL AS %s" % util.quote_string(self._connection, null)

self._copyfile = file
self._pq_execute(query)
Expand All @@ -609,7 +609,7 @@ def copy_to(self, file, table, sep='\t', null='\N', columns=None):
def copy_expert(self, sql, file, size=8196):
if not sql:
return

if not hasattr(file, 'read') and not hasattr(file, 'write'):
raise TypeError("file must be a readable file-like object for"
" COPY FROM; a writeable file-like object for COPY TO.")
Expand Down
4 changes: 2 additions & 2 deletions psycopg2ct/_impl/util.py
@@ -1,5 +1,6 @@
from psycopg2ct._impl import exceptions
from psycopg2ct._impl import libpq
from psycopg2ct._impl.adapters import QuotedString


def pq_set_non_blocking(pgconn, arg, raise_exception=False):
Expand Down Expand Up @@ -31,8 +32,7 @@ def pq_get_last_result(pgconn):
return pgres


def escape_string(conn, value):
from psycopg2ct.extensions import QuotedString
def quote_string(conn, value):
obj = QuotedString(value)
obj.prepare(conn)
return obj.getquoted()
Expand Down

0 comments on commit ae707c4

Please sign in to comment.