From ff7a6ed777714ee0c9ca195a55bb1ab5c0854b68 Mon Sep 17 00:00:00 2001 From: Gord Thompson Date: Sat, 21 Dec 2019 10:57:56 -0700 Subject: [PATCH] Add emoticon-as-literal tests for PostgreSQL. (#637) --- tests2/pgtests.py | 17 +++++++++++++++-- tests3/pgtests.py | 17 +++++++++++++++-- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/tests2/pgtests.py b/tests2/pgtests.py index 8b320e14..e58d1179 100755 --- a/tests2/pgtests.py +++ b/tests2/pgtests.py @@ -16,6 +16,7 @@ [pgtests] connection-string=DSN=PostgreSQL35W +Note: Be sure to use the "Unicode" (not the "ANSI") version of the PostgreSQL ODBC driver. """ import sys, os, re @@ -496,7 +497,7 @@ def test_int_limits(self): v = self.cursor.execute("select a from t1").fetchone()[0] self.assertEqual(v, value) - def test_emoticons(self): + def test_emoticons_as_parameter(self): # https://github.com/mkleehammer/pyodbc/issues/423 # # When sending a varchar parameter, pyodbc is supposed to set ColumnSize to the number @@ -506,13 +507,25 @@ def test_emoticons(self): v = "x \U0001F31C z" - self.cursor.execute("create table t1(s varchar(100))") + self.cursor.execute("CREATE TABLE t1(s varchar(100))") self.cursor.execute("insert into t1 values (?)", v) result = self.cursor.execute("select s from t1").fetchone()[0] self.assertEqual(result, v) + def test_emoticons_as_literal(self): + # https://github.com/mkleehammer/pyodbc/issues/630 + + v = "x \U0001F31C z" + + self.cursor.execute("CREATE TABLE t1(s varchar(100))") + self.cursor.execute("insert into t1 values ('%s')" % v) + + result = self.cursor.execute("select s from t1").fetchone()[0] + + self.assertEqual(result, v) + def main(): from optparse import OptionParser diff --git a/tests3/pgtests.py b/tests3/pgtests.py index 98aeba6c..b64ca3a4 100755 --- a/tests3/pgtests.py +++ b/tests3/pgtests.py @@ -16,6 +16,7 @@ [pgtests] connection-string=DSN=PostgreSQL35W +Note: Be sure to use the "Unicode" (not the "ANSI") version of the PostgreSQL ODBC driver. """ import uuid @@ -593,7 +594,7 @@ def test_cancel(self): self.cursor.execute("select 1") self.cursor.cancel() - def test_emoticons(self): + def test_emoticons_as_parameter(self): # https://github.com/mkleehammer/pyodbc/issues/423 # # When sending a varchar parameter, pyodbc is supposed to set ColumnSize to the number @@ -603,12 +604,24 @@ def test_emoticons(self): v = "x \U0001F31C z" - self.cursor.execute("create table t1(s varchar(100))") + self.cursor.execute("CREATE TABLE t1(s varchar(100))") self.cursor.execute("insert into t1 values (?)", v) result = self.cursor.execute("select s from t1").fetchone()[0] self.assertEqual(result, v) + + def test_emoticons_as_literal(self): + # https://github.com/mkleehammer/pyodbc/issues/630 + + v = "x \U0001F31C z" + + self.cursor.execute("CREATE TABLE t1(s varchar(100))") + self.cursor.execute("insert into t1 values ('%s')" % v) + + result = self.cursor.execute("select s from t1").fetchone()[0] + + self.assertEqual(result, v) def test_output_conversion(self): # Note the use of SQL_WVARCHAR, not SQL_VARCHAR.